// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../chunks/tslib.es6 ../../core/Collection ../../core/CollectionFlattener ../../core/Error ../../core/Logger ../../core/reactiveUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/RandomLCG ../../core/accessorSupport/utils ../../core/accessorSupport/decorators/subclass ../../core/accessorSupport/PropertyOrigin ../support/Sublayer ../support/sublayerUtils".split(" "),function(u,l,x,C,D,E,p,m,J,K,F,G,d,v,H){function I(g,a){const b=[],c={};if(!g)return b; g.forEach(e=>{const h=new v;h.read(e,a);c[h.id]=h;null!=e.parentLayerId&&-1!==e.parentLayerId?(e=c[e.parentLayerId],e.sublayers||(e.sublayers=[]),e.sublayers.unshift(h)):b.unshift(h)});return b}function w(g,a){g&&g.forEach(b=>{a(b);b.sublayers&&b.sublayers.length&&w(b.sublayers,a)})}const q=x.ofType(v);u.SublayersOwner=g=>{g=class extends g{constructor(...a){super(...a);this.allSublayers=new C({getCollections:()=>[this.sublayers],getChildrenFunction(b){return b.sublayers}});this.sublayersSourceJSON= {[d.OriginId.SERVICE]:{},[d.OriginId.PORTAL_ITEM]:{},[d.OriginId.WEB_SCENE]:{},[d.OriginId.WEB_MAP]:{}};this.subtables=null;this.addHandles([p.watch(()=>this.sublayers,(b,c)=>this._handleSublayersChange(b,c),p.sync),p.watch(()=>this.subtables,(b,c)=>this._handleSublayersChange(b,c),p.sync)])}destroy(){this.allSublayers.destroy()}readSublayers(a,b){if(b&&a){var {sublayersSourceJSON:c}=this,e=d.nameToId(b.origin);if(!(ed.OriginId.SERVICE))){this._set("serviceSublayers",this.createSublayersForOrigin("service").sublayers);var {sublayers:h,origin:k}=this.createSublayersForOrigin("web-document");a=F.getProperties(this);a.setDefaultOrigin(k);this._set("sublayers",new q(h));a.setDefaultOrigin("user")}}}findSublayerById(a){return this.allSublayers.find(b=>b.id===a)}createServiceSublayers(){return this.createSublayersForOrigin("service").sublayers}createSublayersForOrigin(a){const b="web-document"=== a?d.nameToId("web-map"):d.nameToId(a);let c=d.OriginId.SERVICE;a=this.sublayersSourceJSON[d.OriginId.SERVICE].layers;let e=this.sublayersSourceJSON[d.OriginId.SERVICE].context,h=null;var k=[d.OriginId.PORTAL_ITEM,d.OriginId.WEB_SCENE,d.OriginId.WEB_MAP].filter(f=>f<=b);for(var r of k)k=this.sublayersSourceJSON[r],H.isSublayerOverhaul(k.layers)&&(c=r,a=k.layers,e=k.context,k.visibleLayers&&(h={visibleLayers:k.visibleLayers,context:k.context}));r=[d.OriginId.PORTAL_ITEM,d.OriginId.WEB_SCENE,d.OriginId.WEB_MAP].filter(f=> f>c&&f<=b);let n=null;for(var t of r){const {layers:f,visibleLayers:y,context:z}=this.sublayersSourceJSON[t];f&&(n={layers:f,context:z});y&&(h={visibleLayers:y,context:z})}t=I(a,e);const A=new Map,B=new Set;if(n)for(const f of n.layers)A.set(f.id,f);if(h?.visibleLayers)for(const f of h.visibleLayers)B.add(f);w(t,f=>{n&&f.read(A.get(f.id),n.context);h&&f.read({defaultVisibility:B.has(f.id)},h.context)});return{origin:d.idToName(c),sublayers:new q({items:t})}}read(a,b){super.read(a,b);this.readSublayers(a, b)}_handleSublayersChange(a,b){b&&(b.forEach(c=>{c.parent=null;c.layer=null}),this.removeHandles("sublayers-owner"));a&&(a.forEach(c=>{c.parent=this;c.layer=this}),this.addHandles([a.on("after-add",({item:c})=>{c.parent=this;c.layer=this}),a.on("after-remove",({item:c})=>{c.parent=null;c.layer=null})],"sublayers-owner"),"tile"===this.type&&this.addHandles(a.on("before-changes",c=>{E.getLogger("esri.layers.TileLayer").error(new D("tilelayer:sublayers-non-modifiable","ISublayer can't be added, moved, or removed from the layer's sublayers", {layer:this}));c.preventDefault()}),"sublayers-owner"))}};l.__decorate([m.property({readOnly:!0})],g.prototype,"allSublayers",void 0);l.__decorate([m.property({readOnly:!0,type:x.ofType(v)})],g.prototype,"serviceSublayers",void 0);l.__decorate([m.property({value:null,type:q,json:{read:!1,write:{allowNull:!0,ignoreOrigin:!0}}})],g.prototype,"sublayers",void 0);l.__decorate([m.property({readOnly:!0})],g.prototype,"sublayersSourceJSON",void 0);l.__decorate([m.property({type:q,json:{read:{source:"tables"}}})], g.prototype,"subtables",void 0);return g=l.__decorate([G.subclass("esri.layers.mixins.SublayersOwner")],g)};u.forEachSublayer=w;Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});