UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.6 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../chunks/tslib.es6.js";import{countIf as t,addMany as r,isSome as s}from"../../../core/arrayUtils.js";import o from"../../../core/ReactiveMap.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import l from"./FeatureItem.js";import n from"./ItemBase.js";import{getSuggestedQueryOutFields as c}from"../Selector2D/selectorUtils.js";let u=class extends n{constructor(e){super(e),this._onChangeController=null,this.featureItems=[],this.featureTitleMap=new o,this.groupLayerItem=null,this.layer=null}get effectiveObjectIds(){return this.objectIds.slice(0,this.maxVisibleFeatureCountPerLayer)}get maxVisibleFeatureCountExceeded(){const{viewModel:e}=this;return this.objectIds.length>e.maxVisibleFeatureCountPerLayer&&this.visibleTotal===e.maxVisibleFeatureCountPerLayer}get maxVisibleFeatureCountPerLayer(){return this.viewModel.maxVisibleFeatureCountPerLayer}get objectIds(){return this.viewModel.effectiveSelectionManager?.getSelection(this.layer)??[]}get total(){return this.objectIds.length}get visible(){return this.featureItems.some((e=>e.visible))}get visibleTotal(){return t(this.featureItems,(e=>e.visible))}cancel(){this._onChangeController?.abort()}reset(){this.featureItems.forEach((e=>e.destroy())),this.featureItems=[]}async sync({controller:e,promises:t}){this.cancel();const o=new Map(this.featureItems.map((e=>[e.objectId,e]))),i=new Map,a=[],l=[];for(const r of this.effectiveObjectIds){const e=o.get(r);e?i.set(r,e):(a.push(r),i.set(r,null))}if(this._onChangeController=e,a.length>0){const t=await this._createFeatureItems(a,e);r(l,t);for(const e of l)null!=e.objectId&&i.set(e.objectId,e)}e.signal.aborted||(this.featureItems=Array.from(i.values()).filter(s),t.push(this.syncTitles(l)))}async syncTitles(e=this.featureItems){const{layer:t}=this,r=e.map((e=>e.graphic));if("getFeatureTitles"in t&&t.getFeatureTitles){(await t.getFeatureTitles(r,{fetchMissingFields:!0})).forEach(((e,t)=>this.featureTitleMap.set(t,e)))}}async _createFeatureItems(e,t){const{layer:r,layerView:s,viewModel:o}=this,i=new Map;if(s){const r=s.createQuery();r.objectIds=e,r.outFields=["*"],r.returnGeometry=!0;const o=await s.queryFeatures(r,t);for(const e of o.features){const t=e.getObjectId();null!=t&&i.set(t,e)}}if(t.signal.aborted)return[];const a=e.filter((e=>!i.has(e)));if(a.length){const{view:e}=this,s=r.createQuery();s.objectIds=a,s.outSpatialReference=e?.spatialReference,s.outFields=e?c(r,e,!0):["*"],s.returnGeometry=!0;const o=await r.queryFeatures(s,t);for(const t of o.features){const e=t.getObjectId();null!=e&&i.set(e,t)}}return Array.from(i.values()).map((e=>new l({graphic:e,layer:r,layerItem:this,viewModel:o})))}};e([i()],u.prototype,"_onChangeController",void 0),e([i()],u.prototype,"effectiveObjectIds",null),e([i()],u.prototype,"featureItems",void 0),e([i()],u.prototype,"featureTitleMap",void 0),e([i()],u.prototype,"groupLayerItem",void 0),e([i()],u.prototype,"layer",void 0),e([i()],u.prototype,"maxVisibleFeatureCountExceeded",null),e([i()],u.prototype,"maxVisibleFeatureCountPerLayer",null),e([i()],u.prototype,"objectIds",null),e([i()],u.prototype,"total",null),e([i()],u.prototype,"visible",null),e([i()],u.prototype,"visibleTotal",null),u=e([a("esri.widgets.support.SelectionList.LayerItem")],u);const p=u;export{p as default};