@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 6 kB
JavaScript
import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../core/Accessor.js";import i from"../../core/Collection.js";import{HandleOwnerMixin as s}from"../../core/HandleOwner.js";import{IdentifiableMixin as r}from"../../core/Identifiable.js";import{isSome as o}from"../../core/maybe.js";import{watch as n,initial as l}from"../../core/reactiveUtils.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import{cast as h}from"../../core/accessorSupport/decorators/cast.js";import"../../core/arrayUtils.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import c from"../../support/actions/ActionBase.js";import d from"../../support/actions/ActionButton.js";import u from"../../support/actions/ActionSlider.js";import y from"../../support/actions/ActionToggle.js";import m from"./ListItemPanel.js";import{isLayerOutsideScaleRange as b,findLayerVisibilityMode as v,findLayerListMode as f,canDisplayLayer as w,getNormalizedChildLayerProperty as g}from"./support/layerListUtils.js";var S;const C=i.ofType({key:"type",defaultKeyValue:"button",base:c,typeMap:{button:d,toggle:y,slider:u}}),_=i.ofType(C),P="layer",j="child-list-mode",O="hide",I="esri.widgets.LayerList.ListItem";let L=S=class extends(r(s(e))){constructor(t){super(t),this.actionsSections=new _,this.actionsOpen=!1,this.checkPublishStatusEnabled=!1,this.children=new(i.ofType(S)),this.childrenSortable=!0,this.hidden=!1,this.layer=null,this.layerView=null,this.listItemCreatedFunction=null,this.open=!1,this.panel=null,this.parent=null,this.sortable=!0,this.view=null}initialize(){if(this.handles.add([n((()=>this.layer),(t=>this._watchLayerProperties(t)),l),n((()=>this.checkPublishStatusEnabled),(t=>this._updateChildrenPublishing(t)),l),n((()=>this.view),(t=>this._updateChildrenView(t)),l),n((()=>this.panel),(t=>this._setListItemOnPanel(t)),l),n((()=>[this.layer,this.view]),(()=>this._getLayerView()),l)]),"function"==typeof this.listItemCreatedFunction){const t={item:this};this.listItemCreatedFunction.call(null,t)}}destroy(){this.view=null}get connectionStatus(){const{layerView:t,publishing:e}=this;if(!e&&t&&"connectionStatus"in t)return t.connectionStatus}get error(){return this.layer?.loadError}get incompatible(){const{layerView:t}=this;return!(!t||!("spatialReferenceSupported"in t))&&!t.spatialReferenceSupported}castPanel(t){return this.get("panel.open")&&!t.hasOwnProperty("open")&&(t.open=!0),t?new m(t):null}get title(){const t=this.get("layer.layer");return(!t||t&&this.get("layer.layer.loaded"))&&this.get("layer.title")||this.get("layer.attributes.title")||""}set title(t){this._override("title",t)}get publishing(){const{layer:t,checkPublishStatusEnabled:e}=this;return e&&t&&"publishingInfo"in t&&"publishing"===t.publishingInfo?.status}get updating(){const{layerView:t,connectionStatus:e,layer:i,publishing:s}=this;return!s&&!e&&(t?t.updating:"loading"===i?.loadStatus||!1)}get visible(){return this.layer?.visible}set visible(t){const e=this.layer;e&&(e.visible=t)}get visibleAtCurrentScale(){return!b(this.layer,this.get("view.scale"))}get visibilityMode(){return v(this.layer)}clone(){return new S({actionsSections:this.actionsSections.clone(),actionsOpen:this.actionsOpen,checkPublishStatusEnabled:this.checkPublishStatusEnabled,children:this.children.clone(),layer:this.layer,listItemCreatedFunction:this.listItemCreatedFunction,open:this.open,panel:this.panel,title:this.title,view:this.view,visible:this.visible})}_setListItemOnPanel(t){t&&(t.listItem=this)}_updateChildrenPublishing(t){const e=this.children;e&&e.forEach((e=>e.checkPublishStatusEnabled=t))}_updateChildrenView(t){const e=this.children;e&&e.forEach((e=>e.view=t))}_addChildren(t){if(this.handles.remove(j),this.children.removeAll(),!t)return;t.forEach((e=>{this.handles.add(n((()=>e.listMode),(()=>this._addChildren(t))),j)}));const e=t.filter((t=>f(t)!==O));this.children.addMany(this._makeChildren(e))}_watchSublayerChanges(t){t&&this.handles.add(t.on("change",(()=>{this._addChildren(t)})),P)}_initializeChildLayers(t){this._addChildren(t),this._watchSublayerChanges(t)}_makeChildren(t){return t.map((t=>w(t)?new S({layer:t,checkPublishStatusEnabled:this.checkPublishStatusEnabled,listItemCreatedFunction:this.listItemCreatedFunction,parent:this,view:this.view}):null)).filter(o).reverse()}_watchLayerProperties(t){if(!this.handles)return;if(this.handles.remove(P),this.handles.remove(j),!t)return;this.handles.add(n((()=>t.listMode),(()=>this._watchLayerProperties(t))),P);if("hide-children"===f(t))return void this.children.removeAll();const e=g(t);e&&this.handles.add(n((()=>t[e]),(()=>{t.hasOwnProperty(e)&&this._initializeChildLayers(t[e])}),l),P)}async _getLayerView(){const{layer:t,view:e}=this;if(t&&e)try{const i=await e.whenLayerView(t);if(i.layer!==this.layer)return;this._set("layerView",i)}catch{}}};t([a({type:_})],L.prototype,"actionsSections",void 0),t([a()],L.prototype,"actionsOpen",void 0),t([a()],L.prototype,"checkPublishStatusEnabled",void 0),t([a({type:i})],L.prototype,"children",void 0),t([a()],L.prototype,"childrenSortable",void 0),t([a({readOnly:!0})],L.prototype,"connectionStatus",null),t([a({readOnly:!0})],L.prototype,"error",null),t([a()],L.prototype,"hidden",void 0),t([a({readOnly:!0})],L.prototype,"incompatible",null),t([a()],L.prototype,"layer",void 0),t([a({readOnly:!0})],L.prototype,"layerView",void 0),t([a()],L.prototype,"listItemCreatedFunction",void 0),t([a()],L.prototype,"open",void 0),t([a({type:m})],L.prototype,"panel",void 0),t([h("panel")],L.prototype,"castPanel",null),t([a()],L.prototype,"parent",void 0),t([a()],L.prototype,"sortable",void 0),t([a()],L.prototype,"title",null),t([a({readOnly:!0})],L.prototype,"publishing",null),t([a({readOnly:!0})],L.prototype,"updating",null),t([a()],L.prototype,"view",void 0),t([a()],L.prototype,"visible",null),t([a({readOnly:!0})],L.prototype,"visibleAtCurrentScale",null),t([a({readOnly:!0})],L.prototype,"visibilityMode",null),L=S=t([p(I)],L);const k=L;export{k as default};