UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.42 kB
import{disposeMaybe as t,isSome as e,isNone as r}from"../../../core/maybe.js";import{C as s}from"../../../chunks/RasterColorizer.glsl.js";import{TextureSamplingMode as i}from"../../webgl/enums.js";import{createTransformTexture as o,getCommonUniforms as a,getColormapUniforms as h,getStretchUniforms as n,getShadedReliefUniforms as l,createRasterTexture as u,createColormapTexture as m}from"../../webgl/rasterUtils.js";const d={bandCount:3,outMin:0,outMax: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 _{constructor(t,e,r=null,s=null){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.lij=null,this.opacity=1,this.lij=t,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?{...d,maxCutOff:[1,1,1],factor:[1,1,1]}:this._symbolizerParameters||d}set symbolizerParameters(t){this._symbolizerParameters=t}get bandIds(){return this._bandIds}set bandIds(t){if(e(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,e(this._rasterTexture)){const e=this._getRasterTextureInterpolation(t);this._rasterTexture.setSamplingMode("bilinear"===e?i.LINEAR:i.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)&&((r(this._rasterTexture)||this._dirty)&&this._updateRasterTexture(t,this.bandIds),e(this._rasterTexture)&&(this._updateColormapTexture(t),this.transformGrid&&r(this._transformGridTexture)&&(this._transformGridTexture=o(t,this.transformGrid))),!0)}getUniforms(){const{symbolizerParameters:t,transformGrid:e,width:r,height:i,opacity:o}=this,u=a(e,[r,i],[this.source.width,this.source.height],o),m=h(t.colormap,t.colormapOffset),d="stretch"===this.symbolizerParameters.type?n(this.symbolizerParameters):null,_="hillshade"===this.symbolizerParameters.type?l(this.symbolizerParameters):null;return new s(u,m,d||_,this._rasterTexture,this._transformGridTexture,this._colormapTexture)}get memoryUsage(){if(r(this._memoryUsed)){const t=[this._rasterTexture,this._transformGridTexture,this._colormapTexture];this._memoryUsed=t.map((t=>e(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(s,i){const o=this.source?this.source.extractBands(i):null;if(!(o&&o.pixels&&o.pixels.length>0))return void(this._rasterTexture=t(this._rasterTexture));const a=r(i)&&r(this.bandIds)||e(i)&&e(this.bandIds)&&i.join("")===this.bandIds.join("");if(e(this._rasterTexture)&&a)return;this._rasterTexture=t(this._rasterTexture);const h=this._getRasterTextureInterpolation(this.interpolation);this._rasterTexture=u(s,o,h,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?"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=m(e,s),void(this._colormap=s)):void 0:(this._colormapTexture=m(e,s),void(this._colormap=s)):(this._colormapTexture=t(this._colormapTexture),void(this._colormap=null))}}export{_ as RasterTile};