/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import i from"../../../core/Error.js";import{property as r,subclass as o}from"../../../core/accessorSupport/decorators.js";import s from"../../../geometry/Extent.js";import{RasterJobHandlerMixin as a}from"../../../layers/mixins/RasterJobHandlerMixin.js";import{pixelAngleThreshold as n,defaultImageSphereSize as l}from"../constants.js";import h from"./ClosestMap.js";import m from"./getVisibleTiles.js";import p from"./PanoramicTileNode.js";let c=class extends(a(t)){constructor(e){super(e),this._maximumPyramidLevel=-1,this._pixelAngleToLevelMap=new h,this._tileMap=new Map,this.horizonPitch=0,this.horizonYaw=0,this.horizonRoll=0,this.raster=null,this._fetchRawTile=async(e,t,i,r)=>{await this._initJobHandler();const{pyramidBlockWidth:o,pyramidBlockHeight:a}=this.storageInfo,{minCol:n,maxCol:l,minRow:h,maxRow:m}=this.storageInfo.blockBoundary[e],p=l-n+1,c=m-h+1,d=i*this.imageSize[0]/p,g=t*this.imageSize[1]/c,f=Math.min((i+1)*this.imageSize[0]/p,this.imageSize[0]),u=Math.min((t+1)*this.imageSize[1]/c,this.imageSize[1]),x=f-d,w=u-g,y=new s({xmin:d-.5,ymin:.5-u,xmax:f-.5,ymax:.5-g,spatialReference:this.raster.rasterInfo.spatialReference}),{pixelBlock:_}=await this.raster.fetchPixels(y,o??x,a??w,r);return _},this.getLevelTiles=e=>{const t=[],{minCol:i,maxCol:r,minRow:o,maxRow:s}=this.storageInfo.blockBoundary[e];for(let a=o;a<=s;a++)for(let o=i;o<=r;o++){const i=this._tileMap.get(`${e}/${a}/${o}`);i&&t.push(i)}return t.length?t:null},this.getLevelWithPixelAngle=e=>this._pixelAngleToLevelMap.get(e)??0,this.getLowResolutionTiles=()=>{const e=this.maximumPyramidLevel;return e<0?null:this.getLevelTiles(e)},this.getTiles=(e,t,i,r,o)=>{const{minCol:s,minRow:a,maxCol:n,maxRow:l}=this.storageInfo.blockBoundary[e];return m(e,[s,a],[n,l],this._tileMap,t,i,r,o)}}initialize(){this._processLevels()}destroy(){this.raster.rasterJobHandler=null,this.raster=null,this._shutdownJobHandler(),this._tileMap.clear(),this._pixelAngleToLevelMap.clear()}async _initJobHandler(){this._rasterJobHandler||(await super._initJobHandler(),this.raster.rasterJobHandler=this._rasterJobHandler)}_processLevels(){const{blockBoundary:e,tileInfo:t}=this.storageInfo,r=e?.length;if(!r)throw new i("panoramic-viewer:missing-pyramid-resolutions","TIFF/MRF must have pyramid resolutions defined",{rasterId:this.raster.rasterId});this._tileMap.clear();for(let i=0;i<r;i++){const{maxCol:r,maxRow:o,minCol:s,minRow:a}=e[i],h=180/(o-a+1),m=360/(r-s+1),c=m/t.size[0];if(c>n)break;this._pixelAngleToLevelMap.set(c,i);for(let e=a;e<=o;e++){const t=180-(e+.5)*h;for(let o=s;o<=r;o++){const r=(o+.5)*m-180;this._tileMap.set(`${i}/${e}/${o}`,new p(i,e,o,m,h,r,t,l/2,[this.horizonPitch,this.horizonRoll,this.horizonYaw],this._fetchRawTile))}}this._maximumPyramidLevel=i}}get rasterInfo(){return this.raster.rasterInfo}get storageInfo(){return this.rasterInfo.storageInfo}get imageSize(){const{width:e,height:t}=this.rasterInfo;return[e,t]}get maximumPyramidLevel(){return this._maximumPyramidLevel}};e([r()],c.prototype,"horizonPitch",void 0),e([r()],c.prototype,"horizonYaw",void 0),e([r()],c.prototype,"horizonRoll",void 0),e([r()],c.prototype,"raster",void 0),c=e([o("esri.widgets.PanoramicViewer.support.PanoramicTilePyramid")],c);const d=c;export{d as default};
