WebTileLayer.js 7.2 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 t from"../request.js";import r from"../core/Error.js";import{MultiOriginJSONMixin as l}from"../core/MultiOriginJSONSupport.js";import{replace as o}from"../core/string.js";import{Url as s,isProtocolRelative as i,normalize as n}from"../core/urlUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/accessorSupport/ensureType.js";import{reader as p}from"../core/accessorSupport/decorators/reader.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{writer as m}from"../core/accessorSupport/decorators/writer.js";import c from"./Layer.js";import{BlendLayer as y}from"./mixins/BlendLayer.js";import{OperationalLayer as f}from"./mixins/OperationalLayer.js";import{PortalLayer as h}from"./mixins/PortalLayer.js";import{RefreshableLayer as d}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as v}from"./mixins/ScaleRangeLayer.js";import w from"./support/LOD.js";import g from"./support/TileInfo.js";import{WMTSLayerInfo as j}from"./support/WMTSLayerInfo.js";import T from"../geometry/Extent.js";import b from"../geometry/SpatialReference.js";import S from"../geometry/Point.js";let R=class extends(y(d(v(f(h(l(c))))))){constructor(...e){super(...e),this.copyright="",this.fullExtent=new T(-20037508.342787,-20037508.34278,20037508.34278,20037508.342787,b.WebMercator),this.legendEnabled=!1,this.isReference=null,this.popupEnabled=!1,this.spatialReference=b.WebMercator,this.subDomains=null,this.tileInfo=new g({size:[256,256],dpi:96,format:"png8",compressionQuality:0,origin:new S({x:-20037508.342787,y:20037508.342787,spatialReference:b.WebMercator}),spatialReference:b.WebMercator,lods:[new w({level:0,scale:591657527.591555,resolution:156543.033928}),new w({level:1,scale:295828763.795777,resolution:78271.5169639999}),new w({level:2,scale:147914381.897889,resolution:39135.7584820001}),new w({level:3,scale:73957190.948944,resolution:19567.8792409999}),new w({level:4,scale:36978595.474472,resolution:9783.93962049996}),new w({level:5,scale:18489297.737236,resolution:4891.96981024998}),new w({level:6,scale:9244648.868618,resolution:2445.98490512499}),new w({level:7,scale:4622324.434309,resolution:1222.99245256249}),new w({level:8,scale:2311162.217155,resolution:611.49622628138}),new w({level:9,scale:1155581.108577,resolution:305.748113140558}),new w({level:10,scale:577790.554289,resolution:152.874056570411}),new w({level:11,scale:288895.277144,resolution:76.4370282850732}),new w({level:12,scale:144447.638572,resolution:38.2185141425366}),new w({level:13,scale:72223.819286,resolution:19.1092570712683}),new w({level:14,scale:36111.909643,resolution:9.55462853563415}),new w({level:15,scale:18055.954822,resolution:4.77731426794937}),new w({level:16,scale:9027.977411,resolution:2.38865713397468}),new w({level:17,scale:4513.988705,resolution:1.19432856685505}),new w({level:18,scale:2256.994353,resolution:.597164283559817}),new w({level:19,scale:1128.497176,resolution:.298582141647617}),new w({level:20,scale:564.248588,resolution:.14929107082380833}),new w({level:21,scale:282.124294,resolution:.07464553541190416}),new w({level:22,scale:141.062147,resolution:.03732276770595208}),new w({level:23,scale:70.5310735,resolution:.01866138385297604})]}),this.type="web-tile",this.urlTemplate=null,this.wmtsInfo=null}normalizeCtorArgs(e,t){return"string"==typeof e?{urlTemplate:e,...t}:e}load(e){const t=this.loadFromPortal({supportedTypes:["WMTS"]},e).then((()=>{let e="";if(this.urlTemplate)if(this.spatialReference.equals(this.tileInfo.spatialReference)){const t=new s(this.urlTemplate);!(!!this.subDomains&&this.subDomains.length>0)&&t.authority.includes("{subDomain}")&&(e="is missing 'subDomains' property")}else e="spatialReference must match tileInfo.spatialReference";else e="is missing the required 'urlTemplate' property value";if(e)throw new r("web-tile-layer:load",`WebTileLayer (title: '${this.title}', id: '${this.id}') ${e}`)}));return this.addResolvingPromise(t),Promise.resolve(this)}get levelValues(){const e=[];if(!this.tileInfo)return null;for(const t of this.tileInfo.lods)e[t.level]=t.levelValue||t.level;return e}readSpatialReference(e,t){return e||t.fullExtent&&t.fullExtent.spatialReference&&b.fromJSON(t.fullExtent.spatialReference)}get tileServers(){if(!this.urlTemplate)return null;const e=[],{urlTemplate:t,subDomains:r}=this,l=new s(t),o=l.scheme?l.scheme+"://":"//",i=o+l.authority+"/";if(l.authority.includes("{subDomain}")){if(r&&r.length>0&&l.authority.split(".").length>1)for(const s of r)e.push(o+l.authority.replace(/\{subDomain\}/gi,s)+"/")}else e.push(i);return e.map((e=>("/"!==e.charAt(e.length-1)&&(e+="/"),e)))}get urlPath(){if(!this.urlTemplate)return null;const e=this.urlTemplate,t=new s(e),r=(t.scheme?t.scheme+"://":"//")+t.authority+"/";return e.substring(r.length)}readUrlTemplate(e,t){return e||t.templateUrl}writeUrlTemplate(e,t){e&&i(e)&&(e="https:"+e),e&&(e=e.replace(/\{z\}/gi,"{level}").replace(/\{x\}/gi,"{col}").replace(/\{y\}/gi,"{row}"),e=n(e)),t.templateUrl=e}fetchTile(e,r,l,o={}){const{signal:s}=o,i=this.getTileUrl(e,r,l),n={responseType:"image",signal:s,query:{...this.refreshParameters}};return t(i,n).then((e=>e.data))}async fetchImageBitmapTile(e,r,l,o={}){const{signal:s}=o,i=this.getTileUrl(e,r,l),n={responseType:"blob",signal:s,query:{...this.refreshParameters}},{data:a}=await t(i,n);return createImageBitmap(a)}getTileUrl(e,t,r){const l=this.levelValues[e];return this.tileServers[t%this.tileServers.length]+o(this.urlPath,{level:l,z:l,col:r,x:r,row:t,y:t})}};e([a({type:String,value:"",json:{write:!0}})],R.prototype,"copyright",void 0),e([a({type:T,json:{write:!0},nonNullable:!0})],R.prototype,"fullExtent",void 0),e([a({readOnly:!0,json:{read:!1,write:!1}})],R.prototype,"legendEnabled",void 0),e([a({type:["show","hide"]})],R.prototype,"listMode",void 0),e([a({json:{read:!0,write:!0}})],R.prototype,"blendMode",void 0),e([a()],R.prototype,"levelValues",null),e([a({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],R.prototype,"isReference",void 0),e([a({type:["WebTiledLayer"],value:"WebTiledLayer"})],R.prototype,"operationalLayerType",void 0),e([a({readOnly:!0,json:{read:!1,write:!1}})],R.prototype,"popupEnabled",void 0),e([a({type:b})],R.prototype,"spatialReference",void 0),e([p("spatialReference",["spatialReference","fullExtent.spatialReference"])],R.prototype,"readSpatialReference",null),e([a({type:[String],json:{write:!0}})],R.prototype,"subDomains",void 0),e([a({type:g,json:{write:!0}})],R.prototype,"tileInfo",void 0),e([a({readOnly:!0})],R.prototype,"tileServers",null),e([a({json:{read:!1}})],R.prototype,"type",void 0),e([a()],R.prototype,"urlPath",null),e([a({type:String,json:{origins:{"portal-item":{read:{source:"url"}}}}})],R.prototype,"urlTemplate",void 0),e([p("urlTemplate",["urlTemplate","templateUrl"])],R.prototype,"readUrlTemplate",null),e([m("urlTemplate",{templateUrl:{type:String}})],R.prototype,"writeUrlTemplate",null),e([a({type:j,json:{write:!0}})],R.prototype,"wmtsInfo",void 0),R=e([u("esri.layers.WebTileLayer")],R);const x=R;export{x as default};