// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define(["../../../geometry/support/spatialReferenceUtils","./LODInfo","./TileCoverage","./TileKey","./TileSpan"],function(u,v,w,x,r){const f=new x("0/0/0/0");class t{static create(a,b){a[1]>b[1]&&([a,b]=[b,a]);const [c,e]=a,[k,g]=b;a=k-c;b=g-e;b=0!==b?a/b:0;const h=(Math.ceil(e)-e)*b,n=(Math.floor(e)-e)*b;return new t(c,Math.floor(e),Math.ceil(g),b,0>a?h:n,0>a?n:h,0>a?k:c,0>a?c:k)}constructor(a,b,c,e,k,g,h,n){this.x=a;this.ymin=b;this.ymax=c;this.invM=e;this.leftAdjust=k;this.rightAdjust=g;this.leftBound= h;this.rightBound=n}incrRow(){this.x+=this.invM}getLeftCol(){return Math.max(this.x+this.leftAdjust,this.leftBound)}getRightCol(){return Math.min(this.x+this.rightAdjust,this.rightBound)}}const p=[[0,0],[0,0],[0,0],[0,0]];class y{constructor(a,b=null,c=a.lods[0].level,e=a.lods[a.lods.length-1].level){this.tileInfo=a;this.fullExtent=b;this.scales=[];this._infoByScale={};this._infoByLevel={};const k=a.lods.filter(h=>h.level>=c&&h.level<=e);this.minScale=k[0].scale;this.maxScale=k[k.length-1].scale; const g=this._lodInfos=k.map(h=>v.create(a,h,b));k.forEach((h,n)=>{this._infoByLevel[h.level]=g[n];this._infoByScale[h.scale]=g[n];this.scales[n]=h.scale},this);this._wrap=a.isWrappable}get spatialReference(){return this.tileInfo.spatialReference}getLODInfoAt(a){return this._infoByLevel["number"===typeof a?a:a.level]}getTileBounds(a,b,c=!1){f.set(b);return(b=this._infoByLevel[f.level])?b.getTileBounds(a,f,c):a}getTileCoords(a,b,c=!1){f.set(b);return(b=this._infoByLevel[f.level])?b.getTileCoords(a, f,c):a}getTileCoverage(a,b=192,c=!0,e="closest"){if(!c&&(a.scale>this.minScale||a.scaleb;b++)p[b][1]===p[d][1]? d=b:(d=t.create(p[b],p[d]),g=Math.min(d.ymin,g),h=Math.max(d.ymax,h),void 0===a[d.ymin]&&(a[d.ymin]=[]),a[d.ymin].push(d),d=b);if(null==g||null==h||100=c.first[1]&&g<=c.last[1])if(k)if(c.size[0]c.last[0]||l=g?l.incrRow():b.splice(d,1)}return e}getTileParentId(a){f.set(a);a=this._lodInfos.indexOf(this._infoByLevel[f.level])-1;if(0>a)return null;this._getTileIdAtLOD(f,this._lodInfos[a],f);return f.id}getTileResolution(a){return(a= this._infoByLevel["object"===typeof a?a.level:a])?a.resolution:-1}getTileScale(a){return(a=this._infoByLevel[a.level])?a.scale:-1}intersects(a,b){f.set(b);b=this._infoByLevel[f.level];const c=a.lodInfo;if(c.resolution>b.resolution){this._getTileIdAtLOD(f,c,f);var e=c.denormalizeCol(f.col,f.world);for(var k of a.spans)if(k.row===f.row&&k.colFrom<=e&&k.colTo>=e)return!0}if(c.resolution{m[0]=Math.min(m[0],q.row);m[1]=Math.max(m[1],q.row);m[2]=Math.min(m[2], q.colFrom);m[3]=Math.max(m[3],q.colTo);return m},[Infinity,-Infinity,Infinity,-Infinity]);e=b.denormalizeCol(f.col,f.world);a=c.getColumnForX(b.getXForColumn(e));k=c.getRowForY(b.getYForRow(f.row));e=c.getColumnForX(b.getXForColumn(e+1))-1;b=c.getRowForY(b.getYForRow(f.row+1))-1;return!(a>l||en||bh.row===f.row&&h.colFrom<=g&&h.colTo>=g)}normalizeBounds(a,b,c){a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];this._wrap&&(b=u.getInfo(this.tileInfo.spatialReference), c=-c*(b.valid[1]-b.valid[0]),a[0]+=c,a[2]+=c);return a}getSmallestInfoForScale(a){const b=this.scales;if(this._infoByScale[a])return this._infoByScale[a];if(a>b[0])return this._infoByScale[b[0]];for(let c=1;cb[c]+1E-6)return this._infoByScale[b[c-1]];return this._infoByScale[b[b.length-1]]}getClosestInfoForScale(a){const b=this.scales;if(this._infoByScale[a])return this._infoByScale[a];a=b.reduce((c,e)=>Math.abs(e-a)