UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 6.93 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import has from"../../../../core/has.js";import{numberMaxFloat32 as t}from"../../../../core/mathUtils.js";import{property as r,subclass as i}from"../../../../core/accessorSupport/decorators.js";import{isFunctionRaster as s}from"../../../../layers/raster/datasets/datasetUtils.js";import{getBytesPerPixel as n}from"../../../../layers/raster/formats/pixelRangeUtils.js";import{convertGeometryToMask as o}from"../../../../layers/raster/functions/clipUtils.js";import{maxMapSizeGpu as a}from"../../../../layers/raster/functions/pixelUtils.js";import{RasterTileContainer as l}from"../../engine/imagery/RasterTileContainer.js";import{BaseImageryTileSubView2D as c}from"./BaseImageryTileSubView2D.js";import{canUseMajorityInterpolationOnDataSource as h}from"../support/util.js";import{defaultColor as d}from"../../../support/HighlightDefaults.js";import{getHighlightName as p}from"../../../support/highlightOptionsUtils.js";const u=[1024,1024];let m=class extends c{constructor(){super(...arguments),this.type="raster"}get canUseWebGLForProcessing(){const{loaded:e,symbolizer:t}=this.layer;if(!e||!t||this.hasDRAInRasterFunction)return!1;const r=t.lookup.colormapLut?.indexedColormap,i=r&&r.length>this._maxIndexedColormapSize,s=n(this.layer.serviceRasterInfo);return!(has("ios")&&s>4)&&this.useWebGLForProcessing&&t.canRenderInWebGL&&!i&&!("majority"===this.layer.interpolation&&h(this.layer))}attach(){super.attach(),this.container=new l(this._tileInfoView),this.container.isCustomTilingScheme=this._isCustomTilingScheme,this.updateRasterFunctionParameters()}detach(){super.detach(),this.container.removeAllChildren(),this.container=null}fetchTile(e,t){return this.layer.fetchTile(e.level,e.row,e.col,t)}updateRasterFunctionParameters(){const{raster:e,type:t}=this.layer,{container:r}=this;if("Function"!==e.datasetFormat||"wcs"===t)return r.rasterFunctionChain=null,r.children.forEach(e=>{const{bitmap:t}=e;t&&(t.suspended=!0,t.processed=!1,t.projected&&(t.invalidateTexture(),t.rasterTexture=null))}),void(this._rasterFunctionState="na");const i=this._rasterFunctionState,{rasterFunction:s,primaryRasters:n}=e,o=s.supportsGPU&&(!n||n.rasters.length<=1),a=o?s.flatWebGLFunctionChain:null,{renderer:l}=this.layer,c=!o||!a?.functions.length||"raster-stretch"===l?.type&&l.dynamicRangeAdjustment||!this.canUseWebGLForProcessing;r.rasterFunctionChain=c?null:this._addProjection(a);const h=null==s?"na":r.rasterFunctionChain?"gpu":"cpu",d=i===h||"na"===i&&"cpu"===h&&0===a?.functions?.length;r.children.forEach(e=>{const{bitmap:t}=e;t&&(t.suspended=!d,t.processed=!1,t.processedTexture=null)}),this._rasterFunctionState=h}async updateTileSource(e,t){const r=this._getBandIds(),i=this._getLayerInterpolation(),{canUseWebGLForProcessing:n}=this,{source:a,globalSymbolizerParams:l,suspended:c,coords:h,resolution:d}=t,p=this.isCPUBasedDRA?l:t.symbolizerParams,{bitmap:u}=e;if([u.x,u.y]=h,u.resolution=d,null!=a?.pixelBlock){const e={extent:a.extent,pixelBlock:a.pixelBlock,srcPixelSize:a.srcTilePixelSize};if(u.rawPixelData=e,n)u.source=a.pixelBlock,u.isRendereredSource=!1;else{const t=await this._renderTileData(e,l);u.source=t,u.isRendereredSource=!0}u.symbolizerParameters=n?p:null,u.transformGrid=n?a.transformGrid:null}else{const e=this.createEmptyTilePixelBlock();u.source=e,u.symbolizerParameters=n?p:null,u.transformGrid=null}const{isBsqTile:m}=this.layer.raster.rasterInfo.storageInfo;u.bandIds=n&&!m?r:null,u.width=this._tileInfoView.size[0],u.height=this._tileInfoView.size[1],u.interpolation=i,u.suspended=c;const{raster:g}=this.layer;if(s(g)){const t=g.getClippingGeometry(this.layerView.view.spatialReference);if(t){const r=g.getTileExtentFromTileInfo(e.key.level,e.key.row,e.key.col,this._tileInfoView.tileInfo);r&&(u.mask=o({srcExtent:r,geometry:t,size:[u.width,u.height]}))}}u.invalidateTexture()}async updateTileSymbolizerParameters(e,t,r){const{local:i,global:s}=t,n=this._getBandIds(),o=this._getLayerInterpolation(),{canUseWebGLForProcessing:a}=this,{bitmap:l}=e,{rawPixelData:c}=l;if(a||null==c)l.isRendereredSource&&null!=c&&(l.source=c.pixelBlock),l.isRendereredSource=!1;else{const e=await this._renderTileData(c,s,r);l.source=e,l.isRendereredSource=!0}l.symbolizerParameters=a?this.layerView.hasTilingEffects?s:i:null;const{isBsqTile:h}=this.layer.raster.rasterInfo.storageInfo;l.bandIds=a&&!h?n:null,l.interpolation=o,l.suspended=!1}updateHighlightOptions(e){if(!e.length)return void(this.container.pixelHighlights=void 0);const r=[],{highlights:i}=this.layerView.view;e.sort((e,t)=>i.findIndex(({name:e})=>e===p(t.options))-i.findIndex(({name:t})=>t===p(e.options)));for(const{target:s,options:n}of e){const{pixelRanges:e}=s,l=p(n),c=(i.find(e=>e.name===l)?.color??d).toUnitRGBA();if(Array.isArray(e)){const i=Array.from({length:2*a},()=>0);for(let t=0;t<e.length;t++)i[2*t]=e[t][0],i[2*t+1]=e[t][1];for(let r=e.length;r<a;r++)i[2*r]=t,i[2*r+1]=-t;const n=s.bandId??0;r.push({ranges:i,bandId:n,color:c,type:"single-band"})}else{const t="extent"===e.type?e:e.extent;if(!t)continue;const i=[t.xmin,t.xmax],n=[t.ymin,t.ymax],{xBandId:a,yBandId:l}=s,h={xRange:i,yRange:n,bandIds:[a,l],color:c,type:"xy-band"};"polygon"===e.type&&(h.maskSize=u,h.mask=o({srcExtent:t,geometry:e,size:u})),r.push(h)}}this.container.pixelHighlights=r,this.canUseWebGLForProcessing||this.doRefresh()}_getLayerInterpolation(){const{interpolation:e,renderer:t}=this.layer;if(!t)return e;const r=t.type;return"raster-colormap"===r||"unique-value"===r?"nearest":"raster-stretch"===t.type&&null!=t.colorRamp?"bilinear"===e||"cubic"===e?"bilinear":"nearest":e}_addProjection(e){return e?.functions?.length&&!e.hasFocalFunction&&e.functions.unshift({name:"Reproject",parameters:{targetImageSize:this._tileInfoView.size,requireNNEdge:e.isSourceSingleBand},pixelType:"f32",id:0,isNoopProcess:!1}),e}_convertPixelHighlights(){return this.container?.pixelHighlights?.map(e=>{const r=e.color.map(e=>Math.round(255*e));if("single-band"===e.type){const i=e.ranges.indexOf(t),s=[],n=-1===i?e.ranges.length/2:i/2;for(let t=0;t<n;t++)s.push([e.ranges[2*t],e.ranges[2*t+1]]);return{bandId:e.bandId,color:r,ranges:s}}return{color:r,xBandId:e.bandIds[0],yBandId:e.bandIds[1],xBandRange:e.xRange,yBandRange:e.yRange,width:e.maskSize?.[0],height:e.maskSize?.[1],xyMask:e.mask}})}async _renderTileData(e,t,r){if(!e.pixelBlock)return null;const i=await this.layer.applyRenderer(e,"stretch"===t?.type?t:void 0,{signal:r}),s=this._convertPixelHighlights();return i&&s&&await this.layer.highlightPixels({pixelBlock:e.pixelBlock.extractBands(this.layer.bandIds),renderedPixelBlock:i,highlightOptions:s},{signal:r}),i}};e([r()],m.prototype,"canUseWebGLForProcessing",null),e([r()],m.prototype,"container",void 0),e([r()],m.prototype,"layer",void 0),e([r()],m.prototype,"type",void 0),m=e([i("esri.views.2d.layers.imagery.ImageryTileView2D")],m);export{m as default};