@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 9.45 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import r from"../../../core/Collection.js";import i from"../../../core/Logger.js";import{removeMaybe as o,abortMaybe as s}from"../../../core/maybe.js";import{ignoreAbortErrors as a,debounce as l,whenOrTimeout as n}from"../../../core/promiseUtils.js";import{watch as c,on as h,whenOnce as p}from"../../../core/reactiveUtils.js";import{property as y,subclass as g}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../../core/support/UpdatingHandles.js";import{isSubtypeGroupLayer as u,isSubtypeSublayer as m}from"../../../layers/support/layerUtils.js";import{isISelectableLayerViewWithHighlights as f,isISelectableLayerWithObjectIds as v,isISelectableLayerWithGraphics as _,isISelectableLayer as C,isISelectableLayerBaseWithEditing as I}from"../../../views/support/selectionUtils.js";import{goTo as b}from"../goToUtils.js";import L from"./GroupLayerItem.js";import S from"./LayerItem.js";import{computeEffectiveCount as w,getNestedLayerItems as M,isLayerItem as H,isGroupLayerItem as E,getNestedFeatureItems as A}from"./selectionListUtils.js";const F=100;let T=class extends t{constructor(e){super(e),this._allLayerItems=null,this._groupItemCache=new Map,this._hoverHighlightHandle=null,this._layerEditAbortControllers=new Map,this._layerEditHandles=new r,this._layerItemCache=new Map,this._onChangeAbortController=null,this._updatingHandles=new d,this.filterText=void 0,this.layer=null,this.maxVisibleFeatureCountPerLayer=500,this.selectionManager=null,this._onSelectionChangeController=async()=>{this._cancelOnSelectionChange();const e=new AbortController;this._onChangeAbortController=e,await this._updatingHandles.addPromise(a(this._generateListItems(e))),this._onChangeAbortController===e&&(this._onChangeAbortController=null);const t=this.layer&&this.effectiveSelectionManager?.getSelection(this.layer);t?.length||(this.layer=null)},this._cancelOnSelectionChange=()=>this._onChangeAbortController?.abort(),this._onSelectionChangeDebounced=l(this._onSelectionChangeController,F),this._cancelOnLayerEdit=e=>this._layerEditAbortControllers.get(e)?.abort()}initialize(){this.addHandles([c(()=>[this.view,this.effectiveSelectionManager,...this._sources],()=>{this._onSelectionChange(),this._refreshLayerEditHandles()}),h(()=>this.effectiveSelectionManager?.sources,"change",()=>{this._onSelectionChange(),this._refreshLayerEditHandles()}),h(()=>this.effectiveSelectionManager,"selection-change",()=>this._onSelectionChange())])}destroy(){this._cancelOnSelectionChange(),this.removeTemporaryHighlight(),this._updatingHandles.destroy(),this._layerEditHandles.drain(o),this._layerEditAbortControllers.forEach(s)}get _sources(){return this.effectiveSelectionManager?.sources.toArray()??[]}get activeLayerItem(){const{layer:e}=this;return e&&this.layerItems.find(t=>t.layer===e)}get allLayerItems(){return this._allLayerItems??[]}get effectiveCount(){return w(this.allLayerItems)}get effectiveSelectionManager(){return this.selectionManager??this.view?.selectionManager}get isUpdating(){return!(!this._onChangeAbortController&&!this._updatingHandles.updating)}get layerItems(){return M(this.allLayerItems)}get layerViewMap(){const e=new Map,{view:t}=this;if(!t)return e;for(const r of t.allLayerViews)if(e.set(r.layer.id,r),u(r.layer))for(const t of r.layer.sublayers)e.set(t.id,r);return e}get maxVisibleFeatureCountExceeded(){return this.allLayerItems.some(e=>e.maxVisibleFeatureCountExceeded)}get state(){const{view:e}=this;return e?e.ready?this.effectiveSelectionManager?"ready":"error":"loading":"disabled"}get viewLayersAndTables(){const{view:e}=this;return e?.map?[...e.map.layers.toArray().reverse(),...e.map.tables.toArray().reverse()]:[]}get visibleFeatureCount(){return this.activeLayerItem?.visibleTotal??this.visibleFeatureItems.length}get visibleFeatureItems(){return this.layerItems.flatMap(e=>e.featureItems.filter(e=>e.visible))}get visibleLayerCount(){const{effectiveSelectionManager:e}=this;return e&&0!==e.count?1===e.count||this.activeLayerItem?1:this.layerItems.filter(e=>e.visible).length:0}addTemporaryHighlight({graphic:e,layerView:t}){this.removeTemporaryHighlight(),t&&e&&f(t)&&(this._hoverHighlightHandle=t.highlight(e,{name:"temporary"}))}clear(){this.effectiveSelectionManager?.clear()}deselectFeatureItem({layer:e,graphic:t,objectId:r}){v(e)&&null!=r?this.effectiveSelectionManager?.remove(e,[r]):_(e)&&this.effectiveSelectionManager?.remove(e,[t])}deselectGroupItem(e){e.items.forEach(e=>{H(e)?this.deselectLayerItem(e):this.deselectGroupItem(e)})}deselectLayerItem({layer:e}){this.replace({layer:e,selection:[]})}deselectItem(e){E(e)?this.deselectGroupItem(e):H(e)?this.deselectLayerItem(e):this.deselectFeatureItem(e)}goToItem(e){H(e)||E(e)?this._goTo(A([e]).map(e=>e.graphic)):this._goTo(e.graphic)}layersToItems(e){const{controller:t,groupLayerItem:r,layers:i,promises:o}=e,{_groupItemCache:s,_layerItemCache:a,effectiveSelectionManager:l,viewLayersAndTables:n}=this,c=i??n;if(!l||0===l.count)return[];const h=[];for(const p of c)switch(p.type){case"subtype-group":case"knowledge-graph":case"group":{const e=s.get(p),r=e??new L({layer:p,viewModel:this});e||s.set(p,r),o.push(r.sync({controller:t,promises:o})),h.push(r)}break;default:if(C(p)){const e=l.getSelection(p);if(!e?.length)continue;const i=a.get(p),s=i??new S({groupLayerItem:r,layer:p,viewModel:this});i||a.set(p,s),o.push(s.sync({controller:t,promises:o})),h.push(s)}}return h}removeFromSelection({layer:e,selection:t}){(v(e)||_(e))&&this.effectiveSelectionManager?.remove(e,t)}removeTemporaryHighlight(){this._hoverHighlightHandle=o(this._hoverHighlightHandle)}selectSingleFeatureItem(e){const t=e.identifier;if(this.effectiveSelectionManager)for(const{layer:r}of this.effectiveSelectionManager.selections)this.replace({layer:r,selection:r===e.layer?[t]:[]})}selectSingleGroupItem(e){if(this.effectiveSelectionManager)for(const{layer:t,selection:r}of this.effectiveSelectionManager.selections)this.replace({layer:t,selection:t.parent===e.layer?r:[]})}selectSingleItem(e){E(e)?this.selectSingleGroupItem(e):H(e)?this.selectSingleLayerItem(e):this.selectSingleFeatureItem(e)}selectSingleLayerItem(e){if(this.effectiveSelectionManager)for(const{layer:t,selection:r}of this.effectiveSelectionManager.selections)this.replace({layer:t,selection:t===e.layer?r:[]})}replace({layer:e,selection:t}){(v(e)||_(e))&&this.effectiveSelectionManager?.replace(e,t)}async _goTo(e){const{view:t}=this;if(t)try{await b(t,e)}catch(r){"AbortError"!==r.name&&i.getLogger(this).warn("Failed to go to feature(s)",r)}}async _generateListItems(e){try{this.removeTemporaryHighlight();const t=[],r=this.layersToItems({controller:e,promises:t});t.length>0&&await Promise.all(t),this._onChangeAbortController===e&&(this._allLayerItems=r)}catch(t){i.getLogger(this).warn("Failed updating selection",t)}}_onSelectionChange(){a(this._onSelectionChangeDebounced())}_refreshLayerEditHandles(){const{effectiveSelectionManager:e}=this;if(this._layerEditHandles.drain(o),!e?.sources.length)return;const t=new Set(e.sources.map(e=>m(e)?e.parent:e));for(const r of t)C(r)&&(_(r)?this._layerEditHandles.push(r.graphics.on("change",()=>{this._onLayerEdit(r)})):I(r)&&this._layerEditHandles.push(r.on("edits",e=>{this._onLayerEdit(r,e)})))}async _onLayerEdit(e,t){try{if(this.removeTemporaryHighlight(),this._cancelOnLayerEdit(e),t&&!t.updatedFeatures.some(e=>null!=e.objectId&&!e.error))return;const r=new AbortController;this._layerEditAbortControllers.set(e,r);const i="subtype-group"===e.type||"knowledge-graph"===e.type?this.allLayerItems.find(t=>t.layer===e):this.layerItems.find(t=>t.layer===e);if(i?.layerView){const e=i.layerView;if(await this._onLayerViewUpdate(e),r.signal.aborted)return;i.reset(),this._onSelectionChange()}this._layerEditAbortControllers.get(e)===r&&this._layerEditAbortControllers.delete(e)}catch(r){i.getLogger(this).warn("Failed updating selected features",r)}}async _onLayerViewUpdate(e){await n(p(()=>e.updating),2e3),await p(()=>!e.updating)}};e([y()],T.prototype,"_allLayerItems",void 0),e([y()],T.prototype,"_groupItemCache",void 0),e([y()],T.prototype,"_hoverHighlightHandle",void 0),e([y()],T.prototype,"_layerEditAbortControllers",void 0),e([y()],T.prototype,"_layerEditHandles",void 0),e([y()],T.prototype,"_layerItemCache",void 0),e([y()],T.prototype,"_onChangeAbortController",void 0),e([y()],T.prototype,"_sources",null),e([y()],T.prototype,"_updatingHandles",void 0),e([y()],T.prototype,"activeLayerItem",null),e([y()],T.prototype,"allLayerItems",null),e([y()],T.prototype,"effectiveCount",null),e([y()],T.prototype,"effectiveSelectionManager",null),e([y()],T.prototype,"filterText",void 0),e([y()],T.prototype,"isUpdating",null),e([y()],T.prototype,"layer",void 0),e([y()],T.prototype,"layerItems",null),e([y()],T.prototype,"layerViewMap",null),e([y()],T.prototype,"maxVisibleFeatureCountExceeded",null),e([y()],T.prototype,"maxVisibleFeatureCountPerLayer",void 0),e([y()],T.prototype,"selectionManager",void 0),e([y()],T.prototype,"state",null),e([y()],T.prototype,"view",void 0),e([y()],T.prototype,"viewLayersAndTables",null),e([y()],T.prototype,"visibleFeatureCount",null),e([y()],T.prototype,"visibleFeatureItems",null),e([y()],T.prototype,"visibleLayerCount",null),T=e([g("esri.widgets.support.SelectionList.SelectionListViewModel")],T);const j=T;export{j as default};