@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 12.8 kB
JavaScript
import{_ as e}from"../../../../chunks/tslib.es6.js";import"../../../../geometry.js";import{HandleOwner as t}from"../../../../core/HandleOwner.js";import i from"../../../../core/Logger.js";import{isSome as s,unwrap as r}from"../../../../core/maybe.js";import{debounce as a,isAbortError as o,eachAlways as l}from"../../../../core/promiseUtils.js";import{property as n}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as h}from"../../../../core/accessorSupport/decorators/subclass.js";import c from"../../../../geometry/Point.js";import u from"../../../../layers/support/PixelBlock.js";import p from"../../../../layers/support/TileInfo.js";import{update as d,unregister as g,register as y,getRasterId as m}from"../../../../layers/support/rasterDatasets/RawBlockCache.js";import{extractBands as _}from"../../../../layers/support/rasterFunctions/pixelUtils.js";import{getWorldWidth as f,computeProjectedScales as b}from"../../../../layers/support/rasterFunctions/rasterProjectionHelper.js";import"../../tiling/PagedTileQueue.js";import w from"../../tiling/TileInfoView.js";import"../../tiling/TileKey.js";import I from"../../tiling/TileQueue.js";import P from"../../tiling/TileStrategy.js";import{TILE_SIZE as C}from"../../engine/webgl/definitions.js";import{getWebGLCapabilities as R}from"../../../webgl/capabilities.js";import S from"../../../../geometry/Extent.js";const T=[0,0];let v=class extends t{constructor(){super(...arguments),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._rasterFunctionState="na",this._globalUpdateRequested=!1,this.attached=!1,this.timeExtent=null,this.redrawOrRefetch=a((async(e={})=>{if(!this.previousLOD||this.layerView.suspended)return;const t=this._rasterFunctionState;e.reprocess&&(await this.updatingHandles.addPromise(this.layer.updateRasterFunction()),this.updateRasterFunctionParameters());const i=this._rasterFunctionState,{type:s}=this;return e.refetch||"raster"!==s&&!!e.reprocess||"cpu"===i||"cpu"===t?this.updatingHandles.addPromise(this.doRefresh()):this.updatingHandles.addPromise(this._redrawImage(e.signal))}))}get useWebGLForProcessing(){return this._get("useWebGLForProcessing")??!0}set useWebGLForProcessing(e){this._set("useWebGLForProcessing",e)}get useProgressiveUpdate(){return null==this._get("useProgressiveUpdate")||this._get("useProgressiveUpdate")}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:i,scale:s}=e.state,r=this._tileInfoView.getClosestInfoForScale(s);if(this.layer.raster){if(!this.useProgressiveUpdate||this._needBlockCacheUpdate){const e=this._srcResolutions[r.level],s=t.toJSON?t:S.fromJSON(t);d(this._blockCacheRegistryUrl,this._blockCacheRegistryId,s,i,e,this.layer.raster.ioConfig.sampling)}this._needBlockCacheUpdate=!1,this.previousLOD?.level!==r.level&&(this.previousLOD=r,null==this._symbolizerParams||this.layerView.hasTilingEffects||this._updateSymbolizerParams(),this._tileStrategy.updateCacheSize(0))}}moveEnd(){!this.layerView.hasTilingEffects&&this.useProgressiveUpdate||(this._abortController&&this._abortController.abort(),this._abortController=new AbortController,0===this._fetchQueue.length&&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._fetchQueue?.updating||this._globalUpdateRequested||!(!this.updatingHandles||!this.updatingHandles.updating)}attach(){R("2d").supportsTextureFloat||(this.useWebGLForProcessing=!1),this._initializeTileInfo(),this._tileInfoView=new w(this.layerView.tileInfo,this.layerView.fullExtent);const e=this._computeFetchConcurrency();this._fetchQueue=new I({tileInfoView:this._tileInfoView,concurrency:e,process:(e,t)=>this._fetchTile1(e,t)});const t=this._getCacheSize(this.useProgressiveUpdate);this._tileStrategy=new P({cachePolicy:"purge",acquireTile:e=>this.acquireTile(e),releaseTile:e=>this.releaseTile(e),cacheSize:t,tileInfoView:this._tileInfoView}),this._updateBlockCacheRegistry()}detach(){this._tileStrategy.destroy(),this._fetchQueue.clear(),this.container.removeAllChildren(),this._fetchQueue=this._tileStrategy=this._tileInfoView=null,g(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryUrl=this._blockCacheRegistryId=null}acquireTile(e){const t=this.container.createTile(e);return this._enqueueTileFetch(t),this.layerView.requestUpdate(),this._needBlockCacheUpdate=!0,this._globalUpdateRequested=this.layerView.hasTilingEffects||!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.tileInfo.size.join(",");if(t&&s(this._emptyTilePixelBlock))return this._emptyTilePixelBlock;e=e||this._tileInfoView.tileInfo.size;const[i,r]=e,a=new u({width:i,height:r,pixels:[new Uint8Array(i*r)],mask:new Uint8Array(i*r),pixelType:"u8"});return t&&(this._emptyTilePixelBlock=a),a}_getBandIds(){if(!("rasterFunctionChain"in this.container)||!this.container.rasterFunctionChain)return this.layer.bandIds;const{bandIds:e,raster:t}=this.layer,i="rasterFunction"in t?t.rasterFunction.rawInputBandIds:null;return e?.length&&i?.length&&1!==t.rasterInfo.bandCount?e.map((e=>i[Math.min(e,i.length-1)])):e||i}updateRasterFunctionParameters(){}_fetchTile1(e,t){const i=s(t)?t.signal:null,a=this.canUseWebGLForProcessing(),{layerView:o}=this,{tileInfo:l}=o,n=!l.isWrappable&&s(f(o.view.spatialReference)),h=a&&this.layer.raster.hasUniqueSourceStorageInfo,c={allowPartialFill:!0,datumTransformation:o.datumTransformation,interpolation:a?"nearest":this.layer.interpolation,registryId:this._blockCacheRegistryId,requestRawData:h,skipRasterFunction:"raster"===this.type&&null!=this.container.rasterFunctionChain,signal:r(i),srcResolution:this._srcResolutions[e.level],timeExtent:o.timeExtent,tileInfo:l,disableWrapAround:n};return this.fetchTile(e,c)}_getCacheSize(e){return e?40:0}_initializeTileInfo(){const{layerView:e}=this,t=e.view.spatialReference,i=new c({x:e.fullExtent.xmin,y:e.fullExtent.ymax,spatialReference:t});if(this._canUseLayerLODs()){const{lods:s}=this.layer.tileInfo,r=s.map((({scale:e})=>e)),a=p.create({spatialReference:t,size:C,scales:r}),o=t.isGeographic?.01*1e-5:.01;if(this._isCustomTilingScheme=Math.abs(a.origin.x-i.x)>o,(0===a.origin.x||a.origin.x>i.x)&&(a.origin=i),!this._isCustomTilingScheme){const e=p.create({spatialReference:t,size:C}).lods.map((({scale:e})=>e));this._isCustomTilingScheme=r.some((t=>!e.some((e=>Math.abs(e-t)<.001))))}return e.set("tileInfo",a),void(this._srcResolutions=s.map((({resolution:e})=>({x:e,y:e}))))}const{scales:s,srcResolutions:r,isCustomTilingScheme:a}=b(this.layer.rasterInfo,t,C),o=p.create({spatialReference:t,size:C,scales:s});(0===o.origin.x||o.origin.x>i.x)&&(o.origin=i),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:i}=e.tileInfo,s=t.view.constraints?.effectiveLODs;if(!(s?.length===i.length&&s.every((({scale:e},t)=>Math.abs(e-i[t].scale)<.001))))return!1;const r=[];for(let a=0;a<i.length-1;a++)r.push(Math.round(10*i[a].resolution/i[a+1].resolution)/10);return r.some((e=>e!==e[0]))}_computeFetchConcurrency(){const{blockBoundary:e}=this.layer.rasterInfo.storageInfo,t=e[e.length-1];return(t.maxCol-t.minCol+1)*(t.maxRow-t.minRow+1)>64?2:10}async _enqueueTileFetch(e,t){this.updatingHandles.addPromise(this._enqueueTileFetch1(e,t))}async _enqueueTileFetch1(e,t){if(!this._fetchQueue.has(e.key.id)){try{const t=await this._fetchQueue.push(e.key),r=this._getBandIds();let a=!this.useProgressiveUpdate||this.layerView.hasTilingEffects&&!this._globalSymbolizerParams;if(this._globalUpdateRequested&&!this.layerView.moving&&0===this._fetchQueue.length){a=!1;try{await this._redrawImage(this._abortController?.signal)}catch(s){o(s)&&i.getLogger(this.declaredClass).error(s)}this._globalUpdateRequested=!1}!this.canUseWebGLForProcessing()&&"rasterVF"!==this.type||this.layerView.hasTilingEffects||null!=this._symbolizerParams||this._updateSymbolizerParams();const l=this._tileInfoView.getTileCoords(T,e.key),n=this._tileInfoView.getTileResolution(e.key);await this.updateTileSource(e,{source:t,symbolizerParams:this._symbolizerParams,globalSymbolizerParams:this._globalSymbolizerParams,suspended:a,bandIds:r,coords:l,resolution:n}),e.once("attach",(()=>this.layerView.requestUpdate())),this.container.addChild(e)}catch(s){o(s)||i.getLogger(this.declaredClass).error(s)}this.layerView.requestUpdate()}}async _redrawImage(e){if(0===this.container.children.length)return;await this.layer.updateRenderer(),this.layerView.hasTilingEffects?await this._updateGlobalSymbolizerParams(e):(this._updateSymbolizerParams(),this._globalSymbolizerParams=null);const t=this.container.children.map((async e=>this.updateTileSymbolizerParameters(e,{local:this._symbolizerParams,global:this._globalSymbolizerParams})));await l(t),this.container.requestRender()}async _updateGlobalSymbolizerParams(e){const t={srcResolution:this._srcResolutions[this.previousLOD.level],registryId:this._blockCacheRegistryId,signal:e},i=await this.layer.fetchPixels(this.layerView.view.extent,this.layerView.view.width,this.layerView.view.height,t);if(!i||!i.pixelBlock)return;const{resolution:s}=this.previousLOD,r=this._getBandIds(),a=this.layer.symbolizer.generateWebGLParameters({pixelBlock:_(i.pixelBlock,r),isGCS:this.layerView.view.spatialReference.isGeographic,resolution:{x:s,y:s},bandIds:r});!this.canUseWebGLForProcessing()&&a&&"stretch"===a.type&&this.layer.renderer&&"raster-stretch"===this.layer.renderer.type&&(a.factor=a.factor.map((e=>255*e)),a.outMin=Math.round(255*a.outMin),a.outMax=Math.round(255*a.outMax)),this._globalSymbolizerParams=a}_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:i}=this,{url:s,raster:r}=t,{multidimensionalDefinition:a}=t.normalizeRasterFetchOptions({multidimensionalDefinition:t.multidimensionalDefinition,timeExtent:i.timeExtent}),o=r.rasterInfo.multidimensionalInfo?r.getSliceIndex(a):null,l=m(s,o);if(l!==this._blockCacheRegistryUrl){if(null!=this._blockCacheRegistryUrl&&g(this._blockCacheRegistryUrl,this._blockCacheRegistryId),this._blockCacheRegistryId=y(l,r.rasterInfo),e){const{view:e}=i,t=this._tileInfoView.getClosestInfoForScale(e.scale),s=this._srcResolutions[t.level];d(l,this._blockCacheRegistryId,e.extent,e.resolution,s,r.ioConfig.sampling)}this._blockCacheRegistryUrl=l}}async doRefresh(){if(!this.attached)return;await this.layer.updateRenderer(),this.layerView.hasTilingEffects||this._updateSymbolizerParams(),this._updateBlockCacheRegistry(!0),this._fetchQueue.reset();const e=[];this._globalUpdateRequested=this.layerView.hasTilingEffects||!this.useProgressiveUpdate,this._tileStrategy.tiles.forEach((t=>e.push(this._enqueueTileFetch(t)))),await l(e)}};e([n()],v.prototype,"_fetchQueue",void 0),e([n()],v.prototype,"_globalUpdateRequested",void 0),e([n()],v.prototype,"attached",void 0),e([n()],v.prototype,"container",void 0),e([n()],v.prototype,"layer",void 0),e([n()],v.prototype,"layerView",void 0),e([n()],v.prototype,"type",void 0),e([n()],v.prototype,"useWebGLForProcessing",null),e([n()],v.prototype,"useProgressiveUpdate",null),e([n()],v.prototype,"timeExtent",void 0),e([n()],v.prototype,"updating",null),v=e([h("esri.views.2d.layers.imagery.BaseImageryTileSubView2D")],v);export{v as BaseImageryTileSubView2D};