require(["esri/dijit/TimeSlider"], function(TimeSlider) { /* code goes here */ });
Description
(Added at v2.0)
The TimeSlider widget is used for visualizing content within a map that contains time-aware layers.
See also
Samples
Search for
samples that use this class.
Constructors
CSS
esri/dijit/TimeSlider | Download source
Properties
Methods
Events
[ On Style Events | Connect Style Event ]
All On Style event listeners receive a single event object. Additionally, the event object also contains a 'target' property whose value is the object which fired the event.
Events
next | {
timeExtent: <TimeExtent >
} | Fires when the next button is clicked or TimeSlider.next() method is invoked. |
pause | {
timeExtent: <TimeExtent >
} | Fires when the pause button is clicked or TImeSlider.pause() method is invoked. |
play | {
timeExtent: <TimeExtent >
} | Fires once when the play button is clicked or Timeslider.play() method is invoked. |
previous | {
timeExtent: <TimeExtent >
} | Fires when the previous button is clicked or TimeSlider.previous() is invoked. |
time-extent-change | {
timeExtent: <TimeExtent >
} | Fires when the timeExtent of the TimeSlider is changed. |
Old Events
next() | Fires when the next button is clicked or TimeSlider.next() method is invoked. |
onTimeExtentChange(timeExtent) | Fires when the timeExtent of the TimeSlider is changed. |
pause() | Fires when the pause button is clicked or TImeSlider.pause() method is invoked. |
play() | Fires once when the play button is clicked or Timeslider.play() method is invoked. |
previous() | Fires when the previous button is clicked or TimeSlider.previous() is invoked. |
Constructor Details
Creates a new TimeSlider object.
Parameters:
<Object > params |
Required |
Parameters for the time slider object. See the options table below for parameters. |
<Node | String > srcNodeRef |
Required |
HTML element where the time slider should be rendered. |
params
properties:
<Boolean > excludeDataAtLeadingThumb |
Optional |
When true, subtracts one second to the time extent's end time to exclude data at the exact end time instant. |
<Boolean > excludeDataAtTrailingThumb |
Optional |
When true, adds one second to the time extent's start time to exclude data at the exact start time instant. |
Property Details
Default value is false.
Known values: true | false
Default value is false.
Known values: true | false
Rate at which the time animation plays. Default value is 1000 milliseconds.
An array of dates representing the stops (tics) on the TimeSlider.
Method Details
The specified number of time stops are created for the input time extent.
Parameters:
<TimeExtent > timeExtent |
Required |
The time extent used to define the time slider's start and end time stops. |
<Number > count |
Optional |
The number of time stops to create. |
Create a time stop for each interval specified, i.e., (week, month, day).
Parameters:
<TimeExtent > timeExtent |
Required |
The time extent used to define the time slider's start and end time stops. |
<Number > timeInterval |
Optional |
The length of the time interval. |
<String > timeIntervalUnits |
Optional |
Valid values are listed in the TimeInfo constants table. |
Sample:
require([
"esri/map", "dojo/_base/connect", "esri/dijit/TimeSlider", "dojo/dom", ...
], function(Map, connect, TimeSlider, dom, ... ) {
var map = new Map( ... );
connect.connect(map,"onLayersAddResult",function(results){
var timeSlider = new TimeSlider({},dom.byId("timeSliderDiv"));
map.setTimeSlider(timeSlider);
timeSlider.setThumbCount(1);
timeSlider.createTimeStopsByTimeInterval(results[1].layer.timeInfo.timeExtent,1,'esriTimeUnitsWeeks');
timeSlider.startup();
})
...
});
Gets the current time extent for the time slider.
Sample:
var startTime = timeSlider.getCurrentTimeExtent().startTime;
Move to the next time step.
Move to the previous time step.
Specify an array of strings to be used as labels. The array position for each string defines which tick it will be placed on.
Parameters:
<String[] > labels |
Required |
An array of strings that define the labels for each tick. |
Sample: Add a label for every other tick.
require([
"esri/dijit/TimeSlider", "dojo/_base/array", ...
], function(TimeSlider, array, ... ) {
var timeSlider = new TimeSlider( ... );
var labels = array.map(timeSlider.timeStops, function(timeStop,i){
if(i%2 === 0){
return timeStop.getUTCFullYear(); }
else{
return "";
}
});
timeSlider.setLabels(labels);
...
});
Determines whether or not loop. Default value is false.
Parameters:
<Boolean > loop |
Required |
True plays the time slider continuously. Default value is false. |
Sample:
timeSlider.setLoop(true);
The number of thumbs to display. A value of one displays a single thumb. Setting the value to 2 displays a range slider.
Parameters:
<Number > thumbCount |
Required |
The number of thumbs to display. Default value is one. |
Sample:
timeSlider.setThumbCount(2);
Array of two integers, the first value determines where to put the first thumb. If it is a two thumb slider the second value determines where to place the additional thumb.
Parameters:
<Number[] > indexes |
Required |
Array of two integers. |
Sample:
timeSlider.setThumbCount(2);
timeSlider.setThumbIndexes([0,1]);
Change the rate at which the time animation plays.
Parameters:
<Number > thumbMovingRate |
Required |
The rate at which the time slider plays. Default value is 1500. |
Sample:
timeSlider.setThumbMovingRate(2000);
Specify the number of ticks to display on the time slider. (Added at v2.1)
Parameters:
<Number > count |
Required |
The number of ticks to display on the slider. |
Sample:
require([
"dojo/date", ...
], function(date, ... ) {
timeSlider.setTickCount(date.difference(timeExtent.startTime,timeExtent.endTime,"day"));
...
});
Manually define the time stop locations by providing an array of dates.
Parameters:
<Date[] > timeStops |
Required |
Array of dates |
Sample:
require([
"esri/dijit/TimeSlider", ...
], function(TimeSlider, ... ) {
var timeSlider = new TimeSlider( ... );
var myTimeStepIntervals = [new Date("01/01/1970"), new Date("01/01/1971"), new Date("01/01/1972"),
new Date("01/01/1973"), new Date("01/01/1974"),new Date("01/01/1975"), new Date("01/01/1976")];
timeSlider.setTimeStops(myTimeStepIntervals);
...
});
Determine if the time is displayed for an instant in time. Only valid when the thumb count is set to one.
Parameters:
<Boolean > createTimeInstants |
Required |
When true, the time slider displays features for the current point in time. When false cumulative data is displayed from the start time to the current thumb location. The default value is false. |
Sample:
timeSlider.singleThumbAsTimeInstant(true);
Finalizes the creation of the widget. (Added at v3.12)
Event Details
[ On Style Events | Connect Style Event ]
Fires when the next button is clicked or TimeSlider.next() method is invoked. (Added at v3.15)
Event Object Properties:
<TimeExtent > timeExtent |
The current time slice of the time slider. |
Fires when the pause button is clicked or TImeSlider.pause() method is invoked. (Added at v3.15)
Event Object Properties:
<TimeExtent > timeExtent |
The current time slice of the time slider. |
Fires once when the play button is clicked or Timeslider.play() method is invoked. (Added at v3.15)
Event Object Properties:
<TimeExtent > timeExtent |
The current time slice of the time slider. |
Fires when the previous button is clicked or TimeSlider.previous() is invoked. (Added at v3.15)
Event Object Properties:
<TimeExtent > timeExtent |
The current time slice of the time slider. |
Fires when the timeExtent of the TimeSlider is changed. (Added at v3.6)
Event Object Properties:
<TimeExtent > timeExtent |
The current time slice of the time slider. |
Sample:
require([
"dojo/dom", ...
], function( dom, ... ) {
timeSlider.on("time-extent-change",extentChanged);
function extentChanged(evt){
//format the dates for display
var timeExtent = evt.timeExtent;
var startVal = timeExtent.startTime.getFullYear();
var endVal = timeExtent.endTime.getFullYear();
dom.byId("timeVal").innerHTML = "<b> Current Time Extent:" + startVal + " TO " + endVal + "<\/b>";
}
...
});
Fires when the next button is clicked or TimeSlider.next() method is invoked. (Added at v3.15)
Fires when the timeExtent of the TimeSlider is changed.
Event Object Properties:
<TimeExtent > timeExtent |
The current time slice of the time slider. |
Sample:
dojo.connect(timeSlider,"onTimeExtentChange",extentChanged);
function extentChanged(timeExtent){
//format the dates for display
var startVal = timeExtent.startTime.getFullYear();
var endVal = timeExtent.endTime.getFullYear();
dojo.byId("timeVal").innerHTML = "<b> Current Time Extent:" + startVal + " TO " + endVal + "<\/b>";
}
Fires when the pause button is clicked or TImeSlider.pause() method is invoked. (Added at v3.15)
Fires once when the play button is clicked or Timeslider.play() method is invoked. (Added at v3.15)
Fires when the previous button is clicked or TimeSlider.previous() is invoked. (Added at v3.15)