KMLLayer.js 4.7 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import"../geometry.js";import r from"../core/Collection.js";import t from"../core/CollectionFlattener.js";import{isSome as o}from"../core/maybe.js";import{MultiOriginJSONMixin as s}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as i}from"../core/promiseUtils.js";import{watch as l,sync as a}from"../core/reactiveUtils.js";import{getFilename as p}from"../core/urlUtils.js";import{property as n}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{reader as u}from"../core/accessorSupport/decorators/reader.js";import{subclass as y}from"../core/accessorSupport/decorators/subclass.js";import{writer as m}from"../core/accessorSupport/decorators/writer.js";import c from"../geometry/SpatialReference.js";import d from"./Layer.js";import{BlendLayer as h}from"./mixins/BlendLayer.js";import{OperationalLayer as f}from"./mixins/OperationalLayer.js";import{PortalLayer as b}from"./mixins/PortalLayer.js";import{RefreshableLayer as j}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as v}from"./mixins/ScaleRangeLayer.js";import{url as g}from"./support/commonProperties.js";import S from"./support/KMLSublayer.js";import{sublayersFromJSON as x,fetchService as L,parseKML as E}from"./support/kmlUtils.js";import w from"../geometry/Extent.js";const F=["kml","xml"];let O=class extends(h(j(v(f(b(s(d))))))){constructor(...e){super(...e),this._visibleFolders=[],this.allSublayers=new t({getCollections:()=>[this.sublayers],getChildrenFunction:e=>e.sublayers}),this.outSpatialReference=c.WGS84,this.path=null,this.legendEnabled=!1,this.operationalLayerType="KML",this.sublayers=null,this.type="kml",this.url=null}initialize(){this.addHandles([l((()=>this.sublayers),((e,r)=>{r&&r.forEach((e=>{e.parent=null,e.layer=null})),e&&e.forEach((e=>{e.parent=this,e.layer=this}))}),a),this.on("sublayer-update",(()=>this.notifyChange("fullExtent")))])}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}readSublayersFromItemOrWebMap(e,r){this._visibleFolders=r.visibleFolders}readSublayers(e,r,t){return x(S,r,t,this._visibleFolders)}writeSublayers(e,r){const t=[],o=e.toArray();for(;o.length;){const e=o[0];e.networkLink||(e.visible&&t.push(e.id),e.sublayers&&o.push(...e.sublayers.toArray())),o.shift()}r.visibleFolders=t}get title(){const e=this._get("title");return e&&"defaults"!==this.originOf("title")?e:this.url?p(this.url,F)||"KML":e||""}set title(e){this._set("title",e)}get visibleSublayers(){const e=this.sublayers,r=[],t=e=>{e.visible&&(r.push(e),e.sublayers&&e.sublayers.forEach(t))};return e&&e.forEach(t),r}get fullExtent(){return this._recomputeFullExtent()}load(e){const r=o(e)?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["KML"],supportsData:!1},e).catch(i).then((()=>this._fetchService(r)))),Promise.resolve(this)}destroy(){super.destroy(),this.allSublayers.destroy()}async _fetchService(e){const r=await Promise.resolve().then((()=>this.resourceInfo?{ssl:!1,data:this.resourceInfo}:L(this.url??"",this.outSpatialReference,this.refreshInterval,e))),t=E(r.data);t&&this.read(t,{origin:"service"})}_recomputeFullExtent(){let e=null;o(this.extent)&&(e=this.extent.clone());const r=t=>{if(t.sublayers)for(const s of t.sublayers.items)r(s),s.visible&&s.fullExtent&&(o(e)?e.union(s.fullExtent):e=s.fullExtent.clone())};return r(this),e}};e([n({readOnly:!0})],O.prototype,"allSublayers",void 0),e([n({type:c})],O.prototype,"outSpatialReference",void 0),e([n({type:String,json:{origins:{"web-scene":{read:!0,write:!0}},read:!1}})],O.prototype,"path",void 0),e([n({readOnly:!0,json:{read:!1,write:!1}})],O.prototype,"legendEnabled",void 0),e([n({type:["show","hide","hide-children"]})],O.prototype,"listMode",void 0),e([n({type:["KML"]})],O.prototype,"operationalLayerType",void 0),e([n({})],O.prototype,"resourceInfo",void 0),e([n({type:r.ofType(S),json:{write:{ignoreOrigin:!0}}})],O.prototype,"sublayers",void 0),e([u(["web-map","portal-item"],"sublayers",["visibleFolders"])],O.prototype,"readSublayersFromItemOrWebMap",null),e([u("service","sublayers",["sublayers"])],O.prototype,"readSublayers",null),e([m("sublayers")],O.prototype,"writeSublayers",null),e([n({readOnly:!0,json:{read:!1}})],O.prototype,"type",void 0),e([n({json:{origins:{"web-map":{read:{source:"title"}}},write:{ignoreOrigin:!0}}})],O.prototype,"title",null),e([n(g)],O.prototype,"url",void 0),e([n({readOnly:!0})],O.prototype,"visibleSublayers",null),e([n({type:w})],O.prototype,"extent",void 0),e([n()],O.prototype,"fullExtent",null),O=e([y("esri.layers.KMLLayer")],O);const M=O;export{M as default};