GroupLayer.js 4.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as i}from"../chunks/tslib.es6.js";import e from"../core/CollectionFlattener.js";import{loadAll as t}from"../core/loadAll.js";import{isSome as s}from"../core/maybe.js";import{MultiOriginJSONMixin as r}from"../core/MultiOriginJSONSupport.js";import{watch as o,sync as l}from"../core/reactiveUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import{getProperties as n}from"../core/accessorSupport/utils.js";import"../core/accessorSupport/ensureType.js";import{subclass as p}from"../core/accessorSupport/decorators/subclass.js";import{writer as y}from"../core/accessorSupport/decorators/writer.js";import d from"./Layer.js";import{BlendLayer as h}from"./mixins/BlendLayer.js";import{OperationalLayer as c}from"./mixins/OperationalLayer.js";import{PortalLayer as m}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as b}from"./mixins/ScaleRangeLayer.js";import{layerLookupMap as u}from"./support/lazyLayerLoader.js";import{createFlattenedTablesCollection as v}from"../support/collectionUtils.js";import{LayersMixin as f}from"../support/LayersMixin.js";import{TablesMixin as j}from"../support/TablesMixin.js";import{getLayerJSON as L}from"../webdoc/support/writeUtils.js";let _=class extends(h(b(c(m(j(f(r(d)))))))){constructor(i){super(i),this._visibilityHandles={},this.allLayers=new e({getCollections:()=>[this.layers],getChildrenFunction:i=>"layers"in i?i.layers:null}),this.allTables=v(this),this.fullExtent=void 0,this.operationalLayerType="GroupLayer",this.spatialReference=void 0,this.type="group"}initialize(){this._enforceVisibility(this.visibilityMode,this.visible),this.addHandles(o((()=>this.visible),this._onVisibilityChange.bind(this),l))}_writeLayers(i,e,t,r){const o=[];if(!i)return o;i.forEach((i=>{const e=L(i,r.webmap?r.webmap.getLayerJSONFromResourceInfo(i):null,r);s(e)&&e.layerType&&o.push(e)})),e.layers=o}set portalItem(i){this._set("portalItem",i)}set visibilityMode(i){const e=this._get("visibilityMode")!==i;this._set("visibilityMode",i),e&&this._enforceVisibility(i,this.visible)}load(i){return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Feature Service","Feature Collection","Scene Service"],layerModuleTypeMap:u},i)),Promise.resolve(this)}loadAll(){return t(this,(i=>{i(this.layers,this.tables)}))}layerAdded(i){i.visible&&"exclusive"===this.visibilityMode?this._turnOffOtherLayers(i):"inherited"===this.visibilityMode&&(i.visible=this.visible),this._visibilityHandles[i.uid]=o((()=>i.visible),(e=>this._onChildVisibilityChange(i,e)),l)}layerRemoved(i){const e=this._visibilityHandles[i.uid];e&&(e.remove(),delete this._visibilityHandles[i.uid]),this._enforceVisibility(this.visibilityMode,this.visible)}_turnOffOtherLayers(i){this.layers.forEach((e=>{e!==i&&(e.visible=!1)}))}_enforceVisibility(i,e){if(!n(this).initialized)return;const t=this.layers;let s=t.find((i=>i.visible));switch(i){case"exclusive":t.length&&!s&&(s=t.getItemAt(0),s.visible=!0),this._turnOffOtherLayers(s);break;case"inherited":t.forEach((i=>{i.visible=e}))}}_onVisibilityChange(i){"inherited"===this.visibilityMode&&this.layers.forEach((e=>{e.visible=i}))}_onChildVisibilityChange(i,e){switch(this.visibilityMode){case"exclusive":e?this._turnOffOtherLayers(i):this._isAnyLayerVisible()||(i.visible=!0);break;case"inherited":i.visible=this.visible}}_isAnyLayerVisible(){return this.layers.some((i=>i.visible))}};i([a({readOnly:!0,dependsOn:[]})],_.prototype,"allLayers",void 0),i([a({readOnly:!0})],_.prototype,"allTables",void 0),i([a()],_.prototype,"fullExtent",void 0),i([a({json:{read:!0,write:!0}})],_.prototype,"blendMode",void 0),i([a({json:{read:!1,write:{ignoreOrigin:!0}}})],_.prototype,"layers",void 0),i([y("layers")],_.prototype,"_writeLayers",null),i([a({type:["GroupLayer"]})],_.prototype,"operationalLayerType",void 0),i([a({json:{origins:{"web-document":{read:!1,write:!1}}}})],_.prototype,"portalItem",null),i([a()],_.prototype,"spatialReference",void 0),i([a({json:{read:!1},readOnly:!0,value:"group"})],_.prototype,"type",void 0),i([a({type:["independent","inherited","exclusive"],value:"independent",json:{write:!0,origins:{"web-map":{read:!1,write:!1}}}})],_.prototype,"visibilityMode",null),_=i([p("esri.layers.GroupLayer")],_);const g=_;export{g as default};