UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 6.35 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import e from"../../../core/Error.js";import"../../../core/has.js";import{deg2rad as t,floatEqualAbsolute as i,floatEqualRelative as s}from"../../../core/mathUtils.js";import{getMetersPerUnitForSR as r}from"../../../core/units.js";import l from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import o from"../../../geometry/SpatialReference.js";import{create as a}from"../../../geometry/support/aaBoundingRect.js";import{isGeographic as h}from"../../../geometry/support/spatialReferenceUtils.js";import{x2lon as c,y2lat as m}from"../../../geometry/support/webMercatorUtils.js";import u from"../../../layers/support/LOD.js";import p from"../../../layers/support/TileInfo.js";const g=12;class f{constructor(e){const t=f.checkUnsupported(e);if(null!=t)throw t;const i=e;this.spatialReference=i.spatialReference,this._isWebMercator=this.spatialReference.isWebMercator,this._isGCS=h(this.spatialReference),this.origin=[i.origin.x,i.origin.y],this.pixelSize=i.size[0],this.dpi=i.dpi;const s=i.lods.reduce((e,t)=>(t.level<e.minLod.level&&(e.minLod=t),e.max=Math.max(e.max,t.level),e),{minLod:i.lods[0],max:-1/0}),r=s.minLod,l=2**r.level;let n=r.resolution*l,o=r.scale*l;this.levels=new Array(s.max+1);for(let a=0;a<this.levels.length;a++)this.levels[a]={resolution:n,scale:o,tileSize:[n*i.size[0],n*i.size[1]]},n/=2,o/=2}clone(){return new f(this.toTileInfo())}toTileInfo(){return new p({dpi:this.dpi,origin:new n({x:this.origin[0],y:this.origin[1],spatialReference:this.spatialReference}),size:[this.pixelSize,this.pixelSize],spatialReference:this.spatialReference,lods:this.levels.map((e,t)=>new u({level:t,scale:e.scale,resolution:e.resolution}))})}getExtent(e,t,i,s){const r=this.levels[e],l=r.tileSize[0],n=r.tileSize[1];s[0]=this.origin[0]+i*l,s[2]=this.origin[0]+(i+1)*l,s[3]=this.origin[1]-t*n,s[1]=this.origin[1]-(t+1)*n}convertExtentToRadians(e,i){this._isWebMercator?(i[0]=c(e[0]),i[1]=m(e[1]),i[2]=c(e[2]),i[3]=m(e[3])):this._isGCS&&(i[0]=t(e[0]),i[1]=t(e[1]),i[2]=t(e[2]),i[3]=t(e[3]))}getExtentGeometry(e,t,i,s=new l){return this.getExtent(e,t,i,v),s.spatialReference=this.spatialReference,s.xmin=v[0],s.ymin=v[1],s.xmax=v[2],s.ymax=v[3],s.zmin=void 0,s.zmax=void 0,s}ensureMaxLod(e){if(null==e)return!1;let t=!1;for(;this.levels.length<=e;){const{resolution:e,scale:i}=this.levels[this.levels.length-1],s=e/2*this.pixelSize;this.levels.push({resolution:e/2,scale:i/2,tileSize:[s,s]}),t=!0}return t}capMaxLod(e){this.levels.length>e+1&&(this.levels.length=e+1)}getMaxLod(){return this.levels.length-1}scaleAtLevel(e){return this.levels[0].scale/2**e}levelAtScale(e){const t=this.levels[0].scale;return e>=t?0:Math.log(t/e)*Math.LOG2E}resolutionAtLevel(e){return this.levels[0].resolution/2**e}compatibleWith(e,t=1/0){if(f.checkUnsupported(e))return!1;const s=new f(e);if(!s.spatialReference.equals(this.spatialReference))return!1;if(s.pixelSize!==this.pixelSize)return!1;const r=Math.min(this.levels.length-1,s.levels.length-1,t),l=this.levels[r].resolution;let n=.5*l;if(!i(s.origin[0],this.origin[0],n)||!i(s.origin[1],this.origin[1],n))return!1;return n=.5*l/2**r/this.pixelSize*g,i(l,s.levels[r].resolution,n)}rootTilesInExtent(e,t=null,i=1/0){const s=new Array,r=this.levels[0].tileSize;if(null==e||0===r[0]||0===r[1])return s;f.computeRowColExtent(e,r,this.origin,v);let l=v[1],n=v[3],o=v[0],a=v[2];const h=a-o,c=n-l;if(h*c>i){const e=Math.floor(Math.sqrt(i));c>e&&(l=l+Math.floor(.5*c)-Math.floor(.5*e),n=l+e),h>e&&(o=o+Math.floor(.5*h)-Math.floor(.5*e),a=o+e)}for(let m=l;m<n;m++)for(let e=o;e<a;e++)s.push([0,m,e]);return null!=t&&(t[0]=this.origin[0]+o*r[0],t[1]=this.origin[1]-n*r[1],t[2]=this.origin[0]+a*r[0],t[3]=this.origin[1]-l*r[1]),s}static computeRowColExtent(e,t,i,s){const r=.001*(e[2]-e[0]+(e[3]-e[1]));s[0]=Math.max(0,Math.floor((e[0]+r-i[0])/t[0])),s[2]=Math.max(0,Math.ceil((e[2]-r-i[0])/t[0])),s[1]=Math.max(0,Math.floor((i[1]-e[3]+r)/t[1])),s[3]=Math.max(0,Math.ceil((i[1]-e[1]-r)/t[1]))}static isPowerOfTwo(e){const t=e.lods,i=t[0].resolution*2**t[0].level;return!t.some(e=>!s(e.resolution,i/2**e.level))}static hasGapInLevels(e){const t=e.lods.map(e=>e.level);t.sort((e,t)=>e-t);for(let i=1;i<t.length;i++)if(t[i]!==t[0]+i)return!0;return!1}static tileSizeSupported(e){const t=e.size[1];return t===e.size[0]&&!(t&t-1)&&t>=128&&t<=512}static hasOriginPerLODs(e){const t=e.origin;return e.lods.some(e=>null!=e.origin&&(e.origin[0]!==t.x||e.origin[1]!==t.y))}static getMissingTileInfoError(){return new e("tilingscheme:tile-info-missing","Tiling scheme must have tiling information")}static checkUnsupported(t){return null==t?x():t.lods.length<1?new e("tilingscheme:generic","Tiling scheme must have at least one level"):f.isPowerOfTwo(t)?f.hasGapInLevels(t)?new e("tilingscheme:gaps","Tiling scheme levels must not have gaps between min and max level"):f.tileSizeSupported(t)?f.hasOriginPerLODs(t)?new e("tilingscheme:multiple-origin","Tiling scheme levels must not have their own origin"):null:new e("tilingscheme:tile-size","Tiles must be square and size must be one of [128, 256, 512]"):new e("tilingscheme:power-of-two","Tiling scheme must be power of two")}static fromExtent(e,t){const i=e[2]-e[0],s=e[3]-e[1],l=r(t),o=1.2*Math.max(i,s),a=256,h=o/a,c=h*l*(96/.0254),m=new f(new p({size:[a,a],origin:new n({x:e[0]-.5*(o-i),y:e[3]+.5*(o-s)}),lods:[new u({level:0,resolution:h,scale:c})],spatialReference:t}));return m.ensureMaxLod(20),m}static makeWebMercatorAuxiliarySphere(e){const t=new f(f.WebMercatorAuxiliarySphereTileInfo);return t.ensureMaxLod(e),t}static makeGCSWithTileSize(e,t=256,i=16){const s=256/t,r=new f(new p({size:[t,t],origin:new n({x:-180,y:90,spatialReference:e}),spatialReference:e,lods:[new u({level:0,resolution:.703125*s,scale:295497598.570834*s})]}));return r.ensureMaxLod(i),r}static{this.WebMercatorAuxiliarySphereTileInfo=new p({size:[256,256],origin:new n({x:-20037508.342787,y:20037508.342787,spatialReference:o.WebMercator}),spatialReference:o.WebMercator,lods:[new u({level:0,resolution:156543.03392800014,scale:591657527.591555})]})}static{this.WebMercatorAuxiliarySphere=f.makeWebMercatorAuxiliarySphere(19)}get test(){}}function x(){return new e("tilingscheme:tile-info-missing","Tiling scheme must have tiling information")}const v=a();export{f as TilingScheme,x as getMissingTileInfoError};