基本信息
以下是所在類或對象的基本信息。
AMD:
require(["esri/core/Collection"], (Collection) => { /* code goes here */ });
ESM:
import Collection from "@arcgis/core/core/Collection";
類:
esri/core/Collection
繼承: Collection > Accessor
自從:用於 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}`);
}
);
相關用法
- JavaScript ArcGIS Collection after-add事件用法及代碼示例
- JavaScript ArcGIS Collection.addMany用法及代碼示例
- JavaScript ArcGIS Collection.add用法及代碼示例
- JavaScript ArcGIS Collection.lastIndexOf用法及代碼示例
- JavaScript ArcGIS Collection.ofType用法及代碼示例
- JavaScript ArcGIS Collection.pop用法及代碼示例
- JavaScript ArcGIS Collection after-remove事件用法及代碼示例
- JavaScript ArcGIS Collection before-changes事件用法及代碼示例
- JavaScript ArcGIS Collection.reverse用法及代碼示例
- JavaScript ArcGIS Collection.find用法及代碼示例
- JavaScript ArcGIS Collection.removeMany用法及代碼示例
- JavaScript ArcGIS Collection.toArray用法及代碼示例
- JavaScript ArcGIS Collection.some用法及代碼示例
- JavaScript ArcGIS Collection.remove用法及代碼示例
- JavaScript ArcGIS Collection.concat用法及代碼示例
- JavaScript ArcGIS Collection.unshift用法及代碼示例
- JavaScript ArcGIS Collection before-add事件用法及代碼示例
- JavaScript ArcGIS Collection.splice用法及代碼示例
- JavaScript ArcGIS Collection.sort用法及代碼示例
- JavaScript ArcGIS Collection.every用法及代碼示例
- JavaScript ArcGIS Collection.push用法及代碼示例
- JavaScript ArcGIS Collection.indexOf用法及代碼示例
- JavaScript ArcGIS Collection.slice用法及代碼示例
- JavaScript ArcGIS Collection.forEach用法及代碼示例
- JavaScript ArcGIS Collection.includes用法及代碼示例
注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 Collection。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。