TimeSlider
require(["esri/widgets/TimeSlider"], function(TimeSlider) { /* code goes here */ });
esri/widgets/TimeSlider
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.
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
};
});
- See also:
Constructors
- new TimeSlider(properties)
- Parameter:properties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class | |
---|---|---|---|---|
String|HTMLElement | The ID or node representing the DOM element containing the widget. more details | more details | Widget | |
String | The name of the class. more details | more details | Accessor | |
Boolean | When | more details | Widget | |
Date[] | Lists the specific locations on the timeline where handle(s) will snap to when manipulated. more details | more details | TimeSlider | |
TimeExtent | The temporal extent of the entire slider. more details | more details | TimeSlider | |
String | The widget's default CSS icon class. more details | more details | TimeSlider | |
String | The unique ID assigned to the widget when the widget is created. more details | more details | Widget | |
String | The widget's default label. more details | more details | TimeSlider | |
Boolean | When | more details | TimeSlider | |
String | The time slider mode. more details | more details | TimeSlider | |
Number | The time (in milliseconds) between animation steps. more details | more details | TimeSlider | |
StopsByDates|StopsByCount|StopsByInterval | Defines specific locations on the time slider where thumbs will snap to when manipulated. more details | more details | TimeSlider | |
TimeExtent | The current time extent of the time slider. more details | more details | TimeSlider | |
Boolean | Shows/hides time in the display. more details | more details | TimeSlider | |
Date[] | The user defined time extent. more details | more details | TimeSlider | |
MapView|SceneView | A reference to the MapView or SceneView. more details | more details | TimeSlider | |
TimeSliderViewModel | The view model for this widget. more details | more details | TimeSlider |
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" });
The name of the class. The declared class name is formatted as
esri.folder.className
.
When
true
, this property indicates whether the widget has been destroyed.
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 Values Description Example instant The slider will show temporal data that falls on a single instance in time. Set the values property to an array with one date. time-window The 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. cumulative-from-start Similar 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.cumulative-from-end Also, 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.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) ] });
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); });
- viewModel TimeSliderViewModelautocast
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
Name | Return Type | Summary | Class | |
---|---|---|---|---|
String | A utility method used for building the value for a widget's | more details | Widget | |
Destroys the widget instance. more details | more details | Widget | ||
Boolean | Emits an event on the instance. more details | more details | Widget | |
Boolean | Indicates whether there is an event listener on the instance that matches the provided event name. more details | more details | Widget | |
Incrementally moves the time extent forward one stop. more details | more details | TimeSlider | ||
Object | Registers an event handler on the instance. more details | more details | Widget | |
Widget teardown helper. more details | more details | Widget | ||
Initiates the time slider's temporal playback. more details | more details | TimeSlider | ||
This method is primarily used by developers when implementing custom widgets. more details | more details | Widget | ||
Incrementally moves the time extent back one stop. more details | more details | TimeSlider | ||
Object | This method is primarily used by developers when implementing custom widgets. more details | more details | Widget | |
Renders widget to the DOM immediately. more details | more details | Widget | ||
This method is primarily used by developers when implementing custom widgets. more details | more details | Widget | ||
Stops the time slider's temporal playback. more details | more details | TimeSlider |
Method Details
A utility method used for building the value for a widget's
class
property. This aids in simplifying CSS class setup.Parameter:repeatable The class names.
Returns:Type Description String The computed class name. 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.
Emits an event on the instance. This method should only be used when creating subclasses of this class.
Parameters:type StringThe name of the event.
event ObjectoptionalThe event payload.
Returns:Type Description Boolean true
if a listener was notified
Indicates whether there is an event listener on the instance that matches the provided event name.
Parameter:type StringThe name of the event.
Returns:Type Description Boolean Returns true if the class supports the input event.
- next()
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();
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 FunctionThe function to call when the event is fired.
Returns:Type Description Object Returns an event handler with a remove()
method that can be called to stop listening for the event(s).Property Type Description remove Function When 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 WatchHandle|WatchHandle[]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.
- previous()
Incrementally moves the time extent back one stop.
Example:timeSlider.previous();
This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.
Returns:Type Description Object The 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.
optionaltimeExtent TimeExtentA 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:
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.
optionaltimeExtent TimeExtentA 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" } } });