UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 6.93 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import{isSome as i}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import{IdentifiableMixin as l}from"../../core/Identifiable.js";import{watch as r,initial as n}from"../../core/reactiveUtils.js";import{property as o,cast as a,subclass as h}from"../../core/accessorSupport/decorators.js";import{get as d}from"../../core/accessorSupport/get.js";import p from"../../support/actions/ActionBase.js";import c from"../../support/actions/ActionButton.js";import u from"../../support/actions/ActionToggle.js";import y from"./ListItemPanel.js";import{isLayerOutsideScaleRange as b,findLayerVisibilityMode as m,findLayerListMode as v,canDisplayLayer as f,getNormalizedChildLayerProperty as g}from"./support/layerListUtils.js";var C;const w=s.ofType({key:"type",defaultKeyValue:"button",base:p,typeMap:{button:c,toggle:u}}),_=s.ofType(w),S="layer",M="child-list-mode",P="hide";let O=C=class extends(l(t)){constructor(e){super(e),this.actionsSections=new _,this.actionsOpen=!1,this.checkPublishStatusEnabled=!1,this.children=new(s.ofType(C)),this.childrenSortable=!0,this.hidden=!1,this.layer=null,this.listItemCreatedFunction=null,this.listModeDisabled=!1,this.open=!1,this.parent=null,this.view=null}initialize(){if(this.addHandles([r(()=>[this.layer,this.layer?.listMode,this.listModeDisabled],()=>this._watchLayerProperties(this.layer),n),r(()=>this.checkPublishStatusEnabled,e=>this._updateChildrenPublishing(e),n),r(()=>this.view,e=>this._updateChildrenView(e),n),r(()=>this.panel,e=>this._setListItemOnPanel(e),n)]),"function"==typeof this.listItemCreatedFunction){const e={item:this};this.listItemCreatedFunction.call(null,e)}}destroy(){this.panel?.destroy(),this.children.destroyAll(),this.view=null}get connectionStatus(){const{layerView:e,publishing:t}=this;if(!t&&e&&"connectionStatus"in e)return e.connectionStatus}get error(){return this.layer?.loadError}get incompatible(){const{layerView:e}=this;return!(!e||!("spatialReferenceSupported"in e))&&!e.spatialReferenceSupported}get layerView(){const{layer:e,view:t}=this;if(!e||!t||"sublayer"===e.type)return null;const i="subtype-sublayer"===e.type?e.parent:e;return t.allLayerViews.find(e=>e.layer===i)??null}set panel(e){const t=this._get("panel");e!==t&&e&&t?.destroy(),this._set("panel",e)}castPanel(e){return this.panel?.open&&!e.hasOwnProperty("open")&&(e.open=!0),e?new y(e):null}get sortable(){return"knowledge-graph-sublayer"!==this.layer?.type&&this._get("sortable")}set sortable(e){this._set("sortable",e)}get title(){const e=d(this,"layer.layer");return(!e||e&&d(this,"layer.layer.loaded"))&&d(this,"layer.title")||d(this,"layer.attributes.title")||""}set title(e){this._override("title",e)}get publishing(){const{layer:e,checkPublishStatusEnabled:t}=this;return!!(t&&e&&"publishingInfo"in e&&"publishing"===e.publishingInfo?.status)}get updating(){const{layerView:e,connectionStatus:t,layer:i,publishing:s}=this;return!s&&!t&&(e?e.updating:"loading"===i?.loadStatus||!1)}get visible(){return!!this.layer?.visible}set visible(e){const t=this.layer;t&&(t.visible=e)}get visibleAtCurrentScale(){return this.layerView?.visibleAtCurrentScale??!b(this.layer,this.view?.scale)}get visibleAtCurrentTimeExtent(){return this.layerView?.visibleAtCurrentTimeExtent??!0}get visibilityMode(){return m(this.layer)}clone(){return new C({actionsSections:this.actionsSections.clone(),actionsOpen:this.actionsOpen,checkPublishStatusEnabled:this.checkPublishStatusEnabled,children:this.children.clone(),childrenSortable:this.childrenSortable,hidden:this.hidden,layer:this.layer,listItemCreatedFunction:this.listItemCreatedFunction,listModeDisabled:this.listModeDisabled,open:this.open,panel:this.panel,parent:this.parent,sortable:this.sortable,title:this.title,view:this.view,visible:this.visible})}_setListItemOnPanel(e){e&&(e.listItem=this)}_updateChildrenPublishing(e){this.children?.forEach(t=>t.checkPublishStatusEnabled=e)}_updateChildrenView(e){const t=this.children;t&&t.forEach(t=>t.view=e)}_createChildren(e){const{listModeDisabled:t,children:i}=this,s=e.filter(e=>!i.some(t=>t.layer===e));i.addMany(this._createChildItems(s,t))}_destroyChildren(e){const{children:t}=this,i=t.filter(t=>!!t.layer&&!e.includes(t.layer));t.destroyMany(i)}_sortChildren(e){this.children.sort((t,i)=>e.indexOf(i.layer)-e.indexOf(t.layer))}_destroyAllChildren(){this.removeHandles(M),this.children.destroyAll()}_watchChildLayerListMode(e){this.removeHandles(M),this.listModeDisabled||this.addHandles(e.toArray().map(t=>r(()=>t.listMode,()=>this._compileChildren(e))),M)}_compileChildren(e){const t=this.listModeDisabled?e:e?.filter(e=>v(e)!==P);e?.length?(this._createChildren(t),this._destroyChildren(t),this._sortChildren(t),this._watchChildLayerListMode(e)):this._destroyAllChildren()}_watchSublayerChanges(e){e&&this.addHandles(e.on("change",()=>this._compileChildren(e)),S)}_initializeChildLayers(e){this._compileChildren(e),this._watchSublayerChanges(e)}_createChildItems(e,t){return e.reverse().map(e=>t||f(e)?new C({layer:e,checkPublishStatusEnabled:this.checkPublishStatusEnabled,listItemCreatedFunction:this.listItemCreatedFunction,listModeDisabled:this.listModeDisabled,parent:this,view:this.view}):null).filter(i)}_watchLayerProperties(e){if(this.removeHandles(S),this.removeHandles(M),!e)return;if("hide-children"===(!this.listModeDisabled&&v(e)))return void this.children.destroyAll();const t=g(e);t&&this.addHandles(r(()=>e[t],i=>{e.hasOwnProperty(t)&&this._initializeChildLayers(i)},n),S)}};e([o({type:_})],O.prototype,"actionsSections",void 0),e([o()],O.prototype,"actionsOpen",void 0),e([o()],O.prototype,"checkPublishStatusEnabled",void 0),e([o({type:s.ofType(O)})],O.prototype,"children",void 0),e([o()],O.prototype,"childrenSortable",void 0),e([o({readOnly:!0})],O.prototype,"connectionStatus",null),e([o({readOnly:!0})],O.prototype,"error",null),e([o()],O.prototype,"hidden",void 0),e([o({readOnly:!0})],O.prototype,"incompatible",null),e([o()],O.prototype,"layer",void 0),e([o({readOnly:!0})],O.prototype,"layerView",null),e([o()],O.prototype,"listItemCreatedFunction",void 0),e([o({nonNullable:!0})],O.prototype,"listModeDisabled",void 0),e([o()],O.prototype,"open",void 0),e([o({type:y})],O.prototype,"panel",null),e([a("panel")],O.prototype,"castPanel",null),e([o()],O.prototype,"parent",void 0),e([o({value:!0})],O.prototype,"sortable",null),e([o()],O.prototype,"title",null),e([o({readOnly:!0})],O.prototype,"publishing",null),e([o({readOnly:!0})],O.prototype,"updating",null),e([o()],O.prototype,"view",void 0),e([o()],O.prototype,"visible",null),e([o({readOnly:!0})],O.prototype,"visibleAtCurrentScale",null),e([o({readOnly:!0})],O.prototype,"visibleAtCurrentTimeExtent",null),e([o({readOnly:!0})],O.prototype,"visibilityMode",null),O=C=e([h("esri.widgets.LayerList.ListItem")],O);const I=O;export{I as default};