@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 8.02 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t}from"../../../chunks/tslib.es6.js";import s from"../../../core/JSONSupport.js";import{property as e}from"../../../core/accessorSupport/decorators/property.js";import{cast as r}from"../../../core/accessorSupport/decorators/cast.js";import"../../../core/has.js";import"../../../core/RandomLCG.js";import{subclass as i}from"../../../core/accessorSupport/decorators/subclass.js";import n from"../PixelBlock.js";import o from"../RasterInfo.js";const a=new Set(["slope","aspect","curvature","hillshade","shadedrelief","statistics"]);let u=class extends s{constructor(){super(...arguments),this.functionArguments=null,this.readingBufferSize=0,this.id=-1,this.isNoopProcess=!1,this.rawInputBandIds=[],this.rawSourceRasterInfos=null,this.isInputBandIdsSwizzled=!1,this.swizzledBandSelection=[],this.isBranch=!1,this.isRoot=!1,this._bindingResult=null}get supportsGPU(){return this._bindingResult.supportsGPU}get flatWebGLFunctionChain(){const t=this.getWebGLProcessorDefinition();if(!t)return null;const s=[t],{parameters:e}=t;let r=e.rasters||e.raster&&[e.raster];for(;r?.length;){s.unshift(...r);const t=[];for(let s=0;s<r.length;s++){const{parameters:e}=r[s],i=e.rasters||e.raster&&[e.raster];i?.length&&t.push(...i)}r=t}for(let a=s.length-1;a>=0;a--)s[a].isNoopProcess&&s.splice(a,1);let i=!1;for(let a=0;a<s.length;a++){const t=s[a];t.id=s.length-a-1;const{rasters:e}=t.parameters;i=i||null!=e&&e.length>1}const n=s.some((({name:t})=>a.has(t.toLowerCase()))),{rawSourceRasterInfos:o}=this;return{functions:s,hasBranches:i,hasFocalFunction:n,isSourceSingleBand:1===o?.[0]?.bandCount}}bind(t,s=!1,e=-1){this.id=e+1;const r=this._getRasterValues();let i=!0;for(let n=0;n<r.length;n++){const e=r[n];if(null!=e&&this._isRasterFunctionValue(e)){const r=e.bind(t,s,this.id+n);if(!r.success)return this._bindingResult=r,r;i=i&&r.supportsGPU}}if(!this.rasterInfo||s){if(this.sourceRasterInfos=this._getSourceRasterInfos(t),this._bindingResult=this._bindSourceRasters(),i&&=this._bindingResult.supportsGPU,this._bindingResult.success&&(this._patchRasterInfo(),i&&this.isRoot)){this.processInputBandIds();this.swizzleInputBandIds(this.rawInputBandIds)||(i=this.rawInputBandIds.length<=3)}return this._bindingResult.supportsGPU=i,this._bindingResult}return this._bindingResult={success:!0,supportsGPU:!0},this._bindingResult}process(t){const s=this._getRasterValues(),e=0===s.length?t.pixelBlocks??t.primaryPixelBlocks:s.map((s=>this._readRasterValue(s,t)));return this._processPixels({...t,pixelBlocks:e})}processInputBandIds(){const t=this._getRasterValues().filter(this._isRasterFunctionValue);if(t.length>1){const s=t.map((t=>t.processInputBandIds()));return this.rawInputBandIds=[...new Set(s.flat())],this.rawInputBandIds}const s=t[0];if(s)return this.rawInputBandIds=s.processInputBandIds(),this.rawInputBandIds;const{bandCount:e}=this.sourceRasterInfos[0],r=Array.from({length:e},((t,s)=>s));return this.rawInputBandIds=this._getInputBandIds(r),this.rawInputBandIds}swizzleInputBandIds(t){const s=this._getRasterValues().filter(this._isRasterFunctionValue);let e=!0;for(const r of s)e=r.swizzleInputBandIds(t)&&e;return!!e&&this._swizzleBandIds(t)}getPrimaryRasters(){const t=[],s=[];return this._getPrimaryRasters(this,t,s),{rasters:t,rasterIds:s}}getWebGLProcessorDefinition(){const t=this._getWebGLParameters(),{raster:s,rasters:e}=this.functionArguments;return e&&Array.isArray(e)&&e.length?(t.rasters=e.map((t=>this._isRasterFunctionValue(t)?t.getWebGLProcessorDefinition():"number"==typeof t?{name:"Constant",parameters:{value:t},pixelType:"f32",id:-1,isNoopProcess:!1}:{name:"Identity",parameters:{value:t},pixelType:"f32",id:-1,isNoopProcess:!1})),t.rasters.some((t=>null!=t))||(t.rasters=null)):this._isRasterFunctionValue(s)&&(t.raster=s.getWebGLProcessorDefinition()),{name:this.functionName,parameters:t,pixelType:this.outputPixelType,id:this.id,isNoopProcess:this.isNoopProcess}}getClippingGeometries(){const t=[];"Clip"===this.functionName&&t.push(this.functionArguments);const{raster:s,rasters:e}=this.functionArguments;if(e&&Array.isArray(e)&&e.length)e.forEach((s=>{if(this._isRasterFunctionValue(s)){const e=s.getClippingGeometries();t.push(...e)}}));else if(this._isRasterFunctionValue(s)){const e=s.getClippingGeometries();t.push(...e)}return t}_getOutputPixelType(t){return"unknown"===this.outputPixelType?t:this.outputPixelType??t}_getWebGLParameters(){return{}}_getInputBandIds(t){return t}_swizzleBandIds(t){return!0}_isInputRasterPrimaryOrConstant(){return!this._getRasterValues().some((t=>t&&"object"==typeof t&&"rasterFunction"in t&&t.rasterFunction))}_removeStatsHistColormapVAT(t){t.statistics=null,t.histograms=null,t.colormap=null,t.attributeTable=null,t.multidimensionalInfo?.variables.forEach((t=>{t.statistics=void 0,t.histograms=void 0}))}_getRasterValues(){const{rasterArgumentNames:t}=this;return"rasters"===t[0]?this.functionArguments.rasters??[]:t.flatMap((t=>this.functionArguments[t]))}_getSourceRasterInfos(t){const s=this._getRasterValues(),{rasterInfos:e,rasterIds:r}=t;if(0===s.length)return e;const i=s.map((t=>t&&"object"==typeof t&&"bind"in t&&t.rasterInfo?t.rasterInfo:"string"==typeof t&&r.includes(t)?e[r.indexOf(t)]:"number"!=typeof t?e[0]:void 0)),n=i.find((t=>t))??e[0];return i.forEach(((t,s)=>{void 0===t&&(i[s]=n)})),i}_getPrimaryRasterId(t){return t?.rasterId}_getPrimaryRasters(t,s=[],e=[]){for(let r=0;r<t.sourceRasters.length;r++){const i=t.sourceRasters[r];if("number"!=typeof i)if("bind"in i)this._getPrimaryRasters(i,s,e);else{const t=i,r=this._getPrimaryRasterId(t);if(null==r)continue;e.includes(r)||(this.mainPrimaryRasterId===r?(s.unshift(t),e.unshift(r)):(s.push(t),e.push(r)))}}}_isRasterFunctionValue(t){return null!=t&&"object"==typeof t&&"getWebGLProcessorDefinition"in t}_readRasterValue(t,s){const{primaryPixelBlocks:e}=s;if(null==t||"$$"===t){const t=e[0];return null==t?null:t.clone()}if("string"==typeof t){const r=s.primaryRasterIds.indexOf(t);return-1===r?null:e[r]}if("number"==typeof t){const s=e[0];if(null==s)return null;const{width:r,height:i,pixelType:o}=s,a=new Float32Array(r*i);a.fill(t);const u=this.sourceRasterInfos[0].bandCount,p=new Array(u).fill(a);return new n({width:r,height:i,pixelType:o,pixels:p})}return t.process(s)}_patchRasterInfo(){const{rasterInfo:t}=this;if(!t?.keyProperties)return;const{bandCount:s,keyProperties:e,statistics:r,histograms:i}=t,n=e.BandProperties;n&&n.length!==s&&(t.keyProperties={...e,BandProperties:void 0}),r&&r.length!==s&&(t.statistics=r.length>s?r.slice(0,s):null),i&&i.length!==s&&(t.histograms=i.length>s?i.slice(0,s):null),e.BAND_COUNT&&Number(e.BAND_COUNT)!==s&&(t.keyProperties={...e,BAND_COUNT:"string"==typeof e.BAND_COUNT?String(s):s})}};t([e({json:{write:!0}})],u.prototype,"functionName",void 0),t([e({json:{write:!0}})],u.prototype,"functionArguments",void 0),t([e()],u.prototype,"rasterArgumentNames",void 0),t([e({json:{write:!0}}),r((t=>t?.toLowerCase()))],u.prototype,"outputPixelType",void 0),t([e({json:{write:!0}})],u.prototype,"mainPrimaryRasterId",void 0),t([e()],u.prototype,"sourceRasters",void 0),t([e({type:[o],json:{write:!0}})],u.prototype,"sourceRasterInfos",void 0),t([e({json:{write:!0}})],u.prototype,"rasterInfo",void 0),t([e({json:{write:!0}})],u.prototype,"readingBufferSize",void 0),t([e({json:{write:!0}})],u.prototype,"id",void 0),t([e()],u.prototype,"isNoopProcess",void 0),t([e()],u.prototype,"supportsGPU",null),t([e()],u.prototype,"rawInputBandIds",void 0),t([e()],u.prototype,"rawSourceRasterInfos",void 0),t([e()],u.prototype,"isInputBandIdsSwizzled",void 0),t([e()],u.prototype,"swizzledBandSelection",void 0),t([e()],u.prototype,"isBranch",void 0),t([e()],u.prototype,"isRoot",void 0),t([e({readOnly:!0})],u.prototype,"flatWebGLFunctionChain",null),t([e()],u.prototype,"_bindingResult",void 0),u=t([i("esri.layers.support.rasterFunctions.BaseRasterFunction")],u);const p=u;export{p as default};