1
2
3
4
5
6
7
const trafficLayer = new MapImageLayer({
url: "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer",
dpi: 48,
imageFormat: "png32",
refreshInterval: 3, // refresh the layer every 3 minutesuseViewTime: false// layer sets its time extent and will ignore view's timeExtent.});
初始化应用后,用户可以更改时钟微件上的时间,以显示该时间段的流量数据。时钟微件初始化如下图所示:
1
2
3
4
5
6
var clock = new Clock({
el: "clock", // container divskin: "clock.svg",
time: Date.now() // number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.});
clock.on("time-change", setDate);
每当用户更改时钟微件上的时间时,都会触发 time-change 事件并更新流量图层的 timeExtent。如果在时钟上单击 live 按钮,则该图层将获取最新的流量数据。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
functionsetDate(time) {
// reset the clock widget show the latest traffic data if the user// clicks on `live` button on the clockif (clock.mode === "live") {
trafficLayer.timeExtent = null;
}
else { // otherwise shows the traffic data where// the clock handles move to trafficLayer.timeExtent = {
start: time,
end: time
};
}
}