@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.18 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../core/CollectionFlattener.js";import{loadAll as i}from"../core/loadAll.js";import r from"../core/Logger.js";import{MultiOriginJSONSupportMixin as s}from"../core/MultiOriginJSONSupport.js";import{debounce as o,throwIfAbortError as a}from"../core/promiseUtils.js";import{watch as l,syncAndInitial as n,on as p,sync as y}from"../core/reactiveUtils.js";import{property as d,subclass as h}from"../core/accessorSupport/decorators.js";import{getProperties as m}from"../core/accessorSupport/utils.js";import c from"../geometry/SpatialReference.js";import u from"./Layer.js";import{BlendLayer as b}from"./mixins/BlendLayer.js";import{OperationalLayer as v}from"./mixins/OperationalLayer.js";import{PortalLayer as f}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as L}from"./mixins/ScaleRangeLayer.js";import{populateGroupLayer as g}from"./support/layersCreator.js";import{layerLookupMap as j}from"./support/lazyLayerLoader.js";import w from"../portal/PortalItem.js";import{createFlattenedTablesCollection as I}from"../support/collectionUtils.js";import{LayersMixin as _}from"../support/LayersMixin.js";import{TablesMixin as O}from"../support/TablesMixin.js";import{WebSceneTag as S}from"../support/tagSymbols.js";import{beforeSave as M}from"../webdoc/support/saveUtils.js";import{getLayerJSON as x}from"../webdoc/support/writeUtils.js";import{writer as P}from"../core/accessorSupport/decorators/writer.js";import{reader as C}from"../core/accessorSupport/decorators/reader.js";let V=class extends(b(L(v(f(O(_(s(u)))))))){constructor(e){super(e),this._allLayers=new t({getCollections:()=>[this.layers],getChildrenFunction:e=>"layers"in e?e.layers:null}),this.allTables=I(this),this.fullExtent=void 0,this.operationalLayerType="GroupLayer",this.spatialReference=void 0,this.type="group",this._debouncedSaveOperations=o(async(e,t,i)=>{const{save:r,saveAs:s}=await import("./save/groupLayerUtils.js");switch(e){case 0:return r(this,t);case 1:return s(this,i,t)}})}initialize(){this._enforceVisibility(this.visibilityMode,this.visible),this.addHandles([l(()=>{let e=this.parent;for(;e&&"parent"in e&&e.parent;)e=e.parent;return e&&S in e},e=>{const t="prevent-adding-tables";this.removeHandles(t),e&&(this.tables.removeAll(),this.addHandles(p(()=>this.tables,"before-add",e=>{e.preventDefault(),r.getLogger(this).errorOnce("tables","tables in group layers in a webscene are not supported. Please move the tables from the group layer to the webscene if you want to persist them.")}),t))},n),l(()=>this.visible,this._onVisibilityChange.bind(this),y)])}destroy(){this.allLayers.destroy(),this.allTables.destroy()}get allLayers(){return this._allLayers}get sourceIsPortalItem(){return this.portalItem&&7===this.originIdOf("portalItem")}_writeLayers(e,t,i,r){const s=[];if(!e)return s;e.forEach(e=>{const t=x(e,r.webmap?r.webmap.getLayerJSONFromResourceInfo(e):null,r);t?.layerType&&s.push(t)}),t.layers=s}set portalItem(e){this._set("portalItem",e)}readPortalItem(e,t,i){const{itemId:r,layerType:s}=t;if("GroupLayer"===s&&r)return new w({id:r,portal:i?.portal})}writePortalItem(e,t){e?.id&&(t.itemId=e.id)}set visibilityMode(e){const t=this._get("visibilityMode")!==e;this._set("visibilityMode",e),t&&this._enforceVisibility(e,this.visible)}async beforeSave(){return M(this)}load(e){const t=this.loadFromPortal({supportedTypes:["Feature Service","Feature Collection","Group Layer","Scene Service","Video Service"],layerModuleTypeMap:j,populateGroupLayer:g},e).catch(e=>{if(a(e),this.sourceIsPortalItem)throw e});return this.addResolvingPromise(t),Promise.resolve(this)}async loadAll(){return i(this,e=>{e(this.layers,this.tables)})}async save(e){return this._debouncedSaveOperations(0,e)}async saveAs(e,t){return this._debouncedSaveOperations(1,t,e)}layerAdded(e){e.visible&&"exclusive"===this.visibilityMode?this._turnOffOtherLayers(e):"inherited"===this.visibilityMode&&(e.visible=this.visible),this.hasHandles(e.uid)?console.error(`Layer read to Grouplayer: uid=${e.uid}`):this.addHandles(l(()=>e.visible,t=>this._onChildVisibilityChange(e,t),y),e.uid)}layerRemoved(e){this.removeHandles(e.uid),this._enforceVisibility(this.visibilityMode,this.visible)}_turnOffOtherLayers(e){this.layers.forEach(t=>{t!==e&&(t.visible=!1)})}_enforceVisibility(e,t){if(!m(this).initialized)return;const i=this.layers;let r=i.find(e=>e.visible);switch(e){case"exclusive":i.length&&!r&&(r=i.at(0),r.visible=!0),this._turnOffOtherLayers(r);break;case"inherited":i.forEach(e=>{e.visible=t})}}_onVisibilityChange(e){"inherited"===this.visibilityMode&&this.layers.forEach(t=>{t.visible=e})}_onChildVisibilityChange(e,t){switch(this.visibilityMode){case"exclusive":t?this._turnOffOtherLayers(e):this._isAnyLayerVisible()||(e.visible=!0);break;case"inherited":e.visible=this.visible}}_isAnyLayerVisible(){return this.layers.some(e=>e.visible)}};e([d({readOnly:!0})],V.prototype,"allLayers",null),e([d({readOnly:!0})],V.prototype,"allTables",void 0),e([d({json:{read:!0,write:!0}})],V.prototype,"blendMode",void 0),e([d()],V.prototype,"fullExtent",void 0),e([d({readOnly:!0})],V.prototype,"sourceIsPortalItem",null),e([d({json:{read:!1,write:{ignoreOrigin:!0}}})],V.prototype,"layers",void 0),e([P("layers")],V.prototype,"_writeLayers",null),e([d({type:["GroupLayer"]})],V.prototype,"operationalLayerType",void 0),e([d({json:{origins:{"web-map":{read:!1,write:{overridePolicy(e,t,i){return{enabled:"Group Layer"===e?.type&&i?.initiator!==this}}}},"web-scene":{read:!1,write:!1}}}})],V.prototype,"portalItem",null),e([C("web-map","portalItem",["itemId"])],V.prototype,"readPortalItem",null),e([P("web-map","portalItem",{itemId:{type:String}})],V.prototype,"writePortalItem",null),e([d({type:c})],V.prototype,"spatialReference",void 0),e([d({json:{read:!1},readOnly:!0,value:"group"})],V.prototype,"type",void 0),e([d({type:["independent","inherited","exclusive"],value:"independent",json:{write:!0,origins:{"web-map":{type:["independent","exclusive"],write:(e,t,i)=>{"inherited"!==e&&(t[i]=e)}}}}})],V.prototype,"visibilityMode",null),V=e([h("esri.layers.GroupLayer")],V);const T=V;export{T as default};