@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 15.1 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import s from"../../../../core/Logger.js";import{assertIsSome as i}from"../../../../core/maybe.js";import{debounce as r,isAbortError as a}from"../../../../core/promiseUtils.js";import{property as o,subclass as n}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as l}from"../../../../core/support/UpdatingHandles.js";import h from"../../../../geometry/Extent.js";import c from"../../../../geometry/Point.js";import{isFunctionRaster as u}from"../../../../layers/raster/datasets/datasetUtils.js";import{update as d,unregister as p,getRasterId as y,register as m}from"../../../../layers/raster/datasets/RawBlockCache.js";import{getWorldWidth as g,computeProjectedScales as _}from"../../../../layers/raster/functions/rasterProjectionHelper.js";import{getStretchCutoff as f}from"../../../../layers/raster/functions/stretchUtils.js";import b from"../../../../layers/support/PixelBlock.js";import R from"../../../../layers/support/TileInfo.js";import w from"../../tiling/TileInfoView.js";import"../../tiling/TileKey.js";import I from"../../tiling/TileQueue.js";import P from"../../tiling/TileStrategy.js";import{tileSize as C}from"../../engine/webgl/definitions.js";import{TaskPriority as U}from"../../../support/Scheduler.js";import{getWebGLCapabilities as S}from"../../../webgl/capabilities.js";const v=[0,0];let x=class extends t{constructor(){super(...arguments),this._updatingHandles=new l,this._emptyTilePixelBlock=null,this._tileStrategy=null,this._tileInfoView=null,this._fetchQueue=null,this._blockCacheRegistryUrl=null,this._blockCacheRegistryId=null,this._srcResolutions=[],this.previousLOD=null,this._needBlockCacheUpdate=!1,this._globalSymbolizerParams=null,this._symbolizerParams=null,this._abortController=null,this._isCustomTilingScheme=!1,this._maxIndexedColormapSize=0,this._rasterFunctionState="na",this._globalUpdateRequested=!1,this.attached=!1,this.timeExtent=null,this.refreshDRAFunctionOnce=r(async()=>{const{fullExtent:e,view:t}=this.layerView;if(e?.intersects(t.extent))try{await this._updateDRAStatistics(this._abortController?.signal)&&await this.doRefresh()}catch{}}),this.redrawOrRefetch=r(async(e={})=>{const t=this._rasterFunctionState,s=e.reprocess||"gpu"===t&&!this.canUseWebGLForProcessing||"cpu"===t&&this.canUseWebGLForProcessing;if(s&&(await this._updatingHandles.addPromise(this.layer.updateRasterFunction()),this.updateRasterFunctionParameters()),!this.previousLOD||this.layerView.suspended)return;const i=this._rasterFunctionState,{type:r}=this;return e.refetch||"raster"!==r&&!!s||"cpu"===i||"cpu"===t?this._updatingHandles.addPromise(this.doRefresh()):this._updatingHandles.addPromise(this._redrawImage(e.signal))})}destroy(){this._updatingHandles.destroy()}get canUseWebGLForProcessing(){return!1}get canUseLocalSymbolizerParams(){return(this.canUseWebGLForProcessing||"rasterVF"===this.type)&&!this.layerView.hasTilingEffects}get hasDRAInRasterFunction(){const{rasterFunction:e}=this.layer;return!!e&&JSON.stringify(e,null,0).includes('"dra":true')}get isCPUBasedDRA(){const{renderer:e}=this.layer;return"raster-stretch"===e?.type&&e.dynamicRangeAdjustment&&(!this.canUseWebGLForProcessing||!("min-max"===e.stretchType||"standard-deviation"===e.stretchType))}get useWebGLForProcessing(){return this._get("useWebGLForProcessing")??!0}set useWebGLForProcessing(e){this._set("useWebGLForProcessing",e)}get useProgressiveUpdate(){return this._get("useProgressiveUpdate")??!0}set useProgressiveUpdate(e){if(this._tileStrategy&&this.useProgressiveUpdate!==e){this._tileStrategy.destroy(),this.container.removeAllChildren();const t=this._getCacheSize(e);this._tileStrategy=new P({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:t,tileInfoView:this._tileInfoView}),this._set("useProgressiveUpdate",e),this.layerView.requestUpdate()}}update(e){this._fetchQueue.pause(),this._fetchQueue.state=e.state,this._tileStrategy.update(e),this._fetchQueue.resume();const{extent:t,resolution:s,scale:i}=e.state,r=this._tileInfoView.getClosestInfoForScale(i);if(this.layer.raster){if(!this.useProgressiveUpdate||this._needBlockCacheUpdate){const e=this._srcResolutions[r.level],i="toJSON"in t?t:h.fromJSON(t);d(this._blockCacheRegistryUrl,this._blockCacheRegistryId,i,s,e,this.layer.raster.ioConfig.sampling)}this._needBlockCacheUpdate=!1,this.previousLOD?.level!==r.level&&(this.previousLOD=r,null!=this._symbolizerParams&&this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._tileStrategy.updateCacheSize(0))}}moveEnd(){(this.isCPUBasedDRA||this.hasDRAInRasterFunction||!this.useProgressiveUpdate)&&(this._abortController&&this._abortController.abort(),this._abortController=new AbortController,0===this._fetchQueue.length&&(this.hasDRAInRasterFunction?(this._globalUpdateRequested=!1,this.refreshDRAFunctionOnce()):this.isCPUBasedDRA&&this._redrawImage(this._abortController.signal).then(()=>{this._globalUpdateRequested=!1,this.layerView.requestUpdate()})));const e=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy.updateCacheSize(e),this.layerView.requestUpdate()}get updating(){return this._globalUpdateRequested||this._updatingHandles?.updating}attach(){const e=S();this._maxIndexedColormapSize=4*(e.maxTextureSize||4096),this._initializeTileInfo(),this._tileInfoView=new w(this.layerView.tileInfo,this.layerView.fullExtent);const t=this._computeFetchConcurrency();this._fetchQueue=new I({tileInfoView:this._tileInfoView,concurrency:t,process:(e,t)=>this._fetchTile(e,t),priority:U.MAPVIEW_FETCH_QUEUE,scheduler:this.scheduler});const s=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy=new P({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:s,tileInfoView:this._tileInfoView}),this._updateBlockCacheRegistry()}detach(){this._tileStrategy.destroy(),this._fetchQueue.clear(),this.container.removeAllChildren(),this._fetchQueue=this._tileStrategy=this._tileInfoView=null,p(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryUrl=this._blockCacheRegistryId=null}acquireTile(e){const t=this.container.createTile(e);return this._updatingHandles.addPromise(this._enqueueTileFetch(t)),this.layerView.requestUpdate(),this._needBlockCacheUpdate=!0,this._globalUpdateRequested=this.isCPUBasedDRA||this.hasDRAInRasterFunction||!this.useProgressiveUpdate,t}releaseTile(e){this._fetchQueue.abort(e.key.id),this.container.removeChild(e),e.once("detach",()=>{e.destroy(),this.layerView.requestUpdate()}),this.layerView.requestUpdate()}createEmptyTilePixelBlock(e=null){const t=null==e||e.join(",")===this._tileInfoView.size.join(",");if(t&&null!=this._emptyTilePixelBlock)return this._emptyTilePixelBlock;e=e||this._tileInfoView.size;const[s,i]=e,r=new b({width:s,height:i,pixels:[new Uint8Array(s*i)],mask:new Uint8Array(s*i),pixelType:"u8"});return t&&(this._emptyTilePixelBlock=r),r}_getBandIds(){if(this.container&&(!("rasterFunctionChain"in this.container)||!this.container.rasterFunctionChain))return this.layer.bandIds;const{bandIds:e,raster:t}=this.layer,s="rasterFunction"in t?t.rasterFunction.rawInputBandIds:null;return e?.length&&s?.length&&1!==t.rasterInfo.bandCount?e.map(e=>s[Math.min(e,s.length-1)]):"rasterFunction"in t?s:e}updateRasterFunctionParameters(){}_fetchTile(e,t){const s=this._getFetchOptions(e.level,t.signal);return this.fetchTile(e,s)}_getFetchOptions(e,t){const{canUseWebGLForProcessing:s}=this,{layerView:i}=this,{tileInfo:r}=i,a=!r.isWrappable&&null!=g(i.view.spatialReference),o=s&&this.layer.raster.hasUniqueSourceStorageInfo,{layer:n}=this.layerView,l=n.serviceRasterInfo?.storageInfo.isBsqTile?n.getRawDisplayBandIds():void 0;return{allowPartialFill:!0,datumTransformation:i.datumTransformation,interpolation:s?"nearest":this.layer.interpolation,registryId:this._blockCacheRegistryId,requestRawData:o,skipRasterFunction:"raster"===this.type&&null!=this.container.rasterFunctionChain,signal:t,srcResolution:this._srcResolutions[e],timeExtent:i.timeExtent,tileInfo:r,bandIds:l,disableWrapAround:a}}_getCacheSize(e){return e?40:0}_initializeTileInfo(){const{layerView:e}=this,t=e.view.spatialReference;if(this._canUseLayerLODs()){const{origin:s,lods:i}=this.layer.tileInfo,r=i.map(({scale:e})=>e),a=R.create({spatialReference:t,size:C,scales:r,origin:s});return e.set("tileInfo",a),void(this._srcResolutions=i.map(({resolution:e})=>({x:e,y:e})))}const{scales:s,srcResolutions:r,isCustomTilingScheme:a}=_(this.layer.serviceRasterInfo,t,{tileSize:C,alignGlobalDatasetWithAGOL:!0,limitToSrcResolution:!1}),o=R.create({spatialReference:t,size:C,scales:s}),n=0===o.origin.x;i(e.fullExtent);const{xmin:l,ymax:h}=e.fullExtent;(n||a&&o.origin.x>l)&&(o.origin=new c({x:l,y:h,spatialReference:t})),this._isCustomTilingScheme=a,e.set("tileInfo",o),this._srcResolutions=r??[]}_canUseLayerLODs(){const{layer:e,layerView:t}=this;if("Map"!==e.raster.tileType)return!1;const{lods:s}=e.tileInfo,i=t.view.constraints?.effectiveLODs;return i?.length===s.length&&i.every(({scale:e},t)=>Math.abs(e-s[t].scale)<.001)}_computeFetchConcurrency(){const{blockBoundary:e}=this.layer.serviceRasterInfo.storageInfo,t=e[e.length-1];return(t.maxCol-t.minCol+1)*(t.maxRow-t.minRow+1)>64?2:10}async _enqueueTileFetch(e,t){if(!this._fetchQueue.has(e.key.id)){try{let t=e.once("detach",()=>t=void 0);const r=await this._fetchQueue.push(e.key),o=this._getBandIds(),n=this.hasDRAInRasterFunction&&u(this.layer.raster)&&!this.layer.raster.processParameters?.stretchCutoff;let l=!this.useProgressiveUpdate||n||this.isCPUBasedDRA&&!this._globalSymbolizerParams;const h=this._globalUpdateRequested&&!this.layerView.moving&&0===this._fetchQueue.length;if(h){if(l=!1,!this.hasDRAInRasterFunction)try{await this._redrawImage(this._abortController?.signal)}catch(i){a(i)&&s.getLogger(this).error(i)}this._globalUpdateRequested=!1}if(!t)return;this.canUseLocalSymbolizerParams&&null==this._symbolizerParams&&this._updateSymbolizerParams();const c=this._tileInfoView.getTileCoords(v,e.key),d=this._tileInfoView.getTileResolution(e.key);await this.updateTileSource(e,{source:r,symbolizerParams:this._symbolizerParams,globalSymbolizerParams:this._globalSymbolizerParams,suspended:l,bandIds:o,coords:c,resolution:d}),t&&(e.once("attach",()=>this.layerView.requestUpdate()),this.container.addChild(e),t.remove()),h&&this.hasDRAInRasterFunction&&u(this.layer.raster)&&!this.layer.raster.processParameters?.extent?.equals(this.layerView.view.extent)&&this.refreshDRAFunctionOnce()}catch(i){a(i)||s.getLogger(this).error(i)}this.layerView.requestUpdate()}}async _updateDRAStatistics(e){if(!u(this.layer.raster))return!1;const t=await this.layer.getDynamicRangeInputRaster();if(!t)return!1;const{raster:s,functionArguments:i}=t,r=this._getFetchOptions(this.previousLOD.level,e),{extent:a,width:o,height:n}=this.layerView.view,{pixelBlock:l}=await s.fetchPixels(a,o,n,{...r,interpolation:"nearest",requestRawData:!1,skipRasterFunction:!1}),h=f(i,{rasterInfo:s.rasterInfo,pixelBlock:l});return this.layer.raster.processParameters={stretchCutoff:h,extent:a},!0}async _redrawImage(e){if(!this.attached||0===this.container.children.length)return;if(await this.layer.updateRenderer(),this.isCPUBasedDRA?await this._updateGlobalSymbolizerParams(e):(this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._globalSymbolizerParams=null),!this.attached||e?.aborted)return;const t=this.container.children.map(async t=>this.updateTileSymbolizerParameters(t,{local:this._symbolizerParams,global:this._globalSymbolizerParams},e));await Promise.allSettled(t),this.attached&&!e?.aborted&&this.container.requestRender()}async _updateGlobalSymbolizerParams(e){const{fullExtent:t,view:s}=this.layerView;if(!t?.intersects(s.extent))return;const i=this._getFetchOptions(this.previousLOD.level,e),r=await this.layer.fetchPixels(s.extent,s.width,s.height,{...i,interpolation:"nearest",requestRawData:!1,skipRasterFunction:!1});if(!r?.pixelBlock)return;const{resolution:a}=this.previousLOD,{isBsqTile:o}=this.layer.raster.rasterInfo.storageInfo,n=o?null:this._getBandIds(),l=this.layer.symbolizer.generateWebGLParameters({pixelBlock:r.pixelBlock.extractBands(n),isGCS:s.spatialReference.isGeographic,resolution:{x:a,y:a},bandIds:n});!this.canUseWebGLForProcessing&&l&&"stretch"===l.type&&"raster-stretch"===this.layer.renderer?.type&&(l.factor=l.factor.map(e=>255*e),l.minOutput=Math.round(255*l.minOutput),l.maxOutput=Math.round(255*l.maxOutput)),this._globalSymbolizerParams=l}_updateSymbolizerParams(){const{resolution:e}=this.previousLOD,t=this._getBandIds();this._symbolizerParams=this.layer.symbolizer.generateWebGLParameters({pixelBlock:null,isGCS:this.layerView.view.spatialReference.isGeographic,resolution:{x:e,y:e},bandIds:t})}_updateBlockCacheRegistry(e=!1){const{layer:t,layerView:s}=this,{raster:i}=t,{multidimensionalDefinition:r}=t.normalizeRasterFetchOptions({multidimensionalDefinition:t.multidimensionalDefinition,timeExtent:s.timeExtent}),a=i.rasterInfo.multidimensionalInfo?i.getSliceIndex(r):null,o=i.rasterInfo.storageInfo.isBsqTile?t.getRawDisplayBandIds():null,n=u(i)?i.primaryRasters.rasters[0]??i:i,l=y(n.rasterId,a,o);if(l!==this._blockCacheRegistryUrl){null!=this._blockCacheRegistryUrl&&p(this._blockCacheRegistryUrl,this._blockCacheRegistryId);const t=n.rawBlockRegistryIds.indexOf(this._blockCacheRegistryId);if(t>-1&&n.rawBlockRegistryIds.splice(t,1),this._blockCacheRegistryId=m(l,n.rasterInfo),n.rawBlockRegistryIds.push(this._blockCacheRegistryId),e){const{view:e}=s,t=this._tileInfoView.getClosestInfoForScale(e.scale),r=this._srcResolutions[t.level];d(l,this._blockCacheRegistryId,e.extent,e.resolution,r,i.ioConfig.sampling)}this._blockCacheRegistryUrl=l}}async doRefresh(){if(!this.attached||!this.previousLOD||this.layerView.suspended)return;await this.layer.updateRenderer(),this.canUseLocalSymbolizerParams&&this._updateSymbolizerParams(),this._updateBlockCacheRegistry(!0),this._fetchQueue.reset();const e=[];this._globalUpdateRequested=this.isCPUBasedDRA||this.hasDRAInRasterFunction||!this.useProgressiveUpdate,this._tileStrategy.refresh(t=>e.push(this._enqueueTileFetch(t))),await this._updatingHandles.addPromise(Promise.allSettled(e))}};e([o()],x.prototype,"_globalUpdateRequested",void 0),e([o()],x.prototype,"attached",void 0),e([o()],x.prototype,"canUseWebGLForProcessing",null),e([o()],x.prototype,"canUseLocalSymbolizerParams",null),e([o()],x.prototype,"hasDRAInRasterFunction",null),e([o()],x.prototype,"isCPUBasedDRA",null),e([o()],x.prototype,"container",void 0),e([o()],x.prototype,"layer",void 0),e([o()],x.prototype,"layerView",void 0),e([o()],x.prototype,"scheduler",void 0),e([o()],x.prototype,"type",void 0),e([o()],x.prototype,"useWebGLForProcessing",null),e([o()],x.prototype,"useProgressiveUpdate",null),e([o()],x.prototype,"timeExtent",void 0),e([o()],x.prototype,"updating",null),x=e([n("esri.views.2d.layers.imagery.BaseImageryTileSubView2D")],x);export{x as BaseImageryTileSubView2D};