12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import"../../geometry.js";import{rasterRendererTypes as t}from"../../rasterRenderers.js";import r from"../../request.js";import i from"../../core/Error.js";import s from"../../core/Logger.js";import{isNone as n,isSome as o}from"../../core/maybe.js";import{property as a}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import{getInfo as m}from"../../geometry/support/spatialReferenceUtils.js";import{sanitizeUrl as u}from"../support/arcgisLayerUrl.js";import{url as d}from"../support/commonProperties.js";import h from"../support/DimensionalDefinition.js";import c from"../support/MultidimensionalSubset.js";import p from"../support/RasterFunction.js";import f from"../support/RasterJobHandler.js";import y from"../support/TileInfo.js";import b from"../support/rasterDatasets/FunctionRaster.js";import{getDefaultMultidimensionalDefinition as g,hasExcludedVariableOrDimension as I,isMultiSliceOrRangeDefinition as J,getSubsetVariablesFromMdInfo as _}from"../support/rasterDatasets/multidimensionalUtils.js";import{create as S}from"../support/rasterFunctions/rasterFunctionHelper.js";import{convertVectorFieldData as R}from"../support/rasterFunctions/vectorFieldUtils.js";import{normalizeRendererJSON as F,getDefaultInterpolation as x,getDefaultBandCombination as v,createDefaultRenderer as H}from"../../renderers/support/rasterRendererHelper.js";import j from"../../renderers/support/RasterSymbolizer.js";import{createFlowMesh as T}from"../../views/2d/engine/flow/dataUtils.js";import D from"../../geometry/SpatialReference.js";const w=s.getLogger("esri.layers.mixins.ImageryTileMixin"),N=s=>{let N=class extends s{constructor(){super(...arguments),this._rasterJobHandler={instance:null,refCount:0,connectionPromise:null},this.bandIds=null,this.copyright=null,this.interpolation="nearest",this.multidimensionalDefinition=null,this.multidimensionalSubset=null,this.raster=null,this.rasterFunction=null,this.sourceJSON=null,this.symbolizer=null}get fullExtent(){return this.rasterInfo?.extent}get rasterInfo(){return this.raster?.rasterInfo}get spatialReference(){return this.rasterInfo?.spatialReference??D.WGS84}get tileInfo(){return this.rasterInfo?.storageInfo.tileInfo}set url(e){this._set("url",u(e,w))}set renderer(e){this._set("renderer",e),this.updateRenderer()}async convertVectorFieldData(e,t){if(n(e)||!this.rasterInfo)return null;const r=this._rasterJobHandler.instance,i=this.rasterInfo.dataType;return r?r.convertVectorFieldData({pixelBlock:e,dataType:i},t):R(e,i)}async createFlowMesh(e,t){const r=this._rasterJobHandler.instance;return r?r.createFlowMesh(e,t):T(e.meshType,e.simulationSettings,e.flowData,o(t.signal)?t.signal:(new AbortController).signal)}normalizeRasterFetchOptions(e){const{multidimensionalInfo:t}=this.rasterInfo??{};if(n(t))return e;let r=e.multidimensionalDefinition||this.multidimensionalDefinition;!n(r)&&r.length||(r=g(this.raster.rasterInfo,{multidimensionalSubset:this.multidimensionalSubset}));const i=e.timeExtent||this.timeExtent;if(o(r)&&o(i)&&(o(i.start)||o(i.end))){r=r.map((e=>e.clone()));const s=t.variables.find((({name:e})=>e===r[0].variableName))?.dimensions?.find((({name:e})=>"StdTime"===e)),a=r.find((({dimensionName:e})=>"StdTime"===e));if(!s||!a)return{...e,multidimensionalDefinition:null};const{start:l,end:m}=i,u=n(l)?null:l.getTime(),d=n(m)?null:m.getTime(),h=u??d,c=d??u;if(o(s.values)){const e=s.values.filter((e=>{if(Array.isArray(e)){if(h===c)return e[0]<=h&&e[1]>=h;const t=e[0]<=h&&e[1]>h||e[0]<c&&e[1]>=c,r=e[0]>=h&&e[1]<=c||e[0]<h&&e[1]>c;return t||r}return h===c?e===h:e>=h&&e<=c}));if(e.length){const t=e.sort(((e,t)=>{if(h===c)return(e[0]??e)-(t[0]??t);return Math.abs((e[1]??e)-c)-Math.abs((t[1]??t)-c)}))[0];a.values=[t]}else r=null}else if(s.hasRegularIntervals&&s.extent){const[e,t]=s.extent;h>t||c<e?r=null:a.values=h===c?[h]:[Math.max(e,h),Math.min(t,c)]}}return o(r)&&I(r,this.multidimensionalSubset)?{...e,multidimensionalDefinition:null}:{...e,multidimensionalDefinition:r}}async updateRenderer(){const{loaded:e,symbolizer:t}=this;if(!e||!t)return;if(JSON.stringify(this._cachedRendererJson)===JSON.stringify(this.renderer))return;const r=this._rasterJobHandler.instance;r&&(t.rendererJSON=F(this.renderer.toJSON()),t.bind(),await r.updateSymbolizer(t),this._cachedRendererJson=this.renderer.toJSON())}async applyRenderer(e,t){const r=e&&e.pixelBlock;if(!(o(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||n(t))return null;if(r&&e.equals(this.spatialReference))return this.tileInfo;const i=m(e);return y.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&&this._compatibleFullExtent.spatialReference.equals(e)||(this._compatibleFullExtent=this.raster.computeExtent(e)),this._compatibleFullExtent):null}async fetchTile(e,t,i,s={}){if(O(this),s.requestAsImageElement){const n=this.getTileUrl(e,t,i);return r(n,{responseType:"image",query:{...this.refreshParameters,...this.raster.ioConfig.customFetchParameters},signal:s.signal}).then((e=>e.data))}if(o(this.rasterInfo.multidimensionalInfo)&&(s=this.normalizeRasterFetchOptions(s),n(s.multidimensionalDefinition))){const r=s.tileInfo||this.rasterInfo.storageInfo.tileInfo;return{extent:this.raster.getTileExtentFromTileInfo(e,t,i,r),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,t,i,s)}async fetchPixels(e,t,r,i={}){return o(this.rasterInfo.multidimensionalInfo)&&(i=this.normalizeRasterFetchOptions(i),n(i.multidimensionalDefinition))?{extent:e,pixelBlock:null}:(await this._initJobHandler(),await this._updateRasterFunction(),this.raster.fetchPixels(e,t,r,i))}async identify(e,t={}){if(O(this),o(this.rasterInfo.multidimensionalInfo)){if(!(this.rasterInfo.hasMultidimensionalTranspose&&!!(J(t.multidimensionalDefinition)||t.transposedVariableName||t.timeExtent))&&(t=this.normalizeRasterFetchOptions(t),n(t.multidimensionalDefinition)))return{location:e,value:null}}return this.raster.identify(e,t)}increaseRasterJobHandlerUsage(){this._rasterJobHandler.refCount++}decreaseRasterJobHandlerUsage(){this._rasterJobHandler.refCount--,this._rasterJobHandler.refCount<=0&&this._shutdownJobHandler()}hasStandardTime(){const e=this.rasterInfo?.multidimensionalInfo;if(n(e)||"standard-time"!==this.rasterInfo?.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(24*(e-25569)*3600*1e3).toString()}getMultidimensionalSubsetVariables(e){const t=e??this.rasterInfo.multidimensionalInfo;return _(this.multidimensionalSubset,t)}_configDefaultSettings(){this._configDefaultInterpolation(),this.multidimensionalDefinition||(this.multidimensionalDefinition=g(this.raster.rasterInfo,{multidimensionalSubset:this.multidimensionalSubset})),this._configDefaultRenderer()}_initJobHandler(){if(null!=this._rasterJobHandler.connectionPromise)return this._rasterJobHandler.connectionPromise;const e=new f;return this._rasterJobHandler.connectionPromise=e.initialize().then((()=>{O(this),this._rasterJobHandler.instance=e,this.raster.rasterJobHandler=e,this.renderer&&this.updateRenderer(),"Function"===this.raster.datasetFormat&&this.raster.syncJobHandler()})).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){O(this);const e=x(this.rasterInfo,this.raster.tileType,this.sourceJSON?.defaultResamplingMethod);this._set("interpolation",e)}}_configDefaultRenderer(){O(this);const e=this.raster.rasterInfo;if(this.bandIds||(this.bandIds=v(e)),!this.renderer){const t=H(e,{bandIds:this.bandIds,variableName:o(this.multidimensionalDefinition)?this.multidimensionalDefinition[0]?.variableName:null});"WCSServer"===this.raster.datasetFormat&&"raster-stretch"===t.type&&((e.statistics?.[0].max??0)>1e24||(e.statistics?.[0].min??0)<-1e24)&&(t.dynamicRangeAdjustment=!0,t.statistics=null,"none"===t.stretchType&&(t.stretchType="min-max")),this.renderer=t}this.symbolizer?(this.symbolizer.rendererJSON=F(this.renderer.toJSON()),this.symbolizer.rasterInfo=e):this.symbolizer=new j({rendererJSON:this.renderer.toJSON(),rasterInfo:e});const t=this.symbolizer.bind();t.success||w.warn("imagery-tile-mixin",t.error||"The given renderer is not supported by the layer.")}async _updateRasterFunction(){if("imagery-tile"!==this.type||JSON.stringify(this.rasterFunction)===JSON.stringify(this._cachedRasterFunctionJson))return;let e=this.raster;if("Function"===e?.datasetFormat){const t=e.rasterFunction.getPrimaryRasters();e=t.rasters[0]}const{rasterFunction:t}=this;if(t){const r=S(t.toJSON(),{raster:e}),i=new b({rasterFunction:r});i.rasterJobHandler=this._rasterJobHandler.instance,await i.open(),this._cachedRasterFunctionJson=this.rasterFunction?.toJSON(),this.raster=i}else this.raster=e}};function O(e){if(!e.raster||!e.rasterInfo)throw new i("imagery-tile","no raster")}return e([a()],N.prototype,"_cachedRendererJson",void 0),e([a()],N.prototype,"_cachedRasterFunctionJson",void 0),e([a()],N.prototype,"_compatibleFullExtent",void 0),e([a()],N.prototype,"_rasterJobHandler",void 0),e([a()],N.prototype,"bandIds",void 0),e([a({json:{origins:{service:{read:{source:"copyrightText"}}}}})],N.prototype,"copyright",void 0),e([a({json:{read:!1}})],N.prototype,"fullExtent",null),e([a()],N.prototype,"interpolation",void 0),e([a()],N.prototype,"ioConfig",void 0),e([a({type:[h]})],N.prototype,"multidimensionalDefinition",void 0),e([a({type:c,json:{write:!0}})],N.prototype,"multidimensionalSubset",void 0),e([a()],N.prototype,"raster",void 0),e([a({type:p})],N.prototype,"rasterFunction",void 0),e([a()],N.prototype,"rasterInfo",null),e([a()],N.prototype,"sourceJSON",void 0),e([a({json:{read:!1}})],N.prototype,"spatialReference",null),e([a({json:{read:!1}})],N.prototype,"tileInfo",null),e([a(d)],N.prototype,"url",null),e([a({types:t})],N.prototype,"renderer",null),e([a()],N.prototype,"symbolizer",void 0),N=e([l("esri.layers.ImageryTileMixin")],N),N};export{N as ImageryTileMixin};
|