timeUtils

AMD: require(["esri/support/timeUtils"], (timeUtils) => { /* code goes here */ });
ESM: import * as timeUtils from "@arcgis/core/support/timeUtils.js";
Object: esri/support/timeUtils
Since: ArcGIS Maps SDK for JavaScript 4.21

Provides utility methods for working with dates.

Method Overview

Name Return Type Summary Object
Promise<TimeExtent>

Returns the time extent of all layers which are "feature based" time-aware and/or have a "layer based" time-aware with Layer.visibilityTimeExtent set.

timeUtils
Promise<Object>

Extracts time slider settings from a WebMap or WebScene if the document contains a time slider widget definition.

timeUtils
Promise<Object>

Extracts time slider settings from a WebMap if the webmap contains a time slider widget definition.

timeUtils

Method Details

getTimeExtentFromLayers

Method
getTimeExtentFromLayers(layers, signal){Promise<TimeExtent>}

Returns the time extent of all layers which are "feature based" time-aware and/or have a "layer based" time-aware with Layer.visibilityTimeExtent set. If the time extent of the layers is set, the method returns the union of the time extents of all layers. If the time extent of a layer is not set, the method returns TimeExtent with start and end set to null. For FeatureLayer or MapImageLayer with hasLiveData set to true, the method fetches the time extent from the server.

Parameters

An array or collection of layers to compute a time extent from.

signal AbortSignal
optional

AbortSignal allows for cancelable requests. If canceled, the promise will be rejected with an error named AbortError. See also AbortController.

Returns
Type Description
Promise<TimeExtent> Returns a promise that resolves to a TimeExtent.
Examples
// Get the time extent of all layers in the view.
const fullTimeExtent = await getTimeExtentFromLayers(view.map.allLayers);
// Get the time extent from an array of layers.
const timeExtent = await getTimeExtentFromLayers([
  earthquakes,
  emergencyCalls
]);

getTimeSliderSettingsFromWebDocument

Method
getTimeSliderSettingsFromWebDocument(document, signal){Promise<Object>}
Since: ArcGIS Maps SDK for JavaScript 4.30 timeUtils since 4.21, getTimeSliderSettingsFromWebDocument added at 4.30.

Extracts time slider settings from a WebMap or WebScene if the document contains a time slider widget definition. Returns an object with properties that can be used to configure the TimeSlider or TimeSliderViewModel. If a document does not contain a time slider definition then null is returned.

Parameters
document WebMap|WebScene

An instance of a webmap or webscene to extract time slider settings from.

signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task.

Returns
Type Description
Promise<Object> When resolved, returns an object with the following properties.
Property Type Description
fullTimeExtent TimeExtent The temporal extent of the entire slider.
loop Boolean When true, the time slider will play its animation in a loop.
mode "instant" | "time-window" | "cumulative-from-start" | "cumulative-from-end" The time slider mode.
playRate Number The time (in milliseconds) between animation steps.
stops StopsByDates | StopsByCount | StopsByInterval Defines specific locations on the time slider where thumbs will snap to when manipulated.
timeExtent TimeExtent The current time extent of the time slider.
Example
// Import and apply time slider settings stored in a webmap.
const map = new WebMap({
  portalItem: {
    id: "your-webmap-id",
  }
});

timeUtils.getTimeSliderSettingsFromWebDocument(map).then((timeSliderSettings) => {
  const timeSlider = new TimeSlider({
    ...timeSliderSettings,
    view
  });
});

getTimeSliderSettingsFromWebMap

Method
getTimeSliderSettingsFromWebMap(webMap, signal){Promise<Object>}
Since: ArcGIS Maps SDK for JavaScript 4.29 timeUtils since 4.21, getTimeSliderSettingsFromWebMap added at 4.29.
Deprecated since 4.30. Use getTimeSliderSettingsFromWebDocument instead.

Extracts time slider settings from a WebMap if the webmap contains a time slider widget definition. Returns an object with properties that can be used to configure the TimeSlider or TimeSliderViewModel. If a webmap does not contain a time slider definition then null is returned.

Parameters
webMap WebMap

An instance of a webmap to extract time slider settings from.

signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task.

Returns
Type Description
Promise<Object> When resolved, returns an object with the following properties.
Property Type Description
fullTimeExtent TimeExtent The temporal extent of the entire slider.
loop Boolean When true, the time slider will play its animation in a loop.
mode "instant" | "time-window" | "cumulative-from-start" | "cumulative-from-end" The time slider mode.
playRate Number The time (in milliseconds) between animation steps.
stops StopsByDates | StopsByCount | StopsByInterval Defines specific locations on the time slider where thumbs will snap to when manipulated.
timeExtent TimeExtent The current time extent of the time slider.
Example
// Import and apply time slider settings stored in a webmap.
const map = new WebMap({
  portalItem: {
    id: "your-webmap-id",
  }
});

timeUtils.getTimeSliderSettingsFromWebMap(map).then((timeSliderSettings) => {
  const timeSlider = new TimeSlider({
    ...timeSliderSettings,
    view
  });
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.