@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.15 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Collection.js";import{EventedMixin as r}from"../../core/Evented.js";import{JSONSupportMixin as i}from"../../core/JSONSupport.js";import{Loadable as s}from"../../core/Loadable.js";import{on as o,sync as l,watch as a,whenOnce as n}from"../../core/reactiveUtils.js";import{stripHTML as p}from"../../core/string.js";import{property as u,subclass as h}from"../../core/accessorSupport/decorators.js";import{ensureType as y}from"../../core/accessorSupport/ensureType.js";import c from"../../geometry/Extent.js";import f from"../../graphic/KMLGraphicOrigin.js";import{computeExtent as d,sublayersFromJSON as m,fetchService as v,parseKML as b}from"./kmlUtils.js";import{reader as g}from"../../core/accessorSupport/decorators/reader.js";var j;let S=j=class extends(r(i(s))){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},l),o(()=>this.sublayers,"after-remove",({item:e})=>{e.layer=e.parent=null},l),a(()=>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},l),a(()=>this.layer,e=>{if(this.sublayers)for(const t of this.sublayers)t.layer=e},l)])}initialize(){n(()=>this.networkLink).then(()=>n(()=>!0===this.visible)).then(()=>this.load())}load(e){if(!this.networkLink)return;if(this.networkLink.viewFormat)return;const r=null!=e?e.signal:null,i=this._fetchService(this._get("networkLink")?.href??"",r).then(e=>{const r=d(e.sublayers);this.fullExtent=c.fromJSON(r),this.sourceJSON=e;const i=y(t.ofType(j),m(j,e));this.sublayers?this.sublayers.addMany(i):this.sublayers=i,this.layer?.emit("sublayer-update"),this.layer&&this.layer.notifyChange("visibleSublayers")});return this.addResolvingPromise(i),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}get origin(){return this.layer?new f(this.layer,this):null}_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:c})],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([g("visible",["visibility"])],S.prototype,"readVisible",null),e([u()],S.prototype,"sourceJSON",void 0),e([u()],S.prototype,"layer",void 0),e([u()],S.prototype,"origin",null),S=j=e([h("esri.layers.support.KMLSublayer")],S);export{S as default};