具有 timeOffset 的 TimeSlider

尝试一下在线预览

此示例演示如何在利用 FeatureLayer 的 timeOffset 属性的同时将 TimeSlider 微件与操作一起 演示timeOffset 属性用于将图层的 timeInfo 偏移某个 TimeInterval,以便覆盖两个或多个具有不同时间范围的时间感知图层的要素。

此应用程序显示五个时间感知要素图层,显示 2014 年至 2018 年之间的加利福尼亚火灾。初始化图层时,会在每个图层上设置 timeOffset  属性,如下所示。timeOffset  属性将火灾数据从其透视年份暂时转移到 2018 年。当 TimeSlider 的 timeExtent 更新时,所有要素图层都会显示当前时间范围内的数据,就好像所有火灾都发生在 2018 年的那个时期一样。

                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// create five new instances of feature layers
// based on the following definitions
const url = "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/California_fires_since_2014/FeatureServer/"
const definitions = [
  { id: 0, year: 2014, offset: 4 },
  { id: 1, year: 2015, offset: 3 },
  { id: 2, year: 2016, offset: 2 },
  { id: 3, year: 2017, offset: 1 },
  { id: 4, year: 2018, offset: 0 }
];
const layers = definitions.map((definition) => {
  return createLayer(definition)
});

// Creates five instances of feature layers each representing
// fires for the given year (between 2014 - 2018)
function createLayer (definition) {
  const year = definition.year;

  return new FeatureLayer({
    url: url + definition.id,
    timeOffset: {
      value: definition.offset,
      unit: "years"
    },
    outFields: ["*"],
    popupTemplate: {
      title: "{ALARM_DATE}",
      content: "{YEAR_}, {ALARM_DATE}, {GIS_ACRES}"
    }
  });
}

它是如何工作的呢?

要开始可视化2014年至2018年每月记录的加州火灾,你可以做以下其中一件事:

  • 点击 play  按钮,自动更新时间可视化。
  • 按下 next  或 previous 按钮,一次完成一个月。
  • 拖动拇指或节段可以跳过几个月。

当 TimeSlider 的  timeExtent  发生变化时,每个图层都会更新以显示落在该 timeExtent 内的火灾。 查询每个 layerView 的统计信息。 查询结果经过处理,然后显示在条形图中。 条形图显示了 2014 年至 2018 年间每年给定时期内燃烧的总英亩数。

                                                    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// update the fire stats between 2014 - 2018 once timeExtent of
// the TimeSlider changes
timeSlider.watch("timeExtent", () =>{
  updateFiresStats();
});

// This function is called when the timeSlider's timeExtent changes
// It queries each layer view for fire stats and updates the chart
function updateFiresStats(){
  layerViewsEachAlways().then((layerViewsResults) => {
    // query each and every fire layerviews for stats and process the results
    queryFeaturesForStats(layerViewsResults).then((fireStatsQueryResults) => {
      monthDiv.innerHTML = "";
      let month;
      let acresBurntList = [];
      let chartLabels = [];
      // fire stats query results are back. Loop through them and process.
      fireStatsQueryResults.map((result) => {
        if (result.error) {
          return promiseUtils.resolve(result.error);
        }
        // The results of the Promise are returned in the value property
        else {
          // if the stats query returned a year for the given layerview
          // then process and update the chart
          if (result.value.year !== null){

            // extract the year and month from the date
            let date = new Date(result.value.year);
            let year = date.getFullYear();

            // array of burnt acres sum returned in the query results
            // for each layerview representing fires between 2014-2018
            acresBurntList.push(result.value.acres_sum.toFixed(2));

            //chart labels will show the year and count of fires for that year
            const label = year + ", " + result.value.fire_counts;
            chartLabels.push(label);
          }
        }
      });
      // query results have been processed. Update the fires chart to display
      // sum of acres burnt for the given month and year
      firesChart.data.datasets[0].data = acresBurntList;
      firesChart.data.labels = chartLabels;
      firesChart.update();
      startMonth = timeSlider.timeExtent.start.toLocaleString("default", { month: "long" });
      endMonth = timeSlider.timeExtent.end.toLocaleString("default", { month: "long" });
      monthDiv.innerHTML = "<b> Month: <span>" + startMonth + " - " + endMonth + "</span></b>";
    });
  });
}

TimeSlider 操作

您还可以使用 actions  菜单直接导航到烧毁英亩数的前三个月。 在 4.21 版中, actions  属性被添加到 TimeSlider 微件中,它允许您创建在从操作菜单中选择项目时发生的自定义操作。

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.