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.

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.

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
]);

getTimeSliderSettingsFromWebMap

Method
getTimeSliderSettingsFromWebMap(webMap, signal){Promise<object>}
Since: ArcGIS Maps SDK for JavaScript 4.29 timeUtils since 4.21, getTimeSliderSettingsFromWebMap added at 4.29.

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.