Layer.js 3.3 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 t}from"../chunks/tslib.es6.js";import"../geometry.js";import e from"../request.js";import r from"../core/Error.js";import o from"../core/Evented.js";import{IdentifiableMixin as i}from"../core/Identifiable.js";import s from"../core/Loadable.js";import a from"../core/Logger.js";import{isAbortError as l}from"../core/promiseUtils.js";import{urlToObject as n}from"../core/urlUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{subclass as y}from"../core/accessorSupport/decorators/subclass.js";import{fromPortalItem as d}from"./support/fromPortalItem.js";import u from"../geometry/Extent.js";import c from"../geometry/SpatialReference.js";let m=0,h=class extends(o.EventedMixin(i(s))){constructor(){super(...arguments),this.attributionDataUrl=null,this.fullExtent=new u(-180,-90,180,90,c.WGS84),this.id=Date.now().toString(16)+"-layer-"+m++,this.legendEnabled=!0,this.listMode="show",this.opacity=1,this.parent=null,this.popupEnabled=!0,this.attributionVisible=!0,this.spatialReference=c.WGS84,this.title=null,this.type=null,this.url=null,this.visible=!0}static async fromArcGISServerUrl(t){const e="string"==typeof t?{url:t}:t;return(await import("./support/arcgisLayers.js")).fromUrl(e)}static fromPortalItem(t){return d(t)}initialize(){this.when().catch((t=>{l(t)||a.getLogger(this.declaredClass).error("#load()",`Failed to load layer (title: '${this.title??"no title"}', id: '${this.id??"no id"}')`,{error:t})}))}destroy(){if(this.parent){const t=this,e=this.parent;"layers"in e&&e.layers.includes(t)?e.layers.remove(t):"tables"in e&&e.tables.includes(t)?e.tables.remove(t):"baseLayers"in e&&e.baseLayers.includes(t)?e.baseLayers.remove(t):"baseLayers"in e&&e.referenceLayers.includes(t)&&e.referenceLayers.remove(t)}}get hasAttributionData(){return null!=this.attributionDataUrl}get parsedUrl(){return n(this.url)}async fetchAttributionData(){const t=this.attributionDataUrl;if(this.hasAttributionData&&t){return(await e(t,{query:{f:"json"},responseType:"json"})).data}throw new r("layer:no-attribution-data","Layer does not have attribution data")}};t([p({type:String})],h.prototype,"attributionDataUrl",void 0),t([p({type:u})],h.prototype,"fullExtent",void 0),t([p({readOnly:!0})],h.prototype,"hasAttributionData",null),t([p({type:String,clonable:!1})],h.prototype,"id",void 0),t([p({type:Boolean,nonNullable:!0})],h.prototype,"legendEnabled",void 0),t([p({type:["show","hide","hide-children"]})],h.prototype,"listMode",void 0),t([p({type:Number,range:{min:0,max:1},nonNullable:!0})],h.prototype,"opacity",void 0),t([p({clonable:!1})],h.prototype,"parent",void 0),t([p({readOnly:!0})],h.prototype,"parsedUrl",null),t([p({type:Boolean})],h.prototype,"popupEnabled",void 0),t([p({type:Boolean})],h.prototype,"attributionVisible",void 0),t([p({type:c})],h.prototype,"spatialReference",void 0),t([p({type:String})],h.prototype,"title",void 0),t([p({readOnly:!0,json:{read:!1}})],h.prototype,"type",void 0),t([p()],h.prototype,"url",void 0),t([p({type:Boolean,nonNullable:!0})],h.prototype,"visible",void 0),h=t([y("esri.layers.Layer")],h);const b=h;export{b as default};