3 lines
87 KiB
JavaScript
3 lines
87 KiB
JavaScript
import{i8 as yt,c3 as te,kg as nt,z as Te,s as C,a7 as Je,aH as H,ab as W,ar as at,e6 as ot,gZ as gt,A as b,B as R,du as lt,C as Q,a6 as xt,E as Ne,_ as ct,aW as We,f as q,a8 as wt,b3 as It,aD as ut,kh as bt,L as Oe,Y as St,h0 as Rt,$ as vt,I as Tt,bm as _t,bn as kt,dp as Ft,dq as Mt,dR as Pt,dO as Ct,dP as Ot,dn as $t,dr as Dt,bS as Bt,eM as Et,bv as Jt,c_ as ue,fx as Nt,fO as xe,D as At,dX as zt,bV as Ht,dt as Lt,F as Wt,bq as qt}from"./index-b5c8f851.js";import{c as Gt,N as $e,l as jt,d as Ut,a as Vt,h as Xt,K as qe,B as Ge,S as Yt,E as Kt,V as je,t as Zt,p as Qt,m as ei,b as ti}from"./ImageHistogramParameters-c0ab9cd7.js";import{h as ht,D as ii,i as si,a as ri,p as ft,d as Ue,o as ni,f as Ve,g as ai}from"./multidimensionalUtils-bffdf14d.js";import{j as oi,n as ye,m as li,L as ci,r as Xe,a as ge,h as ui,g as Ae,P as hi,b as fi,F as di,U as mi,N as pi,R as yi,c as we,B as gi,d as xi,D as wi}from"./RasterSymbolizer-a162ee17.js";import{i as Ye,m as Ke,x as Ze,h as Ii,s as bi}from"./RawBlockCache-63593c2d.js";import{U as ke,R as dt,I as Si,a as Ri,l as vi,c as Ti,u as ie,f as _i,s as ki,W as Fi,T as Mi}from"./dataUtils-c2b057a0.js";import{T as De,D as Ie,j as Qe,r as et,o as Pi,V as Fe,J as Re,e as Ci,Z as Oi,C as $i,U as Di}from"./rasterProjectionHelper-68eba0c9.js";import{R as Be,f as Bi,i as Ei,y as ze,n as Ji,C as Ni}from"./utils-80923cc5.js";import{T as Ai}from"./TilemapCache-fd76717b.js";import"./utils-6d77327b.js";import"./utils-ebbcf3da.js";import"./generateRendererUtils-d29abb94.js";import"./colorUtils-23771bca.js";import"./ByteSizeUnit-d4757d40.js";const tt=8,zi=256;let G=class extends yt(xt){constructor(){super(...arguments),this.datasetName=null,this.datasetFormat=null,this.hasUniqueSourceStorageInfo=!0,this.rasterInfo=null,this.ioConfig={sampling:"closest"}}async init(){const e=De();this.addResolvingPromise(e),await this.when()}normalizeCtorArgs(e){return e!=null&&e.ioConfig&&(e={...e,ioConfig:{resolution:null,bandIds:null,sampling:"closest",tileInfo:te.create(),...e.ioConfig}}),e}get _isGlobalWrappableSource(){const{rasterInfo:e}=this,s=Ie(e.spatialReference);return s!=null&&e.extent.width>=s/2}get _hasNoneOrGCSShiftTransform(){const{transform:e}=this.rasterInfo;return e==null||e.type==="gcs-shift"}set rasterJobHandler(e){var s,t;this._set("rasterJobHandler",e),this.datasetFormat==="Function"&&((t=(s=this.primaryRasters)==null?void 0:s.rasters)==null||t.forEach(i=>i.rasterJobHandler=e))}set url(e){this._set("url",nt(e,Te.getLogger(this)))}async open(e){throw new C("BaseRaster:open-not-implemented","open() is not implemented")}async fetchTile(e,s,t,i={}){const r=i.tileInfo||this.rasterInfo.storageInfo.tileInfo,n=this.getTileExtentFromTileInfo(e,s,t,r);return this.fetchPixels(n,r.size[0],r.size[1],i)}async identify(e,s={}){var O;e=Je(H,e).clone().normalize();const{multidimensionalDefinition:t,timeExtent:i}=s,{rasterInfo:r}=this,{hasMultidimensionalTranspose:n,multidimensionalInfo:o}=r;let{transposedVariableName:l}=s;const c=o!=null&&n&&(i!=null||ht(t));c&&!l&&(l=t!=null&&t.length>0?t[0].variableName??void 0:o.variables[0].name,s={...s,transposedVariableName:l}),s=this._getRequestOptionsWithSliceId(s);const{spatialReference:u,extent:f}=r,{datumTransformation:p}=s;let h=Qe(e,u,p);if(!f.intersects(h))return{location:h,value:null};if(r.transform!=null){const D=r.transform.inverseTransform(h);if(!r.nativeExtent.intersects(D))return{location:D,value:null};h=D}let m=0;const y=l!=null&&o!=null&&r.hasMultidimensionalTranspose;if(this.datasetFormat==="Function"){const D=this.primaryRasters.rasters[0];if(y)return D.identify(h,s);const{pixelSize:N}=r,P=3,$=N.x*P/2,B=N.y*P/2,U=new W({xmin:h.x-$,xmax:h.x+$,ymin:h.y-B,ymax:h.y+B,spatialReference:u}),Y={interpolation:"nearest"},{pixelBlock:A}=await D.fetchPixels(U,P,P,Y),{pixelBlock:z}=await this.fetchPixels(U,P,P,Y);if(A==null)return{location:h,value:null};const L=Math.floor(P*P*.5),ee=!A.mask||A.mask[L]?A.pixels.map(V=>V[L]):null;let E;return z!=null&&(E=!z.mask||z.mask[L]?z.pixels.map(V=>V[L]):void 0),{location:h,value:ee,processedValue:E,pyramidLevel:0}}if(!y){if(s.srcResolution)m=et(s.srcResolution,r,this.ioConfig.sampling).pyramidLevel;else if(m=await this.computeBestPyramidLevelForLocation(e,s),m==null)return{location:h,value:null}}const d=this.identifyPixelLocation(h,m,null,y);if(d===null)return{location:h,value:null};const{row:x,col:g,rowOffset:w,colOffset:I,blockWidth:S}=d,v=l??s.sliceId,F=Ye(this.url,v),T=`${m}/${x}/${g}`;let k=Ke(F,null,T);k==null&&(k=this.fetchRawTile(m,x,g,s),Ze(F,null,T,k));const _=await k;if(!((O=_==null?void 0:_.pixels)!=null&&O.length))return{location:h,value:null};const M=w*S+I;return this._processIdentifyResult(_,{srcLocation:h,position:M,pyramidLevel:m,useTransposedTile:!!y,requestSomeSlices:c,identifyOptions:s})}async fetchPixels(e,s,t,i={}){e=Pi(e),i=this._getRequestOptionsWithSliceId(i);const{_hasNoneOrGCSShiftTransform:r}=this;if(i.requestRawData&&r)return this._fetchPixels(e,s,t,i);const n=Ie(e.spatialReference),o=Fe(e);if(n==null||o===0||o===1&&this._isGlobalWrappableSource&&r)return this._fetchPixels(e,s,t,i);if(o>=3)return{extent:e,pixelBlock:null};const l=[],{xmin:c,xmax:u}=e,f=Math.round(n/(u-c)*s),p=f-Math.round((n/2-c)/(u-c)*s);let h=0;const m=[];for(let g=0;g<=o;g++){const w=new W({xmin:g===0?c:-n/2,xmax:g===o?u-n*g:n/2,ymin:e.ymin,ymax:e.ymax,spatialReference:e.spatialReference}),I=g===0?f-p:g===o?s-h:f;h+=I,m.push(I);const S=i.disableWrapAround&&g>0?null:this._fetchPixels(w,I,t,i);l.push(S)}const y=(await Promise.all(l)).map(g=>g==null?void 0:g.pixelBlock);let d=null;const x={width:s,height:t};return this.rasterJobHandler?d=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:y,srcMosaicSize:x,destDimension:null,coefs:null,sampleSpacing:null,interpolation:"nearest",alignmentInfo:null,blockWidths:m},i)).pixelBlock:d=ke(y,x,{blockWidths:m}),{extent:e,srcExtent:Re(e,this.rasterInfo.spatialReference,i.datumTransformation),pixelBlock:d}}async fetchRawPixels(e,s,t,i={}){s={x:Math.floor(s.x),y:Math.floor(s.y)};const r=await this._fetchRawTiles(e,s,t,i),{nativeExtent:n,nativePixelSize:o,storageInfo:l}=this.rasterInfo,c=2**e,u=o.x*c,f=o.y*c,p=new W({xmin:n.xmin+u*s.x,xmax:n.xmin+u*(s.x+t.width-1),ymin:n.ymax-f*(s.y+t.height-1),ymax:n.ymax-f*s.y,spatialReference:n.spatialReference});if(!r)return{extent:p,srcExtent:p,pixelBlock:null};const{pixelBlocks:h,mosaicSize:m}=r;if(h.length===1&&h[0]!=null&&h[0].width===t.width&&h[0].height===t.height)return{extent:p,srcExtent:p,pixelBlock:r.pixelBlocks[0]};const y=e>0?l.pyramidBlockWidth:l.blockWidth,d=e>0?l.pyramidBlockHeight:l.blockHeight,x={x:s.x%y,y:s.y%d};let g;return this.rasterJobHandler?g=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:h,srcMosaicSize:m,destDimension:t,clipOffset:x,clipSize:t,coefs:null,sampleSpacing:null,interpolation:i.interpolation,alignmentInfo:null,blockWidths:null},i)).pixelBlock:g=ke(h,m,{clipOffset:x,clipSize:t}),{extent:p,srcExtent:p,pixelBlock:g}}fetchRawTile(e,s,t,i){throw new C("BaseRaster:read-not-implemented","fetchRawTile() is not implemented")}computeExtent(e){return Re(this.rasterInfo.extent,e)}decodePixelBlock(e,s){return!this.rasterJobHandler||s.useCanvas?oi(e,s):this.rasterJobHandler.decode({data:e,options:s})}async request(e,s,t=0){const{customFetchParameters:i}=this.ioConfig,{range:r,query:n,headers:o}=s;t=t??s.retryCount??this.ioConfig.retryCount;const l=r?{Range:`bytes=${r.from}-${r.to}`}:null;try{return await at(e,{...s,query:{...n,...i},headers:{...o,...l}})}catch(c){if(t>0)return t--,this.request(e,s,t);throw c}}getSliceIndex(e){const{multidimensionalInfo:s}=this.rasterInfo;return s==null||e==null||e.length===0?null:ii(e,s)}getTileExtentFromTileInfo(e,s,t,i){const r=i.lodAt(e);return this.getTileExtent({x:r.resolution,y:r.resolution},s,t,i.origin,i.spatialReference,i.size)}updateTileInfo(){const{storageInfo:e,spatialReference:s,extent:t,pixelSize:i}=this.rasterInfo;if(!e.tileInfo){const r=[],n=e.maximumPyramidLevel||0;let o=Math.max(i.x,i.y),l=1/.0254*96*o;for(let u=0;u<=n;u++)r.unshift(new ot({level:n-u,resolution:o,scale:l})),o*=2,l*=2;const c=new H({x:t.xmin,y:t.ymax,spatialReference:s});e.tileInfo=new te({origin:c,size:[e.blockWidth,e.blockHeight],spatialReference:s,lods:r}),e.isVirtualTileInfo=!0}}createRemoteDatasetStorageInfo(e,s=512,t=512,i){const{width:r,height:n,nativeExtent:o,pixelSize:l,spatialReference:c}=e,u=new H({x:o.xmin,y:o.ymax,spatialReference:c});i==null&&(i=Math.max(0,Math.round(Math.log(Math.max(r,n))/Math.LN2-8)));const f=this.computeBlockBoundary(o,512,512,{x:o.xmin,y:o.ymax},[l],i);e.storageInfo=new ye({blockWidth:s,blockHeight:t,pyramidBlockWidth:s,pyramidBlockHeight:t,origin:u,firstPyramidLevel:1,maximumPyramidLevel:i,blockBoundary:f})}async computeBestPyramidLevelForLocation(e,s={}){return 0}computeBlockBoundary(e,s,t,i,r,n=0,o=2){if(r.length===1&&n>0){r=[...r];let{x:f,y:p}=r[0];for(let h=0;h<n;h++)f*=o,p*=o,r.push({x:f,y:p})}const l=[],{x:c,y:u}=i;for(let f=0;f<r.length;f++){const{x:p,y:h}=r[f];l.push({minCol:Math.floor((e.xmin-c+.1*p)/s/p),maxCol:Math.floor((e.xmax-c-.1*p)/s/p),minRow:Math.floor((u-e.ymax+.1*h)/t/h),maxRow:Math.floor((u-e.ymin-.1*h)/t/h)})}return l}getPyramidPixelSize(e){const{nativePixelSize:s}=this.rasterInfo,{pyramidResolutions:t,pyramidScalingFactor:i}=this.rasterInfo.storageInfo;if(e===0)return s;if(t!=null&&t.length)return t[e-1];const r=i**e;return{x:s.x*r,y:s.y*r}}identifyPixelLocation(e,s,t,i){const{spatialReference:r,nativeExtent:n,storageInfo:o}=this.rasterInfo,{maximumPyramidLevel:l,origin:c,transposeInfo:u}=o,f=i&&u!=null?u.tileSize[0]:o.blockWidth,p=i&&u!=null?u.tileSize[1]:o.blockHeight,h=Qe(e,r,t);if(!n.intersects(h)||s<0||s>l)return null;const m=this.getPyramidPixelSize(s),{x:y,y:d}=m,x=(c.y-h.y)/d/p,g=(h.x-c.x)/y/f,w=Math.min(p-1,Math.floor((x-Math.floor(x))*p)),I=Math.min(f-1,Math.floor((g-Math.floor(g))*f));return{pyramidLevel:s,row:Math.floor(x),col:Math.floor(g),rowOffset:w,colOffset:I,blockWidth:f,srcLocation:h}}getTileExtent(e,s,t,i,r,n){const[o,l]=n,c=i.x+t*o*e.x,u=c+o*e.x,f=i.y-s*l*e.y,p=f-l*e.y;return new W({xmin:c,xmax:u,ymin:p,ymax:f,spatialReference:r})}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,s,t){const i=this.rasterInfo.storageInfo.blockBoundary[e];return!i||i.maxRow<s||i.maxCol<t||i.minRow>s||i.minCol>t}async _fetchPixels(e,s,t,i={}){let r=Fe(e);if(r>=2)return{extent:e,pixelBlock:null};const n=this._getSourceDataInfo(e,s,t,i),{pyramidLevel:o,srcResolution:l,srcExtent:c,srcWidth:u,srcHeight:f,ul:p}=n;if(u===0||f===0)return{extent:e,srcExtent:c,pixelBlock:null};const{rasterInfo:h}=this,m=h.transform,y=(m==null?void 0:m.type)==="gcs-shift",d=Ie(e.spatialReference)!=null;!y&&d||(r=Fe(n.srcExtent,y));const x=await this._fetchRawTiles(o,p,{width:u,height:f,wrapCount:r},i);if(!x)return{extent:e,srcExtent:c,pixelBlock:null};const g=h.storageInfo,w=o>0?g.pyramidBlockWidth:g.blockWidth,I=o>0?g.pyramidBlockHeight:g.blockHeight;let{x:S,y:v}=h.pixelSize;if(o>0){const{pyramidResolutions:V,pyramidScalingFactor:pt}=g;if(V!=null&&V[o-1])({x:S,y:v}=V[o-1]);else{const Le=pt**o;S*=Le,v*=Le}}const F=h.spatialReference,T=new H({x:S,y:v,spatialReference:F}),k=w===u&&I===f&&p.x%w==0&&p.y%I==0,_=new H({x:(e.xmax-e.xmin)/s,y:(e.ymax-e.ymin)/t,spatialReference:e.spatialReference}),M=!e.spatialReference.equals(F),O=F.isGeographic?1e-9:1e-4,{datumTransformation:D}=i;if(!M&&k&&x.pixelBlocks.length===1&&w===s&&I===t&&this._isSameResolution(l,_,O))return{extent:e,srcExtent:c,srcTilePixelSize:T,pixelBlock:x.pixelBlocks[0]};const N=d&&Ie(c.spatialReference)!=null&&this._hasNoneOrGCSShiftTransform,P=i.requestProjectedLocalDirections&&this.rasterInfo.dataType.startsWith("vector");P&&!this.rasterJobHandler&&await De();const $=this.rasterJobHandler?await this.rasterJobHandler.getProjectionOffsetGrid({projectedExtent:e,srcBufferExtent:x.extent,pixelSize:_.toJSON(),datumTransformation:D,rasterTransform:m,hasWrapAround:r>0||N,isAdaptive:this.ioConfig.optimizeProjectionAccuracy!==!1,includeGCSGrid:P},i):Ci({projectedExtent:e,srcBufferExtent:x.extent,pixelSize:_,datumTransformation:D,rasterTransform:m,hasWrapAround:r>0||N,isAdaptive:!1,includeGCSGrid:P});let B;const U=!i.requestRawData,Y={rows:$.spacing[0],cols:$.spacing[1]},A=this._hasNoneOrGCSShiftTransform?this._getRasterTileAlignmentInfo(o,x.extent.xmin):void 0,{pixelBlocks:z,mosaicSize:L,isPartiallyFilled:ee}=x;let E=null;if(this.rasterJobHandler)({pixelBlock:B,localNorthDirections:E}=await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:z,srcMosaicSize:L,destDimension:U?{width:s,height:t}:null,coefs:U?$.coefficients:null,sampleSpacing:U?Y:null,projectDirections:P,gcsGrid:P?$.gcsGrid:null,isUV:this.rasterInfo.dataType==="vector-uv",interpolation:i.interpolation,alignmentInfo:A,blockWidths:null},i));else{const V=ke(z,L,{alignmentInfo:A});B=U?dt(V,{width:s,height:t},$.coefficients,Y,i.interpolation):V,P&&$.gcsGrid&&(E=Si({width:s,height:t},$.gcsGrid),B=Ri(B,this.rasterInfo.dataType,E))}return i.requestRawData||P?{extent:e,srcExtent:c,srcTilePixelSize:T,pixelBlock:B,transformGrid:$,localNorthDirections:E,isPartiallyFilled:ee}:{extent:e,srcExtent:c,srcTilePixelSize:T,pixelBlock:B}}async _fetchRawTiles(e,s,t,i){const{origin:r,blockBoundary:n}=this.rasterInfo.storageInfo,{blockWidth:o,blockHeight:l}=this.getBlockWidthHeight(e);let{x:c,y:u}=s,{width:f,height:p,wrapCount:h}=t;const m=this._getRasterTileAlignmentInfo(e,0);i.buffer&&(c-=i.buffer.cols,u-=i.buffer.rows,f+=2*i.buffer.cols,p+=2*i.buffer.rows);let y=0,d=0,x=0;h&&m!=null&&({worldColumnCountFromOrigin:d,originColumnOffset:x,rightPadding:y}=m,d*m.blockWidth-y>=c+f&&(y=0));const g=Math.floor(c/o),w=Math.floor(u/l),I=Math.floor((c+f+y-1)/o),S=Math.floor((u+p+y-1)/l),v=n[e];if(!v)return null;const{minRow:F,minCol:T,maxCol:k,maxRow:_}=v;if(h===0&&(S<F||I<T||w>_||g>k))return null;const M=new Array;let O=!1;const D=this.ioConfig.allowPartialFill==null?i.allowPartialFill:this.ioConfig.allowPartialFill;for(let A=w;A<=S;A++)for(let z=g;z<=I;z++){let L=z;if(!i.disableWrapAround&&h&&m!=null&&d<=z&&(L=z-d-x),A>=F&&L>=T&&_>=A&&k>=L){const ee=this._fetchRawTile(e,A,L,i);D?M.push(new Promise(E=>{ee.then(V=>E(V)).catch(()=>{O=!0,E(null)})})):M.push(ee)}else M.push(Promise.resolve(null))}if(M.length===0)return null;const N=await Promise.all(M),P={height:(S-w+1)*l,width:(I-g+1)*o},{spatialReference:$}=this.rasterInfo,B=this.getPyramidPixelSize(e),{x:U,y:Y}=B;return{extent:new W({xmin:r.x+g*o*U,xmax:r.x+(I+1)*o*U,ymin:r.y-(S+1)*l*Y,ymax:r.y-w*l*Y,spatialReference:$}),pixelBlocks:N,mosaicSize:P,isPartiallyFilled:O}}_isSameResolution(e,s,t){return Math.abs(e.x-s.x)<t&&Math.abs(e.y-s.y)<t}_fetchRawTile(e,s,t,i){const r=this.rasterInfo.storageInfo.blockBoundary[e];if(!r)return Promise.resolve(null);const{minRow:n,minCol:o,maxCol:l,maxRow:c}=r;if(s<n||t<o||s>c||t>l)return Promise.resolve(null);const u=Ye(this.url,i.sliceId),f=`${e}/${s}/${t}`;let p=Ke(u,i.registryId,f);if(p==null){const h=new AbortController;p=this.fetchRawTile(e,s,t,{...i,signal:h.signal}),Ze(u,i.registryId,f,p,h),p.catch(()=>Ii(u,i.registryId,f))}return i.signal&>(i,()=>{bi(u,i.registryId,f)}),p}_computeMagDirValues(e){var c;const{bandCount:s,dataType:t}=this.rasterInfo;if(!(s===2&&t==="vector-magdir"||t==="vector-uv")||(e==null?void 0:e.length)!==2||!((c=e[0])!=null&&c.length))return null;const i=e[0].length;if(t==="vector-magdir"){const u=e[1].map(f=>(f+360)%360);return[e[0],u]}const[r,n]=e,o=[],l=[];for(let u=0;u<i;u++){const[f,p]=vi([r[u],n[u]]);o.push(f),l.push(p)}return[o,l]}_getRasterTileAlignmentInfo(e,s){return this._rasterTileAlighmentInfo==null&&(this._rasterTileAlighmentInfo=Oi(this.rasterInfo)),this._rasterTileAlighmentInfo.pyramidsInfo==null?null:{startX:s,halfWorldWidth:this._rasterTileAlighmentInfo.halfWorldWidth,hasGCSSShiftTransform:this._rasterTileAlighmentInfo.hasGCSSShiftTransform,...this._rasterTileAlighmentInfo.pyramidsInfo[e]}}_getSourceDataInfo(e,s,t,i={}){const r={datumTransformation:i.datumTransformation,pyramidLevel:0,pyramidResolution:null,srcExtent:null,srcHeight:0,srcResolution:null,srcWidth:0,ul:{x:0,y:0}};i.srcResolution&&(r.srcResolution=i.srcResolution,this._updateSourceDataInfo(e,r));const n=this.rasterInfo.storageInfo.maximumPyramidLevel||0,{srcWidth:o,srcHeight:l,pyramidLevel:c}=r,u=o/s,f=l/t,p=c<n&&u*f>=16,h=c===n&&this._requireTooManySrcTiles(o,l,s,t);if(p||h||o===0||l===0){const m=new H({x:(e.xmax-e.xmin)/s,y:(e.ymax-e.ymin)/t,spatialReference:e.spatialReference});let y=$i(m,this.rasterInfo.spatialReference,e,r.datumTransformation);const d=!y||i.srcResolution&&y.x+y.y<i.srcResolution.x+i.srcResolution.y;if(p&&i.srcResolution&&d){const x=Math.round(Math.log(Math.max(u,f))/Math.LN2)-1;if(n-c+3>=x){const g=2**x;y={x:i.srcResolution.x*g,y:i.srcResolution.y*g}}}y&&(r.srcResolution=y,this._updateSourceDataInfo(e,r))}return this._requireTooManySrcTiles(r.srcWidth,r.srcHeight,s,t)&&(r.srcWidth=0,r.srcHeight=0),r}_requireTooManySrcTiles(e,s,t,i){const{tileInfo:r}=this.rasterInfo.storageInfo;return Math.ceil(e/r.size[0])*Math.ceil(s/r.size[1])>=zi||e/t>tt||s/i>tt}_updateSourceDataInfo(e,s){s.srcWidth=0,s.srcHeight=0;const{rasterInfo:t}=this,i=t.spatialReference,{srcResolution:r,datumTransformation:n}=s,{pyramidLevel:o,pyramidResolution:l,excessiveReading:c}=et(r,t,this.ioConfig.sampling);if(c)return;let u=s.srcExtent||Re(e,i,n);if(u==null)return;const f=t.transform;f&&(u=f.inverseTransform(u)),s.srcExtent=u;const{x:p,y:h}=t.storageInfo.origin,m=Math.floor((u.xmin-p)/l.x+.1),y=Math.floor((h-u.ymax)/l.y+.1),d=Math.floor((u.xmax-p)/l.x-.1),x=Math.floor((h-u.ymin)/l.y-.1),g=u.width<.1*l.x?0:d-m+1,w=u.height<.1*l.y?0:x-y+1;s.pyramidLevel=o,s.pyramidResolution=l,s.srcWidth=g,s.srcHeight=w,s.ul={x:m,y}}_getRequestOptionsWithSliceId(e){return this.rasterInfo.multidimensionalInfo!=null&&e.sliceId==null&&(e={...e,sliceId:this.getSliceIndex(e.multidimensionalDefinition)}),e}_processIdentifyResult(e,s){const{srcLocation:t,position:i,pyramidLevel:r,useTransposedTile:n}=s,o=e.pixels[0].length/e.width/e.height;if(!(!e.mask||e.mask[i]))return{location:t,value:null};const{multidimensionalInfo:l}=this.rasterInfo;if(l==null||!n){const x=e.pixels.map(I=>I[i]),g={location:t,value:x,pyramidLevel:r},w=this._computeMagDirValues(x.map(I=>[I]));return w!=null&&w.length&&(g.magdirValue=w.map(I=>I[0])),g}let c=e.pixels.map(x=>x.slice(i*o,i*o+o)),u=this._computeMagDirValues(c);const{requestSomeSlices:f,identifyOptions:p}=s;let h=si(l,p.transposedVariableName);if(f){const x=ri(h,p.multidimensionalDefinition,p.timeExtent);c=c.map(g=>x.map(w=>g[w])),u=u==null?void 0:u.map(g=>x.map(w=>g[w])),h=x.map(g=>h[g])}const m=e.noDataValues||this.rasterInfo.noDataValue,y={pixels:c,pixelType:e.pixelType};let d;return m!=null&&(Ti(y,m),d=y.mask),{location:t,value:null,dataSeries:h.map((x,g)=>{const w={value:(d==null?void 0:d[g])===0?null:c.map(I=>I[g]),multidimensionalDefinition:x.multidimensionalDefinition.map(I=>new ft({...I,isSlice:!0}))};return u!=null&&u.length&&(w.magdirValue=[u[0][g],u[1][g]]),w}),pyramidLevel:r}}};b([R()],G.prototype,"_rasterTileAlighmentInfo",void 0),b([R({readOnly:!0})],G.prototype,"_isGlobalWrappableSource",null),b([R({readOnly:!0})],G.prototype,"_hasNoneOrGCSShiftTransform",null),b([R()],G.prototype,"rasterJobHandler",null),b([R(lt)],G.prototype,"url",null),b([R({type:String,json:{write:!0}})],G.prototype,"datasetName",void 0),b([R({type:String,json:{write:!0}})],G.prototype,"datasetFormat",void 0),b([R()],G.prototype,"hasUniqueSourceStorageInfo",void 0),b([R()],G.prototype,"rasterInfo",void 0),b([R()],G.prototype,"ioConfig",void 0),b([R()],G.prototype,"sourceJSON",void 0),G=b([Q("esri.layers.support.rasterDatasets.BaseRaster")],G);const le=G;let re=class extends le{constructor(){super(...arguments),this.datasetFormat="Function",this.tileType="Raster",this.rasterFunction=null}async open(e){var u,f,p,h;await this.init();const{rasterFunction:s}=this;(f=(u=this.primaryRasters)==null?void 0:u.rasters)!=null&&f.length?s.sourceRasters=this.primaryRasters.rasters:(this.primaryRasters=s.getPrimaryRasters(),this.rasterJobHandler&&((p=this.primaryRasters.rasters)==null||p.forEach(m=>m.rasterJobHandler=this.rasterJobHandler)));const{rasters:t,rasterIds:i}=this.primaryRasters,r=t.map(m=>m.rasterInfo?void 0:m.open(e));await Promise.all(r);const n=t.map(({rasterInfo:m})=>m),o=s.bind({rasterInfos:n,rasterIds:i});if(!o.success||n.length===0)throw new C("raster-function:open",`cannot bind the function: ${o.error??""}`);const l=s.functionName==="Table"?s:(h=s.functionArguments)==null?void 0:h.raster;(l==null?void 0:l.functionName)==="Table"&&(s.rasterInfo.attributeTable=Ne.fromJSON(l.functionArguments.attributeTableAsRecordSet)),await this.syncJobHandler();const c=n[0];this.hasUniqueSourceStorageInfo=n.length===1||n.slice(1).every(m=>this._hasSameStorageInfo(m,c)),this.set("sourceJSON",t[0].sourceJSON),this.set("rasterInfo",s.rasterInfo)}async syncJobHandler(){var e;return(e=this.rasterJobHandler)==null?void 0:e.updateRasterFunction(this.rasterFunction)}async fetchPixels(e,s,t,i={}){var w,I;const{rasters:r,rasterIds:n}=this.primaryRasters;let o=!1;const{interpolation:l}=i,c=(w=this.rasterFunction.flatWebGLFunctionChain)==null?void 0:w.hasFocalFunction;!i.requestRawData&&l!=="bilinear"&&c&&(o=r.length===1&&!i.skipRasterFunction,i={...i,interpolation:"bilinear",requestRawData:o});const u=r.map(S=>S.fetchPixels(e,s,t,i)),f=await Promise.all(u),p=f.map(S=>S.pixelBlock),h=o||i.requestRawData?f.map(S=>S.srcTilePixelSize):null;if(i.skipRasterFunction||p.every(S=>S==null))return f[0];const m=((I=f.find(S=>S.pixelBlock!=null))==null?void 0:I.extent)??e,y=this.rasterJobHandler?await this.rasterJobHandler.process({extent:m,primaryPixelBlocks:p,primaryPixelSizes:h,primaryRasterIds:n}):this.rasterFunction.process({extent:m,primaryPixelBlocks:p,primaryPixelSizes:h,primaryRasterIds:n}),{transformGrid:d}=f[0];if(!o||y==null||d==null)return{...f[0],pixelBlock:y};const x={rows:d.spacing[0],cols:d.spacing[1]};let g;return this.rasterJobHandler?g=(await this.rasterJobHandler.mosaicAndTransform({srcPixelBlocks:[y],srcMosaicSize:{width:y.width,height:y.height},destDimension:{width:s,height:t},coefs:d.coefficients,sampleSpacing:x,projectDirections:!1,gcsGrid:null,isUV:!1,interpolation:l,alignmentInfo:void 0,blockWidths:null},i)).pixelBlock:g=dt(y,{width:s,height:t},d.coefficients,x,l),{extent:e,srcExtent:f[0].srcExtent,pixelBlock:g}}_hasSameStorageInfo(e,s){const{storageInfo:t,pixelSize:i,spatialReference:r,extent:n}=e,{storageInfo:o,pixelSize:l,spatialReference:c,extent:u}=s;return i.x===l.x&&i.y===l.y&&r.equals(c)&&n.equals(u)&&t.blockHeight===o.blockHeight&&t.blockWidth===o.blockWidth&&t.maximumPyramidLevel===o.maximumPyramidLevel}};b([R({type:String,json:{write:!0}})],re.prototype,"datasetFormat",void 0),b([R()],re.prototype,"tileType",void 0),b([R()],re.prototype,"rasterFunction",void 0),b([R()],re.prototype,"primaryRasters",void 0),re=b([Q("esri.layers.support.rasterDatasets.FunctionRaster")],re);const Ee=re;function Hi(a,e){if(a.spatialReference.equals(e))return a;const s=We(a.spatialReference),t=We(e);if(s===t)return a;const i=s/t;return{x:a.x*i,y:a.y*i}}async function Li(a,e,s){if(s.type==="extent")return qi(a,e,s);const{width:t,height:i}=a,r=new Uint8Array(t*i),{contains:n,intersects:o}=await ct(()=>import("./geometryEngine-cf15c147.js"),["assets/geometryEngine-cf15c147.js","assets/geometryEngineBase-5b22cc12.js","assets/index-b5c8f851.js","assets/index-86716609.css","assets/hydrated-ca5faac2.js"]);return o(e,s)?s.type==="polyline"?Gi(a,e,s):n(s,e)?a:Wi(a,e,s):new ie({pixelType:a.pixelType,width:t,height:i,mask:r,maskIsAlpha:!1,pixels:[...a.pixels]})}function Wi(a,e,s){if(!a)return a;const{width:t,height:i}=a,r=e.width/t,n=e.height/i,{xmin:o,ymax:l}=e;let c;if(s.type==="extent"){const d=(s.xmin-o)/r,x=(s.xmax-o)/r,g=(l-s.ymax)/n,w=(l-s.ymin)/n;c=[[[d,g],[d,w],[x,w],[x,g],[d,g]]]}else c=s.rings.map(d=>d.map(([x,g])=>[(x-o)/r,(l-g)/n]));const u=document.createElement("canvas");u.width=t,u.height=i;const f=u.getContext("2d");f.fillStyle="#f00",c.forEach(d=>{f.beginPath(),f.moveTo(d[0][0],d[0][1]);for(let x=0;x<d.length;x++)f.lineTo(d[x][0],d[x][1]);f.closePath(),f.fill()});const p=f.getImageData(0,0,t,i).data,h=a.mask,m=t*i,y=new Uint8Array(m);for(let d=0;d<m;d++)h&&!h[d]||(y[d]=p[4*d+3]>127?255:0);return new ie({pixelType:a.pixelType,width:t,height:i,mask:y,maskIsAlpha:!1,pixels:[...a.pixels]})}function qi(a,e,s){const{width:t,height:i}=a,r=new Uint8Array(t*i),n=e.width/t,o=e.height/i;if(s.width/n<.5||s.height/o<.5)return new ie({pixelType:a.pixelType,width:t,height:i,mask:r,pixels:[...a.pixels]});const{xmin:l,xmax:c,ymin:u,ymax:f}=e,{xmin:p,xmax:h,ymin:m,ymax:y}=s,d=Math.max(l,p),x=Math.min(c,h),g=Math.max(u,m),w=Math.min(f,y),I=.5*n,S=.5*o;if(x-d<I||w-g<S||x<l+I||d>c-I||g>f-S||w<u+S)return new ie({pixelType:a.pixelType,width:t,height:i,mask:r,pixels:[...a.pixels]});const v=Math.max(0,(d-l)/n),F=Math.min(t,Math.max(0,(x-l)/n)),T=Math.max(0,(f-w)/o),k=Math.min(i,Math.max(0,(f-g)/o)),_=Math.round(v),M=Math.round(F)-1,O=Math.round(T),D=Math.round(k)-1;if(_===M&&v%1>.5&&F%1<.5||O===D&&T%1>.5&&k%1<.5)return new ie({pixelType:a.pixelType,width:t,height:i,mask:r,pixels:[...a.pixels]});if(_===0&&O===0&&M===t&&D===i)return a;const N=a.mask;for(let P=O;P<=D;P++)for(let $=_;$<=M;$++){const B=P*t+$;r[B]=N?N[B]:255}return new ie({pixelType:a.pixelType,width:t,height:i,mask:r,pixels:[...a.pixels]})}function Gi(a,e,s){const{width:t,height:i}=a,r=new Uint8Array(t*i),n=e.width/t,o=e.height/i,{xmin:l,ymax:c}=e,{paths:u}=s,f=a.mask;for(let p=0;p<u.length;p++){const h=u[p];for(let m=0;m<h.length-1;m++){const[y,d]=h[m],[x,g]=h[m+1];let w=Math.floor((c-d)/o),I=Math.floor((c-g)/o);if(I<w){const v=w;w=I,I=v}w=Math.max(0,w),I=Math.min(i-1,I);const S=(x-y)/(g-d);for(let v=w;v<=I;v++){const F=v===w?Math.max(d,g):(i+1-v)*o,T=v===I?Math.min(d,g):F-o;let k=Math.floor(g===d?(y-l)/n:(S*(F-d)+y-l)/n),_=Math.floor(g===d?(x-l)/n:(S*(T-d)+y-l)/n);if(_<k){const O=k;k=_,_=O}const M=v*t;k=Math.max(0,k),_=Math.min(t-1,_);for(let O=M+k;O<=M+_;O++)r[O]=f?f[O]:255}}}return new ie({pixelType:a.pixelType,width:t,height:i,mask:r,pixels:[...a.pixels]})}function ji(a,e,s,t=!0){const{spatialReference:i}=a,{x:r,y:n}=Hi(s,i);let o,l,c;const u=e.type==="extent"?e:e.extent;let{xmin:f,xmax:p,ymax:h,ymin:m}=u;const{xmin:y,ymax:d}=a.extent;return t?(f=y+(f>y?r*Math.round((f-y)/r):0),h=d-(h<d?n*Math.round((d-h)/n):0),p=y+(p>y?r*Math.round((p-y)/r):0),m=d-(m<d?n*Math.round((d-m)/n):0),o=new W({xmin:f,ymax:h,xmax:p,ymin:m,spatialReference:i}),l=Math.round(o.width/r),c=Math.round(o.height/n)):(l=Math.floor((p-f)/r+.8),c=Math.floor((h-m)/n+.8),f=y+(f>y?r*Math.floor((f-y)/r+.1):0),h=d-(h<d?n*Math.floor((d-h)/n+.1):0),p=f+l*r,m=h-c*n,o=new W({xmin:f,ymax:h,xmax:p,ymin:m,spatialReference:i})),{extent:o,width:l,height:c}}const it=Te.getLogger("esri.layers.mixins.ImageryTileMixin"),Ui=a=>{let e=class extends a{constructor(...t){var i,r;super(...t),this._isConstructedFromFunctionRaster=!1,this._rasterJobHandler={instance:null,refCount:0,connectionPromise:null},this.bandIds=null,this.copyright=null,this.interpolation="nearest",this.multidimensionalSubset=null,this.raster=null,this.rasterInfo=null,this.sourceJSON=null,this.spatialReference=null,this.symbolizer=null,this._isConstructedFromFunctionRaster=((r=(i=t[0])==null?void 0:i.raster)==null?void 0:r.datasetFormat)==="Function"}get fullExtent(){var t;return(t=this.rasterInfo)==null?void 0:t.extent}set multidimensionalDefinition(t){this._set("multidimensionalDefinition",t),this.updateRenderer()}set rasterFunction(t){var i;((i=t==null?void 0:t.functionName)==null?void 0:i.toLowerCase())==="none"&&(t=void 0),this._set("rasterFunction",t),this.updateRasterFunction()}set url(t){this._set("url",nt(t,it))}set renderer(t){t==null&&this.rasterFunction==null?this._configDefaultRenderer("override"):(this._set("renderer",t),this.updateRenderer())}readRenderer(t,i,r){var o,l;const n=(l=(o=i==null?void 0:i.layerDefinition)==null?void 0:o.drawingInfo)==null?void 0:l.renderer;return Vt(n,r)||void 0}async convertVectorFieldData(t,i){if(t==null||!this.rasterInfo)return null;const r=this._rasterJobHandler.instance,n=this.rasterInfo.dataType;return r?r.convertVectorFieldData({pixelBlock:t,dataType:n},i):_i(t,n)}async computeStatisticsHistograms(t,i){t=Je(Xt,t).clone();const{rasterInfo:r}=this,{geometry:n}=t;if(n==null)throw new C("imagery-tile-mixin:compute-statistics-histograms","geometry must be specified");let o=n;const{spatialReference:l}=r;n.spatialReference.equals(l)||(await De(),o=n.type==="extent"?Re(n,l):Di(n,l));const c=t.pixelSize??new H({x:r.pixelSize.x,y:r.pixelSize.y,spatialReference:l}),{extent:u,width:f,height:p}=ji(r,o,c),h=await this.fetchPixels(u,f,p,{...i,interpolation:"nearest"});if(h.pixelBlock==null)throw new C("imagery-tile-mixin:compute-statistics-histograms","failed to fetch pixels");const m=await Li(h.pixelBlock,u,o),y=this._rasterJobHandler.instance;return y?y.computeStatisticsHistograms({pixelBlock:m},i):li(m)}async createFlowMesh(t,i){const r=this._rasterJobHandler.instance;return r?r.createFlowMesh(t,i):ki(t.meshType,t.simulationSettings,t.flowData,i.signal!=null?i.signal:new AbortController().signal)}normalizeRasterFetchOptions(t){var o,l;const{multidimensionalInfo:i}=this.rasterInfo??{};if(i==null)return t;let r=t.multidimensionalDefinition||this.multidimensionalDefinition;r!=null&&r.length||(r=Ue(this.raster.rasterInfo,{multidimensionalSubset:this.multidimensionalSubset}));const n=t.timeExtent||this.timeExtent;if(r!=null&&n!=null&&(n.start!=null||n.end!=null)){r=r.map(x=>x.clone());const c=(l=(o=i.variables.find(({name:x})=>x===r[0].variableName))==null?void 0:o.dimensions)==null?void 0:l.find(({name:x})=>x==="StdTime"),u=r.find(({dimensionName:x})=>x==="StdTime");if(!c||!u)return{...t,multidimensionalDefinition:null};const{start:f,end:p}=n,h=f==null?null:f.getTime(),m=p==null?null:p.getTime(),y=h??m,d=m??h;if(c.values!=null){const x=c.values.filter(g=>{if(Array.isArray(g)){if(y===d)return g[0]<=y&&g[1]>=y;const w=g[0]<=y&&g[1]>y||g[0]<d&&g[1]>=d,I=g[0]>=y&&g[1]<=d||g[0]<y&&g[1]>d;return w||I}return y===d?g===y:g>=y&&g<=d});if(x.length){const g=x.sort((w,I)=>{const S=Array.isArray(w)?w[0]:w,v=Array.isArray(w)?w[1]:w,F=Array.isArray(I)?I[0]:I,T=Array.isArray(I)?I[1]:I;return y===d?S-F:Math.abs(v-d)-Math.abs(T-d)})[0];u.values=[g]}else r=null}else if(c.hasRegularIntervals&&c.extent){const[x,g]=c.extent;y>g||d<x?r=null:u.values=y===d?[y]:[Math.max(x,y),Math.min(g,d)]}}return r!=null&&ni(r,this.multidimensionalSubset)?{...t,multidimensionalDefinition:null}:{...t,multidimensionalDefinition:r}}async updateRasterFunction(){var u,f,p;if(!this.loaded||this.type!=="imagery-tile"||!this.rasterFunction&&!this._cachedRasterFunctionJson||JSON.stringify(this.rasterFunction)===JSON.stringify(this._cachedRasterFunctionJson))return;if(this._isConstructedFromFunctionRaster&&this.raster.datasetFormat==="Function"){const h=this.raster.rasterFunction.toJSON();return!this.rasterFunction&&h&&this._set("rasterFunction",$e.fromJSON(h)),void(this._cachedRasterFunctionJson=(u=this.rasterFunction)==null?void 0:u.toJSON())}let t,i=this.raster,r=!1;i.datasetFormat==="Function"?(t=i.primaryRasters.rasters,i=t[0],r=!0):t=[i];const{rasterFunction:n}=this;if(n){const h={raster:i};t.length>1&&t.forEach(d=>h[d.url]=d);const m=Be(((f=n.functionDefinition)==null?void 0:f.toJSON())??n.toJSON(),h),y=new Ee({rasterFunction:m});y.rasterJobHandler=this._rasterJobHandler.instance,await y.open(),this._cachedRasterFunctionJson=(p=this.rasterFunction)==null?void 0:p.toJSON(),this.raster=y}else this.raster=i,this._cachedRasterFunctionJson=null,await i.when();if(this._cachedRendererJson=null,!r&&!n)return;const{bandIds:o}=this,{bandCount:l}=this.raster.rasterInfo,c=o!=null&&o.length?o.some(h=>h>=l):l>=3;o&&(c||this.renderer&&this.renderer.type!=="raster-stretch")&&this._set("bandIds",null),this._configDefaultRenderer("auto")}async updateRenderer(){const{loaded:t,symbolizer:i}=this;if(!t||!i||!this.renderer)return;const{rasterInfo:r}=this.raster,n=Ve(r,{multidimensionalDefinition:this.multidimensionalDefinition,multidimensionalSubset:this.multidimensionalSubset}),o=n==null?void 0:n.name,l=qe({...this.renderer.toJSON(),variableName:o});if(JSON.stringify(this._cachedRendererJson)===JSON.stringify(l))return;const c=this._rasterJobHandler.instance;c&&(i.rasterInfo=Ge(r,o),i.rendererJSON=l,i.bind(),await c.updateSymbolizer(i),this._cachedRendererJson=l)}async applyRenderer(t,i){const r=t==null?void 0:t.pixelBlock;if(!(r!=null&&r.pixels&&r.pixels.length>0))return null;let n;await this.updateRenderer();const o=this._rasterJobHandler.instance,l=this.bandIds??[];return n=o?await o.symbolize({...t,simpleStretchParams:i,bandIds:l}):this.symbolizer.symbolize({...t,simpleStretchParams:i,bandIds:l}),n}getTileUrl(t,i,r){return this.raster.datasetFormat==="RasterTileServer"?`${this.url}/tile/${t}/${i}/${r}`:""}getCompatibleTileInfo(t,i,r=!1){if(!this.loaded||i==null)return null;if(r&&t.equals(this.spatialReference))return this.tileInfo;const n=It(t);return te.create({size:256,spatialReference:t,origin:n?{x:n.origin[0],y:n.origin[1]}:{x:i.xmin,y:i.ymax}})}getCompatibleFullExtent(t){return this.loaded?(this._compatibleFullExtent&&this._compatibleFullExtent.spatialReference.equals(t)||(this._compatibleFullExtent=this.raster.computeExtent(t)),this._compatibleFullExtent):null}async fetchTile(t,i,r,n={}){var l;if(s(this),n.requestAsImageElement){const c=this.getTileUrl(t,i,r);return at(c,{responseType:"image",query:{...this.refreshParameters,...this.raster.ioConfig.customFetchParameters},signal:n.signal}).then(u=>u.data)}const{rasterInfo:o}=this;if(o.multidimensionalInfo!=null&&(n=this.normalizeRasterFetchOptions(n)).multidimensionalDefinition==null){const c=n.tileInfo||o.storageInfo.tileInfo;return{extent:this.raster.getTileExtentFromTileInfo(t,i,r,c),pixelBlock:null}}return await this._initJobHandler(),await this.updateRasterFunction(),((l=this.renderer)==null?void 0:l.type)==="raster-shaded-relief"&&(n={...n,buffer:{cols:1,rows:1}}),this.raster.fetchTile(t,i,r,n)}async fetchPixels(t,i,r,n={}){return this.rasterInfo.multidimensionalInfo!=null&&(n=this.normalizeRasterFetchOptions(n)).multidimensionalDefinition==null?{extent:t,pixelBlock:null}:(await this._initJobHandler(),await this.updateRasterFunction(),i=Math.round(i),r=Math.round(r),this.raster.fetchPixels(t,i,r,n))}async identify(t,i={}){var l;const{raster:r,rasterInfo:n}=this;if(n.multidimensionalInfo!=null&&!(n.hasMultidimensionalTranspose&&(ht(i.multidimensionalDefinition)||i.transposedVariableName||i.timeExtent))&&(i=this.normalizeRasterFetchOptions(i)).multidimensionalDefinition==null)return{location:t,value:null};const o=(l=this.multidimensionalSubset)==null?void 0:l.areaOfInterest;if(o&&!o.contains(t))throw new C("imagery-tile-mixin:identify","the request cannot be fulfilled when falling outside of the multidimensional subset");return r.identify(t,i)}increaseRasterJobHandlerUsage(){this._rasterJobHandler.refCount++}decreaseRasterJobHandlerUsage(){this._rasterJobHandler.refCount--,this._rasterJobHandler.refCount<=0&&this._shutdownJobHandler()}hasStandardTime(){var n,o,l;const t=(n=this.rasterInfo)==null?void 0:n.multidimensionalInfo;if(t==null||((o=this.rasterInfo)==null?void 0:o.dataType)!=="standard-time")return!1;const i=this.multidimensionalDefinition,r=(l=i==null?void 0:i[0])==null?void 0:l.variableName;return t.variables.some(c=>c.name===r&&(!(i!=null&&i[0].dimensionName)||c.dimensions.some(u=>u.name==="StdTime")))}getStandardTimeValue(t){return new Date(24*(t-25569)*3600*1e3).toString()}getMultidimensionalSubsetVariables(t){var r;const i=t??((r=this.rasterInfo)==null?void 0:r.multidimensionalInfo);return ai(this.multidimensionalSubset,i)}_configDefaultSettings(){this._configDefaultInterpolation(),this.multidimensionalDefinition||(this.multidimensionalDefinition=Ue(this.raster.rasterInfo,{multidimensionalSubset:this.multidimensionalSubset})),this.rasterFunction&&this.raster.datasetFormat==="Function"&&(this._cachedRasterFunctionJson=this.rasterFunction.toJSON()),this._configDefaultRenderer()}_initJobHandler(){if(this._rasterJobHandler.connectionPromise!=null)return this._rasterJobHandler.connectionPromise;const t=new Zt;return this._rasterJobHandler.connectionPromise=t.initialize().then(async()=>{s(this),this._rasterJobHandler.instance=t,this.raster.rasterJobHandler=t,this.raster.datasetFormat==="Function"&&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(){var t;if(this.interpolation==null){s(this);const{raster:i}=this,r=Yt(i.rasterInfo,i.tileType,(t=this.sourceJSON)==null?void 0:t.defaultResamplingMethod);this._set("interpolation",r)}}_configDefaultRenderer(t="no"){var u,f;s(this);const{rasterInfo:i}=this.raster;!this.bandIds&&i.bandCount>1&&(this.bandIds=Kt(i));const r=Ve(i,{multidimensionalDefinition:this.multidimensionalDefinition,multidimensionalSubset:this.multidimensionalSubset}),n=r==null?void 0:r.name;if(!this.renderer||t==="override"){const p=je(i,{bandIds:this.bandIds,variableName:n}),h=i.statistics,m=h&&h.length>0?h[0]:null,y=(m==null?void 0:m.max)??0,d=(m==null?void 0:m.min)??0;this.raster.datasetFormat==="WCSServer"&&p.type==="raster-stretch"&&(y>1e24||d<-1e24)&&(p.dynamicRangeAdjustment=!0,p.statistics=null,p.stretchType==="none"&&(p.stretchType="min-max")),this.renderer=p}const o=qe({...this.renderer.toJSON(),variableName:n}),l=Ge(i,n);this.symbolizer?(this.symbolizer.rendererJSON=o,this.symbolizer.rasterInfo=l):this.symbolizer=new ci({rendererJSON:o,rasterInfo:l});const c=this.symbolizer.bind();if(c.success){if(t==="auto"){const{colormap:p}=this.raster.rasterInfo,h=this.renderer;if(p!=null&&h.type==="raster-colormap"){const m=je(this.raster.rasterInfo);JSON.stringify(m)!==JSON.stringify(h)&&this._configDefaultRenderer("override")}else if(h.type==="raster-stretch"){const m=(u=this.bandIds)==null?void 0:u.length,y=(f=h.statistics)==null?void 0:f.length;!h.dynamicRangeAdjustment&&y&&m&&y!==m&&this._configDefaultRenderer("override")}}}else it.warn("imagery-tile-mixin",c.error||"The given renderer is not supported by the layer."),t==="auto"&&this._configDefaultRenderer("override")}};function s(t){if(!t.raster||!t.rasterInfo)throw new C("imagery-tile","no raster")}return b([R({clonable:!1})],e.prototype,"_cachedRendererJson",void 0),b([R({clonable:!1})],e.prototype,"_cachedRasterFunctionJson",void 0),b([R({clonable:!1})],e.prototype,"_compatibleFullExtent",void 0),b([R({clonable:!1})],e.prototype,"_isConstructedFromFunctionRaster",void 0),b([R({clonable:!1})],e.prototype,"_rasterJobHandler",void 0),b([R()],e.prototype,"bandIds",void 0),b([R({json:{origins:{service:{read:{source:"copyrightText"}}}}})],e.prototype,"copyright",void 0),b([R({json:{read:!1}})],e.prototype,"fullExtent",null),b([R()],e.prototype,"interpolation",void 0),b([R()],e.prototype,"ioConfig",void 0),b([R({type:[ft],json:{write:!0}})],e.prototype,"multidimensionalDefinition",null),b([R({type:Gt,json:{write:!0}})],e.prototype,"multidimensionalSubset",void 0),b([R()],e.prototype,"raster",void 0),b([R({type:$e,json:{name:"renderingRule",write:!0}})],e.prototype,"rasterFunction",null),b([R()],e.prototype,"rasterInfo",void 0),b([R()],e.prototype,"sourceJSON",void 0),b([R({readOnly:!0,type:q,json:{read:!1}})],e.prototype,"spatialReference",void 0),b([R({type:te})],e.prototype,"tileInfo",void 0),b([R(lt)],e.prototype,"url",null),b([R({types:jt,json:{name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy(){var i;const t=((i=this.renderer)==null?void 0:i.type)==="raster-stretch"&&this.renderer.stretchType==="none"&&!this.renderer.useGamma;return{enabled:!this.loaded||this.raster.tileType==="Raster"||!t}}},origins:{"web-scene":{types:Ut,name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy:t=>({enabled:t&&t.type!=="vector-field"&&t.type!=="flow"})}}}}})],e.prototype,"renderer",null),b([wt("renderer")],e.prototype,"readRenderer",null),b([R({clonable:!1})],e.prototype,"symbolizer",void 0),e=b([Q("esri.layers.ImageryTileMixin")],e),e};function Vi(a){const e=a.fields,s=a.records,t=e.some(c=>c.name.toLowerCase()==="oid")?"OBJECTID":"OID",i=[{name:t,type:"esriFieldTypeOID",alias:"OID"}].concat(e.map(c=>({name:c.name,type:"esriFieldType"+c.typeName,alias:c.name}))),r=i.map(c=>c.name),n=[];let o=0,l=0;return s.forEach(c=>{const u={};for(u[t]=o++,l=1;l<r.length;l++)u[r[l]]=c[l-1];n.push({attributes:u})}),{displayFieldName:"",fields:i,features:n}}class mt{static get supportedVersions(){return[5]}static parse(e){const s=new DataView(e),t=3&s.getUint8(0);if(t!==3)return{header:{version:t},recordSet:null};const i=s.getUint32(4,!0),r=s.getUint16(8,!0),n=s.getUint16(10,!0),o={version:t,recordCount:i,headerByteCount:r,recordByteCount:n};let l=32;const c=[],u=[];let f;if(t===3){for(;s.getUint8(l)!==13;)f=String.fromCharCode(s.getUint8(l+11)).trim(),c.push({name:Xe(new Uint8Array(e,l,11)),type:f,typeName:["String","Date","Double","Boolean","String","Integer"][["C","D","F","L","M","N"].indexOf(f)],length:s.getUint8(l+16)}),l+=32;if(l+=1,c.length>0)for(;u.length<i&&e.byteLength-l>n;){const p=[];s.getUint8(l)===32?(l+=1,c.forEach(h=>{if(h.type==="C")p.push(Xe(new Uint8Array(e,l,h.length)).trim());else if(h.type==="N")p.push(parseInt(String.fromCharCode.apply(null,new Uint8Array(e,l,h.length)).trim(),10));else if(h.type==="F")p.push(parseFloat(String.fromCharCode.apply(null,new Uint8Array(e,l,h.length)).trim()));else if(h.type==="D"){const m=String.fromCharCode.apply(null,new Uint8Array(e,l,h.length)).trim();p.push(new Date(parseInt(m.substring(0,4),10),parseInt(m.substring(4,6),10)-1,parseInt(m.substring(6,8),10)))}l+=h.length}),u.push(p)):l+=n}}return{header:o,fields:c,records:u,recordSet:Vi({fields:c,records:u})}}}const ne=new Map;ne.set("int16","esriFieldTypeSmallInteger"),ne.set("int32","esriFieldTypeInteger"),ne.set("int64","esriFieldTypeInteger"),ne.set("float32","esriFieldTypeSingle"),ne.set("float64","esriFieldTypeDouble"),ne.set("text","esriFieldTypeString");const st=8;let de=class extends le{constructor(){super(...arguments),this.storageInfo=null,this.datasetFormat="CRF"}async open(e){await this.init();const{data:s}=await this.request(this.url+"/conf.json",{signal:e==null?void 0:e.signal});if(!this._validateHeader(s))throw new C("cloudraster:open","Invalid or unsupported conf.json.");this.datasetName=this.url.slice(this.url.lastIndexOf("/")+1);const{storageInfo:t,rasterInfo:i}=this._parseHeader(s);if(i.dataType==="thematic"){const r=await this._fetchAuxiliaryInformation();i.attributeTable=r}this._set("storageInfo",t),this._set("rasterInfo",i),this.ioConfig.retryCount=this.ioConfig.retryCount||0}async fetchRawTile(e,s,t,i={}){const{transposeInfo:r}=this.rasterInfo.storageInfo,{transposedVariableName:n}=i,o=!(!r||!n),l=o?0:this.rasterInfo.storageInfo.maximumPyramidLevel-e;if(l<0)return null;const c=this._buildCacheFilePath(l,s,t,i.multidimensionalDefinition,n),u=this._getIndexRecordFromBundle(s,t,o),f=await this.request(c,{range:{from:0,to:this.storageInfo.headerSize-1},responseType:"array-buffer",signal:i.signal});if(!f)return null;const p=new Uint8Array(f.data),h=this._getTileEndAndContentType(p,u);if(h.recordSize===0)return null;const m=await this.request(c,{range:{from:h.position,to:h.position+h.recordSize},responseType:"array-buffer",signal:i.signal});if(!m)return null;const[y,d]=this._getTileSize(o);return this.decodePixelBlock(m.data,{width:y,height:d,planes:null,pixelType:null,returnInterleaved:o})}_validateHeader(e){const s=["origin","extent","geodataXform","LODInfos","blockWidth","blockHeight","bandCount","pixelType","pixelSizeX","pixelSizeY","format","packetSize"];return e&&e.type==="RasterInfo"&&!s.some(t=>!e[t])}_parseHeader(e){var Y,A,z,L,ee;const s=["u1","u2","u4","u8","s8","u16","s16","u32","s32","f32","f64"][e.pixelType],{bandCount:t,colormap:i,blockWidth:r,blockHeight:n,firstPyramidLevel:o,maximumPyramidLevel:l}=e,c=(Y=e.statistics)==null?void 0:Y.map(E=>({min:E.min,max:E.max,avg:E.mean,stddev:E.standardDeviation,median:E.median,mode:E.mode})),u=(L=(z=(A=e.histograms)==null?void 0:A[0])==null?void 0:z.counts)!=null&&L.length?e.histograms:null,f=e.extent.spatialReference,p=(ee=e.geodataXform)==null?void 0:ee.spatialReference,h=new q(f!=null&&f.wkid||f!=null&&f.wkt||f!=null&&f.wkt2?f:p);let m=new W({xmin:e.extent.xmin,ymin:e.extent.ymin,xmax:e.extent.xmax,ymax:e.extent.ymax,spatialReference:h});const y=new H({x:e.pixelSizeX,y:e.pixelSizeY,spatialReference:h}),d=Math.round((m.xmax-m.xmin)/y.x),x=Math.round((m.ymax-m.ymin)/y.y),g=this._parseTransform(e.geodataXform),w=g?m:null;g&&(m=g.forwardTransform(m),y.x=(m.xmax-m.xmin)/d,y.y=(m.ymax-m.ymin)/x);const I=e.properties??{},S=e.format.toLowerCase().replace("cache/",""),v=new H(e.origin.x,e.origin.y,h);let F,T,k,_;if(i!=null&&i.colors)for(F=[],T=0;T<i.colors.length;T++)k=i.colors[T],_=i.values?i.values[T]:T,F.push([_,255&k,k<<16>>>24,k<<8>>>24,k>>>24]);const M=e.LODInfos,O=[];for(T=0;T<M.levels.length;T++)O.push(new ot({level:M.levels[T],resolution:M.resolutions[T],scale:96/.0254*M.resolutions[T]}));const D=new te({dpi:96,lods:O,format:S,origin:v,size:[r,n],spatialReference:h}),N={recordSize:st,packetSize:e.packetSize,headerSize:e.packetSize*e.packetSize*st+64},P=[{maxCol:Math.ceil(d/r)-1,maxRow:Math.ceil(x/n)-1,minCol:0,minRow:0}];let $=2;if(l>0)for(T=0;T<l;T++)P.push({maxCol:Math.ceil(d/$/r)-1,maxRow:Math.ceil(x/$/n)-1,minCol:0,minRow:0}),$*=2;const B=e.mdInfo;let U=null;if(B&&I._yxs){const E=I._yxs;U={packetSize:E.PacketSize,tileSize:[E.TileXSize,E.TileYSize]}}return{storageInfo:N,rasterInfo:new ge({width:d,height:x,pixelType:s,bandCount:t,extent:m,nativeExtent:w,transform:g,spatialReference:h,pixelSize:y,keyProperties:I,statistics:c,histograms:u,multidimensionalInfo:B,colormap:F,storageInfo:new ye({blockWidth:r,blockHeight:n,pyramidBlockWidth:r,pyramidBlockHeight:n,origin:v,tileInfo:D,transposeInfo:U,firstPyramidLevel:o,maximumPyramidLevel:l,blockBoundary:P})})}}_parseTransform(e){var t,i;if(!Bi(e))throw new C("cloudraster:open","the data contains unsupported geodata transform types");const s=Ei(e);if(s.type==="identity")return null;if(s.type!=="polynomial"||!((t=s.forwardCoefficients)!=null&&t.length)||!((i=s.inverseCoefficients)!=null&&i.length))throw new C("cloudraster:open","the data contains unsupported geodata transforms - both forward and inverse coefficients are required currently");return s}async _fetchAuxiliaryInformation(e){const s=this.request(this.url+"/conf.vat.json",{signal:e}).then(n=>n.data).catch(()=>null),t=this.request(this.url+"/conf.vat.dbf",{responseType:"array-buffer",signal:e}).then(n=>n.data).catch(()=>null),i=await Promise.all([s,t]);let r;if(i[0]){let n=i[0].fields;const o=i[0].values;if(n&&o){n=n.map(c=>({type:c.name==="OID"?"esriFieldTypeOID":ne.get(c.type),name:c.name,alias:c.alias||c.name}));const l=o.map(c=>({attributes:c}));n&&o&&(r={fields:n,features:l})}}return!r&&i[1]&&(r=mt.parse(i[1]).recordSet),Ne.fromJSON(r)}_buildCacheFilePath(e,s,t,i,r){const n=this._getPackageSize(!!r),o=Math.floor(s/n)*n,l=Math.floor(t/n)*n,c="R"+this._toHexString4(o)+"C"+this._toHexString4(l);let u="L";u+=e>=10?e.toString():"0"+e.toString();const{multidimensionalInfo:f}=this.rasterInfo,p=i==null?void 0:i[0];if(f==null||!p)return`${this.url}/_alllayers/${u}/${c}.bundle`;let h="_yxs";if(!r){h=f.variables.find(d=>d.name===p.variableName).dimensions[0].values.indexOf(p.values[0]).toString(16);const y=4-h.length;for(let d=0;d<y;d++)h="0"+h;h="S"+h}const m=this._getVariableFolderName(r||p.variableName);return`${this.url}/_alllayers/${m}/${h}/${u}/${c}.bundle`}_getPackageSize(e=!1){const{transposeInfo:s}=this.rasterInfo.storageInfo;return e&&s!=null?s.packetSize??0:this.storageInfo.packetSize}_getTileSize(e=!1){const{storageInfo:s}=this.rasterInfo,{transposeInfo:t}=s;return e&&t!=null?t.tileSize:s.tileInfo.size}_getVariableFolderName(e){return(e=e.trim())===""?"_v":e.replaceAll(/[\{|\}\-]/g,"_").replace("\\*","_v")}_getIndexRecordFromBundle(e,s,t=!1){const i=this._getPackageSize(t),r=i*(e%i)+s%i;if(r<0)throw new Error("Invalid level / row / col");return 20+r*this.storageInfo.recordSize+44}_getTileEndAndContentType(e,s){const t=e.subarray(s,s+8);let i,r=0;for(i=0;i<5;i++)r|=(255&t[i])<<8*i;const n=0xffffffffff&r;for(r=0,i=5;i<8;i++)r|=(255&t[i])<<8*(i-5);return{position:n,recordSize:0xffffffffff&r}}_toHexString4(e){let s=e.toString(16);if(s.length!==4){let t=4-s.length;for(;t-- >0;)s="0"+s}return s}};b([R({readOnly:!0})],de.prototype,"storageInfo",void 0),b([R({type:String,json:{write:!0}})],de.prototype,"datasetFormat",void 0),de=b([Q("esri.layers.support.rasterDatasets.CloudRaster")],de);const Xi=de;let me=class extends le{constructor(){super(...arguments),this.datasetFormat="MEMORY",this.data=null}async open(e){await this.init();const s=this.data,{pixelBlock:t,statistics:i,histograms:r,name:n,keyProperties:o,nativeExtent:l,transform:c}=this.data,{width:u,height:f,pixelType:p}=t,h=s.extent??new W({xmin:-.5,ymin:.5,xmax:u-.5,ymax:f-.5,spatialReference:new q({wkid:3857})}),m=s.isPseudoSpatialReference??!s.extent,y={x:h.width/u,y:h.height/f},d=new ge({width:u,height:f,pixelType:p,extent:h,nativeExtent:l,transform:c,pixelSize:y,spatialReference:h.spatialReference,bandCount:t.pixels.length,keyProperties:o||{},statistics:i,isPseudoSpatialReference:m,histograms:r});this.createRemoteDatasetStorageInfo(d,512,512),this._set("rasterInfo",d),this.updateTileInfo(),await this._buildInMemoryRaster(t,{width:512,height:512},e),this.datasetName=n,this.url="/InMemory/"+n}fetchRawTile(e,s,t,i={}){const r=this._pixelBlockTiles.get(`${e}/${s}/${t}`);return Promise.resolve(r)}async _buildInMemoryRaster(e,s,t){var u,f;const i=this.rasterInfo.storageInfo.maximumPyramidLevel,r=this.rasterJobHandler?this.rasterJobHandler.split({pixelBlock:e,tileSize:s,maximumPyramidLevel:i},t):Promise.resolve(Fi(e,s,i)),n=this.rasterInfo.statistics!=null,o=this.rasterInfo.histograms!=null,l=n?Promise.resolve({statistics:null,histograms:null}):this.rasterJobHandler?this.rasterJobHandler.estimateStatisticsHistograms({pixelBlock:e},t):Promise.resolve(ui(e)),c=await ut([r,l]);if(!c[0].value&&c[1].value)throw new C("inmemory-raster:open","failed to build in memory raster");this._pixelBlockTiles=c[0].value,n||(this.rasterInfo.statistics=(u=c[1].value)==null?void 0:u.statistics),o||(this.rasterInfo.histograms=(f=c[1].value)==null?void 0:f.histograms)}};b([R({type:String,json:{write:!0}})],me.prototype,"datasetFormat",void 0),b([R()],me.prototype,"data",void 0),me=b([Q("esri.layers.support.rasterDatasets.InMemoryRaster")],me);const Yi=me;function he(a,e){if(!a||!e)return[];let s=e;e.includes("/")?(s=e.slice(0,e.indexOf("/")),e=e.slice(e.indexOf("/")+1)):e="";const t=[];if(e){const r=he(a,s);for(let n=0;n<r.length;n++)he(r[n],e).forEach(o=>t.push(o));return t}const i=a.getElementsByTagNameNS("*",s);if(!i||i.length===0)return[];for(let r=0;r<i.length;r++)t.push(i[r]||i.item(r));return t}function X(a,e){if(!a||!e)return null;let s=e;e.includes("/")?(s=e.slice(0,e.indexOf("/")),e=e.slice(e.indexOf("/")+1)):e="";const t=he(a,s);return t.length>0?e?X(t[0],e):t[0]:null}function Z(a,e=null){const s=e?X(a,e):a;let t;return s?(t=s.textContent||s.nodeValue,t?t.trim():null):null}function Ki(a,e){const s=he(a,e),t=[];let i;for(let r=0;r<s.length;r++)i=s[r].textContent||s[r].nodeValue,i&&(i=i.trim(),i!==""&&t.push(i));return t}function be(a,e){return Ki(a,e).map(s=>Number(s))}function oe(a,e){const s=Z(a,e);return Number(s)}function Me(a,e){var i;const s=(i=a==null?void 0:a.nodeName)==null?void 0:i.toLowerCase(),t=e.toLowerCase();return s.slice(s.lastIndexOf(":")+1)===t}function rt(a,e){if(!a||!e)return null;const s=[];for(let t=0;t<a.length;t++)s.push(a[t]),s.push(e[t]);return s}function Zi(a){const e=X(a,"GeodataXform"),s=_e(oe(e,"SpatialReference/WKID")||Z(e,"SpatialReference/WKT"));if(e.getAttribute("xsi:type")!=="typens:PolynomialXform")return{spatialReference:s,transform:null};const t=oe(e,"PolynomialOrder")??1,i=be(e,"CoeffX/Double"),r=be(e,"CoeffY/Double"),n=be(e,"InverseCoeffX/Double"),o=be(e,"InverseCoeffY/Double"),l=rt(i,r),c=rt(n,o);return{spatialReference:s,transform:l&&c&&l.length&&c.length?new ze({spatialReference:s,polynomialOrder:t,forwardCoefficients:l,inverseCoefficients:c}):null}}function Qi(a){var p;const e=oe(a,"NoDataValue"),s=X(a,"Histograms/HistItem"),t=oe(s,"HistMin"),i=oe(s,"HistMax"),r=oe(s,"BucketCount"),n=(p=Z(s,"HistCounts"))==null?void 0:p.split("|").map(h=>Number(h));let o,l,c,u;he(a,"Metadata/MDI").forEach(h=>{const m=Number(h.textContent??h.nodeValue);switch(h.getAttribute("key").toUpperCase()){case"STATISTICS_MINIMUM":o=m;break;case"STATISTICS_MAXIMUM":l=m;break;case"STATISTICS_MEAN":c=m;break;case"STATISTICS_STDDEV":u=m}});const f=oe(a,"Metadata/SourceBandIndex");return{noDataValue:e,histogram:n!=null&&n.length&&t!=null&&i!=null?{min:t,max:i,size:r||n.length,counts:n}:null,sourceBandIndex:f,statistics:o!=null&&l!=null?{min:o,max:l,avg:c,stddev:u}:null}}function _e(a){if(!a)return null;let e=Number(a);if(!isNaN(e)&&e!==0)return new q({wkid:e});if(a=String(a).trim(),bt(a))return new q({wkt2:a});const s=a.toUpperCase();if(s.startsWith("COMPD_CS")){if(!s.includes("VERTCS")||!s.includes("GEOGCS")&&!s.startsWith("PROJCS"))return null;const t=s.indexOf("VERTCS"),i=s.indexOf("PROJCS"),r=i>-1?i:s.indexOf("GEOGCS");if(r===-1)return null;const n=a.slice(r,a.lastIndexOf("]",t)+1).trim(),o=a.slice(t,a.lastIndexOf("]")).trim();e=Pe(n);const l=new q(e?{wkid:e}:{wkt:n}),c=Pe(o);return c&&(l.vcsWkid=c),l}return s.startsWith("GEOGCS")||s.startsWith("PROJCS")?(e=Pe(a),new q(e!==0?{wkid:e}:{wkt:a})):null}function Pe(a){var i;const e=a.replaceAll("]","[").replaceAll('"',"").split("[").map(r=>r.trim()).filter(r=>r!==""),s=e[e.length-1].split(","),t=(i=s[0])==null?void 0:i.toLowerCase();if((t==="epsg"||t==="esri")&&a.endsWith('"]]')){const r=Number(s[1]);if(!isNaN(r)&&r!==0)return r}return 0}function He(a){var t;if(((t=a==null?void 0:a.documentElement.tagName)==null?void 0:t.toLowerCase())!=="pamdataset")return{};const e={spatialReference:null,transform:null,metadata:{},rasterBands:[],statistics:null,histograms:null};a.documentElement.childNodes.forEach(i=>{if(i.nodeType===1){if(Me(i,"SRS")){if(!e.spatialReference){const r=Z(i);e.spatialReference=_e(r)}}else if(Me(i,"Metadata"))if(i.getAttribute("domain")==="xml:ESRI"){const{spatialReference:r,transform:n}=Zi(i);e.transform=n,e.spatialReference||(e.spatialReference=r)}else he(i,"MDI").forEach(r=>e.metadata[r.getAttribute("key")]=Z(r));else if(Me(i,"PAMRasterBand")){const r=Qi(i);r.sourceBandIndex!=null&&e.rasterBands[r.sourceBandIndex]==null?e.rasterBands[r.sourceBandIndex]=r:e.rasterBands.push(r)}}});const s=e.rasterBands;if(s.length){const i=!!s[0].statistics;e.statistics=i?s.map(n=>n.statistics).filter(Oe):null;const r=!!s[0].histogram;e.histograms=r?s.map(n=>n.histogram).filter(Oe):null}return e}let ve=class extends le{async open(a){await this.init();const e=await this._fetchData(a);let{spatialReference:s,statistics:t,histograms:i,transform:r}=await this._fetchAuxiliaryData(a);const n=!s;n&&(s=new q({wkid:3857})),i!=null&&i.length&&t==null&&(t=Ae(i));const{width:o,height:l}=e;let c=new W({xmin:-.5,ymin:.5-l,xmax:o-.5,ymax:.5,spatialReference:s});const u=r?r.forwardTransform(c):c;let f=!0;if(r){const h=r.forwardCoefficients;f=h&&h[1]===0&&h[2]===0,f&&(r=null,c=u)}const p=new Yi({data:{extent:u,nativeExtent:c,transform:r,pixelBlock:e,statistics:t,histograms:i,keyProperties:{DateType:"Processed"},isPseudoSpatialReference:n}});await p.open(),p.data=null,this._set("rasterInfo",p.rasterInfo),this._inMemoryRaster=p}fetchRawTile(a,e,s,t={}){return this._inMemoryRaster.fetchRawTile(a,e,s,t)}async _fetchData(a){const{data:e}=await this.request(this.url,{responseType:"array-buffer",signal:a==null?void 0:a.signal}),s=hi(e).toUpperCase();if(s!=="JPG"&&s!=="PNG"&&s!=="GIF"&&s!=="BMP")throw new C("image-aux-raster:open","the data is not a supported format");this._set("datasetFormat",s);const t=s.toLowerCase(),i=t==="gif"||t==="bmp"||!St("ios"),r=await this.decodePixelBlock(e,{format:t,useCanvas:i,hasNoZlibMask:!0});if(r==null)throw new C("image-aux-raster:open","the data cannot be decoded");return r}async _fetchAuxiliaryData(a){var c;const e=a==null?void 0:a.signal,s=this.ioConfig.skipExtensions??[],t=s.includes("aux.xml")?null:this.request(this.url+".aux.xml",{responseType:"xml",signal:e}),i=this.datasetFormat,r=i==="JPG"?"jgw":i==="PNG"?"pgw":i==="BMP"?"bpw":null,n=r&&s.includes(r)?null:this.request(this.url.slice(0,this.url.lastIndexOf("."))+"."+r,{responseType:"text",signal:e}),o=await ut([t,n]);if(e!=null&&e.aborted)throw Rt();const l=He((c=o[0].value)==null?void 0:c.data);if(!l.transform){const u=o[1].value?o[1].value.data.split(`
|
|
`).slice(0,6).map(f=>Number(f)):null;l.transform=(u==null?void 0:u.length)===6?new ze({forwardCoefficients:[u[4],u[5],u[0],-u[1],u[2],-u[3]]}):null}return l}};b([R({type:String,json:{write:!0}})],ve.prototype,"datasetFormat",void 0),ve=b([Q("esri.layers.support.rasterDatasets.ImageAuxRaster")],ve);const Se=ve;let pe=class extends le{constructor(){super(...arguments),this._levelOffset=0,this._tilemapCache=null,this._slices=null,this.datasetFormat="RasterTileServer",this.tileType=null}async open(a){var F,T;await this.init();const e=a==null?void 0:a.signal,s=this.sourceJSON?{data:this.sourceJSON}:await this.request(this.url,{query:{f:"json"},signal:e});s.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));const t=s.data;if(this.sourceJSON=t,!t)throw new C("imageserverraster:open","cannot initialize tiled image service, missing service info");if(!t.tileInfo)throw new C("imageserverraster:open","use ImageryLayer to open non-tiled image services");this._fixScaleInServiceInfo();const i=["jpg","jpeg","png","png8","png24","png32","mixed"];this.tileType=t.cacheType,this.tileType==null&&(i.includes(t.tileInfo.format.toLowerCase())?this.tileType="Map":t.tileInfo.format.toLowerCase()==="lerc"?this.tileType="Elevation":this.tileType="Raster"),this.datasetName=((F=t.name)==null?void 0:F.slice(t.name.indexOf("/")+1))??"";const r=await this._fetchRasterInfo({signal:e});if(r==null)throw new C("image-server-raster:open","cannot initialize image service");Qt(r,t);const n=this.tileType==="Map"?es(t.tileInfo,t):te.fromJSON(t.tileInfo);vt(n);const[o,l]=this._computeMinMaxLOD(r,n),{extent:c,pixelSize:u}=r,f=.5/r.width*u.x,p=Math.max(u.x,u.y),{lods:h}=n;(this.tileType!=="Map"&&t.maxScale!==0||Math.abs(u.x-u.y)>f||!h.some(k=>Math.abs(k.resolution-p)<f))&&(u.x=u.y=o.resolution,r.width=Math.ceil((c.xmax-c.xmin)/u.x-.1),r.height=Math.ceil((c.ymax-c.ymin)/u.y-.1));const m=o.level-l.level,[y,d]=n.size,x=[],g=[];h.forEach((k,_)=>{k.level>=l.level&&k.level<=o.level&&x.push({x:k.resolution,y:k.resolution}),_<h.length-1&&g.push(Math.round(10*k.resolution/h[_+1].resolution)/10)}),x.sort((k,_)=>k.x-_.x);const w=this.computeBlockBoundary(c,y,d,n.origin,x,m),I=x.length>1?x.slice(1):null;let S;t.transposeInfo&&(S={tileSize:[t.transposeInfo.rows,t.transposeInfo.cols],packetSize:((T=r.keyProperties)==null?void 0:T._yxs.PacketSize)??0});const v=g.length<=1||g.length>=3&&g.slice(0,-1).every(k=>k===g[0])?g[0]??2:Math.round(10/(l.resolution/o.resolution)**(-1/m))/10;if(r.storageInfo=new ye({blockWidth:n.size[0],blockHeight:n.size[1],pyramidBlockWidth:n.size[0],pyramidBlockHeight:n.size[1],pyramidResolutions:I,pyramidScalingFactor:v,compression:n.format,origin:n.origin,firstPyramidLevel:1,maximumPyramidLevel:m,tileInfo:n,transposeInfo:S,blockBoundary:w}),this._fixGCSShift(r),this._set("rasterInfo",r),t.capabilities.toLowerCase().includes("tilemap")){const k={tileInfo:r.storageInfo.tileInfo,parsedUrl:Tt(this.url),url:this.url,tileServers:[]};this._tilemapCache=new Ai({layer:k})}}async fetchRawTile(a,e,s,t={}){const{storageInfo:i,extent:r}=this.rasterInfo,{transposeInfo:n}=i,o=n!=null&&!!t.transposedVariableName;if(this._slices&&!o&&t.sliceId==null)return null;const l=o?0:i.maximumPyramidLevel-a+this._levelOffset,c=`${this.url}/tile/${l}/${e}/${s}`,u=this._slices?o?{variable:t.transposedVariableName}:{sliceId:t.sliceId||0}:null,{data:f}=await this.request(c,{query:u,responseType:"array-buffer",signal:t.signal});if(!f)return null;const p=o?n.tileSize:i.tileInfo.size,h=await this.decodePixelBlock(f,{width:p[0],height:p[1],planes:null,pixelType:null,isPoint:this.tileType==="Elevation",returnInterleaved:o,noDataValue:this.rasterInfo.noDataValue});if(h==null)return null;const m=i.blockBoundary[a];if(i.compression!=="jpg"||s>m.minCol&&s<m.maxCol&&e>m.minRow&&e<m.maxRow)return h;const{origin:y,blockWidth:d,blockHeight:x}=i,{x:g,y:w}=this.getPyramidPixelSize(a),I=Math.round((r.xmin-y.x)/g)%d,S=Math.round((r.xmax-y.x)/g)%d||d,v=Math.round((y.y-r.ymax)/w)%x,F=Math.round((y.y-r.ymin)/w)%x||x,T=s===m.minCol?I:0,k=e===m.minRow?v:0,_=s===m.maxCol?S:d,M=e===m.maxRow?F:x;return Mi(h,{x:T,y:k},{width:_-T,height:M-k}),h}getSliceIndex(a){if(!this._slices||a==null||a.length===0)return null;const e=a;for(let s=0;s<this._slices.length;s++){const t=this._slices[s].multidimensionalDefinition;if(t.length===e.length&&!t.some(i=>{const r=e.find(n=>i.variableName===n.variableName&&n.dimensionName===i.dimensionName);return r?(Array.isArray(i.values[0])?`${i.values[0][0]}-${i.values[0][1]}`:i.values[0])!==(Array.isArray(r.values[0])?`${r.values[0][0]}-${r.values[0][1]}`:r.values[0]):!0}))return s}return null}async fetchVariableStatisticsHistograms(a,e){var r,n,o;const s=this.request(this.url+"/statistics",{query:{variable:a,f:"json"},signal:e}).then(l=>{var c;return(c=l.data)==null?void 0:c.statistics}),t=this.request(this.url+"/histograms",{query:{variable:a,f:"json"},signal:e}).then(l=>{var c;return(c=l.data)==null?void 0:c.histograms}),i=await Promise.all([s,t]);return i[0]&&i[0].forEach(l=>{l.avg=l.mean,l.stddev=l.standardDeviation}),(o=(n=(r=i[1])==null?void 0:r[0])==null?void 0:n.counts)!=null&&o.length||(i[1]=null),{statistics:i[0]||null,histograms:i[1]||null}}async computeBestPyramidLevelForLocation(a,e={}){if(!this._tilemapCache)return 0;let s=this.identifyPixelLocation(a,0,e.datumTransformation);if(s===null)return null;let t=0;const{maximumPyramidLevel:i}=this.rasterInfo.storageInfo;let r=i-t+this._levelOffset;const n=s.srcLocation;for(;r>=0;){try{if(await this._tilemapCache.fetchAvailability(r,s.row,s.col,e)==="available")break}catch{}if(r--,t++,s=this.identifyPixelLocation(n,t,e.datumTransformation),s===null)return null}return r===-1||s==null?null:t}async _fetchRasterInfo(a){const e=this.sourceJSON;if(this.tileType==="Map"){const n=e.fullExtent||e.extent,o=Math.ceil((n.xmax-n.xmin)/e.pixelSizeX-.1),l=Math.ceil((n.ymax-n.ymin)/e.pixelSizeY-.1),c=q.fromJSON(e.spatialReference||n.spatialReference),u=new H({x:e.pixelSizeX,y:e.pixelSizeY,spatialReference:c});return new ge({width:o,height:l,bandCount:3,extent:W.fromJSON(n),spatialReference:c,pixelSize:u,pixelType:"u8",statistics:null,keyProperties:{DataType:"processed"}})}const{signal:s}=a,t=ei(this.url,this.sourceJSON,{signal:s,query:this.ioConfig.customFetchParameters}),i=e.hasMultidimensions?this.request(`${this.url}/slices`,{query:{f:"json"},signal:s}).then(n=>{var o;return(o=n.data)==null?void 0:o.slices}).catch(()=>null):null,r=await Promise.all([t,i]);return this._slices=r[1],r[0]}_fixScaleInServiceInfo(){const{sourceJSON:a}=this;a.minScale&&a.minScale<0&&(a.minScale=0),a.maxScale&&a.maxScale<0&&(a.maxScale=0)}_fixGCSShift(a){const{extent:e,spatialReference:s}=a;e.xmin>-1&&e.xmax>181&&(s!=null&&s.wkid)&&s.isGeographic&&(a.nativeExtent=a.extent,a.transform=new Ji,a.extent=a.transform.forwardTransform(e))}_computeMinMaxLOD(a,e){const{pixelSize:s}=a,t=.5/a.width*s.x,{lods:i}=e,r=e.lodAt(Math.max.apply(null,i.map(p=>p.level))),n=e.lodAt(Math.min.apply(null,i.map(p=>p.level))),{tileType:o}=this;if(o==="Map")return this._levelOffset=i[0].level,[r,n];if(o==="Raster")return[i.find(p=>p.resolution===s.x)??r,n];const{minScale:l,maxScale:c}=this.sourceJSON;let u=r;c>0&&(u=i.find(p=>Math.abs(p.scale-c)<t),u||(u=i.filter(p=>p.scale>c).sort((p,h)=>p.scale>h.scale?1:-1)[0]??r));let f=n;return l>0&&(f=i.find(p=>Math.abs(p.scale-l)<t)??n,this._levelOffset=f.level-n.level),[u,f]}};function es(a,e){if(!a)return null;const{minScale:s,maxScale:t,minLOD:i,maxLOD:r}=e;if(i!=null&&r!=null)return te.fromJSON({...a,lods:a.lods.filter(({level:n})=>n!=null&&n>=i&&n<=r)});if(s!==0&&t!==0){const n=c=>Math.round(1e4*c)/1e4,o=s?n(s):1/0,l=t?n(t):-1/0;return te.fromJSON({...a,lods:a.lods.filter(c=>{const u=n(c.scale);return u<=o&&u>=l})})}return te.fromJSON(a)}b([R({type:String,json:{write:!0}})],pe.prototype,"datasetFormat",void 0),b([R()],pe.prototype,"tileType",void 0),pe=b([Q("esri.layers.support.rasterDatasets.ImageServerRaster")],pe);const ts=pe,K=new Map;K.set("Int8","s8"),K.set("UInt8","u8"),K.set("Int16","s16"),K.set("UInt16","u16"),K.set("Int32","s32"),K.set("UInt32","u32"),K.set("Float32","f32"),K.set("Float64","f32"),K.set("Double64","f32");const se=new Map;se.set("none",{blobExtension:".til",isOneSegment:!0,decoderFormat:"bip"}),se.set("lerc",{blobExtension:".lrc",isOneSegment:!1,decoderFormat:"lerc"}),se.set("deflate",{blobExtension:".pzp",isOneSegment:!0,decoderFormat:"deflate"}),se.set("jpeg",{blobExtension:".pjg",isOneSegment:!0,decoderFormat:"jpg"});let ce=class extends le{constructor(){super(...arguments),this._files=null,this._storageIndex=null,this.datasetFormat="MRF"}async open(a){var y;await this.init(),this.datasetName=this.url.slice(this.url.lastIndexOf("/")+1);const e=a?a.signal:null,s=await this.request(this.url,{responseType:"xml",signal:e}),{rasterInfo:t,files:i}=this._parseHeader(s.data);if(((y=this.ioConfig.skipExtensions)==null?void 0:y.indexOf("aux.xml"))===-1){const d=await this._fetchAuxiliaryData(a);d!=null&&(t.statistics=d.statistics??t.statistics,t.histograms=d.histograms,d.histograms&&t.statistics==null&&(t.statistics=Ae(d.histograms)))}this._set("rasterInfo",t),this._files=i;const r=await this.request(i.index,{responseType:"array-buffer",signal:e});this._storageIndex=this._parseIndex(r.data);const{blockWidth:n,blockHeight:o}=this.rasterInfo.storageInfo,l=this.rasterInfo.storageInfo.pyramidScalingFactor,{width:c,height:u}=this.rasterInfo,f=[],p=this._getBandSegmentCount();let h=0,m=-1;for(;h<this._storageIndex.length;){m++;const d=Math.ceil(c/n/l**m)-1,x=Math.ceil(u/o/l**m)-1;h+=(d+1)*(x+1)*p*4,f.push({maxRow:x,maxCol:d,minCol:0,minRow:0})}this.rasterInfo.storageInfo.blockBoundary=f,m>0&&(this.rasterInfo.storageInfo.firstPyramidLevel=1,this.rasterInfo.storageInfo.maximumPyramidLevel=m),this.updateTileInfo()}async fetchRawTile(a,e,s,t={}){const{blockWidth:i,blockHeight:r,blockBoundary:n}=this.rasterInfo.storageInfo,o=n[a];if(!o||o.maxRow<e||o.maxCol<s||o.minRow>e||o.minCol>s)return null;const{bandCount:l,pixelType:c}=this.rasterInfo,{ranges:u,actualTileWidth:f,actualTileHeight:p}=this._getTileLocation(a,e,s);if(!u||u.length===0)return null;if(u[0].from===0&&u[0].to===0){const _=new Uint8Array(i*r);return new ie({width:i,height:r,pixels:null,mask:_,validPixelCount:0})}const{bandIds:h}=this.ioConfig,m=this._getBandSegmentCount(),y=[];let d=0;for(d=0;d<m;d++)h&&!h.includes(d)||y.push(this.request(this._files.data,{range:{from:u[d].from,to:u[d].to},responseType:"array-buffer",signal:t.signal}));const x=await Promise.all(y),g=x.map(_=>_.data.byteLength).reduce((_,M)=>_+M),w=new Uint8Array(g);let I=0;for(d=0;d<m;d++)w.set(new Uint8Array(x[d].data),I),I+=x[d].data.byteLength;const S=se.get(this.rasterInfo.storageInfo.compression).decoderFormat,v=await this.decodePixelBlock(w.buffer,{width:i,height:r,format:S,planes:(h==null?void 0:h.length)||l,pixelType:c});if(v==null)return null;let{noDataValue:F}=this.rasterInfo;if(F!=null&&S!=="lerc"&&!v.mask&&(F=F[0],F!=null)){const _=v.width*v.height,M=new Uint8Array(_);if(Math.abs(F)>1e24)for(d=0;d<_;d++)Math.abs((v.pixels[0][d]-F)/F)>1e-6&&(M[d]=1);else for(d=0;d<_;d++)v.pixels[0][d]!==F&&(M[d]=1);v.mask=M}let T=0,k=0;if(f!==i||p!==r){let _=v.mask;if(_)for(d=0;d<r;d++)if(k=d*i,d<p)for(T=f;T<i;T++)_[k+T]=0;else for(T=0;T<i;T++)_[k+T]=0;else for(_=new Uint8Array(i*r),v.mask=_,d=0;d<p;d++)for(k=d*i,T=0;T<f;T++)_[k+T]=1}return v}_parseIndex(a){if(a.byteLength%16>0)throw new Error("invalid array buffer must be multiples of 16");let e,s,t,i,r,n;if(fi){for(s=new Uint8Array(a),i=new ArrayBuffer(a.byteLength),t=new Uint8Array(i),r=0;r<a.byteLength/4;r++)for(n=0;n<4;n++)t[4*r+n]=s[4*r+3-n];e=new Uint32Array(i)}else e=new Uint32Array(a);return e}_getBandSegmentCount(){return se.get(this.rasterInfo.storageInfo.compression).isOneSegment?1:this.rasterInfo.bandCount}_getTileLocation(a,e,s){const{blockWidth:t,blockHeight:i,pyramidScalingFactor:r}=this.rasterInfo.storageInfo,{width:n,height:o}=this.rasterInfo,l=this._getBandSegmentCount();let c,u,f,p=0,h=0;for(f=0;f<a;f++)h=r**f,c=Math.ceil(n/t/h),u=Math.ceil(o/i/h),p+=c*u;h=r**a,c=Math.ceil(n/t/h),u=Math.ceil(o/i/h),p+=e*c+s,p*=4*l;const m=this._storageIndex.subarray(p,p+4*l);let y=0,d=0;const x=[];for(let g=0;g<l;g++)y=m[4*g]*2**32+m[4*g+1],d=y+m[4*g+2]*2**32+m[4*g+3],x.push({from:y,to:d});return{ranges:x,actualTileWidth:s<c-1?t:Math.ceil(n/h)-t*(c-1),actualTileHeight:e<u-1?i:Math.ceil(o/h)-i*(u-1)}}_parseHeader(a){const e=X(a,"MRF_META/Raster");if(!e)throw new C("mrf:open","not a valid MRF format");const s=X(e,"Size"),t=parseInt(s.getAttribute("x"),10),i=parseInt(s.getAttribute("y"),10),r=parseInt(s.getAttribute("c"),10),n=(Z(e,"Compression")||"none").toLowerCase();if(!se.has(n))throw new C("mrf:open","currently does not support compression "+n);const o=Z(e,"DataType")||"UInt8",l=K.get(o);if(l==null)throw new C("mrf:open","currently does not support pixel type "+o);const c=X(e,"PageSize"),u=parseInt(c.getAttribute("x"),10),f=parseInt(c.getAttribute("y"),10),p=X(e,"DataValues");let h,m;if(p&&(m=p.getAttribute("NoData"),m!=null&&(h=m.trim().split(" ").map(M=>parseFloat(M)))),X(a,"MRF_META/CachedSource"))throw new C("mrf:open","currently does not support MRF referencing other data files");const y=X(a,"MRF_META/GeoTags"),d=X(y,"BoundingBox");let x,g=!1;if(d!=null){const M=parseFloat(d.getAttribute("minx")),O=parseFloat(d.getAttribute("miny")),D=parseFloat(d.getAttribute("maxx")),N=parseFloat(d.getAttribute("maxy")),P=Z(y,"Projection")||"";let $=q.WGS84;if(P!=="LOCAL_CS[]")if(P.toLowerCase().startsWith("epsg:")){const B=Number(P.slice(5));isNaN(B)||B===0||($=new q({wkid:B}))}else $=_e(P)??q.WGS84;else g=!0,$=new q({wkid:3857});x=new W(M,O,D,N),x.spatialReference=$}else g=!0,x=new W({xmin:-.5,ymin:.5-i,xmax:t-.5,ymax:.5,spatialReference:new q({wkid:3857})});const w=X(a,"MRF_META/Rsets"),I=parseInt((w==null?void 0:w.getAttribute("scale"))||"2",10),S=x.spatialReference,v=new ye({origin:new H({x:x.xmin,y:x.ymax,spatialReference:S}),blockWidth:u,blockHeight:f,pyramidBlockWidth:u,pyramidBlockHeight:f,compression:n,pyramidScalingFactor:I}),F=new H({x:x.width/t,y:x.height/i,spatialReference:S}),T=new ge({width:t,height:i,extent:x,isPseudoSpatialReference:g,spatialReference:S,bandCount:r,pixelType:l,pixelSize:F,noDataValue:h,storageInfo:v}),k=Z(a,"datafile"),_=Z(a,"IndexFile");return{rasterInfo:T,files:{mrf:this.url,index:_||this.url.replace(".mrf",".idx"),data:k||this.url.replace(".mrf",se.get(n).blobExtension)}}}async _fetchAuxiliaryData(a){try{const{data:e}=await this.request(this.url+".aux.xml",{responseType:"xml",signal:a==null?void 0:a.signal});return He(e)}catch{return null}}};b([R()],ce.prototype,"_files",void 0),b([R()],ce.prototype,"_storageIndex",void 0),b([R({type:String,json:{write:!0}})],ce.prototype,"datasetFormat",void 0),ce=b([Q("esri.layers.support.rasterIO.MRFRaster")],ce);const is=ce,Ce=(a,e)=>{var s;return(s=a.get(e))==null?void 0:s.values},fe=(a,e)=>{var s,t;return(t=(s=a.get(e))==null?void 0:s.values)==null?void 0:t[0]};let ae=class extends le{constructor(){super(...arguments),this._files=null,this._headerInfo=null,this._bufferSize=1048576,this.datasetFormat="TIFF"}async open(a){var m,y,d,x;await this.init();const e=a?a.signal:null,{data:s}=await this.request(this.url,{range:{from:0,to:this._bufferSize},responseType:"array-buffer",signal:e});if(!s)throw new C("tiffraster:open","failed to open url "+this.url);this.datasetName=this.url.slice(this.url.lastIndexOf("/")+1,this.url.lastIndexOf("."));const{littleEndian:t,firstIFDPos:i,isBigTiff:r}=di(s),n=[];await this._readIFDs(n,s,t,i,0,r?8:4,e);const{imageInfo:o,rasterInfo:l}=this._parseIFDs(n),c=mi(n),u=pi(n);if(this._headerInfo={littleEndian:t,isBigTiff:r,ifds:n,pyramidIFDs:c,maskIFDs:u,...o},this._set("rasterInfo",l),!o.isSupported)throw new C("tiffraster:open","this tiff is not supported: "+o.message);if(!o.tileWidth)throw new C("tiffraster:open","none-tiled tiff is not optimized for access, convert to COG and retry.");l.isPseudoSpatialReference&&Te.getLogger(this).warn("The spatial reference for this tiff is unsupported. Only EPSG spatial reference codes and Esri WKTs are supported.");const f=(y=(m=n[0].get("PREDICTOR"))==null?void 0:m.values)==null?void 0:y[0];if(((x=(d=n[0].get("SAMPLEFORMAT"))==null?void 0:d.values)==null?void 0:x[0])===3&&f===2)throw new C("tiffraster:open","unsupported horizontal difference encoding. Predictor=3 is supported for floatting point data");const{skipExtensions:h=[]}=this.ioConfig;if(!h.includes("aux.xml")){const g=await this._fetchAuxiliaryMetaData(a);g!=null&&this._processPAMInfo(g,l)}h.includes("vat.dbf")||l.bandCount!==1||l.pixelType!=="u8"||(l.attributeTable=await this._fetchAuxiliaryTable(a),l.attributeTable!=null&&(l.keyProperties.DataType="thematic")),this.updateTileInfo()}async fetchRawTile(a,e,s,t={}){var r;if(!((r=this._headerInfo)!=null&&r.isSupported)||this.isBlockOutside(a,e,s))return null;const i=await this._fetchRawTiffTile(a,e,s,!1,t);if(i!=null&&this._headerInfo.hasMaskBand){const n=await this._fetchRawTiffTile(a,e,s,!0,t);n!=null&&n.pixels[0]instanceof Uint8Array&&(i.mask=n.pixels[0])}return i}_parseIFDs(a){var O,D;const e=yi(a),{width:s,height:t,tileWidth:i,tileHeight:r,planes:n,pixelType:o,compression:l,firstPyramidLevel:c,maximumPyramidLevel:u,pyramidBlockWidth:f,pyramidBlockHeight:p,tileBoundary:h,affine:m,metadata:y}=e,d=((O=e.extent.spatialReference)==null?void 0:O.wkt)||((D=e.extent.spatialReference)==null?void 0:D.wkid);let x=_e(d),g=!!e.isPseudoGeographic;x==null&&(g=!0,x=new q({wkid:3857}));const w=new W({...e.extent,spatialReference:x}),I=new H(w?{x:w.xmin,y:w.ymax,spatialReference:x}:{x:0,y:0}),S=new ye({blockWidth:i,blockHeight:r,pyramidBlockWidth:f,pyramidBlockHeight:p,compression:l,origin:I,firstPyramidLevel:c,maximumPyramidLevel:u,blockBoundary:h}),v=new H({x:(w.xmax-w.xmin)/s,y:(w.ymax-w.ymin)/t,spatialReference:x}),F=y?{BandProperties:y.bandProperties,DataType:y.dataType}:{};let T=null;const k=fe(a[0],"PHOTOMETRICINTERPRETATION"),_=Ce(a[0],"COLORMAP");if(k<=3&&(_==null?void 0:_.length)>3&&_.length%3==0){T=[];const N=_.length/3;for(let P=0;P<N;P++)T.push([P,_[P]>>>8,_[P+N]>>>8,_[P+2*N]>>>8])}const M=new ge({width:s,height:t,bandCount:n,pixelType:o,pixelSize:v,storageInfo:S,spatialReference:x,isPseudoSpatialReference:g,keyProperties:F,extent:w,colormap:T,statistics:y?y.statistics:null});return m!=null&&m.length&&(M.nativeExtent=new W({xmin:-.5,ymin:.5-t,xmax:s-.5,ymax:.5,spatialReference:x}),M.transform=new ze({polynomialOrder:1,forwardCoefficients:[m[2]+m[0]/2,m[5]-m[3]/2,m[0],m[3],-m[1],-m[4]]}),M.extent=M.transform.forwardTransform(M.nativeExtent),M.pixelSize=new H({x:(w.xmax-w.xmin)/s,y:(w.ymax-w.ymin)/t,spatialReference:x}),S.origin.x=-.5,S.origin.y=.5),{imageInfo:e,rasterInfo:M}}_processPAMInfo(a,e){if(e.statistics=a.statistics??e.statistics,e.histograms=a.histograms,a.histograms&&e.statistics==null&&(e.statistics=Ae(a.histograms)),a.transform&&e.transform==null){e.transform=a.transform,e.nativeExtent=e.extent;const s=e.transform.forwardTransform(e.nativeExtent);e.pixelSize=new H({x:(s.xmax-s.xmin)/e.width,y:(s.ymax-s.ymin)/e.height,spatialReference:e.spatialReference}),e.extent=s}e.isPseudoSpatialReference&&a.spatialReference&&(e.spatialReference=a.spatialReference,e.extent.spatialReference=e.nativeExtent.spatialReference=e.storageInfo.origin.spatialReference=e.spatialReference)}async _readIFDs(a,e,s,t,i,r=4,n){if(!t)return null;(t>=e.byteLength||t<0)&&(e=(await this.request(this.url,{range:{from:t+i,to:t+i+this._bufferSize},responseType:"array-buffer",signal:n})).data,i=t+i,t=0);const o=await this._readIFD(e,s,t,i,we.tiffTags,r,n);if(a.push(o.ifd),!o.nextIFD)return null;await this._readIFDs(a,e,s,o.nextIFD-i,i,r,n)}async _readIFD(a,e,s,t,i=we.tiffTags,r=4,n){var l,c;if(!a)return null;const o=gi(a,e,s,t,i,r);if(o.success){const u=[];if((l=o.ifd)==null||l.forEach(f=>{f.values||u.push(f)}),u.length>0){const f=u.map(h=>h.offlineOffsetSize).filter(Oe),p=Math.min.apply(null,f.map(h=>h[0]));if(Math.min.apply(null,f.map(h=>h[0]+h[1]))-p<=this._bufferSize){const{data:h}=await this.request(this.url,{range:{from:p,to:p+this._bufferSize},responseType:"array-buffer",signal:n});a=h,t=p,u.forEach(m=>xi(a,e,m,t))}}if((c=o.ifd)!=null&&c.has("GEOKEYDIRECTORY")){const f=o.ifd.get("GEOKEYDIRECTORY"),p=f==null?void 0:f.values;if(p&&p.length>4){const h=p[0]+"."+p[1]+"."+p[2],m=await this._readIFD(a,e,f.valueOffset+6-t,t,we.geoKeys,2,n);f.data=m.ifd,f.data&&f.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[h]})}}return o}if(o.requiredBufferSize&&o.requiredBufferSize!==a.byteLength)return(a=(await this.request(this.url,{range:{from:t,to:t+o.requiredBufferSize+4},responseType:"array-buffer",signal:n})).data).byteLength<o.requiredBufferSize?null:this._readIFD(a,e,0,t,we.tiffTags,4,n)}async _fetchRawTiffTile(a,e,s,t,i={}){const r=this._getTileLocation(a,e,s,t);if(!r)return null;const{ranges:n,actualTileWidth:o,actualTileHeight:l,ifd:c}=r,u=n.map(v=>this.request(this.url,{range:v,responseType:"array-buffer",signal:i.signal})),f=await Promise.all(u),p=f.map(v=>v.data.byteLength).reduce((v,F)=>v+F),h=f.length===1?f[0].data:new ArrayBuffer(p),m=[0],y=[0];if(f.length>1){const v=new Uint8Array(h);for(let F=0,T=0;F<f.length;F++){const k=f[F].data;v.set(new Uint8Array(k),T),m[F]=T,T+=k.byteLength,y[F]=k.byteLength}}const{blockWidth:d,blockHeight:x}=this.getBlockWidthHeight(a),g=await this.decodePixelBlock(h,{format:"tiff",customOptions:{headerInfo:this._headerInfo,ifd:c,offsets:m,sizes:y},width:d,height:x,planes:null,pixelType:null});if(g==null)return null;let w,I,S;if(o!==d||l!==x){let v=g.mask;if(v)for(w=0;w<x;w++)if(S=w*d,w<l)for(I=o;I<d;I++)v[S+I]=0;else for(I=0;I<d;I++)v[S+I]=0;else for(v=new Uint8Array(d*x),g.mask=v,w=0;w<l;w++)for(S=w*d,I=0;I<o;I++)v[S+I]=1}return g}_getTileLocation(a,e,s,t=!1){const{firstPyramidLevel:i,blockBoundary:r}=this.rasterInfo.storageInfo,n=a===0?0:a-(i-1),{_headerInfo:o}=this;if(!o)return null;const l=t?o.maskIFDs[n]:n===0?o==null?void 0:o.ifds[0]:o==null?void 0:o.pyramidIFDs[n-1];if(!l)return null;const c=wi(l,o),u=Ce(l,"TILEOFFSETS");if(u===void 0)return null;const f=Ce(l,"TILEBYTECOUNTS"),{minRow:p,minCol:h,maxRow:m,maxCol:y}=r[n];if(e>m||s>y||e<p||s<h)return null;const d=fe(l,"IMAGEWIDTH"),x=fe(l,"IMAGELENGTH"),g=fe(l,"TILEWIDTH"),w=fe(l,"TILELENGTH"),I=[];if(c){const{bandCount:S}=this.rasterInfo;for(let v=0;v<S;v++){const F=v*(m+1)*(y+1)+e*(y+1)+s;I[v]={from:u[F],to:u[F]+f[F]-1}}}else{const S=e*(y+1)+s;I.push({from:u[S],to:u[S]+f[S]-1})}for(let S=0;S<I.length;S++)if(I[S].from==null||!I[S].to||I[S].to<0)return null;return{ranges:I,ifd:l,actualTileWidth:s===y&&d%g||g,actualTileHeight:e===m&&x%w||w}}async _fetchAuxiliaryMetaData(a){try{const{data:e}=await this.request(this.url+".aux.xml",{responseType:"xml",signal:a==null?void 0:a.signal});return He(e)}catch{return null}}async _fetchAuxiliaryTable(a){try{const{data:e}=await this.request(this.url+".vat.dbf",{responseType:"array-buffer",signal:a==null?void 0:a.signal}),s=mt.parse(e);return s!=null&&s.recordSet?Ne.fromJSON(s.recordSet):null}catch{return null}}};b([R()],ae.prototype,"_files",void 0),b([R()],ae.prototype,"_headerInfo",void 0),b([R()],ae.prototype,"_bufferSize",void 0),b([R({type:String,json:{write:!0}})],ae.prototype,"datasetFormat",void 0),ae=b([Q("esri.layers.support.rasterDatasets.TIFFRaster")],ae);const ss=ae,j=new Map;j.set("CRF",{desc:"Cloud Raster Format",constructor:Xi}),j.set("MRF",{desc:"Meta Raster Format",constructor:is}),j.set("TIFF",{desc:"GeoTIFF",constructor:ss}),j.set("RasterTileServer",{desc:"Raster Tile Server",constructor:ts}),j.set("JPG",{desc:"JPG Raster Format",constructor:Se}),j.set("PNG",{desc:"PNG Raster Format",constructor:Se}),j.set("GIF",{desc:"GIF Raster Format",constructor:Se}),j.set("BMP",{desc:"BMP Raster Format",constructor:Se});class rs{static get supportedFormats(){const e=new Set;return j.forEach((s,t)=>e.add(t)),e}static async open(e){const{url:s,ioConfig:t,sourceJSON:i}=e;let r=e.datasetFormat;r==null&&s.lastIndexOf(".")&&(r=s.slice(s.lastIndexOf(".")+1).toUpperCase()),r==="OVR"||r==="TIF"?r="TIFF":r!=="JPG"&&r!=="JPEG"&&r!=="JFIF"||(r="JPG"),s.toLowerCase().includes("/imageserver")&&!s.toLowerCase().includes("/wcsserver")&&(r="RasterTileServer");const n={url:s,sourceJSON:i,datasetFormat:r,ioConfig:t??{bandIds:null,sampling:null}};let o,l;if(r&&this.supportedFormats.has(r)){if(r==="CRF"&&!(t!=null&&t.enableCRF))throw new C("rasterfactory:open",`cannot open raster: ${s}`);return o=j.get(r).constructor,l=new o(n),await l.open({signal:e.signal}),l}if(r)throw new C("rasterfactory:open","not a supported format "+r);const c=Array.from(j.keys());let u=0;const f=()=>(r=c[u++],r&&(r!=="CRF"||t!=null&&t.enableCRF)?(o=j.get(r).constructor,l=new o(n),l.open({signal:e.signal}).then(()=>l).catch(()=>f())):null);return f()}static register(e,s,t){j.has(e.toUpperCase())||j.set(e.toUpperCase(),{desc:s,constructor:t})}}let J=class extends _t(kt(Ft(Mt(Pt(Ui(Ct(Ot($t(Dt(Bt(qt))))))))))){constructor(...a){super(...a),this._primaryRasters=[],this.bandIds=null,this.interpolation=null,this.legendEnabled=!0,this.isReference=null,this.listMode="show",this.sourceJSON=null,this.version=null,this.type="imagery-tile",this.operationalLayerType="ArcGISTiledImageServiceLayer",this.popupEnabled=!0,this.popupTemplate=null,this.fields=null,this._debouncedSaveOperations=Et(async(e,s,t)=>{const{save:i,saveAs:r}=await ct(()=>import("./imageryUtils-d2a4f71d.js"),["assets/imageryUtils-d2a4f71d.js","assets/utils-941a520e.js","assets/index-b5c8f851.js","assets/index-86716609.css","assets/originUtils-cfe4feaf.js","assets/multiOriginJSONSupportUtils-c978f4c3.js","assets/jsonContext-4c9e0fec.js","assets/saveAPIKeyUtils-3004b15e.js"]);switch(e){case xe.SAVE:return i(this,s);case xe.SAVE_AS:return r(this,t,s)}})}normalizeCtorArgs(a,e){return typeof a=="string"?{url:a,...e}:a}load(a){const e=a!=null?a.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Image Service"]},a).catch(Jt).then(()=>this._openRaster(e))),Promise.resolve(this)}get defaultPopupTemplate(){return this.createPopupTemplate()}get rasterFields(){var o;const a=[new ue({name:"Raster.ServicePixelValue",alias:"Pixel Value",domain:null,editable:!1,length:50,type:"string"}),new ue({name:"Raster.ServicePixelValue.Raw",alias:"Raw Pixel Value",domain:null,editable:!1,length:50,type:"string"})],{rasterInfo:e}=this,s=e==null?void 0:e.attributeTable,t=s!=null?s.fields:null,i="Raster.";if(t){const l=t.filter(c=>c.type!=="oid"&&c.name.toLowerCase()!=="value").map(c=>{const u=c.clone();return u.name=i+c.name,u});a.push(...l)}const r=e==null?void 0:e.dataType,n=e==null?void 0:e.multidimensionalInfo;if((r==="vector-magdir"||r==="vector-uv")&&n!=null){const l=(o=n.variables[0].unit)==null?void 0:o.trim(),c="Magnitude"+(l?` (${l})`:"");a.push(new ue({name:"Raster.Magnitude",alias:c,domain:null,editable:!1,type:"double"})),a.push(new ue({name:"Raster.Direction",alias:"Direction (°)",domain:null,editable:!1,type:"double"}))}return a}createPopupTemplate(a){const{rasterFields:e}=this,s=new Set(e.map(({name:t})=>t).filter(t=>t.toLowerCase()!=="raster.servicepixelvalue.raw"));return Nt({fields:e,title:this.title},{...a,visibleFieldNames:s})}async generateRasterInfo(a,e){var s;if(!(a=Je($e,a)))return this.rasterInfo;try{const t={raster:this._primaryRasters[0]};this._primaryRasters.length>1&&this._primaryRasters.forEach(n=>t[n.url]=n);const i=Be(((s=a.functionDefinition)==null?void 0:s.toJSON())??a.toJSON(),t),r=new Ee({rasterFunction:i});return await r.open(e),r.rasterInfo}catch(t){throw t instanceof C?t:new C("imagery-tile-layer","the given raster function is not supported")}}async save(a){return this._debouncedSaveOperations(xe.SAVE,a)}async saveAs(a,e){return this._debouncedSaveOperations(xe.SAVE_AS,e,a)}write(a,e){const s=this._primaryRasters[0]??this.raster;if(this.loaded?s.datasetFormat==="RasterTileServer"&&(s.tileType==="Raster"||s.tileType==="Map"):this.url&&/\/ImageServer(\/|\/?$)/i.test(this.url))return super.write(a,e);if(e!=null&&e.messages){const t=`${e.origin}/${e.layerContainerType||"operational-layers"}`;e.messages.push(new C("layer:unsupported",`Layers (${this.title}, ${this.id}) of type '${this.declaredClass}' are not supported in the context of '${t}'`,{layer:this}))}return null}async _openRaster(a){var t;let e=!1;if(this.raster)this.raster.rasterInfo||await this.raster.open(),this.raster.datasetFormat==="Function"?(e=!0,this._primaryRasters=this.raster.primaryRasters.rasters):this._primaryRasters=[this.raster],this.url=this.raster.url;else{const{rasterFunction:i}=this,r=[this.url];i&&Ni(i.toJSON(),r);const n=await Promise.all(r.map(l=>rs.open({url:l,sourceJSON:this.sourceJSON,ioConfig:{sampling:"closest",...this.ioConfig,customFetchParameters:this.customParameters},signal:a}))),o=n.findIndex(l=>l==null);if(o>-1)throw new C("imagery-tile-layer:open",`cannot open raster: ${r[o]}`);if(this._primaryRasters=n,i){const l={raster:this._primaryRasters[0]};this._primaryRasters.length>1&&this._primaryRasters.forEach(f=>l[f.url]=f);const c=Be(((t=i.functionDefinition)==null?void 0:t.toJSON())??i.toJSON(),l),u=new Ee({rasterFunction:c});try{await u.open(),this.raster=u}catch(f){const p=Te.getLogger(this);f instanceof C&&p.error("imagery-tile-layer:open",f.message),p.warn("imagery-tile-layer:open","the raster function cannot be applied and is removed"),this._set("rasterFunction",null),this.raster=n[0]}}else this.raster=n[0]}const s=this.raster.rasterInfo;if(!s)throw new C("imagery-tile-layer:load","cannot load resources on "+this.url);if(this._set("rasterInfo",e?s:this._primaryRasters[0].rasterInfo),this._set("spatialReference",s.spatialReference),this.sourceJSON=this.sourceJSON||this.raster.sourceJSON,this.sourceJSON!=null){const i=this.raster.tileType==="Map"&&this.sourceJSON.minLOD!=null&&this.sourceJSON.maxLOD!=null?this.sourceJSON:{...this.sourceJSON,minScale:0,maxScale:0};this.read(i,{origin:"service"})}else this.read({tileInfo:this.rasterInfo.storageInfo.tileInfo.toJSON()},{origin:"service"});this.title||(this.title=this.raster.datasetName),this.raster.tileType==="Map"&&(this.popupEnabled=!1),this._configDefaultSettings(),this.addHandles(At(()=>this.customParameters,i=>{this.raster&&(this.raster.ioConfig.customFetchParameters=i)}))}};b([R({clonable:!1})],J.prototype,"_primaryRasters",void 0),b([R({type:[zt],json:{write:{overridePolicy(){var a;return{enabled:!this.loaded||this.raster.tileType==="Raster"||((a=this.bandIds)==null?void 0:a.join(","))!=="0,1,2"}}}}})],J.prototype,"bandIds",void 0),b([R({json:{write:{overridePolicy(){return{enabled:!this.loaded||this.raster.tileType==="Raster"||this.interpolation!=="bilinear"}}}}}),Ht(ti)],J.prototype,"interpolation",void 0),b([R(Lt)],J.prototype,"legendEnabled",void 0),b([R({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],J.prototype,"isReference",void 0),b([R({type:["show","hide"]})],J.prototype,"listMode",void 0),b([R({json:{read:!0,write:!0}})],J.prototype,"blendMode",void 0),b([R()],J.prototype,"sourceJSON",void 0),b([R({readOnly:!0,json:{origins:{service:{read:{source:"currentVersion"}}}}})],J.prototype,"version",void 0),b([R({readOnly:!0,json:{read:!1}})],J.prototype,"type",void 0),b([R({type:["ArcGISTiledImageServiceLayer"]})],J.prototype,"operationalLayerType",void 0),b([R({type:Boolean,value:!0,json:{read:{source:"disablePopup",reader:(a,e)=>!e.disablePopup},write:{target:"disablePopup",overridePolicy(){return{enabled:!this.loaded||this.raster.tileType==="Raster"}},writer(a,e,s){e[s]=!a}}}})],J.prototype,"popupEnabled",void 0),b([R({type:Wt,json:{read:{source:"popupInfo"},write:{target:"popupInfo",overridePolicy(){return{enabled:!this.loaded||this.raster.tileType==="Raster"}}}}})],J.prototype,"popupTemplate",void 0),b([R({readOnly:!0})],J.prototype,"defaultPopupTemplate",null),b([R({readOnly:!0,type:[ue]})],J.prototype,"fields",void 0),b([R({readOnly:!0,type:[ue]})],J.prototype,"rasterFields",null),J=b([Q("esri.layers.ImageryTileLayer")],J);const Rs=J;export{Rs as default};
|