12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../chunks/tslib.es6.js";import r from"../core/Collection.js";import{referenceSetter as t}from"../core/collectionUtils.js";import s from"../core/Logger.js";import{isPromiseLike as o}from"../core/promiseUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{subclass as i}from"../core/accessorSupport/decorators/subclass.js";import l from"../layers/Layer.js";function n(e,r,t){let s,o;if(e)for(let a=0,i=e.length;a<i;a++){if(s=e.getItemAt(a),s[r]===t)return s;if("group"===s?.type&&(o=n(s.layers,r,t),o))return o}}const d=d=>{let y=class extends d{constructor(...e){super(...e),this.layers=new r;const t=e=>{e.parent&&"remove"in e.parent&&e.parent.remove(e)},o=e=>{e.parent=this,this.layerAdded(e),"elevation"!==e.type&&"base-elevation"!==e.type||s.getLogger(this.declaredClass).error(`Layer 'title:${e.title}, id:${e.id}' of type '${e.type}' is not supported as an operational layer and will therefore be ignored.`)},a=e=>{e.parent=null,this.layerRemoved(e)};this.layers.on("before-add",(e=>t(e.item))),this.layers.on("after-add",(e=>o(e.item))),this.layers.on("after-remove",(e=>a(e.item)))}destroy(){const e=this.layers.removeAll();for(const r of e)this.layerRemoved(r),r.destroy();this.layers.destroy()}set layers(e){this._set("layers",t(e,this._get("layers")))}add(e,r){const t=this.layers;if(r=t.getNextIndex(r),e instanceof l){const s=e;s.parent===this?this.reorder(s,r):t.add(s,r)}else o(e)?e.then((e=>{this.destroyed||this.add(e,r)})):s.getLogger(this.declaredClass).error("#add()","The item being added is not a Layer or a Promise that resolves to a Layer.")}addMany(e,r){const t=this.layers;r=t.getNextIndex(r),e.slice().forEach((e=>{e.parent!==this?(t.add(e,r),r+=1):this.reorder(e,r)}))}findLayerById(e){return n(this.layers,"id",e)}findLayerByUid(e){return n(this.layers,"uid",e)}remove(e){return this.layers.remove(e)}removeMany(e){return this.layers.removeMany(e)}removeAll(){return this.layers.removeAll()}reorder(e,r){return this.layers.reorder(e,r)}layerAdded(e){}layerRemoved(e){}};return e([a()],y.prototype,"layers",null),y=e([i("esri.support.LayersMixin")],y),y};export{d as LayersMixin};
|