Time-based layer
This sample demonstrates how to display traffic information from a MapImageLayer within a specified time extent. You can view the traffic information at different times by changing the time on the clock widget.
This app displays a dynamic traffic map service with capabilities for visualizing traffic speeds and incidents. The historical, live, and predictive traffic data is updated every five minutes through traffic feeds. You can learn more about the data here.
How it works
The traffic service requires a token for authentication. This sample uses an API Key to authenticate. You can either replace it with your own API Key, or remove it and log in once prompted. Alternatively, you can use another authentication method to access the traffic service.
The world traffic MapImageLayer is initialized with a refresh interval of three minutes. Its useViewTime property is set to false
so that the time extent can be set directly on the layer.
Once the app is initialized, the user can change the time on the clock widget to display traffic data for that time period. The clock widget is initialized as shown below:
Whenever the user changes the time on the clock widget, the time-change
event is triggered and the traffic layer's timeExtent is updated. If the live
button is clicked on the clock, then the layer will fetch the latest traffic data.