@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 21.8 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../request.js";import i from"../../../core/Error.js";import{JSONSupport as r}from"../../../core/JSONSupport.js";import o from"../../../core/Logger.js";import{debounce as n,onAbort as s}from"../../../core/promiseUtils.js";import{QueueProcessor as l}from"../../../core/QueueProcessor.js";import{property as a,subclass as c}from"../../../core/accessorSupport/decorators.js";import{ensureClass as f}from"../../../core/accessorSupport/ensureType.js";import u from"../../../geometry/Extent.js";import m from"../../../geometry/Point.js";import h from"../../../geometry/SpatialReference.js";import{isFunctionRaster as p,getPixelSpaceCoverage as d}from"./datasetUtils.js";import{isMultiSliceOrRangeDefinition as x,getSliceIndex as y,createSlices as g,getSliceIds as I}from"./multidimensionalUtils.js";import{clearRegisteredIds as R,getRasterId as w,getBlock as S,putBlock as k,deleteBlock as b,decreaseRefCount as T}from"./RawBlockCache.js";import{convertNoDataToMask as v}from"../formats/pixelRangeUtils.js";import{decode as P}from"../formats/RasterCodec.js";import{mosaic as B,approximateTransform as _,getLocalArithmeticNorthRotations as M,compositeBands as C}from"../functions/pixelUtils.js";import{getWorldWidth as W,load as H,projectPoint as z,snapPyramid as L,shiftExtent as E,getWorldWrapCount as j,projectExtent as D,getProjectionOffsetGrid as O,getRasterDatasetAlignmentInfo as A,projectResolution as q}from"../functions/rasterProjectionHelper.js";import{convertToLocalDirections as F,uvComponentToVector as G}from"../functions/vectorFieldUtils.js";import{sanitizeUrl as J}from"../../support/arcgisLayerUrl.js";import{url as N}from"../../support/commonProperties.js";import V from"../../support/DimensionalDefinition.js";import U from"../../support/LOD.js";import Q from"../../support/RasterStorageInfo.js";import $ from"../../support/TileInfo.js";const X=8,K=256;let Y=0,Z=class extends r{constructor(){super(...arguments),this._tileFetchQueue=new l({concurrency:32,process:(e,t)=>this.fetchRawTile(e.pyramidLevel,e.row,e.col,{...e.options,signal:t})}),this.datasetName=null,this.datasetFormat=null,this.hasUniqueSourceStorageInfo=!0,this.rasterInfo=null,this.ioConfig={sampling:"closest"},this.rawBlockRegistryIds=[],this.refresh=n(async e=>{await this._openPromise;const t=await this._refresh(e);return t.dataChanged&&R(this.rasterId,this.rawBlockRegistryIds),t})}normalizeCtorArgs(e){return e?.ioConfig&&(e={...e,ioConfig:{resolution:null,bandIds:null,sampling:"closest",tileInfo:$.create(),...e.ioConfig}}),e}get _isGlobalWrappableSource(){const{rasterInfo:e}=this,t=W(e.spatialReference);return null!=t&&e.extent.width>=t/2}get _hasNoneOrGCSShiftTransform(){const{transform:e}=this.rasterInfo;return null==e||"gcs-shift"===e.type}set rasterJobHandler(e){this._set("rasterJobHandler",e),p(this)&&this.primaryRasters?.rasters?.forEach(t=>t.rasterJobHandler=e)}get rasterId(){return this.url||"rasterId-"+Y++}set url(e){this._set("url",J(e,o.getLogger(this)))}async open(e){return this._openPromise??=H().then(()=>this._open(e)),this._openPromise}async fetchTile(e,t,r,o={}){const n=o.tileInfo||this.rasterInfo.storageInfo.tileInfo,s=this.getTileExtentFromTileInfo(e,t,r,n);if(!s)throw new i("imagery-tile:out-of-bounds","Level for fetch tile out of range");return o={noClip:!0,...o},this.fetchPixels(s,n.size[0],n.size[1],o)}async identify(e,t={}){e=f(m,e).clone().normalize();const{multidimensionalDefinition:i,timeExtent:r}=t,{rasterInfo:o}=this,{hasMultidimensionalTranspose:n,multidimensionalInfo:s}=o;let{transposedVariableName:l}=t;const a=null!=s&&n&&(null!=r||x(i));if(a&&!l){l=null!=i&&i.length>0?i[0].variableName??void 0:s.variables[0].name,t={...t,transposedVariableName:l}}t=this._getRequestOptionsWithSliceId(t);const{spatialReference:c,extent:h}=o,{datumTransformation:d}=t;let y=z(e,c,d);if(!h.intersects(y))return{location:y,value:null};if(null!=o.transform){const e=o.transform.inverseTransform(y);if(!o.nativeExtent.intersects(e))return{location:e,value:null};y=e}let g=0;const I=null!=l&&null!=s&&o.hasMultidimensionalTranspose;if(p(this)){const e=this.primaryRasters.rasters[0];if(I)return e.identify(y,t);const{pixelSize:r}=o,n=3,s=r.x*n/2,l=r.y*n/2,a=new u({xmin:y.x-s,xmax:y.x+s,ymin:y.y-l,ymax:y.y+l,spatialReference:c}),f={interpolation:"nearest",multidimensionalDefinition:i,sliceId:t.sliceId,bandIds:t.bandIds},{pixelBlock:m}=await e.fetchPixels(a,n,n,f),{pixelBlock:h}=await this.fetchPixels(a,n,n,f);if(null==m)return{location:y,value:null};const p=Math.floor(n*n*.5),d=!m.mask||m.mask[p]?m.pixels.map(e=>e[p]):null;let x;return null!=h&&(x=!h.mask||h.mask[p]?h.pixels.map(e=>e[p]):void 0),{location:y,value:d,processedValue:x,pyramidLevel:0}}if(!I)if(t.srcResolution){g=L(t.srcResolution,o,this.ioConfig.sampling).pyramidLevel}else if(g=await this.computeBestPyramidLevelForLocation(e,t),null==g)return{location:y,value:null};const R=this.identifyPixelLocation(y,g,null,I);if(null===R)return{location:y,value:null};const{row:w,col:S,rowOffset:k,colOffset:b,blockWidth:T}=R,v=await this._fetchRawTile(g,w,S,t);if(!v?.pixels?.length)return{location:y,value:null};const P=k*T+b;return this._processIdentifyResult(v,{srcLocation:y,position:P,pyramidLevel:g,useTransposedTile:!!I,requestSomeSlices:a,identifyOptions:t})}async fetchPixels(e,t,i,r={}){e=E(e),r=this._getRequestOptionsWithSliceId(r);const{_hasNoneOrGCSShiftTransform:o}=this;if(r.requestRawData&&o)return this._fetchPixels(e,t,i,r);const n=W(e.spatialReference),s=j(e);if(null==n||0===s||1===s&&this._isGlobalWrappableSource&&o)return this._fetchPixels(e,t,i,r);if(s>=3)return{extent:e,pixelBlock:null};const l=[],{xmin:a,xmax:c}=e,f=Math.round(n/(c-a)*t),m=f-Math.round((n/2-a)/(c-a)*t);let h=0;const p=[];for(let g=0;g<=s;g++){const o=new u({xmin:0===g?a:-n/2,xmax:g===s?c-n*g:n/2,ymin:e.ymin,ymax:e.ymax,spatialReference:e.spatialReference}),d=0===g?f-m:g===s?t-h:f;h+=d,p.push(d);const x=r.disableWrapAround&&g>0?null:this._fetchPixels(o,d,i,r);l.push(x)}const d=(await Promise.all(l)).map(e=>e?.pixelBlock);let x=null;const y={width:t,height:i};if(this.rasterJobHandler){x=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:d,srcMosaicSize:y,destDimension:null,coefs:null,sampleSpacing:null,interpolation:"nearest",alignmentInfo:null,blockWidths:p},r)).pixelBlock}else x=B(d,y,{blockWidths:p});return{extent:e,srcExtent:D(e,this.rasterInfo.spatialReference,r.datumTransformation),pixelBlock:x}}async fetchRawPixels(e,t,i,r={}){t={x:Math.floor(t.x),y:Math.floor(t.y)};const o=await this._fetchRawTiles(e,t,i,r),{nativeExtent:n,nativePixelSize:s,storageInfo:l}=this.rasterInfo,a=2**e,c=s.x*a,f=s.y*a,m=new u({xmin:n.xmin+c*t.x,xmax:n.xmin+c*(t.x+i.width-1),ymin:n.ymax-f*(t.y+i.height-1),ymax:n.ymax-f*t.y,spatialReference:n.spatialReference});if(!o)return{extent:m,srcExtent:m,pixelBlock:null};const{pixelBlocks:h,mosaicSize:p}=o;if(1===h.length&&null!=h[0]&&h[0].width===i.width&&h[0].height===i.height)return{extent:m,srcExtent:m,pixelBlock:o.pixelBlocks[0]};const d=e>0?l.pyramidBlockWidth:l.blockWidth,x=e>0?l.pyramidBlockHeight:l.blockHeight,y={x:t.x%d,y:t.y%x};let g;if(this.rasterJobHandler){g=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:h,srcMosaicSize:p,destDimension:i,clipOffset:y,clipSize:i,coefs:null,sampleSpacing:null,interpolation:r.interpolation,alignmentInfo:null,blockWidths:null},r)).pixelBlock}else g=B(h,p,{clipOffset:y,clipSize:i});return{extent:m,srcExtent:m,pixelBlock:g}}fetchRawTile(e,t,r,o){throw new i("BaseRaster:read-not-implemented","fetchRawTile() is not implemented")}computeExtent(e){return D(this.rasterInfo.extent,e)}decodePixelBlock(e,t){return!this.rasterJobHandler||t.useCanvas?P(e,t):this.rasterJobHandler.decode({data:e,options:t})}async request(e,i,r=0){const{customFetchParameters:o}=this.ioConfig,{range:n,query:s,headers:l}=i;r=r??i.retryCount??this.ioConfig.retryCount;const a=n?{Range:`bytes=${n.from}-${n.to}`}:null;try{return await t(e,{...i,query:{...s,...o},headers:{...l,...a}})}catch(c){if(r>0)return r--,this.request(e,i,r);throw c}}getSliceIndex(e){const{multidimensionalInfo:t}=this.rasterInfo;return null==t||null==e||0===e.length?null:y(e,t)}getTileExtentFromTileInfo(e,t,i,r){const o=r.lodAt(e);return o?this.getTileExtent({x:o.resolution,y:o.resolution},t,i,r.origin,r.spatialReference,r.size):null}updateTileInfo(){const{storageInfo:e,spatialReference:t,extent:i,pixelSize:r}=this.rasterInfo,{pyramidResolutions:o}=e;if(!e.tileInfo){const n=[],s=e.maximumPyramidLevel||0;let l=(r.x+r.y)/2,a=1/.0254*96*l;for(let e=0;e<=s&&(n.unshift(new U({level:s-e,resolution:l,scale:a})),e!==s);e++)if(o){const t=(o[e].x+o[e].y)/2;a*=t/l,l=t}else l*=2,a*=2;const c=new m({x:i.xmin,y:i.ymax,spatialReference:t});e.tileInfo=new $({origin:c,size:[e.blockWidth,e.blockHeight],spatialReference:t,lods:n}),e.isVirtualTileInfo=!0}}createRemoteDatasetStorageInfo(e,t=512,i=512,r){const{width:o,height:n,nativeExtent:s,pixelSize:l,spatialReference:a}=e,c=new m({x:s.xmin,y:s.ymax,spatialReference:a});null==r&&(r=Math.max(0,Math.round(Math.log(Math.max(o,n))/Math.LN2-8)));const f=this.computeBlockBoundary(s,512,512,{x:s.xmin,y:s.ymax},[l],r);e.storageInfo=new Q({blockWidth:t,blockHeight:i,pyramidBlockWidth:t,pyramidBlockHeight:i,origin:c,firstPyramidLevel:1,maximumPyramidLevel:r,blockBoundary:f})}async computeBestPyramidLevelForLocation(e,t={}){return 0}computeBlockBoundary(e,t,i,r,o,n=0,s=2){if(1===o.length&&n>0){o=[...o];let{x:e,y:t}=o[0];for(let i=0;i<n;i++)e*=s,t*=s,o.push({x:e,y:t})}const l=[],{x:a,y:c}=r;for(let f=0;f<o.length;f++){const{x:r,y:n}=o[f];l.push({minCol:Math.floor((e.xmin-a+.1*r)/t/r),maxCol:Math.floor((e.xmax-a-.1*r)/t/r),minRow:Math.floor((c-e.ymax+.1*n)/i/n),maxRow:Math.floor((c-e.ymin-.1*n)/i/n)})}return l}getPyramidPixelSize(e){const{nativePixelSize:t}=this.rasterInfo,{pyramidResolutions:i,pyramidScalingFactor:r}=this.rasterInfo.storageInfo;if(0===e)return t;if(null!=i&&i.length)return i[e-1];const o=r**e;return{x:t.x*o,y:t.y*o}}identifyPixelLocation(e,t,i,r){const{spatialReference:o,nativeExtent:n,storageInfo:s}=this.rasterInfo,{maximumPyramidLevel:l,origin:a,transposeInfo:c}=s,f=r&&null!=c?c.tileSize[0]:s.blockWidth,u=r&&null!=c?c.tileSize[1]:s.blockHeight,m=z(e,o,i);if(!n.intersects(m))return null;if(t<0||t>l)return null;const h=this.getPyramidPixelSize(t),{x:p,y:d}=h,x=(a.y-m.y)/d/u,y=(m.x-a.x)/p/f,g=Math.min(u-1,Math.floor((x-Math.floor(x))*u)),I=Math.min(f-1,Math.floor((y-Math.floor(y))*f));return{pyramidLevel:t,row:Math.floor(x),col:Math.floor(y),rowOffset:g,colOffset:I,blockWidth:f,srcLocation:m}}getTileExtent(e,t,i,r,o,n){const[s,l]=n,a=r.x+i*s*e.x,c=a+s*e.x,f=r.y-t*l*e.y,m=f-l*e.y;return new u({xmin:a,xmax:c,ymin:m,ymax:f,spatialReference:o})}getBlockWidthHeight(e){return{blockWidth:e>0?this.rasterInfo.storageInfo.pyramidBlockWidth:this.rasterInfo.storageInfo.blockWidth,blockHeight:e>0?this.rasterInfo.storageInfo.pyramidBlockHeight:this.rasterInfo.storageInfo.blockHeight}}isBlockOutside(e,t,i){const r=this.rasterInfo.storageInfo.blockBoundary[e];return!r||r.maxRow<t||r.maxCol<i||r.minRow>t||r.minCol>i}updateImageSpaceRasterInfo(e){const{pixelSize:t}=e,{width:i,height:r}=e,o=h.WebMercator;e.spatialReference=o,e.extent=e.nativeExtent=new u({xmin:-.5,ymax:.5,xmax:i-.5,ymin:.5-r,spatialReference:o}),e.isPseudoSpatialReference=!0,e.transform=null,e.pixelSize=new m({x:1,y:1,spatialReference:o});const{extent:n,storageInfo:s}=e;if(s){s.origin=new m({x:n.xmin,y:n.ymax,spatialReference:o});const{pyramidResolutions:i,tileInfo:r}=s;if(i&&i.forEach(e=>{e.x/=t.x,e.y/=t.y}),r){r.origin=s.origin;const t=(e.nativePixelSize.x+e.nativePixelSize.y)/2;r.lods.forEach((e,i)=>{e.resolution=t*2**i,e.scale=96*e.resolution/.0254})}}}async _refresh(e){return{dataChanged:!0}}async _fetchPixels(e,t,i,r={}){let o=j(e);if(o>=2)return{extent:e,pixelBlock:null};const n=this._getSourceDataInfo(e,t,i,r),{pyramidLevel:s,srcResolution:l,srcExtent:a,srcWidth:c,srcHeight:f,ul:u}=n;if(0===c||0===f)return{extent:e,srcExtent:a,pixelBlock:null};const{rasterInfo:h}=this,p=h.transform,d="gcs-shift"===p?.type,x=null!=W(e.spatialReference);!d&&x||(o=j(n.srcExtent,d));const y=await this._fetchRawTiles(s,u,{width:c,height:f,wrapCount:o},r);if(!y)return{extent:e,srcExtent:a,pixelBlock:null};const g=h.storageInfo,I=s>0?g.pyramidBlockWidth:g.blockWidth,R=s>0?g.pyramidBlockHeight:g.blockHeight;let{x:w,y:S}=h.pixelSize;if(s>0){const{pyramidResolutions:e,pyramidScalingFactor:t}=g;if(null!=e&&e[s-1])({x:w,y:S}=e[s-1]);else{const e=t**s;w*=e,S*=e}}const k=h.spatialReference,b=new m({x:w,y:S,spatialReference:k}),T=I===c&&R===f&&u.x%I===0&&u.y%R===0,v=new m({x:(e.xmax-e.xmin)/t,y:(e.ymax-e.ymin)/i,spatialReference:e.spatialReference}),P=!e.spatialReference.equals(k),C=k.isGeographic?1e-9:1e-4,{datumTransformation:z}=r;if(!P&&T&&1===y.pixelBlocks.length&&I===t&&R===i&&ee(l,v,C))return{extent:e,srcExtent:a,srcTilePixelSize:b,pixelBlock:y.pixelBlocks[0]};const L=x&&null!=W(a.spatialReference)&&this._hasNoneOrGCSShiftTransform,E=r.requestProjectedLocalDirections&&this.rasterInfo.dataType.startsWith("vector");E&&!this.rasterJobHandler&&await H();const D=this.rasterJobHandler?await this.rasterJobHandler.getProjectionOffsetGrid({projectedExtent:e,srcBufferExtent:y.extent,pixelSize:v.toJSON(),datumTransformation:z,rasterTransform:p,hasWrapAround:o>0||L,isAdaptive:!1!==this.ioConfig.optimizeProjectionAccuracy,includeGCSGrid:E},r):O({projectedExtent:e,srcBufferExtent:y.extent,pixelSize:v,datumTransformation:z,rasterTransform:p,hasWrapAround:o>0||L,isAdaptive:!1,includeGCSGrid:E});let A;const q=!r.requestRawData,G={rows:D.spacing[0],cols:D.spacing[1]},J=this._hasNoneOrGCSShiftTransform?this._getRasterTileAlignmentInfo(s,y.extent.xmin):void 0,{pixelBlocks:N,mosaicSize:V,isPartiallyFilled:U}=y;let Q=null;if(this.rasterJobHandler){const e=await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:N,srcMosaicSize:V,destDimension:q?{width:t,height:i}:null,coefs:q?D.coefficients:null,sampleSpacing:q?G:null,projectDirections:E,gcsGrid:E?D.gcsGrid:null,isUV:"vector-uv"===this.rasterInfo.dataType,interpolation:r.interpolation,alignmentInfo:J,blockWidths:null},r);({pixelBlock:A,localNorthDirections:Q}=e)}else{const e=B(N,V,{alignmentInfo:J});A=q?_(e,{width:t,height:i},D.coefficients,G,r.interpolation):e,E&&D.gcsGrid&&(Q=M({width:t,height:i},D.gcsGrid),A=F(A,this.rasterInfo.dataType,Q))}return r.requestRawData||E?{extent:e,srcExtent:a,srcTilePixelSize:b,pixelBlock:A,transformGrid:D,localNorthDirections:Q,isPartiallyFilled:U}:{extent:e,srcExtent:a,srcTilePixelSize:b,pixelBlock:A}}async _fetchRawTiles(e,t,i,r){const{origin:o,blockBoundary:n}=this.rasterInfo.storageInfo,{blockWidth:s,blockHeight:l}=this.getBlockWidthHeight(e);let{x:a,y:c}=t,{width:f,height:m,wrapCount:h}=i;const p=this._getRasterTileAlignmentInfo(e,0);r.buffer&&(a-=r.buffer.cols,c-=r.buffer.rows,f+=2*r.buffer.cols,m+=2*r.buffer.rows);let d=0,x=0,y=0;if(h&&null!=p){({worldColumnCountFromOrigin:x,originColumnOffset:y,rightPadding:d}=p);x*p.blockWidth-d>=a+f&&(d=0)}const g=Math.floor(a/s),I=Math.floor(c/l),R=Math.floor((a+f+d-1)/s),w=Math.floor((c+m+d-1)/l),S=n[e];if(!S)return null;const{minRow:k,minCol:b,maxCol:T,maxRow:v}=S;if(0===h&&(w<k||R<b||I>v||g>T))return null;const P=new Array;let B=!1;const _=null==this.ioConfig.allowPartialFill?r.allowPartialFill:this.ioConfig.allowPartialFill;for(let u=I;u<=w;u++)for(let t=g;t<=R;t++){let i=t;if(!r.disableWrapAround&&h&&null!=p&&x<=t&&(i=t-x-y),u>=k&&i>=b&&v>=u&&T>=i){const t=this._fetchRawTile(e,u,i,r);_?P.push(new Promise(e=>{t.then(t=>e(t)).catch(()=>{B=!0,e(null)})})):P.push(t)}else P.push(Promise.resolve(null))}if(0===P.length)return null;const M=await Promise.all(P),C={height:(w-I+1)*l,width:(R-g+1)*s},{spatialReference:W}=this.rasterInfo,H=this.getPyramidPixelSize(e),{x:z,y:L}=H;return{extent:new u({xmin:o.x+g*s*z,xmax:o.x+(R+1)*s*z,ymin:o.y-(w+1)*l*L,ymax:o.y-I*l*L,spatialReference:W}),pixelBlocks:M,mosaicSize:C,isPartiallyFilled:B}}_fetchRawTile(e,t,i,r){const{storageInfo:o}=this.rasterInfo,n=null!=o.transposeInfo&&!!r.transposedVariableName;if(!n){const r=o.blockBoundary[e];if(!r)return Promise.resolve(null);const{minRow:n,minCol:s,maxCol:l,maxRow:a}=r;if(t<n||i<s||t>a||i>l)return Promise.resolve(null)}const l=n?r.transposeVariableName:r.sliceId,a=o.isBsqTile?r.bandIds:null,c=w(this.rasterId,l,a),f=`${e}/${t}/${i}`;let u=S(c,r.registryId,f);if(null==u){const n=new AbortController,s=r.bandIds?.slice();if(s?.length&&o.isBsqTile){const o=new Set(s),l=[],a=Array.from(o);for(const s of a)l.push(this._tileFetchQueue.push({pyramidLevel:e,row:t,col:i,options:{...r,bandIds:[s]}},{signal:n.signal}));u=Promise.all(l).then(e=>{if(e.some(e=>null==e))return null;if(a.length!==s.length){const t=[];for(const i of s){let r=e[a.indexOf(i)];t.includes(r)&&(r=r.clone()),t.push(r)}e=t}return this.rasterJobHandler?this.rasterJobHandler.compositeBands({pixelBlocks:e},{signal:n.signal,transferPixelsToWorker:!0}):C(e)})}else u=this._tileFetchQueue.push({pyramidLevel:e,row:t,col:i,options:r},{signal:n.signal});k(c,r.registryId,f,u,n),u.catch(()=>b(c,r.registryId,f))}return r.signal&&s(r,()=>{T(c,r.registryId,f)}),u}_computeMagDirValues(e){const{bandCount:t,dataType:i}=this.rasterInfo;if(!(2===t&&"vector-magdir"===i||"vector-uv"===i)||2!==e?.length||!e[0]?.length)return null;const r=e[0].length;if("vector-magdir"===i){const t=e[1].map(e=>(e+360)%360);return[e[0],t]}const[o,n]=e,s=[],l=[];for(let a=0;a<r;a++){const[e,t]=G([o[a],n[a]]);s.push(e),l.push(t)}return[s,l]}_getRasterTileAlignmentInfo(e,t){return null==this._rasterTileAlignmentInfo&&(this._rasterTileAlignmentInfo=A(this.rasterInfo)),null==this._rasterTileAlignmentInfo.pyramidsInfo?null:{startX:t,halfWorldWidth:this._rasterTileAlignmentInfo.halfWorldWidth,hasGCSSShiftTransform:this._rasterTileAlignmentInfo.hasGCSSShiftTransform,...this._rasterTileAlignmentInfo.pyramidsInfo[e]}}_getSourceDataInfo(e,t,i,r={}){const o={datumTransformation:r.datumTransformation,pyramidLevel:0,pyramidResolution:null,srcExtent:null,srcHeight:0,srcResolution:null,srcWidth:0,ul:{x:0,y:0}};r.srcResolution&&(o.srcResolution=r.srcResolution,this._updateSourceDataInfo(e,o));const n=this.rasterInfo.storageInfo.maximumPyramidLevel||0,{srcWidth:s,srcHeight:l,pyramidLevel:a}=o,c=s/t,f=l/i,u=a<n&&c*f>=16,h=a===n&&this._requireTooManySrcTiles(s,l,t,i);if(u||h||(0===s||0===l)){const s=new m({x:(e.xmax-e.xmin)/t,y:(e.ymax-e.ymin)/i,spatialReference:e.spatialReference});let l=q(s,this.rasterInfo.spatialReference,e,o.datumTransformation);const h=!l||r.srcResolution&&l.x+l.y<r.srcResolution.x+r.srcResolution.y;if(u&&r.srcResolution&&h){const e=Math.round(Math.log(Math.max(c,f))/Math.LN2)-1;if(n-a+3>=e){const t=2**e;l={x:r.srcResolution.x*t,y:r.srcResolution.y*t}}}l&&(o.srcResolution=l,this._updateSourceDataInfo(e,o))}return this._requireTooManySrcTiles(o.srcWidth,o.srcHeight,t,i)&&(o.srcWidth=0,o.srcHeight=0),o}_requireTooManySrcTiles(e,t,i,r){const{tileInfo:o}=this.rasterInfo.storageInfo,n=Math.ceil(e/o.size[0])*Math.ceil(t/o.size[1]),s=e/i,l=t/r,a=Math.max(1,(i+r)/1024);return n>=K*a||s>X||l>X}_updateSourceDataInfo(e,t){t.srcWidth=0,t.srcHeight=0;const{rasterInfo:i}=this,r=i.spatialReference,{srcResolution:o,datumTransformation:n}=t,{pyramidLevel:s,pyramidResolution:l,excessiveReading:a}=L(o,i,this.ioConfig.sampling);if(a)return;let c=t.srcExtent||D(e,r,n);if(null==c)return;const f=i.transform;f&&(c=f.inverseTransform(c)),t.srcExtent=c;const{origin:u}=i.storageInfo,{width:m,height:h,ul:p}=d(c,u,l,s);t.pyramidLevel=s,t.pyramidResolution=l,t.srcWidth=m,t.srcHeight=h,t.ul=p}_getRequestOptionsWithSliceId(e){return null!=this.rasterInfo.multidimensionalInfo&&null==e.sliceId&&(e={...e,sliceId:this.getSliceIndex(e.multidimensionalDefinition)}),e}_processIdentifyResult(e,t){const{srcLocation:i,position:r,pyramidLevel:o,useTransposedTile:n}=t,s=e.pixels[0].length/e.width/e.height;if(!(!e.mask||e.mask[r]))return{location:i,value:null};const{multidimensionalInfo:l}=this.rasterInfo;if(null==l||!n){const t=e.pixels.map(e=>e[r]),n={location:i,value:t,pyramidLevel:o},s=this._computeMagDirValues(t.map(e=>[e]));return s?.length&&(n.magdirValue=s.map(e=>e[0])),n}let a=e.pixels.map(e=>e.slice(r*s,r*s+s)),c=this._computeMagDirValues(a);const{requestSomeSlices:f,identifyOptions:u}=t;let m=g(l,u.transposedVariableName);if(f){const e=I(m,u.multidimensionalDefinition,u.timeExtent);a=a.map(t=>e.map(e=>t[e])),c=c?.map(t=>e.map(e=>t[e])),m=e.map(e=>m[e])}const h=e.noDataValues||this.rasterInfo.noDataValue,p={pixels:a,pixelType:e.pixelType};let d;null!=h&&(v(p,h),d=p.mask);return{location:i,value:null,dataSeries:m.map((e,t)=>{const i={value:0===d?.[t]?null:a.map(e=>e[t]),multidimensionalDefinition:e.multidimensionalDefinition.map(e=>new V({...e,isSlice:!0}))};return c?.length&&(i.magdirValue=[c[0][t],c[1][t]]),i}),pyramidLevel:o}}};function ee(e,t,i){return Math.abs(e.x-t.x)<i&&Math.abs(e.y-t.y)<i}e([a()],Z.prototype,"_rasterTileAlignmentInfo",void 0),e([a()],Z.prototype,"_tileFetchQueue",void 0),e([a({readOnly:!0})],Z.prototype,"_isGlobalWrappableSource",null),e([a({readOnly:!0})],Z.prototype,"_hasNoneOrGCSShiftTransform",null),e([a()],Z.prototype,"_openPromise",void 0),e([a()],Z.prototype,"rasterJobHandler",null),e([a({readOnly:!0})],Z.prototype,"rasterId",null),e([a(N)],Z.prototype,"url",null),e([a({type:String,json:{write:!0}})],Z.prototype,"datasetName",void 0),e([a({type:String,json:{write:!0}})],Z.prototype,"datasetFormat",void 0),e([a()],Z.prototype,"hasUniqueSourceStorageInfo",void 0),e([a()],Z.prototype,"rasterInfo",void 0),e([a()],Z.prototype,"ioConfig",void 0),e([a()],Z.prototype,"sourceJSON",void 0),e([a()],Z.prototype,"rawBlockRegistryIds",void 0),Z=e([c("esri.layers.raster.datasets.BaseRaster")],Z);export{Z as default};