This sample demonstrates how visualize the precipitation forecast for the next 72 hours across the contiguous United States with 6-hour interval using the TimeSlider widget. Users can also change the MapView's timeZone so that the precipitation forecast can be visualized in different time zones. The TimeSlider widget simplifies the process of visualizing temporal data in a JavaScript application. In this case, users can visualize when precipitation is forecasted to fall in 6 hour intervals. The temporal data visualization can also be displayed in different time zones when the user changes the MapView's time zone from the input time zone calcite component. Viewing this temporal data can be useful if users need to know when precipitation will be falling in their area in their local time.
The TimeZoneLabel widget displays the time zone of the MapView so users are aware of which time zone the dates are being displayed in.
The map displays the Quantitative Precipitation Forecast (QPF) for the next 72 hours across the contiguous United States. Data is updated hourly from the National Digital Forecast Database and produced by the National Weather Service. Visit the portal item page in ArcGIS Online for more information.
** TimeSlider widget**
There are four different mode options when initializing the TimeSlider widget: instant
, time-window
, cumulative-from-start
, and cumulative-from-end
. The default mode
for the time slider is time-window
. The sample uses this default mode, meaning the slider will show precipitation data that falls within a given time range, which is 6 hours in this case.
We are setting the view property on the time slider widget. The TimeSlider widget will update the view's timeExtent whenever the time slider's timeExtent changes. Setting the view
property will affect any time-aware layer in the view.
// time slider widget initialization
const timeSlider = new TimeSlider({
container: "timeSlider",
mode: "time-window",
view: view
});
view.ui.add(timeSlider, "manual");
Once the layer view has loaded, the fullTimeExtent of the time slider widget is set as shown below. The end
time of the layer.timeInfo.fullTimeExtent for the service does not make full hour. So the TimeExtent.expandTo() method is called to around up the time slider's full
to fit full hours.
view.whenLayerView(layer).then((lv) => {
// around up the full time extent to full hour
timeSlider.fullTimeExtent = layer.timeInfo.fullTimeExtent.expandTo("hours");
timeSlider.stops = {
interval: layer.timeInfo.interval
};
});
Changing MapView timeZone
Users can change the MapView's timeZone by setting the timeZone property at runtime. In this sample, users use the input time zone component to change the time zone. The dates displayed on the time slider widget and the time slider's temporal visualization will change to honor the chosen time zone .
// calcite input time zone component allows users to pick from one of the IANA
// time zones without having to add the time zones manually to a drop down
const timezonePicker = document.getElementById("timezone-picker");
view.ui.add("timezone-picker", "top-right");
// Change the map view's time zone when user picks a time zone from the component
timezonePicker.addEventListener("calciteInputTimeZoneChange", () => {
view.timeZone = timezonePicker.value;
});