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


JavaScript ArcGIS Collection用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

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

ESM: import Collection from "@arcgis/core/core/Collection";

類: esri/core/Collection

繼承: Collection > Accessor

子類: SceneModifications

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

集合存儲相同類型的項目的數組。它提供了用於處理集合中的項目的有用實用方法,包括filter()、find() 和reduce()。

集合可以是任何類型。例如,GraphicsLayer.graphics 是存儲在 GraphicsLayer 中的圖形集合。您可以使用 Collection 類中的方法在 GraphicsLayer 中添加、刪除、重新排序或操作圖形。

集合的另一個示例是 Map.layers ,它是包含在 Map 中的操作層的集合。

// Removes a layer from the map using Collection.remove();
map.layers.remove(layer);

每次從集合中添加、移動或刪除項目時都會觸發更改事件。

從 4.18 版開始,您可以使用 for...of 遍曆 Collection 的項目。

// a collection of graphics displayed in the view
const graphics = view.graphics;

for (const graphic of graphics){
  // do something with each view graphic
}

從版本 4.23 開始,reactiveUtils 可用於監視集合中項目的屬性更改。

// reactiveUtils watch method can be used to watch the visible
// property of each layer within the map.allLayer's collection
const handle = reactiveUtils.watch(
  () => view.map.allLayers.every((layer) => layer.visible),
  (allVisible) => {
    console.log(`All layers are visible = ${allVisible}`);
  }
);

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 Collection。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。