/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{clone as t}from"../../../../../core/lang.js";import{urlToObject as e,isAbsolute as i,join as l,addQueryParameters as s}from"../../../../../core/urlUtils.js";import r from"../../../../../geometry/Extent.js";import o from"../../../../../layers/support/TileInfo.js";import{TilemapCache as n}from"../../../../../layers/support/TilemapCache.js";import a from"../TilemapIndex.js";import p from"../TilemapRequest.js";import{request as h}from"./VectorTilesRequestManager.js";class m{constructor(h,m,u){this.tilemap=null,this.tileInfo=null,this.capabilities=null,this.fullExtent=null,this.initialExtent=null,this.name=h,this.sourceUrl=m;const f=e(this.sourceUrl),c=t(u),x=c.tiles;if(f)for(let t=0;t<x.length;t++){const r=e(x[t]);r&&(i(r.path)||(r.path=l(f.path,r.path)),x[t]=s(r.path,{...f.query,...r.query}))}this.tileServers=x;const d=u.capabilities&&u.capabilities.split(",").map(t=>t.toLowerCase().trim()),y=!0===u?.exportTilesAllowed,T=!0===d?.includes("tilemap"),I=y&&u.hasOwnProperty("maxExportTilesCount")?u.maxExportTilesCount:0;this.capabilities={operations:{supportsExportTiles:y,supportsTileMap:T},exportTiles:y?{maxExportTilesCount:+I}:null},this.tileInfo=o.fromJSON(c.tileInfo);const g=u.tileMap?s(l(f.path,u.tileMap),f.query??{}):null;T?(this.type="vector-tile",this.tilemap=new p(new n({layer:{parsedUrl:f,tileInfo:this.tileInfo},minLOD:c.minLOD??this.tileInfo.lods[0].level,maxLOD:c.maxLOD??this.tileInfo.lods[this.tileInfo.lods.length-1].level}),g)):g&&(this.tilemap=new a(g)),this.fullExtent=r.fromJSON(u.fullExtent),this.initialExtent=r.fromJSON(u.initialExtent)}destroy(){this.tilemap?.destroy()}async getRefKey(t,e){return this.tilemap?this.tilemap.dataKey(t,e):t}requestTile(t,e,i,l){const s=this.tileServers[e%this.tileServers.length];return h(s,t,e,i,l)}isCompatibleWith(t){const e=this.tileInfo,i=t.tileInfo;if(!e.spatialReference.equals(i.spatialReference))return!1;if(!e.origin.equals(i.origin))return!1;if(Math.round(e.dpi)!==Math.round(i.dpi))return!1;const l=e.lods,s=i.lods,r=Math.min(l.length,s.length);for(let o=0;o<r;o++){const t=l[o],e=s[o];if(t.level!==e.level||Math.round(t.scale)!==Math.round(e.scale))return!1}return!0}}export{m as default};
