/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{create as e}from"../../../../geometry/support/aaBoundingRect.js";import{getWorldWidth as i}from"../../viewpointUtils.js";import{RasterTile as t}from"./RasterTile.js";import s from"../webgl/TileContainer.js";import{RasterColorizerTechnique as h}from"../webgl/shaderGraph/techniques/raster/RasterColorizerTechnique.js";import{RasterHighlightTechnique as r}from"../webgl/shaderGraph/techniques/raster/RasterHighlightTechnique.js";import{RasterProcessorTechnique as n}from"../webgl/shaderGraph/techniques/raster/RasterProcessorTechnique.js";class o extends s{constructor(){super(...arguments),this.isCustomTilingScheme=!1}get pixelHighlights(){return this._pixelHighlights}set pixelHighlights(e){this._pixelHighlights=e,this.children.forEach(({bitmap:e})=>e.highlightTexture=null),this.requestRender()}createTile(e){const i=this._getTileBounds(e),[s,h]=this.tilingScheme.size,r=this.tilingScheme.getTileResolution(e.level);return new t(e,r,i[0],i[3],s,h)}onAttach(){super.onAttach(),this._colorizerTechnique=new h,this._processorTechnique=new n,this._highlightTechnique=new r}onDetach(){super.onDetach(),this._colorizerTechnique?.shutdown(),this._colorizerTechnique=void 0,this._processorTechnique?.shutdown(),this._processorTechnique=void 0,this._highlightTechnique?.shutdown(),this._highlightTechnique=void 0}doRender(e){if(!this.visible||1!==e.drawPhase||!this._colorizerTechnique)return;const{rasterFunctionChain:i}=this;if(i?.functions?.length){if(!this._processorTechnique)return;const{functions:t,hasBranches:s}=i;for(const i of t){if("Constant"===i.name||"Identity"===i.name)continue;e.rasterFunction=i,e.hasBranches=s,super.doRender(e);const t=this.children.map(e=>e.bitmap);this._processorTechnique.render(e,{bitmaps:t})}}if(this._pixelHighlights?.length&&this._highlightTechnique)for(const s of this._pixelHighlights){e.pixelHighlightOptions=s,super.doRender(e);const i=this.children.map(e=>e.bitmap);this._highlightTechnique.render(e,{bitmaps:i})}e.rasterFunction=null,e.pixelHighlightOptions=void 0,super.doRender(e);const t=this.children.map(e=>e.bitmap);this._colorizerTechnique.render(e,{bitmaps:t})}_getTileBounds(t){const s=this.tilingScheme.getTileBounds(e(),t);if(this.isCustomTilingScheme&&t.world){const e=i(this.tilingScheme.spatialReference);if(e){const i=this.tilingScheme.getLODInfoAt(t.level);if(!i)return s;const{resolution:h}=i,r=h*this.tilingScheme.size[0];s[0]=e*t.world+this.tilingScheme.origin.x+t.col*r,s[2]=s[0]+r}}return s}}export{o as RasterTileContainer};
