@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 15.9 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../request.js";import r from"../../core/Error.js";import i from"../../core/Logger.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import{Integer as n,ensureClass as o}from"../../core/accessorSupport/ensureType.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{enumeration as a}from"../../core/accessorSupport/decorators/enumeration.js";import{reader as l}from"../../core/accessorSupport/decorators/reader.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import u from"../../geometry/Point.js";import d from"../../geometry/SpatialReference.js";import{getInfo as m}from"../../geometry/support/spatialReferenceUtils.js";import{sanitizeUrl as h}from"../support/arcgisLayerUrl.js";import{url as p}from"../support/commonProperties.js";import f from"../support/DimensionalDefinition.js";import y from"../support/MultidimensionalSubset.js";import{interpolationKebab as b}from"../support/rasterEnums.js";import g from"../support/RasterFunction.js";import R from"../support/RasterJobHandler.js";import F from"../support/TileInfo.js";import _ from"../support/rasterDatasets/FunctionRaster.js";import{getEffectiveMultidimensionalDefinition as I,getDefaultVariableInfo as J,isMultiSliceOrRangeDefinition as v,convertOleDateTimeToEpoch as S,getSubsetVariablesFromMdInfo as w,getDefaultMultidimensionalDefinition as x}from"../support/rasterDatasets/multidimensionalUtils.js";import{snapToRaster as j,clip as D}from"../support/rasterFunctions/clipUtils.js";import{create as H}from"../support/rasterFunctions/rasterFunctionHelper.js";import{load as N,projectExtent as T,projectPolygon as O}from"../support/rasterFunctions/rasterProjectionHelper.js";import{computeStatisticsHistograms as P}from"../support/rasterFunctions/stretchUtils.js";import{convertVectorFieldData as z}from"../support/rasterFunctions/vectorFieldUtils.js";import{normalizeRendererJSON as C,getVariableRasterInfo as E,getDefaultInterpolation as U,matchPresetRenderer as M,getDefaultBandCombination as k,getFunctionColorRamp as q,createDefaultRenderer as B}from"../../renderers/support/rasterRendererHelper.js";import L from"../../renderers/support/RasterSymbolizer.js";import{rasterRendererTypes as V,websceneRasterRendererTypes as A,read as $}from"../../renderers/support/rasterTypeUtils.js";import G from"../../rest/support/ImageHistogramParameters.js";import{createFlowMesh as W}from"../../views/2d/engine/flow/dataUtils.js";const K=K=>{let Q=class extends K{constructor(...e){super(...e),this._isConstructedFromFunctionRaster=!1,this._rasterJobHandler={instance:null,refCount:0,connectionPromise:null},this.bandIds=null,this.copyright=null,this.interpolation=null,this.multidimensionalSubset=null,this.raster=null,this.serviceRasterInfo=null,this.sourceJSON=null,this.spatialReference=null,this.symbolizer=null,this._isConstructedFromFunctionRaster="Function"===e[0]?.raster?.datasetFormat}get fullExtent(){return this.serviceRasterInfo?.extent}set multidimensionalDefinition(e){this._set("multidimensionalDefinition",e),this.updateRenderer()}set rasterFunction(e){"none"===e?.functionName?.toLowerCase()&&(e=void 0),this._set("rasterFunction",e),this.updateRasterFunction()}set url(e){this._set("url",h(e,i.getLogger(this)))}get renderer(){if("imagery-tile"!==this.type)return this.internalRenderer;const{activePresetRendererName:e,presetRenderers:t}=this;if(e){const r=t?.find((({name:t})=>t===e));return r?.renderer.clone()}return this.internalRenderer}set renderer(e){"imagery-tile"===this.type&&(this.activePresetRendererName=null),this.internalRenderer=e}set internalRenderer(e){null==e&&null==this.rasterFunction?this._configDefaultRenderer("override"):(this._set("internalRenderer",e),this.updateRenderer())}readRenderer(e,t,r){const i=t?.layerDefinition?.drawingInfo?.renderer;return $(i,r)||void 0}async convertVectorFieldData(e,t){const{serviceRasterInfo:r}=this;if(null==e||!r)return null;const i=this._rasterJobHandler.instance,s=r.dataType;return i?i.convertVectorFieldData({pixelBlock:e,dataType:s},t):z(e,s)}async computeStatisticsHistograms(e,t){await this.load(t),e=o(G,e).clone();const{serviceRasterInfo:i}=this;if(null==i)throw new r("imagery-tile-mixin:compute-statistics-histograms","serviceRasterInfo must be specified");const{geometry:s}=e;if(null==s)throw new r("imagery-tile-mixin:compute-statistics-histograms","geometry must be specified");let n=s;const{spatialReference:a}=i;s.spatialReference.equals(a)||(await N(),n="extent"===s.type?T(s,a):O(s,a));const l=e.pixelSize??new u({x:i.pixelSize.x,y:i.pixelSize.y,spatialReference:a}),{extent:c,width:d,height:m}=j(i,n,l),h=await this.fetchPixels(c,d,m,{...t,interpolation:"nearest"});if(null==h.pixelBlock)throw new r("imagery-tile-mixin:compute-statistics-histograms","failed to fetch pixels");const p=await D(h.pixelBlock,c,n),f=this._rasterJobHandler.instance;return f?f.computeStatisticsHistograms({pixelBlock:p},t):P(p)}async createFlowMesh(e,t){const r=this._rasterJobHandler.instance;return r?r.createFlowMesh(e,t):W(e.meshType,e.simulationSettings,e.flowData,null!=t.signal?t.signal:(new AbortController).signal)}normalizeRasterFetchOptions(e){const{multidimensionalInfo:t}=this.serviceRasterInfo??{};if(null==t)return e;const r=I({rasterInfo:this.raster.rasterInfo,multidimensionalDefinition:e.multidimensionalDefinition||this.multidimensionalDefinition,timeExtent:e.timeExtent??this.timeExtent,multidimensionalSubset:this.multidimensionalSubset});return{...e,multidimensionalDefinition:r}}async updateRasterFunction(){return this.loaded&&"imagery-tile"===this.type&&(this.rasterFunction||this._cachedRasterFunctionJson)&&JSON.stringify(this.rasterFunction)!==JSON.stringify(this._cachedRasterFunctionJson)?(this._cachedRasterFunctionJson=this.rasterFunction?.toJSON(),this._rasterFunctionUpdatePromise=this._updateRasterFunction(),this._rasterFunctionUpdatePromise):this._rasterFunctionUpdatePromise}async updateRenderer(){const{loaded:e,symbolizer:t}=this;if(!e||!t||!this.renderer)return;const{rasterInfo:r}=this.raster,i=J(r,{multidimensionalDefinition:this.multidimensionalDefinition,multidimensionalSubset:this.multidimensionalSubset}),s=i?.name,n=C({...this.renderer.toJSON(),variableName:s});if(JSON.stringify(this._cachedRendererJson)===JSON.stringify(n))return;const o=this._rasterJobHandler.instance;o&&(t.rasterInfo=E(r,s),t.rendererJSON=n,t.bind(),await o.updateSymbolizer(t),this._cachedRendererJson=n)}async applyRenderer(e,t){const r=e?.pixelBlock;if(!(null!=r&&r.pixels&&r.pixels.length>0))return null;let i;await this.updateRenderer();const s=this._rasterJobHandler.instance,n=this.bandIds??[];return i=s?await s.symbolize({...e,simpleStretchParams:t,bandIds:n}):this.symbolizer.symbolize({...e,simpleStretchParams:t,bandIds:n}),i}getTileUrl(e,t,r){return"RasterTileServer"===this.raster.datasetFormat?`${this.url}/tile/${e}/${t}/${r}`:""}getCompatibleTileInfo(e,t,r=!1){if(!this.loaded||null==t)return null;if(r&&e.equals(this.spatialReference))return this.tileInfo;const i=m(e);return F.create({size:256,spatialReference:e,origin:i?{x:i.origin[0],y:i.origin[1]}:{x:t.xmin,y:t.ymax}})}getCompatibleFullExtent(e){return this.loaded?(this._compatibleFullExtent?.spatialReference.equals(e)||(this._compatibleFullExtent=this.raster.computeExtent(e)),this._compatibleFullExtent):null}async fetchTile(e,r,i,s={}){if(X(this),s.requestAsImageElement){const n=this.getTileUrl(e,r,i);return t(n,{responseType:"image",query:{...this.refreshParameters,...this.raster.ioConfig.customFetchParameters},signal:s.signal}).then((e=>e.data))}const{serviceRasterInfo:n}=this;if(null!=n.multidimensionalInfo&&null==(s=this.normalizeRasterFetchOptions(s)).multidimensionalDefinition){const t=s.tileInfo||n.storageInfo.tileInfo;return{extent:this.raster.getTileExtentFromTileInfo(e,r,i,t),pixelBlock:null}}return await this._initJobHandler(),await this.updateRasterFunction(),"raster-shaded-relief"===this.renderer?.type&&(s={...s,buffer:{cols:1,rows:1}}),this.raster.fetchTile(e,r,i,s)}async fetchPixels(e,t,r,i={}){return null!=this.serviceRasterInfo.multidimensionalInfo&&null==(i=this.normalizeRasterFetchOptions(i)).multidimensionalDefinition?{extent:e,pixelBlock:null}:(await this._initJobHandler(),await this.updateRasterFunction(),t=Math.round(t),r=Math.round(r),this.raster.fetchPixels(e,t,r,i))}async identify(e,t={}){await this.load();const{raster:i,serviceRasterInfo:s}=this;if(null!=s?.multidimensionalInfo){if(!(s.hasMultidimensionalTranspose&&!!(v(t.multidimensionalDefinition)||t.transposedVariableName||t.timeExtent))&&null==(t=this.normalizeRasterFetchOptions(t)).multidimensionalDefinition)return{location:e,value:null}}const n=this.multidimensionalSubset?.areaOfInterest;if(n&&!n.contains(e))throw new r("imagery-tile-mixin:identify","the request cannot be fulfilled when falling outside of the multidimensional subset");return i.identify(e,t)}increaseRasterJobHandlerUsage(){this._rasterJobHandler.refCount++}decreaseRasterJobHandlerUsage(){this._rasterJobHandler.refCount--,this._rasterJobHandler.refCount<=0&&this._shutdownJobHandler()}hasStandardTime(){const e=this.serviceRasterInfo?.multidimensionalInfo;if(null==e||"standard-time"!==this.serviceRasterInfo?.dataType)return!1;const t=this.multidimensionalDefinition,r=t?.[0]?.variableName;return e.variables.some((e=>e.name===r&&(!t?.[0].dimensionName||e.dimensions.some((e=>"StdTime"===e.name)))))}getStandardTimeValue(e){return new Date(S(e)).toISOString()}getMultidimensionalSubsetVariables(e){const t=e??this.serviceRasterInfo?.multidimensionalInfo;return w(this.multidimensionalSubset,t)}_configDefaultSettings(){this._configDefaultInterpolation(),this.multidimensionalDefinition||(this.multidimensionalDefinition=x(this.raster.rasterInfo,{multidimensionalSubset:this.multidimensionalSubset})),this.rasterFunction&&"Function"===this.raster.datasetFormat&&(this._cachedRasterFunctionJson=this.rasterFunction.toJSON()),this._configDefaultRenderer()}_initJobHandler(){if(null!=this._rasterJobHandler.connectionPromise)return this._rasterJobHandler.connectionPromise;const e=new R;return this._rasterJobHandler.connectionPromise=e.initialize().then((async()=>{X(this),this._rasterJobHandler.instance=e,this.raster.rasterJobHandler=e,"Function"===this.raster.datasetFormat&&this.raster.syncJobHandler(),this.rasterFunction&&await this.updateRasterFunction().catch((()=>{})),this.renderer&&this.updateRenderer()})).catch((()=>{})),this._rasterJobHandler.connectionPromise}_shutdownJobHandler(){this._rasterJobHandler.instance&&this._rasterJobHandler.instance.destroy(),this._rasterJobHandler.instance=null,this._rasterJobHandler.connectionPromise=null,this._rasterJobHandler.refCount=0,this._cachedRendererJson=null,this.raster&&(this.raster.rasterJobHandler=null)}_configDefaultInterpolation(){if(null==this.interpolation){X(this);const{raster:e}=this,t=U(e.rasterInfo,e.tileType,this.sourceJSON?.defaultResamplingMethod);this._set("interpolation",t)}}_configDefaultRenderer(e="no"){X(this);const{rasterInfo:t}=this.raster,r=J(t,{multidimensionalDefinition:this.multidimensionalDefinition,multidimensionalSubset:this.multidimensionalSubset}),s=r?.name,n=M({variableName:s,rasterFunctionName:this.rasterFunction?.functionName,presetRenderers:this.presetRenderers});if(!this.bandIds&&t.bandCount>1&&(this.bandIds=n?.bandIds??k(t)),!this.renderer||"override"===e){const e=q(this.raster),r=n?.renderer??B(t,{bandIds:this.bandIds,variableName:s,rasterFunctionColorRamp:e}),i=t.statistics,o=i&&i.length>0?i[0]:null,a=o?.max??0,l=o?.min??0;"WCSServer"===this.raster.datasetFormat&&"raster-stretch"===r.type&&(a>1e24||l<-1e24)&&(r.dynamicRangeAdjustment=!0,r.customStatistics=null,"none"===r.stretchType&&(r.stretchType="min-max")),this.renderer=r}const o=C({...this.renderer.toJSON(),variableName:s}),a=E(t,s);this.symbolizer?(this.symbolizer.rendererJSON=o,this.symbolizer.rasterInfo=a):this.symbolizer=new L({rendererJSON:o,rasterInfo:a});const l=this.symbolizer.bind();if(l.success){if("auto"===e){const{colormap:e}=this.raster.rasterInfo,t=this.renderer;if(null!=e&&"raster-colormap"===t.type){const e=B(this.raster.rasterInfo);JSON.stringify(e)!==JSON.stringify(t)&&this._configDefaultRenderer("override")}else if("raster-stretch"===t.type){const e=this.bandIds?.length,r=t.customStatistics?.length;!t.dynamicRangeAdjustment&&r&&e&&r!==e&&this._configDefaultRenderer("override")}}}else i.getLogger(this).warn("imagery-tile-mixin",l.error||"The given renderer is not supported by the layer."),"auto"===e&&this._configDefaultRenderer("override")}async _updateRasterFunction(){if(this._isConstructedFromFunctionRaster&&"Function"===this.raster.datasetFormat){const e=this.raster.rasterFunction.toJSON();return void(!this.rasterFunction&&e&&this._set("rasterFunction",g.fromJSON(e)))}let e,t=this.raster,r=!1;"Function"===t.datasetFormat?(e=t.primaryRasters.rasters,t=e[0],r=!0):e=[t];const{rasterFunction:i}=this;if(i){const r={raster:t};e.length>1&&e.forEach((e=>r[e.url]=e));const s=H(i.functionDefinition?.toJSON()??i.toJSON(),r),n=new _({rasterFunction:s});n.rasterJobHandler=this._rasterJobHandler.instance,await n.open(),this.raster=n}else this.raster=t,await t.open();if(this._cachedRendererJson=null,!r&&!i)return;const{bandIds:s}=this,{bandCount:n}=this.raster.rasterInfo,o=s?.length?s.some((e=>e>=n)):n>=3;s&&(o||this.renderer&&"raster-stretch"!==this.renderer.type)&&this._set("bandIds",null),this._configDefaultRenderer("auto")}};function X(e){if(!e.raster||!e.serviceRasterInfo)throw new r("imagery-tile","no raster")}return e([s({clonable:!1})],Q.prototype,"_cachedRendererJson",void 0),e([s({clonable:!1})],Q.prototype,"_cachedRasterFunctionJson",void 0),e([s({clonable:!1})],Q.prototype,"_compatibleFullExtent",void 0),e([s({clonable:!1})],Q.prototype,"_isConstructedFromFunctionRaster",void 0),e([s({clonable:!1})],Q.prototype,"_rasterJobHandler",void 0),e([s({clonable:!1})],Q.prototype,"_rasterFunctionUpdatePromise",void 0),e([s({type:[n],json:{write:{overridePolicy(){return{enabled:!this.loaded||"Raster"===this.raster.tileType||"0,1,2"!==this.bandIds?.join(",")}}}}})],Q.prototype,"bandIds",void 0),e([s({json:{origins:{service:{read:{source:"copyrightText"}}}}})],Q.prototype,"copyright",void 0),e([s({json:{read:!1}})],Q.prototype,"fullExtent",null),e([s({json:{write:{overridePolicy(){return{enabled:!this.loaded||"Raster"===this.raster.tileType||"bilinear"!==this.interpolation}}}}}),a(b)],Q.prototype,"interpolation",void 0),e([s()],Q.prototype,"ioConfig",void 0),e([s({type:[f],json:{write:!0}})],Q.prototype,"multidimensionalDefinition",null),e([s({type:y,json:{write:!0}})],Q.prototype,"multidimensionalSubset",void 0),e([s()],Q.prototype,"raster",void 0),e([s({type:g})],Q.prototype,"rasterFunction",null),e([s()],Q.prototype,"serviceRasterInfo",void 0),e([s()],Q.prototype,"sourceJSON",void 0),e([s({readOnly:!0,type:d,json:{read:!1}})],Q.prototype,"spatialReference",void 0),e([s({type:F})],Q.prototype,"tileInfo",void 0),e([s(p)],Q.prototype,"url",null),e([s()],Q.prototype,"renderer",null),e([s({types:V,json:{name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy(){const e="raster-stretch"===this.renderer?.type&&"none"===this.renderer.stretchType&&!this.renderer.useGamma;return{enabled:!this.loaded||"Raster"===this.raster.tileType||!e}}},origins:{"web-scene":{types:A,name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy:e=>({enabled:e&&"vector-field"!==e.type&&"flow"!==e.type})}}}}})],Q.prototype,"internalRenderer",null),e([l("internalRenderer")],Q.prototype,"readRenderer",null),e([s({clonable:!1})],Q.prototype,"symbolizer",void 0),Q=e([c("esri.layers.mixins.ImageryTileMixin")],Q),Q};export{K as ImageryTileMixin};