Layer.js 3.4 KB

12345678910
  1. // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  2. // See https://js.arcgis.com/4.7/esri/copyright.txt for details.
  3. //>>built
  4. define("require dojo/Deferred ../core/Accessor ../core/Error ../core/Evented ../core/Identifiable ../core/Loadable ../core/urlUtils ../core/promiseUtils ../core/Logger ../config ../kernel ../request ../geometry/SpatialReference ../geometry/Extent".split(" "),function(f,m,c,e,n,p,q,r,d,g,t,h,u,k,v){var w=0,l=g.getLogger("esri.layers.Layer");c=c.createSubclass([n,p,q],{declaredClass:"esri.layers.Layer",properties:{attributionDataUrl:null,credential:{value:null,readOnly:!0,dependsOn:["loaded","parsedUrl"],
  5. get:function(){var a=this.loaded&&this.parsedUrl&&h.id&&h.id.findCredential(this.parsedUrl.path)||null;a&&a.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));return a}},fullExtent:new v(-180,-90,180,90,k.WGS84),hasAttributionData:{readOnly:!0,dependsOn:["attributionDataUrl"],get:function(){return null!=this.attributionDataUrl}},id:{get:function(){return Date.now().toString(16)+"-layer-"+w++}},legendEnabled:!0,listMode:"show",opacity:{value:1,type:Number,cast:function(a){return 0>a?0:1<a?1:a}},
  6. parent:null,parsedUrl:{readOnly:!0,dependsOn:["url"],get:function(){var a=this._get("url");return a?r.urlToObject(a):null}},popupEnabled:!0,attributionVisible:!0,spatialReference:k.WGS84,title:null,token:{dependsOn:["credential.token"],get:function(){var a=this.get("parsedUrl.query.token"),b=this.get("credential.token");return a||b||null},set:function(a){a?this._override("token",a):this._clearOverride("token")}},type:{type:String,readOnly:!0,value:null,json:{read:!1}},url:{value:null},visible:!0},
  7. initialize:function(){this.when().catch(function(a){g.getLogger(this.declaredClass).error("#load()","Failed to load layer (title: '"+this.title+"', id: '"+this.id+"')",a)}.bind(this))},createLayerView:function(a){return a?this.importLayerViewModule(a).then(function(b){b.default&&(b=b.default);return new b({layer:this,view:a})}.bind(this)):d.reject(new e("layerview:module-unavailable","No LayerView module available for layer '${layer.declaredClass}' and view type: '${view.type}'",{view:a,layer:this}))},
  8. destroyLayerView:function(a){a.destroy()},fetchAttributionData:function(){var a=this.attributionDataUrl;this.hasAttributionData&&a?a=u(a,{query:{f:"json"},responseType:"json"}).then(function(a){return a.data}):(a=new m,a.reject(new e("layer:no-attribution-data","Layer does not have attribution data")),a=a.promise);return a},refresh:function(){this.emit("refresh")},importLayerViewModule:function(a){return d.reject(new e("layerview:override-method","Must provide implementation in '${layer.declaredClass}'",
  9. {view:a,layer:this}))}});c.fromArcGISServerUrl=function(a){"string"===typeof a&&(a={url:a});var b=d.create(function(a){f(["./support/arcgisLayers"],a)}).then(function(b){return b.fromUrl(a)});b.catch(function(b){l.error("#fromArcGISServerUrl({ url: '"+a.url+"'})","Failed to create layer from arcgis server url",b)});return b};c.fromPortalItem=function(a){!a||a.portalItem||"object"!==typeof a||a.declaredClass&&"esri.portal.PortalItem"!==a.declaredClass||(a={portalItem:a});var b=d.create(function(a){f(["../portal/support/portalLayers"],
  10. a)}).then(function(b){return b.fromItem(a)});b.catch(function(b){var c=a&&a.portalItem;l.error("#fromPortalItem()","Failed to create layer from portal item (portal: '"+(c&&c.portal&&c.portal.url||t.portalUrl)+"', id: '"+(c&&c.id||"unset")+"')",b)});return b};return c});