当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS GeoJSONLayer.timeInfo用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/layers/GeoJSONLayer"], (GeoJSONLayer) => { /* code goes here */ });

ESM: import GeoJSONLayer from "@arcgis/core/layers/GeoJSONLayer";

类: esri/layers/GeoJSONLayer

继承: GeoJSONLayer > Layer > Accessor

自从:用于 JavaScript 4.11 的 ArcGIS API

用法说明

GeoJSONLayer.timeInfo函数(或属性)的定义如下:

timeInfo TimeInfo autocast


TimeInfo 提供诸如存储每个要素的 startend 时间以及该图层的 fullTimeExtent 的日期字段等信息。如果为 GeoJSONLayer 设置 timeInfo 属性及其 startFieldendField 属性,则必须在层初始化时进行设置。加载图层后,timeInfo 参数无法更改。 timeInfofullTimeExtent 是根据其startFieldendField 属性自动计算的。如果日期信息存储在纪元/unix 时间戳中,则日期字段是在层初始化时创建的。如果日期信息未存储在纪元/unix 时间戳中,则它们必须转换为纪元时间戳,以便可以为图层创建日期字段。以下代码片段展示了如何根据 ISO-8601 字符串在 GeoJSONLayer 中创建日期字段。

// intercept the geojson data after it is fetched so that we can parse
// the ISO-8601 string values to epoch timestamp before the GeoJSONLayer is created.
esriConfig.request.interceptors.push({
  urls: geojsonUrl,
  after: function(response) {
   if (response.url?.valueOf().toLowerCase().includes("earthquakes")) {
      const geojson = response.data;
      geojson.features.forEach((feature) => {
        const unixDate = Date.parse(feature.properties.isoDate);
        feature.properties.unixDate = unixDate;
      });
    }
  }
});

// create a time aware GeoJSONLayer by setting its timeInfo property in
// the constructor. We must also set the fields parameter in the layer
// constructor to indicate that the unixDate field is a date field.
// in this case, unixDate must contain unix timestamp.
const layer = new GeoJSONLayer({
  url: geojsonUrl,
  popupTemplate: {
    title: "{name}",
    content: "ISO date: {isoDate} <br> Unix date: {unixDate}"
  },
  fields: [
    {
       "name": "unixDate",
       "alias": "unixDate",
       "type": "date"
     }
  ],
  timeInfo: {
    startField: "unixDate",
    interval: {
      unit: "years",
      value: 1
    }
  }
});

默认值:null

例子:

// create geojson layer from usgs earthquakes geojson feed
const geojsonLayer = new GeoJSONLayer({
  url: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson",
  copyright: "USGS Earthquakes",
  fields: [
    { "name": "mag", "type": "double" },
    { "name": "place", "type": "string" },
    { "name": "time", "type": "date" }, // date field
    { "name": "depth", "type": "double" }
  ],
  // timeInfo can be used to do temporal queries
  // set the startField and endField.
  // timeExtent is automatically calculated from the start and end date fields
  // The date values must be in milliseconds number from the UNIX epoch specified in UTC.
  timeInfo: {
    startField: "time"
  }
});

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 GeoJSONLayer.timeInfo。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。