ArcGIS for javascript4.14 新特性演示(一)

先上图:更新之一是可以在要素图层上设置时间“offset”的功能。

示例演示如何在利用FeatureLayer的timeOffset属性的同时使用TimeSlider小部件。该属性用于将图层的timeInfo偏移一定的TimeInterval,以覆盖来自两个或多个具有不同时间范围的时间感知图层的要素

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(function(definition){
  return createLayer(definition)
});

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年之间的加利福尼亚大火。初始化图层后,timeOffset将在每个图层上设置属性,如下所示。该timeOffset属性临时将火灾数据从其视角年份转移到2018年。当TimeSlider的timeExtent更新时,所有要素图层都将显示当前时间范围内的数据,就好像所有火灾都发生在2018年的那个时期一样。

// update the fire stats between 2014 - 2018 once timeExtent of
// the TimeSlider changes
timeSlider.watch("timeExtent", function(){
  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(function(layerViewsResults) {
    // query each and every fire layerviews for stats and process the results
    queryFeaturesForStats(layerViewsResults).then(function(fireStatsQueryResults){
      // fire stats query results are back. Loop through them and process.
      fireStatsQueryResults.map(function(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>";
    });
  });
}
标签

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值