@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.11 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../request.js";import{deprecatedModule as r}from"../core/deprecate.js";import o from"../core/Error.js";import{JSONMap as a}from"../core/jsonMap.js";import i from"../core/Logger.js";import{MultiOriginJSONSupportMixin as s}from"../core/MultiOriginJSONSupport.js";import{property as n,subclass as l}from"../core/accessorSupport/decorators.js";import p from"../geometry/Point.js";import g from"../geometry/SpatialReference.js";import u from"./BaseTileLayer.js";import{OperationalLayer as d}from"./mixins/OperationalLayer.js";import y from"./support/LOD.js";import c from"./support/TileInfo.js";const m=new a({BingMapsAerial:"aerial",BingMapsRoad:"road",BingMapsHybrid:"hybrid"}),h="https://dev.virtualearth.net";r(i.getLogger("esri.layers.BingMapsLayer"),"esri.layers.BingMapsLayer",{version:"4.33",warnOnce:!0});let b=class extends(d(s(u))){constructor(e){super(e),this.type="bing-maps",this.tileInfo=new c({size:[256,256],dpi:96,origin:new p({x:-20037508.342787,y:20037508.342787,spatialReference:g.WebMercator}),spatialReference:g.WebMercator,lods:[new y({level:1,resolution:78271.5169639999,scale:295828763.795777}),new y({level:2,resolution:39135.7584820001,scale:147914381.897889}),new y({level:3,resolution:19567.8792409999,scale:73957190.948944}),new y({level:4,resolution:9783.93962049996,scale:36978595.474472}),new y({level:5,resolution:4891.96981024998,scale:18489297.737236}),new y({level:6,resolution:2445.98490512499,scale:9244648.868618}),new y({level:7,resolution:1222.99245256249,scale:4622324.434309}),new y({level:8,resolution:611.49622628138,scale:2311162.217155}),new y({level:9,resolution:305.748113140558,scale:1155581.108577}),new y({level:10,resolution:152.874056570411,scale:577790.554289}),new y({level:11,resolution:76.4370282850732,scale:288895.277144}),new y({level:12,resolution:38.2185141425366,scale:144447.638572}),new y({level:13,resolution:19.1092570712683,scale:72223.819286}),new y({level:14,resolution:9.55462853563415,scale:36111.909643}),new y({level:15,resolution:4.77731426794937,scale:18055.954822}),new y({level:16,resolution:2.38865713397468,scale:9027.977411}),new y({level:17,resolution:1.19432856685505,scale:4513.988705}),new y({level:18,resolution:.597164283559817,scale:2256.994353}),new y({level:19,resolution:.298582141647617,scale:1128.497176}),new y({level:20,resolution:.1492910708238085,scale:564.248588})]}),this.key=null,this.style="road",this.culture="en-US",this.region=null,this.portalUrl=null,this.hasAttributionData=!0}get bingMetadata(){return this._get("bingMetadata")}set bingMetadata(e){this._set("bingMetadata",e)}get copyright(){return null!=this.bingMetadata?this.bingMetadata.copyright:null}get operationalLayerType(){return m.toJSON(this.style)}get bingLogo(){return null!=this.bingMetadata?this.bingMetadata.brandLogoUri:null}load(e){return this.key?this.addResolvingPromise(this._getMetadata()):this.portalUrl?this.addResolvingPromise(this._getPortalBingKey().then(()=>this._getMetadata())):this.addResolvingPromise(Promise.reject(new o("bingmapslayer:load","Bing layer must have bing key."))),Promise.resolve(this)}getTileUrl(e,t,r){if(!this.loaded||null==this.bingMetadata)return null;const o=this.bingMetadata.resourceSets[0].resources[0],a=o.imageUrlSubdomains[t%o.imageUrlSubdomains.length],i=this._getQuadKey(e,t,r);return o.imageUrl.replace("{subdomain}",a).replace("{quadkey}",i)}async fetchAttributionData(){return this.load().then(()=>{if(null==this.bingMetadata)return null;return{contributors:this.bingMetadata.resourceSets[0].resources[0].imageryProviders.map(e=>({attribution:e.attribution,coverageAreas:e.coverageAreas.map(e=>({zoomMin:e.zoomMin-(e.zoomMin?1:0),zoomMax:e.zoomMax-(e.zoomMin?1:0),score:1,bbox:[e.bbox[0],e.bbox[1],e.bbox[2],e.bbox[3]]}))}))}})}_getMetadata(){const e={road:"roadOnDemand",aerial:"aerial",hybrid:"aerialWithLabelsOnDemand"}[this.style];return t(`${h}/REST/v1/Imagery/Metadata/${e}`,{responseType:"json",query:{include:"ImageryProviders",uriScheme:"https",key:this.key,suppressStatus:!0,output:"json",culture:this.culture,userRegion:this.region}}).then(e=>{const t=e.data;if(200!==t.statusCode)throw new o("bingmapslayer:getmetadata",t.statusDescription);if(this.bingMetadata=t,0===this.bingMetadata.resourceSets.length)throw new o("bingmapslayer:getmetadata","no bing resourcesets");if(0===this.bingMetadata.resourceSets[0].resources.length)throw new o("bingmapslayer:getmetadata","no bing resources")}).catch(e=>{throw new o("bingmapslayer:getmetadata",e.message)})}_getPortalBingKey(){return t(this.portalUrl??"",{responseType:"json",authMode:"no-prompt",query:{f:"json"}}).then(e=>{if(!e.data.bingKey)throw new o("bingmapslayer:getportalbingkey","The referenced Portal does not contain a valid bing key");this.key=e.data.bingKey}).catch(e=>{throw new o("bingmapslayer:getportalbingkey",e.message)})}_getQuadKey(e,t,r){let o="";for(let a=e;a>0;a--){let e=0;const i=1<<a-1;0!==(r&i)&&(e+=1),0!==(t&i)&&(e+=2),o+=e.toString()}return o}};e([n({json:{read:!1,write:!1},value:null})],b.prototype,"bingMetadata",null),e([n({json:{read:!1,write:!1},value:"bing-maps",readOnly:!0})],b.prototype,"type",void 0),e([n({type:c})],b.prototype,"tileInfo",void 0),e([n({type:String,readOnly:!0,json:{read:!1,write:!1}})],b.prototype,"copyright",null),e([n({type:String,json:{write:!1,read:!1}})],b.prototype,"key",void 0),e([n({type:m.apiValues,nonNullable:!0,json:{read:{source:"layerType",reader:m.read}}})],b.prototype,"style",void 0),e([n({type:["BingMapsAerial","BingMapsHybrid","BingMapsRoad"]})],b.prototype,"operationalLayerType",null),e([n({type:String,json:{write:!1,read:!1}})],b.prototype,"culture",void 0),e([n({type:String,json:{write:!1,read:!1}})],b.prototype,"region",void 0),e([n({type:String,json:{write:!0,read:!0}})],b.prototype,"portalUrl",void 0),e([n({type:Boolean,json:{write:!1,read:!1}})],b.prototype,"hasAttributionData",void 0),e([n({type:String,readOnly:!0})],b.prototype,"bingLogo",null),b=e([l("esri.layers.BingMapsLayer")],b);const w=b;export{w as default};