@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.37 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/Collection.js";import s from"../../core/Evented.js";import{watch as i,on as o,initial as a}from"../../core/reactiveUtils.js";import{property as r}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import c from"../LayerList/ListItem.js";import{findLayerListMode as d}from"../LayerList/support/layerListUtils.js";const m={layerListMode:"layer-list-mode"},n="hide",h=e.ofType(c);let p=class extends s.EventedAccessor{constructor(t){super(t),this.catalogItems=new h,this.checkPublishStatusEnabled=!1,this.catalogLayer=null,this.listItemCreatedFunction=null,this.listModeDisabled=!1,this.view=null}initialize(){this.addHandles([i((()=>[this.catalogLayer?.loaded,this.view?.ready]),(()=>this._compileList()),a),o((()=>this.catalogLayer?.dynamicGroupLayer.layers),"change",(()=>this._compileList())),i((()=>[this.listItemCreatedFunction,this.checkPublishStatusEnabled,this.listModeDisabled]),(()=>this._recompileList()))])}destroy(){this.view=null,this.catalogItems.removeAll()}get state(){const{view:t,catalogLayer:e}=this;return t?.ready&&e?.loaded?"ready":t&&e?"loading":"disabled"}get totalItems(){return this.catalogItems.flatten((t=>t.children)).length}triggerAction(t,e){t&&!t.disabled&&this.emit("trigger-action",{action:t,item:e})}_createListItem(t){const{view:e,listItemCreatedFunction:s,checkPublishStatusEnabled:i,listModeDisabled:o}=this;return new c({checkPublishStatusEnabled:i,listModeDisabled:o,layer:t,listItemCreatedFunction:s,view:e})}_removeAllItems(){this.catalogItems.removeAll()}_getViewableLayers(t){return t?this.listModeDisabled?t:t.filter((t=>d(t)!==n)):void 0}_watchLayersListMode(t){this.removeHandles(m.layerListMode),t&&!this.listModeDisabled&&this.addHandles(i((()=>t.filter((t=>"listMode"in t)).map((t=>t.listMode)).toArray()),(()=>this._compileList())),m.layerListMode)}_compileList(){const{catalogLayer:t}=this;if(!t?.loaded)return;const e=t?.dynamicGroupLayer.layers;this._watchLayersListMode(e);const s=this._getViewableLayers(e);s?.length?(this._createNewItems(s),this._removeItems(s),this._sortItems(s)):this._removeAllItems()}_createNewItems(t){const{catalogItems:e}=this;t.forEach((t=>{e.some((e=>e.layer===t))||e.add(this._createListItem(t))}))}_removeItems(t){const{catalogItems:e}=this,s=[];e.forEach((e=>{e&&t?.includes(e.layer)||s.push(e)})),e.removeMany(s)}_sortItems(t){const{catalogItems:e}=this;e.sort(((e,s)=>{const i=t.indexOf(e.layer),o=t.indexOf(s.layer);return i>o?-1:i<o?1:0}))}_recompileList(){this._removeAllItems(),this._compileList()}};t([r({type:h})],p.prototype,"catalogItems",void 0),t([r()],p.prototype,"checkPublishStatusEnabled",void 0),t([r()],p.prototype,"catalogLayer",void 0),t([r()],p.prototype,"listItemCreatedFunction",void 0),t([r({nonNullable:!0})],p.prototype,"listModeDisabled",void 0),t([r({readOnly:!0})],p.prototype,"state",null),t([r()],p.prototype,"totalItems",null),t([r()],p.prototype,"view",void 0),p=t([l("esri.widgets.CatalogLayerList.CatalogLayerListViewModel")],p);const y=p;export{y as default};