require(["esri/widgets/TimeSlider"], function(TimeSlider) { /* code goes here */ });
Class: esri/widgets/TimeSlider
Inheritance: TimeSlider Widget Accessor
Since: ArcGIS API for JavaScript 4.12
beta

The TimeSlider widget simplifies visualization of temporal data in your application. Before adding the TimeSlider to your application, you first should understand how it can be configured to correctly display your temporal data.

The fullTimeExtent property defines the entire time period within which you can visualize your time aware data using the TimeSlider widget. You can visualize temporal data up to a point in time, from a point in time, at an instant of time, or from data that falls within a time range by setting the mode property. The stops property defines specific locations on the TimeSlider where thumbs will snap to when manipulated. You can set this property to be either an array of dates, a number of evenly spaced stops or a specific time interval (e.g. days). The values property defines the current location of the thumbs.

widgets-timeSlider

The TimeSlider widget can be configured to manipulate your time aware data in two different ways as outlined below:

Update the view's timeExtent

The TimeSlider widget can be configured to update the view's timeExtent when the view property is set on the widget. Whenever a TimeSlider's timeExtent is updated, the assigned view's timeExtent will also be updated. All time-aware layers will automatically update to conform to the view's timeExtent.

// Create a TimeSlider for the first decade of the 21st century.
// set the TimeSlider's view property.
// Only show content for the 1st year of the decade for all
// time aware layers in the view.
var timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  view: view,
  // show data within a given time range
  // in this case data within one year
  mode: "time-window",
  fullTimeExtent: { // entire extent of the timeSlider
    start: new Date(2000, 0, 1),
    end: new Date(2010, 0, 1)
  },
  values:[ // location of timeSlider thumbs
    new Date(2000, 0, 1),
    new Date(2001, 1, 1)
  ]
});
view.ui.add(timeSlider, "manual");

Watching the TimeSlider's timeExtent

The TimeSlider widget can also be configured to apply custom logic whenever the TimeSlider is manipulated by watching its timeExtent property. For example, when the TimeSlider's timeExtent is updated, you may want to update the timeExtent property of client-side filters and effects on a FeatureLayerView, CSVLayerView, or GeoJSONLayerView. A FeatureFilter can be used to filter out data that is not included in the current timeExtent, and a FeatureEffect can be used to apply a visual effect to features that are included in or excluded from the current timeExtent. The FeatureEffect can only be used in a 2D MapView.

Warning: Setting both the TimeSlider's view property (explained above) and applying a timeExtent to a client-side effect may result in excluded features not being rendered to the view. This is because excluded features have been filtered out by the view's timeExtent, so the effect will not show.

// Create a time slider to update layerView filter
var timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  mode: "cumulative-from-start",
});
view.ui.add(timeSlider, "manual");

// wait until the layer view is loaded
let timeLayerView;
view.whenLayerView(layer).then(function(layerView) {
  timeLayerView = layerView;
  const fullTimeExtent = layer.timeInfo.fullTimeExtent;
  const start = fullTimeExtent.start;

  // set up time slider properties based on layer timeInfo
  timeSlider.fullTimeExtent = fullTimeExtent;
  timeSlider.values = [start];
  timeSlider.stops = {
    interval: layer.timeInfo.interval
  };
});

timeSlider.watch("timeExtent", function(value){
  // update layer view filter to reflect current timeExtent
  timeLayerView.filter = {
    timeExtent: value
  };
});
For information about gaining full control of widget styles, see the Styling topic.
See also:

Constructors

new TimeSlider(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String|HTMLElement

The ID or node representing the DOM element containing the widget.

more details
more detailsWidget
String

The name of the class.

more details
more detailsAccessor
Boolean

When true, this property indicates whether the widget has been destroyed.

more details
more detailsWidget
Date[]

Lists the specific locations on the timeline where handle(s) will snap to when manipulated.

more details
more detailsTimeSlider
TimeExtent

The temporal extent of the entire slider.

more details
more detailsTimeSlider
String

The widget's default CSS icon class.

more details
more detailsTimeSlider
String

The unique ID assigned to the widget when the widget is created.

more details
more detailsWidget
String

The widget's default label.

more details
more detailsTimeSlider
Boolean

When true, the time slider will play its animation in a loop.

more details
more detailsTimeSlider
String

The time slider mode.

more details
more detailsTimeSlider
Number

The time (in milliseconds) between animation steps.

more details
more detailsTimeSlider
StopsByDates|StopsByCount|StopsByInterval

Defines specific locations on the time slider where thumbs will snap to when manipulated.

more details
more detailsTimeSlider
TimeExtent

The current time extent of the time slider.

more details
more detailsTimeSlider
Boolean

Shows/hides time in the display.

more details
more detailsTimeSlider
Date[]

The user defined time extent.

more details
more detailsTimeSlider
MapView|SceneView

A reference to the MapView or SceneView.

more details
more detailsTimeSlider
TimeSliderViewModel

The view model for this widget.

more details
more detailsTimeSlider

Property Details

The ID or node representing the DOM element containing the widget. This property can only be set once. The following examples are all valid use cases when working with widgets.

Examples:
// Create the HTML div element programmatically at runtime and set to the widget's container
const basemapGallery = new BasemapGallery({
  view: view,
  container: document.createElement("div")
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
// Specify an already-defined HTML div element in the widget's container

const basemapGallery = new BasemapGallery({
  view: view,
  container: basemapGalleryDiv
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

// HTML markup
<body>
  <div id="viewDiv"></div>
  <div id="basemapGalleryDiv"></div>
</body>
// Specify the widget while adding to the view's UI
const basemapGallery = new BasemapGallery({
  view: view
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
declaredClass Stringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

destroyed Boolean inherited

When true, this property indicates whether the widget has been destroyed.

effectiveStops Date[]readonly

Lists the specific locations on the timeline where handle(s) will snap to when manipulated.

Default Value:null
Example:
// Add yearly stops starting from the beginning of 2001.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 5, 1),
    end: new Date(2010, 0, 1)
  },
  stops: {
    interval: {
      value: 1,
      unit: "years"
    },
    timeExtent: {
      start: new Date(2001, 0, 1),
      end: new Date(2010, 0, 1)
   }
  }
});
timeSlider.effectiveStops.forEach((stop) => {
  console.log(stop);
});
fullTimeExtent TimeExtentautocast

The temporal extent of the entire slider. It defines the entire time period within which you can visualize your time aware data using the time slider widget.

Example:
// Create a new TimeSlider with set dates
var timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  view: view
});

// wait for the time-aware layer to load
layer.when(function() {
  // set up time slider properties based on layer timeInfo
  timeSlider.fullTimeExtent = layer.timeInfo.fullTimeExtent;
  timeSlider.stops = {
   interval: layer.timeInfo.interval
  };
});
iconClass Stringreadonly

The widget's default CSS icon class.

The unique ID assigned to the widget when the widget is created. If not set by the developer, it will default to the container ID, or if that is not present then it will be automatically generated.

label String

The widget's default label.

loop Boolean

When true, the time slider will play its animation in a loop.

Default Value:true
Example:
// Start a time slider animation that advances every second
// and restarts when it reaches the end.
timeSlider.set({
  loop: true,
  playRate: 1000
});
timeSlider.play();
mode String

The time slider mode. This property is used for defining if the temporal data will be displayed cumulatively up to a point in time, a single instant in time, or within a time range. See the following table for possible values.

Possible ValuesDescriptionExample
instantThe slider will show temporal data that falls on a single instance in time. Set the values property to an array with one date.mode-instance
time-windowThe slider will show temporal data that falls within a given time range. This is the default. Set values property to an array with two dates.mode-instance
cumulative-from-startSimilar to time-window with the start time is always pinned to the start of the slider. Set the values property to have one date, which is the end date.mode-instance
cumulative-from-endAlso, similar to the time-window with the end time pinned to the end of the slider. Set the values property to have one date, which is the start date.mode-instance

Possible Values:"instant"|"time-window"|"cumulative-from-start"|"cumulative-from-end"

Default Value:"time-window"
Example:
// Create a single thumbed time slider that includes all historic content.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  view: view,
  mode: "cumulative-from-start",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2010, 0, 1)
  },
  values: [new Date(2001, 0, 1)] //end date
});
playRate Number

The time (in milliseconds) between animation steps.

Default Value:1000
Example:
// Start a time slider animation that advances
// ten times a second and stops when it reaches the end.
timeSlider.set({
  loop: false,
  playRate: 100
});
timeSlider.play();
Autocasts from Object

Defines specific locations on the time slider where thumbs will snap to when manipulated. If unspecified, ten evenly spaced stops will be added.

To define regularly spaced stops based on specified time interval and time extent, use StopsByInterval. Use StopsByCount to define evenly spaced timeline stops. Lastly, for irregular dates use StopsByDates. Please refer below for examples of each of these objects.

If a declaration using StopsByInterval will result in excess of 10,000 stops then TimeSlider will default to generating ten evenly spaced stops.

Default Value:{ count : 10 }
Example:
// Add yearly stops starting from the beginning of 2001.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 5, 1),
    end: new Date(2010, 0, 1)
  },
  stops: {
    interval: {
      value: 1,
      unit: "years"
    },
    timeExtent: {
      start: new Date(2001, 0, 1),
      end: new Date(2010, 0, 1)
    }
  }
});

// Add ten stops that are evenly distributed for the year 2005 only.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 5, 1),
    end: new Date(2010, 0, 1)
  },
  stops: {
    count: 10,
    timeExtent: {
      start: new Date(2005, 0, 1),
      end: new Date(2006, 0, 1)
    }
  }
});

// Explicitly define nine stops.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2010, 0, 1)
  },
  values: [
    new Date(2000, 0, 1),
    new Date(2000, 0, 1)],
  stops: {
    dates: [
      new Date(2000, 0, 1), new Date(2001, 3, 8), new Date(2002, 0, 10),
      new Date(2003, 12, 8), new Date(2004, 2, 19), new Date(2005, 7, 5),
      new Date(2006, 9, 11), new Date(2007, 11, 21), new Date(2008, 1, 10)
    ]
  }
});
timeExtent TimeExtentreadonly

The current time extent of the time slider. This property can be watched for updates and used to update the time extent property in queries and/or the layer filters and effects.

Default Value:null
Example:
// Display the time extent to the console whenever it changes.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  mode: "time-window",
  fullTimeExtent: {
    start: new Date(2019, 2, 3),
    end: new Date(2019, 2, 5)
  },
  values: [
    new Date(2019, 2, 1),
    new Date(2019, 2, 28)
  ]
});
timeSlider.watch("timeExtent", function(timeExtent){
  console.log("Time extent now starts at", timeExtent.start, "and finishes at:", timeExtent.end);
});
timeVisible Boolean

Shows/hides time in the display.

Default Value:false
Example:
// For time sliders with a small time extent it may be useful to display times as shown below.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  mode: "time-window",
  timeVisible: true,
  fullTimeExtent: {
    start: new Date(2019, 2, 3),
    end: new Date(2019, 2, 5)
  },
  values: [
    new Date(2019, 2, 1),
    new Date(2019, 2, 28)
  ]
});
values Date[]

The user defined time extent. Values define the current location of time slider thumbs. The "time-window" mode has two values, the other modes only have one.

Default Value:null
Example:
// Create a time slider and print handle positions to the console whenever they change.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  view: view,
  mode: "instant",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2010, 0, 1)
  },
  values: [
    new Date(2000, 0, 1) // Initialize the current time for the beginning of the fullTimeExtent.
  ]
});
timeSlider.watch("values", function(values){
  console.log("The current time is: ", values[0]);
});

A reference to the MapView or SceneView. If this property is set, the TimeSlider widget will update the view's timeExtent property whenever the time slider is manipulated or updated programmatically. This property will affect any time-aware layer in the view.

Example:
// Create and then add a TimeSlider widget and then listen to changes in the View's time extent.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  view: view,
  mode: "instant",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2010, 0, 1)
  },
  values: [new Date(2000, 0, 1)]
});
view.ui.add(timeSlider, "top-left");

view.watch("timeExtent", function(timeExtent){
  console.log("New view time is: ", timeExtent.start);
});

The view model for this widget. This is a class that contains all the logic (properties and methods) that controls this widget's behavior. See the TimeSliderViewModel class to access all properties and methods on the widget.

Example:
// Below is an example of initializing a TimeSlider widget using properties
// on the viewModel instead of the widget.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  viewModel: {
    view: view,
    mode: "instant",
    fullTimeExtent: {
      start: new Date(2000, 0, 1),
      end: new Date(2010, 0, 1)
    },
    values: [new Date(2000, 0, 1)]
  }
});

Method Overview

NameReturn TypeSummaryClass
String

A utility method used for building the value for a widget's class property.

more details
more detailsWidget

Destroys the widget instance.

more details
more detailsWidget
Boolean

Emits an event on the instance.

more details
more detailsWidget
Boolean

Indicates whether there is an event listener on the instance that matches the provided event name.

more details
more detailsWidget

Incrementally moves the time extent forward one stop.

more details
more detailsTimeSlider
Object

Registers an event handler on the instance.

more details
more detailsWidget

Widget teardown helper.

more details
more detailsWidget

Initiates the time slider's temporal playback.

more details
more detailsTimeSlider

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Incrementally moves the time extent back one stop.

more details
more detailsTimeSlider
Object

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Renders widget to the DOM immediately.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Stops the time slider's temporal playback.

more details
more detailsTimeSlider

Method Details

classes(classNames){String}inherited

A utility method used for building the value for a widget's class property. This aids in simplifying CSS class setup.

Parameter:
classNames Array<(string|Array<string>|Object)>
repeatable

The class names.

Returns:
TypeDescription
StringThe computed class name.
See also:
Example:
// .tsx syntax showing how to set CSS classes while rendering the widget

render() {
  const dynamicIconClasses = {
    [CSS.myIcon]: this.showIcon,
    [CSS.greyIcon]: !this.showIcon
  };

  return (
    <div class={classes(CSS.root, CSS.mixin, dynamicIconClasses)} />
  );
}
destroy()inherited

Destroys the widget instance.

emit(type, event){Boolean}inherited

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters:
type String

The name of the event.

event Object
optional

The event payload.

Returns:
TypeDescription
Booleantrue if a listener was notified
hasEventListener(type){Boolean}inherited

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter:
type String

The name of the event.

Returns:
TypeDescription
BooleanReturns true if the class supports the input event.

Incrementally moves the time extent forward one stop.

Example:
// Advance the slider's time extent.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  mode: "instant",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2010, 0, 1)
  },
  values: [new Date(2000, 0, 1)]
});
timeSlider.next();
on(type, listener){Object}inherited

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters:

A event type, or an array of event types, to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event(s).
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
own(handles)inherited

Widget teardown helper. Any handles added to it will be automatically removed when the widget is destroyed.

Parameter:

Handles marked for removal once the widget is destroyed.

play()

Initiates the time slider's temporal playback.

Example:
// Start a TimeSlider animation if not already playing.
if (timeSlider.state === "ready") {
  timeSlider.play();
}
postInitialize()inherited

This method is primarily used by developers when implementing custom widgets. Executes after widget is ready for rendering.

Incrementally moves the time extent back one stop.

Example:
timeSlider.previous();
render(){Object}inherited

This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.

Returns:
TypeDescription
ObjectThe rendered virtual node.
renderNow()inherited

Renders widget to the DOM immediately.

scheduleRender()inherited

This method is primarily used by developers when implementing custom widgets. Schedules widget rendering. This method is useful for changes affecting the UI.

stop()

Stops the time slider's temporal playback.

Example:
// Stop the current TimeSlider animation.
if (timeSlider.viewModel.state === "playing") {
  timeSlider.stop();
}

Type Definitions

StopsByCount Object

Specifies number of stops for the time slider widget. The time slider stops are divided into evenly spaced stops.

Properties:
count Number

Specifies number of stops count.

timeExtent TimeExtent
optional

A period of time with definitive start and end dates. The time slider widget's fullTimeExtent will be used if this property is not specified.

Example:
// Add ten evenly spaced stops.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2004, 2, 19)
  },
  values: [
    new Date(2000, 0, 1),
    new Date(2000, 3, 8)
  ],
  stops: {
    count: 10
  }
});
StopsByDates Object

Specifies an array of dates for the time slider widget. Can be used to create irregularly spaced stops.

Property:
dates Date[]

Array of dates.

Example:
// Explicitly define 5 stops.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2004, 2, 19)
  },
  values: [
    new Date(2000, 0, 1),
    new Date(2001, 3, 8)
  ],
  stops: {
    dates: [
      new Date(2000, 0, 1),
      new Date(2001, 3, 8),
      new Date(2002, 0, 10),
      new Date(2003, 12, 8),
      new Date(2004, 2, 19)
    ]
  }
});
StopsByInterval Object

Defines regularly spaced stops on the time slider from a TimeInterval. The optional TimeExtent can confine the subdivision to a specific time frame. StopByInterval is useful when the spacing is in terms of months and years, which cannot be reliably expressed in milliseconds.

Properties:
interval TimeInterval

Specifies a granularity of temporal data and allows you to visualize the data at specified intervals. It can be set at regular interval such as every hour or every day.

timeExtent TimeExtent
optional

A period of time with definitive start and end dates. The time slider widget's fullTimeExtent will be used if this property is not specified.

Example:
// Add yearly intervals starting from the beginning of the TimeSlider.
const timeSlider = new TimeSlider({
  container: "timeSliderDiv",
  fullTimeExtent: {
    start: new Date(2000, 0, 1),
    end: new Date(2015, 2, 19)
  },
  values: [
    new Date(2000, 0, 1),
    new Date(2001, 0, 1)
  ],
  stops: {
    interval: {
      value: 1,
      unit: "years"
    }
  }
});

API Reference search results

NameTypeModule
Loading...