UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.78 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{disposeMaybe as t}from"../../../core/maybe.js";import{C as e}from"../../../chunks/RasterColorizer.glsl.js";import{TextureSamplingMode as r}from"../../webgl/enums.js";import{createTransformTexture as s,getCommonUniforms as i,getColormapUniforms as o,getStretchUniforms as a,getShadedReliefUniforms as l,createRasterTexture as h,createColormapTexture as n}from"../../webgl/rasterUtils.js";const u={bandCount:3,minOutput:0,maxOutput:1,minCutOff:[0,0,0],maxCutOff:[255,255,255],factor:[1/255,1/255,1/255],useGamma:!1,gamma:[1,1,1],gammaCorrection:[1,1,1],colormap:null,colormapOffset:null,stretchType:"none",type:"stretch"};class m{constructor(t,e,r=null,s=null){this.lij=t,this.type="raster-tile",this._memoryUsed=null,this._source=null,this._symbolizerParameters=null,this._bandIds=null,this._interpolation=null,this._dirty=!1,this._transformGrid=null,this.isRendereredSource=!1,this.symbolizerRenderer=null,this.rawPixelData=null,this.opacity=1,this.source=e,this.width=r||e.width,this.height=s||e.height}get source(){return this._source}set source(e){this._source=e,this._rasterTexture=t(this._rasterTexture),this._memoryUsed=null}get symbolizerParameters(){return this.isRendereredSource?{...u,maxCutOff:[1,1,1],factor:[1,1,1]}:this._symbolizerParameters||u}set symbolizerParameters(t){this._symbolizerParameters=t}get bandIds(){return this._bandIds}set bandIds(t){if(null!=t&&t.length>0){this._bandIds&&t.every(((t,e)=>!!this._bandIds?.[e]&&t===this._bandIds[e]))||(this._bandIds=t,this._dirty=!0)}else this._bandIds=null}get interpolation(){return this._interpolation||"nearest"}set interpolation(t){if(this._interpolation=t,null!=this._rasterTexture){const e=this._getRasterTextureInterpolation(t);this._rasterTexture.setSamplingMode("bilinear"===e?r.LINEAR:r.NEAREST)}}get transformGrid(){return this._transformGrid}set transformGrid(e){this._transformGrid=e,this._transformGridTexture=t(this._transformGridTexture),this._memoryUsed=null}bind(t){return!!(this.source&&this.source.pixels&&this.source.pixels.length>0)&&((null==this._rasterTexture||this._dirty)&&this._updateRasterTexture(t,this.bandIds),null!=this._rasterTexture&&(this._updateColormapTexture(t),this.transformGrid&&null==this._transformGridTexture&&(this._transformGridTexture=s(t,this.transformGrid))),!0)}getUniforms(t){const{symbolizerParameters:r,transformGrid:s,width:h,height:n,opacity:u}=this,m=i(s,[h,n],[this.source.width,this.source.height],u),d=o(r.colormap,r.colormapOffset),_="stretch"===this.symbolizerParameters.type?a(this.symbolizerParameters):null,c="hillshade"===this.symbolizerParameters.type?l(this.symbolizerParameters):null,p=t.emptyTexture;return new e(m,d,_||c,this._rasterTexture??p,this._transformGridTexture??p,this._colormapTexture??p)}get isBilinearWithStretchColorRamp(){const{symbolizerParameters:t}=this;return"bilinear"===this.interpolation&&null!=t.colormap&&"stretch"===t.type}get memoryUsage(){if(null==this._memoryUsed){const t=[this._rasterTexture,this._transformGridTexture,this._colormapTexture];this._memoryUsed=t.map((t=>null!=t?t.descriptor.width*t.descriptor.height*4:0)).reduce(((t,e)=>t+e),0)}return this._memoryUsed}release(){return this._rasterTexture=t(this._rasterTexture),this._transformGridTexture=t(this._transformGridTexture),this._colormapTexture=t(this._colormapTexture),this.source=null,this.transformGrid=null,this.rawPixelData=null,!0}_updateRasterTexture(e,r){const s=this.source?this.source.extractBands(r):null;if(!(s?.pixels&&s.pixels.length>0))return void(this._rasterTexture=t(this._rasterTexture));const i=null==r&&null==this.bandIds||null!=r&&null!=this.bandIds&&r.join("")===this.bandIds.join("");if(null!=this._rasterTexture&&i)return;this._rasterTexture=t(this._rasterTexture);const o=this._getRasterTextureInterpolation(this.interpolation);this._rasterTexture=h(e,s,o,this.isRendereredSource||this.hasStretchTypeNone())}hasStretchTypeNone(){return"stretchType"in this.symbolizerParameters&&"none"===this.symbolizerParameters.stretchType&&!this.symbolizerParameters.useGamma&&"u8"===this.source.pixelType}_getRasterTextureInterpolation(t){return"lut"===this.symbolizerParameters.type||"nearest"===t||"majority"===t||this.isBilinearWithStretchColorRamp?"nearest":"bilinear"}_updateColormapTexture(e){const r=this._colormap,s=this.symbolizerParameters.colormap;return s?r?s.length!==r.length||s.some(((t,e)=>t!==r[e]))?(this._colormapTexture=t(this._colormapTexture),this._colormapTexture=n(e,s),void(this._colormap=s)):void 0:(this._colormapTexture=n(e,s),void(this._colormap=s)):(this._colormapTexture=t(this._colormapTexture),void(this._colormap=null))}}export{m as RasterTile};