當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。