UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.25 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Collection.js";import r from"../../core/Evented.js";import s from"../../core/JSONSupport.js";import i from"../../core/Loadable.js";import{on as o,watch as l,whenOnce as a,sync as n}from"../../core/reactiveUtils.js";import{stripHTML as p}from"../../core/string.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import{ensureType as y}from"../../core/accessorSupport/ensureType.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{reader as h}from"../../core/accessorSupport/decorators/reader.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import d from"../../geometry/Extent.js";import{computeExtent as f,sublayersFromJSON as m,fetchService as v,parseKML as b}from"./kmlUtils.js";var j;let S=j=class extends(r.EventedMixin(s.JSONSupportMixin(i))){constructor(...e){super(...e),this.description=null,this.fullExtent=null,this.id=null,this.networkLink=null,this.parent=null,this.sublayers=null,this.title=null,this.sourceJSON=null,this.layer=null,this.addHandles([o((()=>this.sublayers),"after-add",(({item:e})=>{e.parent=this,e.layer=this.layer}),n),o((()=>this.sublayers),"after-remove",(({item:e})=>{e.layer=e.parent=null}),n),l((()=>this.sublayers),((e,t)=>{if(t)for(const r of t)r.layer=r.parent=null;if(e)for(const r of e)r.parent=this,r.layer=this.layer}),n),l((()=>this.layer),(e=>{if(this.sublayers)for(const t of this.sublayers)t.layer=e}),n)])}initialize(){a((()=>this.networkLink)).then((()=>a((()=>!0===this.visible)))).then((()=>this.load()))}load(e){if(!this.networkLink)return;if(this.networkLink.viewFormat)return;const r=null!=e?e.signal:null,s=this._fetchService(this._get("networkLink")?.href??"",r).then((e=>{const r=f(e.sublayers);this.fullExtent=d.fromJSON(r),this.sourceJSON=e;const s=y(t.ofType(j),m(j,e));this.sublayers?this.sublayers.addMany(s):this.sublayers=s,this.layer?.emit("sublayer-update"),this.layer&&this.layer.notifyChange("visibleSublayers")}));return this.addResolvingPromise(s),Promise.resolve(this)}get visible(){return this._get("visible")}set visible(e){this._get("visible")!==e&&(this._set("visible",e),this.layer&&this.layer.notifyChange("visibleSublayers"))}readVisible(e,t){return!!t.visibility}_fetchService(e,t){return v(e,this.layer.outSpatialReference,this.layer.refreshInterval,t).then((e=>b(e.data)))}};e([u()],S.prototype,"description",void 0),e([u({type:d})],S.prototype,"fullExtent",void 0),e([u()],S.prototype,"id",void 0),e([u({readOnly:!0,value:null})],S.prototype,"networkLink",void 0),e([u({json:{write:{allowNull:!0}}})],S.prototype,"parent",void 0),e([u({type:t.ofType(S),json:{write:{allowNull:!0}}})],S.prototype,"sublayers",void 0),e([u({value:null,json:{read:{source:"name",reader:e=>p(e)}}})],S.prototype,"title",void 0),e([u({value:!0})],S.prototype,"visible",null),e([h("visible",["visibility"])],S.prototype,"readVisible",null),e([u()],S.prototype,"sourceJSON",void 0),e([u()],S.prototype,"layer",void 0),S=j=e([c("esri.layers.support.KMLSublayer")],S);const k=S;export{k as default};