anymap-ts 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/anymap_ts/static/deckgl.js +1 -1
- package/anymap_ts/static/leaflet.js +1 -1
- package/anymap_ts/static/mapbox.css +1 -1
- package/anymap_ts/static/mapbox.js +26608 -408
- package/anymap_ts/static/maplibre.js +1 -1
- package/anymap_ts/static/openlayers.js +7 -7
- package/package.json +1 -1
- package/src/core/BaseMapRenderer.ts +3 -24
- package/src/mapbox/MapboxRenderer.ts +2006 -80
- package/src/mapbox/index.ts +2 -0
|
@@ -26819,7 +26819,7 @@ ${o.replace(/gl_FragColor/g,"fragColor")}`:t.length===1?`
|
|
|
26819
26819
|
fragColor.rgb *= fragColor.a;
|
|
26820
26820
|
`}
|
|
26821
26821
|
}
|
|
26822
|
-
`}function sPe(A,t,e){let i=A.createShader(t);return i?(A.shaderSource(i,e),A.compileShader(i),A.getShaderParameter(i,A.COMPILE_STATUS)?i:(console.error("Shader compile error:",A.getShaderInfoLog(i)),A.deleteShader(i),null)):null}function chi(A,t,e){let i=A.createProgram();return i?(A.attachShader(i,t),A.attachShader(i,e),A.linkProgram(i),A.getProgramParameter(i,A.LINK_STATUS)?i:(console.error("Program link error:",A.getProgramInfoLog(i)),A.deleteProgram(i),null)):null}function Rx(A,t,e){let i=A.getUniformLocation(t,e);if(!i)throw new Error(`Failed to get uniform location for ${e}`);return i}function wKt(A){let t=A.createTexture();if(!t)throw new Error("Failed to create texture");return t}function oPe(A){let t=A.createBuffer();if(!t)throw new Error("Failed to create buffer");return t}function WPe(A,t){let e=t===2?A.RG:t===3?A.RGB:t>=4?A.RGBA:A.RED,i=t===2?A.RG32F:t===3?A.RGB32F:t>=4?A.RGBA32F:A.R32F;return{format:e,internalFormat:i}}function LKt(A){A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MIN_FILTER,A.NEAREST),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MAG_FILTER,A.NEAREST),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE)}function VPe(A,t,e){let i=new Float32Array(A.length);for(let r=0;r<A.length;r++){let n=A[r];t!==null&&n===t||n!==n?i[r]=NaN:i[r]=n/e}return{normalized:i,scale:e}}function ZPe(A,t){if(t===1&&A.length===1)return A[0];let e=A[0].length,i=new Float32Array(e*t);for(let r=0;r<e;r++)for(let n=0;n<t;n++)i[r*t+n]=A[n][r];return i}function XPe(A){let t=[],e=[],i=2/A,r=1/A,n=(s,o)=>{let a=-1+s*i,l=1-o*i,g=s*r,h=o*r;t.push(a,l),e.push(g,h)};for(let s=0;s<A;s++){for(let o=0;o<=A;o++)n(o,s),n(o,s+1);s<A-1&&(n(A,s+1),n(0,s+1))}return{vertexArr:new Float32Array(t),texCoordArr:new Float32Array(e)}}function hhi(A){let t=A.replace("#","");if(t.length!==6)throw new Error(`Invalid hex color: ${A}`);let e=parseInt(t,16);return[e>>16&255,e>>8&255,e&255]}var uhi=class{constructor(A){this.texture=null,this.dirty=!0;let{colors:t,floatData:e,length:i}=this.build(A);this.colors=t,this.floatData=e,this.length=i,this.dirty=!0}apply(A){let{colors:t,floatData:e,length:i}=this.build(A);this.colors=t,this.floatData=e,this.length=i,this.dirty=!0}ensureTexture(A){return(!this.texture||this.dirty)&&this.upload(A),this.texture}upload(A){this.texture||(this.texture=wKt(A)),A.bindTexture(A.TEXTURE_2D,this.texture),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MIN_FILTER,A.LINEAR),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MAG_FILTER,A.LINEAR),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE),A.texImage2D(A.TEXTURE_2D,0,A.RGB16F,this.length,1,0,A.RGB,A.FLOAT,this.floatData),A.bindTexture(A.TEXTURE_2D,null),this.dirty=!1}dispose(A){this.texture&&(A.deleteTexture(this.texture),this.texture=null)}build(A){if(!Array.isArray(A)||A.length===0)throw new Error("colormap must be a non-empty array of [r, g, b] values or hex strings");let t=[];for(let n of A)if(typeof n=="string")t.push(hhi(n));else if(Array.isArray(n)&&n.length>=3)t.push([n[0],n[1],n[2]]);else throw new Error("colormap entries must be arrays shaped like [r, g, b] or hex strings");let e=t.flat(),i=e.some(n=>n>1),r=new Float32Array(e.map(n=>i?n/255:n));return{colors:t,floatData:r,length:t.length}}};function Ihi(A=!1,t=!1){return A&&t?"mapbox-wgs84":A?"mapbox":t?"wgs84-globe":"maplibre-globe"}function $Pe(A){let{projectionMode:t,shaderData:e,customShaderConfig:i}=A,r=i&&i.bands.length>0,n=e?.variantName??"base";return[r&&i?["custom",i.bands.join("_"),n].join("_"):n,t].join("_")}var phi=A=>A instanceof Float32Array?A:new Float32Array(A),tHe=A=>A==="mapbox"||A==="mapbox-wgs84",dhi=A=>A==="maplibre-globe"||A==="wgs84-globe";function Chi(A){let t=A.includes("wgs84")?"wgs84":"mercator",e=tHe(A)?"mapbox-globe":"maplibre-globe";return{inputSpace:t,projection:e}}function Bhi(A,t){let{fragmentShaderSource:e,shaderData:i,customShaderConfig:r,projectionMode:n}=t,s=r||void 0,o=s&&s.bands.length>0,a=t.variantName||$Pe({projectionMode:n,shaderData:i,customShaderConfig:r}),{inputSpace:l,projection:g}=Chi(n),h=ahi({inputSpace:l,projection:g,shaderData:i}),p=o&&s?ghi({bands:s.bands,customUniforms:s.customUniforms?Object.keys(s.customUniforms):[],customFrag:s.customFrag}):e,d=sPe(A,A.VERTEX_SHADER,h),E=sPe(A,A.FRAGMENT_SHADER,p);if(!d||!E)throw new Error(`Failed to create shaders for variant: ${a}`);let f=chi(A,d,E);if(!f)throw new Error(`Failed to create program for variant: ${a}`);let Q=new Map,y=new Map;if(o&&s){for(let z of s.bands){let F=A.getUniformLocation(f,z);F&&Q.set(z,F)}if(s.customUniforms)for(let z of Object.keys(s.customUniforms)){let F=A.getUniformLocation(f,z);F&&y.set(z,F)}}let S=dhi(n),v=tHe(n),M=z=>S?A.getUniformLocation(f,z):null,H=z=>v?A.getUniformLocation(f,z):null,Y={program:f,scaleLoc:Rx(A,f,"scale"),scaleXLoc:Rx(A,f,"scale_x"),scaleYLoc:Rx(A,f,"scale_y"),shiftXLoc:Rx(A,f,"shift_x"),shiftYLoc:Rx(A,f,"shift_y"),worldXOffsetLoc:Rx(A,f,"u_worldXOffset"),matrixLoc:S?null:Rx(A,f,"matrix"),projMatrixLoc:M("u_projection_matrix"),fallbackMatrixLoc:M("u_projection_fallback_matrix"),tileMercatorCoordsLoc:M("u_projection_tile_mercator_coords"),clippingPlaneLoc:M("u_projection_clipping_plane"),projectionTransitionLoc:M("u_projection_transition"),opacityLoc:Rx(A,f,"opacity"),texScaleLoc:Rx(A,f,"u_texScale"),texOffsetLoc:Rx(A,f,"u_texOffset"),vertexLoc:A.getAttribLocation(f,"vertex"),pixCoordLoc:A.getAttribLocation(f,"pix_coord_in"),climLoc:A.getUniformLocation(f,"clim"),fillValueLoc:A.getUniformLocation(f,"fillValue"),scaleFactorLoc:A.getUniformLocation(f,"u_scaleFactor"),addOffsetLoc:A.getUniformLocation(f,"u_addOffset"),cmapLoc:o?null:A.getUniformLocation(f,"cmap"),colormapLoc:A.getUniformLocation(f,"colormap"),texLoc:o?null:A.getUniformLocation(f,"tex"),projectionMode:n,useCustomShader:!!o,bandTexLocs:Q,customUniformLocs:y,globeToMercMatrixLoc:H("u_globe_to_merc"),globeTransitionLoc:H("u_globe_transition"),tileRenderLoc:H("u_tile_render"),dataScaleLoc:A.getUniformLocation(f,"u_dataScale"),reprojectLoc:A.getUniformLocation(f,"u_reproject"),latBoundsLoc:A.getUniformLocation(f,"u_latBounds"),latIsAscendingLoc:A.getUniformLocation(f,"u_latIsAscending")};return A.deleteShader(d),A.deleteShader(E),{shaderProgram:Y,variantName:a}}function Ehi(A,t,e,i,r,n){let s=(l,g)=>{l&&g&&A.uniformMatrix4fv(l,!1,phi(g))},o=(l,g)=>{l&&g&&A.uniform4f(l,...g)},a=(l,g)=>{l&&g!==void 0&&A.uniform1f(l,g)};switch(t.projectionMode){case"maplibre-globe":case"wgs84-globe":{if(!i)return;s(t.projMatrixLoc,i.mainMatrix),s(t.fallbackMatrixLoc,i.fallbackMatrix),o(t.tileMercatorCoordsLoc,i.tileMercatorCoords),o(t.clippingPlaneLoc,i.clippingPlane),a(t.projectionTransitionLoc,i.projectionTransition);break}case"mapbox":case"mapbox-wgs84":{s(t.matrixLoc,e),s(t.globeToMercMatrixLoc,r?.globeToMercatorMatrix),a(t.globeTransitionLoc,r?.transition??1),t.tileRenderLoc&&A.uniform1i(t.tileRenderLoc,n?1:0);break}default:{s(t.matrixLoc,e);break}}}var $q=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function TKt(A,t,e,i){let r=Math.max(0,A),n=Math.min(1,e),s=Math.max(0,t),o=Math.min(1,i),a=n-r,l=o-s;return new Float32Array([2/a,0,0,0,0,2/l,0,0,0,0,1,0,-(r+n)/a,-(s+o)/l,0,1])}function UKt(A){let t=2**A.z;return{x0:A.x/t,x1:(A.x+1)/t,y0:A.y/t,y1:(A.y+1)/t}}function fhi(A,t){return A.x0<t.x1&&A.x1>t.x0&&A.y0<t.y1&&A.y1>t.y0}function PKt(A){if(!A)return{xMin:-180,xMax:180,yMin:-90,yMax:90};let t=A.xMax-A.xMin,e=A.yMax-A.yMin,i=t>=350&&e>=170;return{xMin:i?-180:A.xMin,xMax:i?180:A.xMax,yMin:i?-90:A.yMin,yMax:i?90:A.yMax}}function aPe(A,t){return Math.floor($1(A)*Math.pow(2,t))}function lPe(A,t){let e=Math.max(-Xq,Math.min(Xq,A)),i=Math.pow(2,t);return Math.floor((1-Math.log(Math.tan(e*Math.PI/180)+1/Math.cos(e*Math.PI/180))/Math.PI)/2*i)}function eHe(A,t){let[[e,i],[r,n]]=t,s=Math.max(-Xq,i),o=Math.min(Xq,n),a=aPe(e,A),l=aPe(r,A),g=lPe(o,A),h=lPe(s,A),p=Math.pow(2,A),d=[],E=new Set;a>l&&(l+=p);for(let f=a;f<=l;f++){let Q=(f%p+p)%p;for(let y=g;y<=h;y++){let S=Math.max(0,Math.min(p-1,y)),v=`${A},${Q},${S}`;E.has(v)||(E.add(v),d.push([A,Q,S]))}}return d}function AHe(A,t,e){let[[i,r],[n,s]]=t,{xMin:o,xMax:a,yMin:l,yMax:g}=PKt(e),h=a-o,p=g-l,d=Math.pow(2,A),E=Y=>Math.floor((Y-o)/h*d),f=Y=>{let z=Math.max(Math.min(Y,g),l),F=(g-z)/p;return Math.floor(F*d)},Q=E(i),y=E(n),S=f(s),v=f(r),M=[],H=new Set;Q>y&&(y+=d);for(let Y=Q;Y<=y;Y++){let z=(Y%d+d)%d;for(let F=S;F<=v;F++){let N=Math.max(0,Math.min(d-1,F)),P=`${A},${z},${N}`;H.has(P)||(H.add(P),M.push([A,z,N]))}}return M}function m3(A){return A.join(",")}function gPe(A){let[t,e,i]=A,r=1/2**(t+1),n=(2*e+1)*r,s=(2*i+1)*r;return[r,n,s]}function _hi(A,t){return t?Math.min(Math.max(0,Math.floor(A)),t):Math.max(0,Math.floor(A))}function got(A,t=0){let e=parseInt(A,10);if(!isNaN(e))return e;let i=A.match(/(\d+)$/);return i?parseInt(i[1],10):t}function $1(A){let t=A;return A>180?t=A-360:A<-180&&(t=A+360),(t+180)/360}function C6(A){let t=Math.max(-Xq,Math.min(Xq,A));return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2}function YT(A){let t=Math.PI*(1-2*A);return 180/Math.PI*Math.atan(Math.sinh(t))}function oot(A){return A*360-180}function mhi(A,t,e,i){let r=Math.pow(2,A),{xMin:n,xMax:s,yMin:o,yMax:a}=PKt(i),l=s-n,g=a-o,h=n+t/r*l,p=n+(t+1)/r*l,d=a-e/r*g,E=a-(e+1)/r*g;return{west:h,east:p,south:E,north:d}}function iHe(A,t,e,i){let r=t-1,n=Math.floor(e/2),s=Math.floor(i/2);for(;r>=0;){let o=m3([r,n,s]),a=A.get(o);if(a&&a.data)return{tile:a,ancestorZ:r,ancestorX:n,ancestorY:s};r--,n=Math.floor(n/2),s=Math.floor(s/2)}return null}function rHe(A,t,e,i,r,n=2){let s=0,o=[];for(let a=1;a<=n;a++){let l=t+a;if(l>r)break;let g=Math.pow(2,a),h=e*g,p=i*g,d=g*g,E=[];for(let Q=0;Q<g;Q++)for(let y=0;y<g;y++){let S=h+y,v=p+Q,M=m3([l,S,v]),H=A.get(M);H&&H.data&&E.push({tile:H,childZ:l,childX:S,childY:v})}let f=E.length/d;if(f===1)return E;f>s&&(s=f,o=E)}return o.length>0?o:null}function cPe(A,t){if(t==="EPSG:3857")return{x0:(A.xMin+zC)/(2*zC),y0:(zC-A.yMax)/(2*zC),x1:(A.xMax+zC)/(2*zC),y1:(zC-A.yMin)/(2*zC)};let e=A.yMin,i=A.yMax;e>i&&([e,i]=[i,e]);let r={x0:$1(A.xMin),y0:C6(i),x1:$1(A.xMax),y1:C6(e)};return t==="EPSG:4326"&&(r.latMin=e,r.latMax=i),r}function T_t(A,t,e,i){let r=(A-t)/(e-t);return Math.floor(Math.max(0,Math.min(i-1,r*i)))}function Qhi(A){let t=new Float32Array(A.length);for(let e=0;e<A.length;e+=2)t[e]=A[e],t[e+1]=1-A[e+1];return t}function nHe(A){return A?.type==="globe"||A?.name==="globe"}function yhi(A,t,e,i){let r=A&&typeof A=="object"&&!Array.isArray(A)&&!ArrayBuffer.isView(A)?A:null,n=r?.shaderData,s,o=r?.defaultProjectionData;o&&o.mainMatrix&&o.fallbackMatrix&&o.tileMercatorCoords&&o.clippingPlane&&typeof o.projectionTransition=="number"&&(s={mainMatrix:o.mainMatrix,fallbackMatrix:o.fallbackMatrix,tileMercatorCoords:o.tileMercatorCoords,clippingPlane:o.clippingPlane,projectionTransition:o.projectionTransition});let a=null;s?.mainMatrix&&s.mainMatrix.length?a=s.mainMatrix:Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array?a=A:r?.modelViewProjectionMatrix?a=r.modelViewProjectionMatrix:r?.projectionMatrix&&(a=r.projectionMatrix);let l=Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array;return{matrix:a,shaderData:n,projectionData:s,mapbox:!!t||l?{projection:t??{name:"mercator"},globeToMercatorMatrix:e??$q,transition:typeof i=="number"?i:1}:void 0}}function xhi(A,t){if(!A)return[0];let e=A.getBounds?A.getBounds():null;if(!e)return[0];let i=typeof A.getRenderWorldCopies=="function"?A.getRenderWorldCopies():!0;if(t||!i)return[0];let r=e.getWest(),n=e.getEast(),s=n;r>n&&(s=n+360);let o=Math.floor((r+180)/360),a=Math.floor((s+180)/360),l=[];for(let g=o;g<=a;g++)l.push(g);return l.length>0?l:[0]}function HKt(A,t,e){if(!t.useCustomShader||!e)return;let i=2;for(let r of e.bands){let n=t.bandTexLocs.get(r);n&&A.uniform1i(n,i),i++}}function whi(A,t){let{bandData:e,bandTextures:i,bandTexturesUploaded:r,bandTexturesConfigured:n,customShaderConfig:s,width:o,height:a,ensureTexture:l}=t,g=2;for(let h of s.bands){let p=e.get(h);if(!p)return!1;let d=i.get(h);if(!d)if(l){let E=l(h);E&&(d=E,i.set(h,d))}else d=A.createTexture(),d&&i.set(h,d);if(!d)return!1;A.activeTexture(A.TEXTURE0+g),A.bindTexture(A.TEXTURE_2D,d),n.has(h)||(LKt(A),n.add(h)),r.has(h)||(A.texImage2D(A.TEXTURE_2D,0,A.R32F,o,a,0,A.RED,A.FLOAT,p),r.add(h)),g++}return!0}function bhi(A,t,e,i){A.bindBuffer(A.ARRAY_BUFFER,e),A.enableVertexAttribArray(t.vertexLoc),A.vertexAttribPointer(t.vertexLoc,2,A.FLOAT,!1,0,0),A.bindBuffer(A.ARRAY_BUFFER,i),A.enableVertexAttribArray(t.pixCoordLoc),A.vertexAttribPointer(t.pixCoordLoc,2,A.FLOAT,!1,0,0)}function Shi(A,t){let{texture:e,data:i,width:r,height:n,channels:s,configured:o}=t;A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,e),o||LKt(A);let{format:a,internalFormat:l}=WPe(A,s);return A.texImage2D(A.TEXTURE_2D,0,l,r,n,0,a,A.FLOAT,i),{configured:!0,uploaded:!0}}function A6t(A,t,e,i,r){let n=e.wgs84Bounds??null,s,o,a,l;n?(s=(n.lon1-n.lon0)/2,o=(n.lat1-n.lat0)/2,a=(n.lon0+n.lon1)/2,l=(n.lat0+n.lat1)/2):(s=(e.mercatorBounds.x1-e.mercatorBounds.x0)/2,o=(e.mercatorBounds.y1-e.mercatorBounds.y0)/2,a=(e.mercatorBounds.x0+e.mercatorBounds.x1)/2,l=(e.mercatorBounds.y0+e.mercatorBounds.y1)/2),A.uniform1f(t.scaleLoc,0),A.uniform1f(t.scaleXLoc,s),A.uniform1f(t.scaleYLoc,o),A.uniform1f(t.shiftXLoc,a),A.uniform1f(t.shiftYLoc,l);let g=e.texScale??[1,1],h=e.texOffset??[0,0];A.uniform2f(t.texScaleLoc,g[0],g[1]),A.uniform2f(t.texOffsetLoc,h[0],h[1]);let p=e.mercatorBounds.latMin!==void 0&&e.mercatorBounds.latMax!==void 0,d=p&&!n;if(t.reprojectLoc!==null&&A.uniform1i(t.reprojectLoc,d?1:0),d&&t.latBoundsLoc!==null&&p&&A.uniform2f(t.latBoundsLoc,e.mercatorBounds.latMin,e.mercatorBounds.latMax),d&&t.latIsAscendingLoc!==null&&A.uniform1i(t.latIsAscendingLoc,e.latIsAscending?1:0),bhi(A,t,e.vertexBuffer,e.pixCoordBuffer),e.useIndexedMesh&&e.indexBuffer&&A.bindBuffer(A.ELEMENT_ARRAY_BUFFER,e.indexBuffer),t.useCustomShader&&r){if(!whi(A,{bandData:e.bandData,bandTextures:e.bandTextures,bandTexturesUploaded:e.bandTexturesUploaded,bandTexturesConfigured:e.bandTexturesConfigured,customShaderConfig:r,width:e.width,height:e.height,ensureTexture:e.ensureBandTexture}))return!1}else A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,e.texture),t.texLoc!==null&&A.uniform1i(t.texLoc,0);for(let E of i)A.uniform1f(t.worldXOffsetLoc,E),e.useIndexedMesh&&e.indexBuffer?A.drawElements(A.TRIANGLES,e.vertexCount,A.UNSIGNED_INT,0):A.drawArrays(A.TRIANGLE_STRIP,0,e.vertexCount);return!0}function hPe(A,t,e,i){return A.bindBuffer(A.ARRAY_BUFFER,t.vertexBuffer),t.geometryUploaded||A.bufferData(A.ARRAY_BUFFER,e,A.STATIC_DRAW),A.bindBuffer(A.ARRAY_BUFFER,t.pixCoordBuffer),t.geometryUploaded||(A.bufferData(A.ARRAY_BUFFER,i,A.STATIC_DRAW),t.geometryUploaded=!0),t.pixCoordBuffer}function uPe(A,t,e,i,r,n,s,o,a,l){return{mercatorBounds:t,vertexBuffer:A.vertexBuffer,pixCoordBuffer:e,vertexCount:i,texture:A.tileTexture,bandData:A.bandData,bandTextures:A.bandTextures,bandTexturesUploaded:A.bandTexturesUploaded,bandTexturesConfigured:A.bandTexturesConfigured,width:r,height:r,texScale:n,texOffset:s,ensureBandTexture:g=>o.ensureBandTexture(a,g),latIsAscending:l}}function vhi(A,t,e,i,r,n,s,o,a,l,g=!1,h,p,d=!0){HKt(A,t,l);let E=s.length/2;for(let f of e){let[Q,y,S]=f,v=m3(f),M=r.get(v),H=a?.[v],Y=null,z=v,F=[1,1],N=[0,0];if(M&&M.data)Y=M;else{let st=iHe(r,Q,y,S);if(st){Y=st.tile,z=m3([st.ancestorZ,st.ancestorX,st.ancestorY]);let it=Q-st.ancestorZ,W=Math.pow(2,it),X=y%W,rt=S%W;F=[1/W,1/W],N=[X/W,rt/W]}else if(h!==void 0){let it=rHe(r,Q,y,S,h);if(it&&it.length>0){let W;if(H)W=H;else{let[X,rt,gt]=gPe(f);W={x0:rt-X,x1:rt+X,y0:gt-X,y1:gt+X}}for(let X of it){if(!X.tile.data||!X.tile.vertexBuffer||!X.tile.pixCoordBuffer||!X.tile.tileTexture)continue;let rt=X.childZ-Q,gt=Math.pow(2,rt),ft=X.childX%gt,mt=X.childY%gt,St=W.x1-W.x0,wt=W.y1-W.y0,kt={x0:W.x0+ft/gt*St,x1:W.x0+(ft+1)/gt*St,y0:W.y0+mt/gt*wt,y1:W.y0+(mt+1)/gt*wt};if(H?.latMin!==void 0&&H?.latMax!==void 0){let Ie=H.latMax-H.latMin;kt.latMin=H.latMin+mt/gt*Ie,kt.latMax=H.latMin+(mt+1)/gt*Ie}if(H?.lonMin!==void 0&&H?.lonMax!==void 0){let Ie=H.lonMax-H.lonMin;kt.lonMin=H.lonMin+ft/gt*Ie,kt.lonMax=H.lonMin+(ft+1)/gt*Ie}let Dt=hPe(A,X.tile,s,o),Pt=m3([X.childZ,X.childX,X.childY]),ee=uPe(X.tile,kt,Dt,E,n,[1,1],[0,0],r,Pt,d);A6t(A,t,ee,g?[0]:i,l)}continue}}}if(!Y||!Y.data||!Y.vertexBuffer||!Y.pixCoordBuffer||!Y.tileTexture)continue;if(g&&p?.[v]){let st=p[v];F=st.texScale,N=st.texOffset}let P=hPe(A,Y,s,o),K;if(H)K=H;else{let[st,it,W]=gPe(f);K={x0:it-st,x1:it+st,y0:W-st,y1:W+st}}let At=uPe(Y,K,P,E,n,F,N,r,z,d);A6t(A,t,At,g?[0]:i,l)}}var Dhi=class sHe{constructor(t,e,i){this.shaderCache=new Map,this.customShaderConfig=null,this.gl=sHe.resolveGl(t),this.fragmentShaderSource=e,this.customShaderConfig=i||null}updateMultiBandConfig(t){if(t&&this.customShaderConfig){let e=JSON.stringify(t.bands)!==JSON.stringify(this.customShaderConfig.bands),i=t.customFrag!==this.customShaderConfig.customFrag;(e||i)&&this.shaderCache.clear()}else t!==this.customShaderConfig&&this.shaderCache.clear();this.customShaderConfig=t}static resolveGl(t){if(t&&typeof t.getUniformLocation=="function"&&typeof t.drawBuffers=="function")return t.getExtension("EXT_color_buffer_float"),t.getExtension("OES_texture_float_linear"),t;throw new Error("Invalid WebGL2 context: missing required WebGL2 methods")}getProgram(t,e,i=!1,r=!1){let n=Ihi(i,r),s=e||this.customShaderConfig,o=$Pe({projectionMode:n,shaderData:t,customShaderConfig:s}),a=this.shaderCache.get(o);if(a)return a;let{shaderProgram:l}=Bhi(this.gl,{fragmentShaderSource:this.fragmentShaderSource,shaderData:t,customShaderConfig:s,projectionMode:n,variantName:o});return this.shaderCache.set(o,l),l}applyCommonUniforms(t,e,i,r,n,s,o,a=!1){let l=this.gl;if(l.enable(l.BLEND),l.blendFunc(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA),l.activeTexture(l.TEXTURE1),l.bindTexture(l.TEXTURE_2D,e),t.cmapLoc&&l.uniform1i(t.cmapLoc,1),t.colormapLoc&&l.uniform1i(t.colormapLoc,1),t.climLoc&&l.uniform2f(t.climLoc,i.clim[0],i.clim[1]),l.uniform1f(t.opacityLoc,i.opacity),t.fillValueLoc&&l.uniform1f(t.fillValueLoc,i.fillValue??NaN),t.scaleFactorLoc&&l.uniform1f(t.scaleFactorLoc,i.scaleFactor),t.addOffsetLoc&&l.uniform1f(t.addOffsetLoc,i.offset),t.dataScaleLoc&&l.uniform1f(t.dataScaleLoc,i.fixedDataScale),l.uniform2f(t.texScaleLoc,1,1),l.uniform2f(t.texOffsetLoc,0,0),r?.customUniforms)for(let[g,h]of Object.entries(r.customUniforms)){let p=t.customUniformLocs.get(g);p&&l.uniform1f(p,h)}o&&Ehi(l,t,o,n,s,a)}renderTiles(t,e,i,r,n,s,o,a,l,g=!1,h,p,d=!0){vhi(this.gl,t,e,i,r,n,s,o,a,l,g,h,p,d)}dispose(){let t=this.gl;for(let[,e]of this.shaderCache)t.deleteProgram(e.program);this.shaderCache.clear()}};function OKt(A,t){let e=t instanceof Error?t.message:String(t);return`[zarr-layer] Invalid proj4 string: "${A.slice(0,50)}${A.length>50?"...":""}". Error: ${e}. Check your dataset metadata or find CRS definitions at https://epsg.io/`}function khi(A,t){let e;try{e=V1(A,"EPSG:3857")}catch(i){throw new Error(OKt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function Rhi(A,t){let e;try{e=V1(A,"EPSG:4326")}catch(i){throw new Error(OKt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function oHe(A,t){let[e,i,r,n]=A;return r<=e||n<=i?(console.warn(`[zarr-layer] Invalid bounds in ${t}: max must be greater than min`),!1):!0}function YKt(A,t,e,i,r,n=!0){if(!oHe(e,"sourceCRSToPixel"))return[i/2,r/2];let[s,o,a,l]=e,g=(A-s)/(a-s),h=(t-o)/(l-o),p=g*i,d=n?h*r:(1-h)*r;return[p,d]}function i6t(A,t,e,i,r,n=!0){let[s,o,a,l]=e;if(!oHe(e,"pixelToSourceCRS"))return[(s+a)/2,(o+l)/2];let g=i<=1?.5:A/i,h=r<=1?.5:t/r,p=s+g*(a-s),d=n?o+h*(l-o):l-h*(l-o);return[p,d]}function hot(A){let t;try{t=V1("EPSG:4326",A)}catch(e){throw new Error(OKt(A,e))}return{forward:(e,i)=>t.forward([e,i]),inverse:(e,i)=>t.inverse([e,i])}}function IPe(A,t,e){let{xMin:i,yMin:r,xMax:n,yMax:s}=A,o=1/0,a=-1/0,l=1/0,g=-1/0;for(let h=0;h<=e;h++){let p=h/e,d=[[i+p*(n-i),r],[i+p*(n-i),s],[i,r+p*(s-r)],[n,r+p*(s-r)]];for(let[E,f]of d){let[Q,y]=t.forward(E,f);if(!isFinite(Q)||!isFinite(y))continue;let S=(Q+zC)/(2*zC),v=(zC-y)/(2*zC);o=Math.min(o,S),a=Math.max(a,S),l=Math.min(l,v),g=Math.max(g,v)}}return isFinite(o)?{x0:o,y0:l,x1:a,y1:g}:null}function aHe(A,t,e,i,r,n,s,o,a,l,g=!0){if(o&&a){let v=l??hot(o),M=g?A+.5:A,H=g?t+.5:t,[Y,z]=i6t(M,H,a,i,r,s),[F,N]=v.inverse(Y,z);return{lat:N,lon:F}}let h=i<=1?.5:g?(A+.5)/i:A/i,p=r<=1?.5:g?(t+.5)/r:t/r,d=e.x0+h*(e.x1-e.x0),E=e.y0+p*(e.y1-e.y0),f=oot(d),Q=e.y1-e.y0,y=Q===0?.5:(E-e.y0)/Q;return{lat:n==="EPSG:4326"&&e.latMin!==void 0&&e.latMax!==void 0?s?e.latMin+y*(e.latMax-e.latMin):e.latMax-y*(e.latMax-e.latMin):YT(E),lon:f}}function lHe(A,t,e,i,r,n){let[s,o,a]=A,l=Math.pow(2,s),g=(o+t/i)/l,h=(a+e/i)/l;if(r==="EPSG:4326"){let{xMin:f,xMax:Q,yMin:y,yMax:S}=n,v=f+g*(Q-f);return{lat:S-h*(S-y),lon:v}}let p=g*360-180,d=180-h*360;return{lat:360/Math.PI*Math.atan(Math.exp(d*Math.PI/180))-90,lon:p}}function JKt(A){let t=1/0,e=-1/0,i=1/0,r=-1/0;if(A.type==="Point"){let[s,o]=A.coordinates;return{west:s,east:s,south:o,north:o}}let n=s=>{for(let[o,a]of s)o<t&&(t=o),o>e&&(e=o),a<i&&(i=a),a>r&&(r=a)};return A.type==="Polygon"?A.coordinates.forEach(n):A.coordinates.forEach(s=>s.forEach(n)),{west:t,east:e,south:i,north:r}}function Mhi(A,t,e,i,r,n,s,o,a){let l=JKt(A);if(s&&o){let M=a??hot(s),H=5,Y=[];for(let W=0;W<=H;W++){let X=W/H,rt=l.west+X*(l.east-l.west),gt=l.south+X*(l.north-l.south);Y.push([rt,l.south]),Y.push([rt,l.north]),Y.push([l.west,gt]),Y.push([l.east,gt])}let z=1/0,F=-1/0,N=1/0,P=-1/0;for(let[W,X]of Y){let[rt,gt]=M.forward(W,X);if(!isFinite(rt)||!isFinite(gt))continue;let[ft,mt]=YKt(rt,gt,o,e,i,n);z=Math.min(z,ft),F=Math.max(F,ft),N=Math.min(N,mt),P=Math.max(P,mt)}if(!isFinite(z)||!isFinite(F)||!isFinite(N)||!isFinite(P))return null;let K=Math.max(0,Math.floor(z)),At=Math.min(e,Math.floor(F)+1),st=Math.max(0,Math.floor(N)),it=Math.min(i,Math.floor(P)+1);return At<=K||it<=st?null:{minX:K,maxX:At,minY:st,maxY:it}}let g=$1(l.west),h=$1(l.east),p=C6(l.north),d=C6(l.south),E=Math.max(t.x0,Math.min(g,h)),f=Math.min(t.x1,Math.max(g,h)),Q,y,S,v;if(r==="EPSG:4326"&&t.latMin!==void 0&&t.latMax!==void 0){let M=t.latMax,H=t.latMin,Y=Math.min(Math.max(l.north,H),M),z=Math.min(Math.max(l.south,H),M),F=M-H;if(F===0)return null;let N=X=>n?(X-H)/F:(M-X)/F,P=N(Y),K=N(z),At=Math.min(P,K),st=Math.max(P,K);if(f<=E||st<=At)return null;let it=(E-t.x0)/(t.x1-t.x0)*e,W=(f-t.x0)/(t.x1-t.x0)*e;Q=Math.max(0,Math.floor(it)),y=Math.min(e,Math.ceil(W)),S=Math.max(0,Math.floor(At*i)),v=Math.min(i,Math.ceil(st*i))}else{let M=Math.max(t.y0,Math.min(p,d)),H=Math.min(t.y1,Math.max(p,d));if(f<=E||H<=M)return null;let Y=(E-t.x0)/(t.x1-t.x0)*e,z=(f-t.x0)/(t.x1-t.x0)*e,F=(M-t.y0)/(t.y1-t.y0)*i,N=(H-t.y0)/(t.y1-t.y0)*i;Q=Math.max(0,Math.floor(Y)),y=Math.min(e,Math.ceil(z)),S=Math.max(0,Math.floor(F)),v=Math.min(i,Math.ceil(N))}return y<=Q||v<=S?null:{minX:Q,maxX:y,minY:S,maxY:v}}function U_t(A,t){let e=!1,[i,r]=A;for(let n=0,s=t.length-1;n<t.length;s=n++){let o=t[n][0],a=t[n][1],l=t[s][0],g=t[s][1];a>r!=g>r&&i<(l-o)*(r-a)/(g-a)+o&&(e=!e)}return e}function Ghi(A,t){if(t.type==="Point")return A[0]===t.coordinates[0]&&A[1]===t.coordinates[1];if(t.type==="Polygon"){if(!U_t(A,t.coordinates[0]))return!1;for(let e=1;e<t.coordinates.length;e++)if(U_t(A,t.coordinates[e]))return!1;return!0}for(let e of t.coordinates)if(U_t(A,e[0])){let i=!1;for(let r=1;r<e.length;r++)if(U_t(A,e[r])){i=!0;break}if(!i)return!0}return!1}function gHe(A,t){let e=Math.min(...A.map(h=>h[0])),i=Math.max(...A.map(h=>h[0])),r=Math.min(...A.map(h=>h[1])),n=Math.max(...A.map(h=>h[1])),s=h=>h[0]>=e&&h[0]<=i&&h[1]>=r&&h[1]<=n;for(let h of A)if(Ghi(h,t))return!0;if(t.type==="Point"&&s([t.coordinates[0],t.coordinates[1]]))return!0;if(t.type!=="Point"){let h=t.type==="Polygon"?t.coordinates:t.coordinates.flatMap(p=>p);for(let p of h)for(let[d,E]of p)if(s([d,E]))return!0}let o=[[A[0],A[1]],[A[1],A[2]],[A[2],A[3]],[A[3],A[0]]],a=h=>h.slice(0,-1).map((p,d)=>[h[d],h[d+1]]),l=t.type==="Polygon"?a(t.coordinates[0]):t.type==="MultiPolygon"?t.coordinates.flatMap(h=>a(h[0])):[],g=(h,p,d,E)=>{let f=(Y,z)=>Y[0]*z[1]-Y[1]*z[0],Q=(Y,z)=>[Y[0]-z[0],Y[1]-z[1]],y=Q(p,h),S=Q(E,d),v=f(y,S);if(v===0)return!1;let M=f(Q(d,h),S)/v,H=f(Q(d,h),y)/v;return M>=0&&M<=1&&H>=0&&H<=1};for(let h of o)for(let p of l)if(g(h[0],h[1],p[0],p[1]))return!0;return!1}function Fhi(A,t,e,i,r,n){let s=[],o=[[0,0],[1,0],[1,1],[0,1]];for(let[a,l]of o){let g=lHe(A,t+a,e+l,i,r,n);s.push([g.lon,g.lat])}return s}function Nhi(A,t,e,i,r,n,s,o,a,l){let g=[[0,0],[1,0],[1,1],[0,1]],h=[];for(let[p,d]of g){let{lon:E,lat:f}=aHe(i+p,r+d,A,t,e,n,s,o,a,l,!1);h.push([E,f])}return h}function Lhi(A,t,e,i,r,n,s){let o=Fhi(A,t,e,i,r,n);return gHe(o,s)}function Thi(A,t,e,i,r,n,s,o,a,l,g){let h=Nhi(A,t,e,i,r,n,o,a,l,g);return gHe(h,s)}function Uhi(A,t,e,i){let r=[[A.west,A.south],[A.east,A.north]];return e==="EPSG:4326"?AHe(t,r,i):eHe(t,r)}function Phi(A,t,e,i){let r=JKt(A);return Uhi(r,t,e,i)}function Hhi(A,t,e,i,r,n,s,o,a,l){if(o&&a){let E=l??hot(o),[f,Q]=E.forward(A,t),[y,S,v,M]=a;if(f<y||f>v||Q<S||Q>M)return null;let[H,Y]=YKt(f,Q,a,i,r,s),z=Math.floor(H),F=Math.floor(Y);return z<0||z>=i||F<0||F>=r?null:{x:z,y:F}}let g,h;if(n==="EPSG:4326"&&e.latMin!==void 0&&e.latMax!==void 0){g=($1(A)-e.x0)/(e.x1-e.x0);let E=e.latMax-e.latMin;if(E===0)return null;h=s?(t-e.latMin)/E:(e.latMax-t)/E}else g=($1(A)-e.x0)/(e.x1-e.x0),h=(C6(t)-e.y0)/(e.y1-e.y0);if(g<0||g>1||h<0||h>1)return null;let p=Math.floor(g*i),d=Math.floor(h*r);return{x:Math.min(p,i-1),y:Math.min(d,r-1)}}function Ohi(A,t,e,i,r,n,s,o,a){let l=[],g=[[]],h=[[]];for(let p=0;p<r.length;p++){let d=r[p],E=d.toLowerCase(),f=a[p]*o[p],Q=n[d];if(["x","lon","longitude"].includes(E))g=g.map(y=>[...y,t]);else if(["y","lat","latitude"].includes(E))g=g.map(y=>[...y,e]);else{let y=i[d],S,v;if(y===void 0){S=[],v=[];for(let Y=0;Y<o[p];Y++){let z=f+Y;z<s[p]&&(S.push(z),Q&&v.push(Q[z]))}}else if(Array.isArray(y)){S=[],v=[];for(let Y of y){let z;Q?(z=Q.indexOf(Y),z<0&&(z=typeof Y=="number"?Y:0)):z=typeof Y=="number"?Y:0,z>=f&&z<f+o[p]&&(S.push(z),v.push(Y))}}else if(typeof y=="object"&&"selected"in y){let Y=y.selected,z=y.type,F=Array.isArray(Y)?Y:[Y];S=[],v=[];for(let N of F){let P;z==="index"?P=typeof N=="number"?N:0:Q?(P=Q.indexOf(N),P<0&&(P=typeof N=="number"?N:0)):P=typeof N=="number"?N:0,P>=f&&P<f+o[p]&&(S.push(P),Array.isArray(Y)&&v.push(N))}}else{let Y;Q?(Y=Q.indexOf(y),Y<0&&(Y=typeof y=="number"?y:0)):Y=typeof y=="number"?y:0,S=[Y],v=[]}let M=[],H=[];for(let Y=0;Y<S.length;Y++)for(let z=0;z<g.length;z++)M.push([...g[z],S[Y]]),v.length>0?H.push([...h[z],v[Y]]):H.push([...h[z]]);g=M.length>0?M:g.map(Y=>[...Y,0]),h.length=0,h.push(...H.length>0?H:h.map(()=>[]))}}for(let p=0;p<g.length;p++){let d=g[p],E=h[p]||[],f=d.map((v,M)=>{let H=r[M].toLowerCase();return["x","lon","longitude","y","lat","latitude"].includes(H)?v:v-a[M]*o[M]}),Q=new Array(r.length);Q[r.length-1]=1;for(let v=r.length-2;v>=0;v--)Q[v]=Q[v+1]*o[v+1];let y=0;for(let v=0;v<r.length;v++)y+=f[v]*Q[v];let S=A[y];l.push({keys:E,value:S})}return l}function jKt(A,t,e){if(t.length===0)return Array.isArray(A)&&A.push(e),A;let i=A;for(let r=0;r<t.length;r++){let n=t[r];if(r===t.length-1){i[n]||(i[n]=[]);let s=i[n];Array.isArray(s)&&s.push(e)}else i[n]||(i[n]={}),i=i[n]}return A}function pPe(A,t,e,i,r,n,s){let o=t.map((l,g)=>{let h=l.toLowerCase();if(["x","lon","longitude"].includes(h))return[n];if(["y","lat","latitude"].includes(h))return[s];let p=A[l],d=e[l],E=r[g],f;if(p===void 0)f=Array(i[g]).fill(null).map((y,S)=>S);else if(Array.isArray(p))f=p.map(y=>{let S=d?d.indexOf(y):typeof y=="number"?y:0;return S>=0?S:typeof y=="number"?y:0});else if(typeof p=="object"&&"selected"in p){let y=p.selected,S=p.type;f=(Array.isArray(y)?y:[y]).map(M=>{if(S==="index")return typeof M=="number"?M:0;if(d){let H=d.indexOf(M);return H>=0?H:typeof M=="number"?M:0}return typeof M=="number"?M:0})}else if(d){let y=d.indexOf(p);f=[y>=0?y:typeof p=="number"?p:0]}else f=[typeof p=="number"?p:0];return f.map(y=>Math.floor(y/E)).filter((y,S,v)=>v.indexOf(y)===S)}),a=[[]];return o.forEach(l=>{let g=[];l.forEach(h=>{a.forEach(p=>{g.push([...p,h])})}),a=g}),a}function cHe(A,t){if(!Number.isFinite(A)||t?.fillValue!==void 0&&t.fillValue!==null&&A===t.fillValue)return null;let e=A;return t?.scaleFactor!==void 0&&t.scaleFactor!==1&&(e*=t.scaleFactor),t?.addOffset!==void 0&&t.addOffset!==0&&(e+=t.addOffset),e}async function Yhi(A,t,e,i,r,n,s,o,a){let l=i.describe(),g=l.dimensions,h=l.coordinates,p=l.shape||[],d=l.chunks||[],E=st=>Array.isArray(st)?!0:st&&typeof st=="object"&&"selected"in st?Array.isArray(st.selected):!1,f=Object.keys(e).filter(st=>!E(e[st])).length,y=g.length-f>2,S=y?{}:[],v=[],M=[],H=g.map(st=>{let it=st.toLowerCase();return["x","lon","longitude"].includes(it)?"lon":["y","lat","latitude"].includes(it)?"lat":st}),Y=y?H:["lat","lon"],z=()=>{let st={lat:v,lon:M};if(y){let it=W=>{let X=W.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(X))return;let rt=e[W],gt;if(Array.isArray(rt))gt=rt;else if(rt&&typeof rt=="object"&&"selected"in rt){let ft=rt.selected;gt=Array.isArray(ft)?ft:[ft]}else rt!==void 0&&typeof rt!="object"?gt=[rt]:h[W]&&(gt=h[W]);gt&&(st[W]=gt)};g.forEach(it)}return st},F=i.levels[s];if(!F)throw new Error(`No level path found for level index ${s}`);let N=got(F,s),P=Phi(t,N,r,n);if(P.length===0)return{[A]:S,dimensions:Y,coordinates:z()};let K=new Map;await Promise.all(P.map(async st=>{let[,it,W]=st,X=pPe(e,g,h,p,d,it,W),rt=m3(st),gt=new Map;await Promise.all(X.map(async ft=>{try{let mt=await i.getChunk(F,ft),St=new Float32Array(mt.data),wt=ft.join(",");gt.set(wt,St)}catch(mt){console.warn(`Failed to fetch chunk ${ft} for tile ${rt}:`,mt)}})),K.set(rt,gt)}));for(let st of P){let it=m3(st),W=K.get(it);if(!W||W.size===0)continue;let[,X,rt]=st,gt=pPe(e,g,h,p,d,X,rt);for(let ft=0;ft<o;ft++)for(let mt=0;mt<o;mt++){if(!Lhi(st,mt,ft,o,r,n,t))continue;let St=[];for(let kt of gt){let Dt=kt.join(","),Pt=W.get(Dt);if(!Pt)continue;let ee=Ohi(Pt,mt,ft,e,g,h,p,d,kt);for(let{keys:Ie,value:Tt}of ee){let $e=cHe(Tt,a);$e!==null&&St.push({keys:Ie,value:$e})}}if(St.length===0)continue;let wt=lHe(st,mt+.5,ft+.5,o,r,n);v.push(wt.lat),M.push(wt.lon);for(let{keys:kt,value:Dt}of St)kt.length>0?jKt(S,kt,Dt):Array.isArray(S)&&S.push(Dt)}}return{[A]:S,dimensions:Y,coordinates:z()}}async function Jhi(A,t,e,i,r,n,s,o,a,l,g=1,h,p,d,E,f,Q){let y=rt=>Array.isArray(rt)?!0:rt&&typeof rt=="object"&&"selected"in rt?Array.isArray(rt.selected):!1,S=Object.keys(e).filter(rt=>!y(e[rt])).length,M=a.length-S>2,H=M?{}:[],Y=[],z=[],F=a.map(rt=>{let gt=rt.toLowerCase();return["x","lon","longitude"].includes(gt)?"lon":["y","lat","latitude"].includes(gt)?"lat":rt}),N=M?F:["lat","lon"],P=()=>{let rt={lat:Y,lon:z};if(M){let gt=ft=>{let mt=ft.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(mt))return;let St=e[ft],wt;if(Array.isArray(St))wt=St;else if(St&&typeof St=="object"&&"selected"in St){let kt=St.selected;wt=Array.isArray(kt)?kt:[kt]}else St!==void 0&&typeof St!="object"?wt=[St]:l[ft]&&(wt=l[ft]);wt&&(rt[ft]=wt)};a.forEach(gt)}return rt};if(!i)return{[A]:H,dimensions:N,coordinates:P()};let K=0,At=r,st=0,it=n;if(!f){let rt=JKt(t),gt=$1(rt.west),ft=$1(rt.east),mt=C6(rt.north),St=C6(rt.south),wt=Math.max(s.x0,Math.min(gt,ft)),kt=Math.min(s.x1,Math.max(gt,ft));if(o==="EPSG:4326"&&s.latMin!==void 0&&s.latMax!==void 0){let Dt=s.latMax,Pt=s.latMin,ee=Math.min(Math.max(rt.north,Pt),Dt),Ie=Math.min(Math.max(rt.south,Pt),Dt),Tt=Dt-Pt;if(Tt===0)return{[A]:H,dimensions:N,coordinates:P()};let $e=Ci=>d?(Ci-Pt)/Tt:(Dt-Ci)/Tt,Ne=$e(ee),be=$e(Ie),xt=Math.min(Ne,be),Ue=Math.max(Ne,be);if(kt<=wt||Ue<=xt)return{[A]:H,dimensions:N,coordinates:P()};let OA=(wt-s.x0)/(s.x1-s.x0)*r,_e=(kt-s.x0)/(s.x1-s.x0)*r;K=Math.max(0,Math.floor(OA)),At=Math.min(r,Math.ceil(_e+1)),st=Math.max(0,Math.floor(xt*n)),it=Math.min(n,Math.ceil(Ue*n))}else{let Dt=Math.max(s.y0,Math.min(mt,St)),Pt=Math.min(s.y1,Math.max(mt,St));if(kt<=wt||Pt<=Dt)return{[A]:H,dimensions:N,coordinates:P()};let ee=(wt-s.x0)/(s.x1-s.x0)*r,Ie=(kt-s.x0)/(s.x1-s.x0)*r,Tt=(Dt-s.y0)/(s.y1-s.y0)*n,$e=(Pt-s.y0)/(s.y1-s.y0)*n;K=Math.max(0,Math.floor(ee)),At=Math.min(r,Math.ceil(Ie+1)),st=Math.max(0,Math.floor(Tt)),it=Math.min(n,Math.ceil($e+1))}if(At<=K||it<=st)return{[A]:H,dimensions:N,coordinates:P()}}let W=f?hot(f):void 0;for(let rt=st;rt<it;rt++)for(let gt=K;gt<At;gt++){if(!Thi(s,r,n,gt,rt,o,t,d,f,Q,W))continue;let{lat:ft,lon:mt}=aHe(gt,rt,s,r,n,o,d,f,Q,W),St=(rt*r+gt)*g,wt=[];for(let kt=0;kt<g;kt++){let Dt=i[St+kt],Pt=cHe(Dt,E);if(Pt!==null)if(M&&p){let ee=h?.[kt],Ie=ee&&ee.length===p.length?ee:[kt];wt.push({keys:Ie,value:Pt})}else wt.push({keys:[],value:Pt})}if(wt.length!==0){Y.push(ft),z.push(mt);for(let{keys:kt,value:Dt}of wt)kt.length>0?jKt(H,kt,Dt):Array.isArray(H)&&H.push(Dt)}}return{[A]:H,dimensions:N,coordinates:P()}}function hHe(){return{lastFetchTime:0,throttleTimeout:null,throttledPending:!1}}function uHe(A,t){if(t<=0)return 0;let i=Date.now()-A.lastFetchTime;return i<t?t-i:0}function IHe(A,t,e){A.throttleTimeout||(A.throttledPending=!0,A.throttleTimeout=setTimeout(()=>{A.throttleTimeout=null,A.throttledPending=!1,e()},t))}function pHe(A){A.lastFetchTime=Date.now()}function dHe(A){A.throttleTimeout&&(clearTimeout(A.throttleTimeout),A.throttleTimeout=null),A.throttledPending=!1}function CHe(){return{controllers:new Map,currentVersion:0}}function BHe(A,t){for(let[e,i]of A.controllers)e<t&&(i.abort(),A.controllers.delete(e))}function X_t(A){for(let t of A.controllers.values())t.abort();A.controllers.clear()}function jhi(A){for(let t of A.controllers.values())if(!t.signal.aborted)return!0;return!1}function EHe(){return{callback:void 0,metadataLoading:!1,chunksLoading:!1}}function fHe(A,t){A.callback=t}function _He(A){if(!A.callback)return;let t={loading:A.metadataLoading||A.chunksLoading,metadata:A.metadataLoading,chunks:A.chunksLoading,error:null};A.callback(t)}var qhi=class{constructor({store:A,selector:t,fillValue:e,dimIndices:i,coordinates:r,maxCachedTiles:n=64,bandNames:s=[],fixedDataScale:o=1}){this.tiles=new Map,this.gl=null,this.store=A,this.selector=t,this.fillValue=e,this.dimIndices=i,this.coordinates=r,this.maxCachedTiles=n,this.bandNames=s,this.fixedDataScale=o}setGL(A){this.gl=A}updateBandNames(A){this.bandNames=A}updateSelector(A){this.selector=A}getDimKeyForName(A){let t=A.toLowerCase();return["lat","latitude","y"].includes(t)?"lat":["lon","longitude","x","lng"].includes(t)?"lon":["time","t","time_counter"].includes(t)?"time":["depth","z","level","lev","elevation"].includes(t)?"elevation":A}arraysEqual(A,t){if(!A||!t||A.length!==t.length)return!1;for(let e=0;e<A.length;e++)if(A[e]!==t[e])return!1;return!0}normalizeSelection(A,t){if(A===void 0)return[0];let e=t?this.coordinates[t]:void 0,i=r=>{let n=typeof r=="object"&&r!==null&&!Array.isArray(r)&&"selected"in r,s=n?r.selected:r;if((n&&r.type?r.type:"value")!=="index"&&e&&(typeof s=="number"||typeof s=="string")){let a=e.indexOf(s);if(a>=0)return a}return typeof s=="number"?s:0};return typeof A=="object"&&A!==null&&!Array.isArray(A)&&"selected"in A?(Array.isArray(A.selected)?A.selected:[A.selected]).map(n=>i({selected:n,type:A.type})):Array.isArray(A)?A.map(r=>i(r)):[i(A)]}computeChunkIndices(A,t){let[e,i,r]=t,n=this.store.dimensions||[],s=A.chunks,o=new Array(n.length).fill(0);for(let a=0;a<n.length;a++){let l=n[a],g=this.getDimKeyForName(l);if(g==="lon")o[a]=i;else if(g==="lat")o[a]=r;else{let h=APe(this.selector,g,l,this.dimIndices),d=this.normalizeSelection(h,l).map(y=>Math.max(0,Math.min(y,A.shape[a]-1))),E=Math.floor(d[0]/s[a]);d.some(y=>Math.floor(y/s[a])!==E)&&console.warn(`Selector for dimension '${l}' spans multiple chunks \u2013 using chunk index ${E} for tile ${t.join(",")}`);let Q=Math.max(0,Math.ceil(A.shape[a]/s[a])-1);o[a]=Math.min(E,Q)}}return o}extractSliceFromChunk(A,t,e,i){let r=this.store.tileSize,n=this.store.tileSize,s=1,o=this.store.dimensions||[],a=e.chunks,l=[],g=-1,h=-1,p=n,d=r,E=[],f=[];for(let M=0;M<o.length;M++){let H=o[M],Y=this.getDimKeyForName(H);if(Y==="lat")g=M,p=Math.min(t[M],n),l.push(-1);else if(Y==="lon")h=M,d=Math.min(t[M],r),l.push(-1);else{let z=APe(this.selector,Y,H,this.dimIndices),F=this.normalizeSelection(z,H),N=i[M]*a[M],P=F.map(K=>Math.max(0,Math.min(K-N,t[M]-1)));E[M]=P,l.push(P[0]),P.length>1&&f.push(M)}}let Q=M=>{let H=0,Y=1;for(let z=M.length-1;z>=0;z--)H+=M[z]*Y,Y*=t[z];return H},y=[[]];f.forEach(M=>{let H=E[M],Y=[];y.forEach(z=>{H.forEach(F=>{Y.push([...z,F])})}),y=Y}),s=y.length||1;let S=new Map,v=[];for(let M=0;M<s;M++){let H=new Float32Array(r*n);H.fill(this.fillValue),v.push(H)}for(let M=0;M<p;M++)for(let H=0;H<d;H++)g>=0&&(l[g]=M),h>=0&&(l[h]=H),y.forEach((Y,z)=>{let F=[...l],N=0;for(let At=0;At<f.length;At++)F[f[At]]=Y[N++];let P=Q(F),K=M*r+H;P<A.length&&(v[z][K]=A[P])});for(let M=0;M<s;M++){let H=this.bandNames[M]||`band_${M}`;S.set(H,v[M])}return{channels:s,bandData:S}}applyNormalization(A,t){let e=t.bandData;A.bandData=new Map,A.bandTexturesUploaded.clear();let i=[];for(let[r,n]of e){let{normalized:s}=VPe(n,this.fillValue,this.fixedDataScale);A.bandData.set(r,s),i.push(s)}A.data=ZPe(i,t.channels),A.channels=t.channels,this.gl&&A.tileTexture&&this.uploadTileTexture(A)}uploadTileTexture(A){if(!this.gl||!A.tileTexture||!A.data)return;let t=this.gl;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,A.tileTexture),A.textureConfigured||(LKt(t),A.textureConfigured=!0);let{format:e,internalFormat:i}=WPe(t,A.channels),r=this.store.tileSize;t.texImage2D(t.TEXTURE_2D,0,i,r,r,0,e,t.FLOAT,A.data),A.textureUploaded=!0}getOrCreateTile(A){let t=this.tiles.get(A);return t?(this.tiles.delete(A),this.tiles.set(A,t),t):(t={chunkData:null,chunkShape:null,chunkIndices:void 0,data:null,bandData:new Map,channels:1,selectorHash:null,selectorVersion:0,loading:!1,latBounds:null,geoBounds:null,mercatorBounds:null,tileTexture:this.gl?wKt(this.gl):null,bandTextures:new Map,bandTexturesUploaded:new Set,bandTexturesConfigured:new Set,textureUploaded:!1,textureConfigured:!1,vertexBuffer:this.gl?oPe(this.gl):null,pixCoordBuffer:this.gl?oPe(this.gl):null,geometryUploaded:!1},this.tiles.set(A,t),this.evictOldTiles(),t)}evictOldTiles(){for(;this.tiles.size>this.maxCachedTiles;){let A=this.tiles.keys().next().value;if(!A)break;let t=this.tiles.get(A);if(t&&this.gl){t.tileTexture&&this.gl.deleteTexture(t.tileTexture);for(let e of t.bandTextures.values())this.gl.deleteTexture(e);t.vertexBuffer&&this.gl.deleteBuffer(t.vertexBuffer),t.pixCoordBuffer&&this.gl.deleteBuffer(t.pixCoordBuffer)}this.tiles.delete(A)}}get(A){let t=this.tiles.get(A);return t&&(this.tiles.delete(A),this.tiles.set(A,t)),t}upsert(A){return this.getOrCreateTile(A)}ensureBandTexture(A,t){let e=this.tiles.get(A);if(!e||!this.gl)return null;let i=e.bandTextures.get(t);return i||(i=wKt(this.gl),e.bandTextures.set(t,i)),i}getTile(A){return this.tiles.get(m3(A))}setTileBounds(A,t){let e=this.tiles.get(A);if(!e)return;let i={min:t.latMin,max:t.latMax},r={west:t.lonMin,south:t.latMin,east:t.lonMax,north:t.latMax},n={x0:t.x0,y0:t.y0,x1:t.x1,y1:t.y1};(e.latBounds?.min!==i.min||e.latBounds?.max!==i.max||e.geoBounds?.west!==r.west||e.geoBounds?.east!==r.east||e.mercatorBounds?.x0!==n.x0||e.mercatorBounds?.x1!==n.x1||e.mercatorBounds?.y0!==n.y0||e.mercatorBounds?.y1!==n.y1)&&(e.latBounds=i,e.geoBounds=r,e.mercatorBounds=n)}async reextractTileSlices(A,t,e){for(let i of A){let r=m3(i),n=this.tiles.get(r);if(!n)continue;let s=this.store.levels[i[0]];if(!s)continue;let o=await this.store.getLevelArray(s),a=this.computeChunkIndices(o,i);if(n.chunkData&&n.chunkShape&&this.arraysEqual(n.chunkIndices,a)){if(e<n.selectorVersion)continue;let g=this.extractSliceFromChunk(n.chunkData,n.chunkShape,o,a);this.applyNormalization(n,g),n.selectorHash=t,n.selectorVersion=e}else n.selectorHash=null,n.chunkData=null,n.chunkShape=null,n.chunkIndices=void 0}}async fetchTile(A,t,e,i,r){let[n]=A,s=this.store.levels[n];if(!s)return null;let o=await this.store.getLevelArray(s),a=m3(A),l=this.getOrCreateTile(a);if(r&&(l.latBounds={min:r.latMin,max:r.latMax},l.geoBounds={west:r.lonMin,south:r.latMin,east:r.lonMax,north:r.latMax},l.mercatorBounds={x0:r.x0,y0:r.y0,x1:r.x1,y1:r.y1}),l.data&&l.selectorHash===t)return l;if(l.loading)return null;l.loading=!0;try{let g=this.computeChunkIndices(o,A);if(l.chunkData&&l.chunkShape&&this.arraysEqual(l.chunkIndices,g)){if(e<l.selectorVersion)return l.loading=!1,null;let Q=this.extractSliceFromChunk(l.chunkData,l.chunkShape,o,g);return this.applyNormalization(l,Q),l.selectorHash=t,l.selectorVersion=e,l.loading=!1,l}let p=await this.store.getChunk(s,g,{signal:i}),d=p.shape.map(Q=>Number(Q)),E=p.data instanceof Float32Array?new Float32Array(p.data.buffer):Float32Array.from(p.data);if(e<l.selectorVersion)return l.loading=!1,null;l.chunkData=E,l.chunkShape=d,l.chunkIndices=g;let f=this.extractSliceFromChunk(E,d,o,g);return this.applyNormalization(l,f),l.selectorHash=t,l.selectorVersion=e,l.loading=!1,l}catch(g){return l.loading=!1,g instanceof DOMException&&g.name==="AbortError"||console.error("Error fetching tile data:",g),null}}markGeometryDirty(){for(let A of this.tiles.values())A.geometryUploaded=!1}clear(){if(this.gl)for(let A of this.tiles.values()){A.tileTexture&&this.gl.deleteTexture(A.tileTexture);for(let t of A.bandTextures.values())this.gl.deleteTexture(t);A.vertexBuffer&&this.gl.deleteBuffer(A.vertexBuffer),A.pixCoordBuffer&&this.gl.deleteBuffer(A.pixCoordBuffer)}this.tiles.clear()}};function mHe(A,t,e,i,r){let n=m3([A,t,e]),s=i?.[n];if(s)return s;let o=mhi(A,t,e,r);return{x0:$1(o.west),x1:$1(o.east),y0:C6(o.north),y1:C6(o.south),latMin:o.south,latMax:o.north,lonMin:o.west,lonMax:o.east}}function QHe(A,t){let e=Math.max(A.x0,t.x0),i=Math.min(A.x1,t.x1),r=Math.max(A.y0,t.y0),n=Math.min(A.y1,t.y1);if(i<=e||n<=r)return null;let s=A.lonMin??oot(A.x0),o=A.lonMax??oot(A.x1),a=A.latMin??YT(A.y1),l=A.latMax??YT(A.y0),g=o-s,h=oot(e),p=oot(i),d=g>0?(p-h)/g:1,E=g>0?(h-s)/g:0;return{overlap:{x0:e,y0:r,x1:i,y1:n},latBounds:{min:a,max:l},texScale:[d,1],texOffset:[E,0]}}function yHe({renderer:A,mode:t,tileId:e,context:i,regions:r}){return r?Khi(A,e,i,r):zhi(A,t,e,i)}function Khi(A,t,e,i){if(i.length===0)return!0;let r=UKt(t),n={lon0:r.x0,lon1:r.x1,lat0:(YT(r.y1)+90)/180,lat1:(YT(r.y0)+90)/180},s=TKt(r.x0,r.y0,r.x1,r.y1),{colormapTexture:o,uniforms:a,customShaderConfig:l}=e,g=e.isGlobe??!0,h=i.some(E=>!!E.wgs84Bounds),p=A.getProgram(e.shaderData,l,!0,h);A.gl.useProgram(p.program),A.applyCommonUniforms(p,o,a,l,e.projectionData,{projection:{name:g?"globe":"mercator"},globeToMercatorMatrix:$q,transition:g?0:1},s,!0),HKt(A.gl,p,l);let d=!1;for(let E of i){let f;if(E.wgs84Bounds){let v=E.wgs84Bounds,M=v.lat0<n.lat1&&v.lat1>n.lat0,H;if(v.crossesAntimeridian){let z=v.lon0<1&&n.lon0<1&&n.lon1>v.lon0,F=n.lon0<v.lon1&&n.lon1>0;H=z||F}else H=v.lon0<n.lon1&&v.lon1>n.lon0;f=M&&H}else f=fhi(E.mercatorBounds,r);if(!f)continue;let Q=!!E.useIndexedMesh&&!!E.indexBuffer,y={mercatorBounds:E.mercatorBounds,vertexBuffer:E.vertexBuffer,pixCoordBuffer:E.pixCoordBuffer,vertexCount:Q?E.vertexCount??E.vertexArr.length/2:E.vertexArr.length/2,texture:E.texture,bandData:E.bandData??new Map,bandTextures:E.bandTextures??new Map,bandTexturesUploaded:E.bandTexturesUploaded??new Set,bandTexturesConfigured:E.bandTexturesConfigured??new Set,width:E.width,height:E.height,indexBuffer:Q?E.indexBuffer:void 0,useIndexedMesh:Q,wgs84Bounds:E.wgs84Bounds,latIsAscending:E.latIsAscending};A6t(A.gl,p,y,[0],l)||(d=!0)}return d}function zhi(A,t,e,i){let r=t.getTiledState?.();return r?.tileCache?t.getCRS()==="EPSG:4326"?Whi(A,t,e,i,r):Xhi(A,t,e,i,r):!0}function Whi(A,t,e,i,r){let{customShaderConfig:n}=i,{visibleTiles:s,tileBounds:o}=r,a=t.getXYLimits(),l=t.getMaxLevelIndex(),g=t.getLevels();if(!a||s.length===0)return!0;let h=UKt(e),p=TKt(h.x0,h.y0,h.x1,h.y1),d=[];for(let v of s){let M=m3(v),H=o?.[M];H&&H.x0<h.x1&&H.x1>h.x0&&H.y0<h.y1&&H.y1>h.y0&&d.push(v)}if(d.length===0)return!1;let E=A.getProgram(i.shaderData,n,!0,!1);A.gl.useProgram(E.program);let f=g[l]??"",Q=got(f,l),y=!1,S=!1;for(let v of d){let M=Vhi(A,E,v,h,p,r,i,a,Q);M.rendered&&(y=!0),M.missing&&(S=!0)}return S||!y}function Vhi(A,t,e,i,r,n,s,o,a){let{tileCache:l,vertexArr:g,pixCoordArr:h,tileSize:p,tileBounds:d}=n,{colormapTexture:E,uniforms:f,customShaderConfig:Q}=s,y=m3(e),S=l.get(y),v=e,M=!1;if(!S?.data){M=!0;let rt=iHe(l,e[0],e[1],e[2]);if(rt)S=rt.tile,v=[rt.ancestorZ,rt.ancestorX,rt.ancestorY];else{let gt=rHe(l,e[0],e[1],e[2],a);if(gt&>.length>0){let ft=!1;for(let mt of gt){if(!mt.tile.data)continue;Zhi(A,t,mt,i,r,n,s,o)&&(ft=!0)}return{rendered:ft,missing:!0}}return{rendered:!1,missing:!0}}}let[H,Y,z]=v,F=m3(v),N=mHe(H,Y,z,d,o),P=QHe(N,i);if(!P)return{rendered:!1,missing:M};let{overlap:K,latBounds:At,texScale:st,texOffset:it}=P,W={[F]:{x0:K.x0,y0:K.y0,x1:K.x1,y1:K.y1,latMin:At.min,latMax:At.max}},X=s.isGlobe??!0;return A.applyCommonUniforms(t,E,f,Q,s.projectionData,{projection:{name:X?"globe":"mercator"},globeToMercatorMatrix:$q,transition:X?0:1},r,!0),A.renderTiles(t,[v],[0],l,p,g,h,W,Q,!0,void 0,{[F]:{texScale:st,texOffset:it}},n.latIsAscending),{rendered:!0,missing:M}}function Zhi(A,t,e,i,r,n,s,o){let{tileCache:a,vertexArr:l,pixCoordArr:g,tileSize:h,tileBounds:p}=n,{colormapTexture:d,uniforms:E,customShaderConfig:f}=s,Q=[e.childZ,e.childX,e.childY],y=m3(Q),S=mHe(e.childZ,e.childX,e.childY,p,o),v=QHe(S,i);if(!v)return!1;let{overlap:M,latBounds:H,texScale:Y,texOffset:z}=v,F={[y]:{x0:M.x0,y0:M.y0,x1:M.x1,y1:M.y1,latMin:H.min,latMax:H.max}},N=s.isGlobe??!0;return A.applyCommonUniforms(t,d,E,f,s.projectionData,{projection:{name:N?"globe":"mercator"},globeToMercatorMatrix:$q,transition:N?0:1},r,!0),A.renderTiles(t,[Q],[0],a,h,l,g,F,f,!0,void 0,{[y]:{texScale:Y,texOffset:z}},n.latIsAscending),!0}function Xhi(A,t,e,i,r){let{tileCache:n,vertexArr:s,pixCoordArr:o,tileSize:a,tileBounds:l}=r,{colormapTexture:g,uniforms:h,customShaderConfig:p}=i,d=t.getLevels(),E=t.getMaxLevelIndex(),f=UKt(e),Q=TKt(f.x0,f.y0,f.x1,f.y1),y=[e.z,e.x,e.y],S=y.join(","),v=l?.[S],M={[S]:{x0:f.x0,y0:f.y0,x1:f.x1,y1:f.y1,latMin:v?.latMin,latMax:v?.latMax}},H=d[E]??"",Y=got(H,E),z=A.getProgram(i.shaderData,p,!0);A.gl.useProgram(z.program);let F=i.isGlobe??!0;return A.applyCommonUniforms(z,g,h,p,i.projectionData,{projection:{name:F?"globe":"mercator"},globeToMercatorMatrix:$q,transition:F?0:1},Q,!0),A.renderTiles(z,[y],[0],n,a,s,o,M,p,!0,Y),!n.get(S)?.data}function dPe(A){if(!(!A||A.latMin===void 0||A.latMax===void 0||A.lonMin===void 0||A.lonMax===void 0))return{latMin:A.latMin,latMax:A.latMax,lonMin:A.lonMin,lonMax:A.lonMax,x0:A.x0,y0:A.y0,x1:A.x1,y1:A.y1}}var $hi=class{constructor(A,t,e,i,r=100,n=1){this.isMultiscale=!0,this.tileCache=null,this.vertexArr=new Float32Array,this.pixCoordArr=new Float32Array,this.currentSubdivisions=0,this.maxLevelIndex=0,this.tileSize=$Ue,this.visibleTiles=[],this.crs="EPSG:4326",this.xyLimits=null,this.tileBounds={},this.pendingChunks=new Set,this.currentLevel=null,this.selectorVersion=0,this.throttleState=hHe(),this.requestCanceller=CHe(),this.loadingManager=EHe(),this.zarrStore=A,this.variable=t,this.selector=e,this.invalidate=i,this.throttleMs=r,this.fixedDataScale=n}async initialize(){this.loadingManager.metadataLoading=!0,this.emitLoadingState();try{let A=this.zarrStore.describe();this.maxLevelIndex=A.levels.length-1,this.tileSize=A.tileSize||$Ue,this.crs=A.crs,this.xyLimits=A.xyLimits;let t=HT(this.variable,this.selector);this.tileCache=new qhi({store:this.zarrStore,selector:this.selector,fillValue:A.fill_value??0,dimIndices:A.dimIndices,coordinates:A.coordinates,maxCachedTiles:Uci,bandNames:t,crs:this.crs,fixedDataScale:this.fixedDataScale}),this.updateGeometryForProjection(!1)}finally{this.loadingManager.metadataLoading=!1,this.emitLoadingState()}}update(A,t){if(!this.tileCache)return;this.tileCache.setGL(t);let e=A.getProjection?A.getProjection():null,i=nHe(e);this.updateGeometryForProjection(i);let r=this.getVisibleTilesWithContext(A);this.visibleTiles=r.tiles,this.tileBounds=this.computeTileBounds(this.visibleTiles),r.pyramidLevel!==null&&(this.currentLevel=r.pyramidLevel);for(let[o,a]of Object.entries(this.tileBounds)){let l=dPe(a);l&&this.tileCache.setTileBounds(o,l)}let n=JSON.stringify(this.selector),s=[];for(let o of this.visibleTiles){let a=m3(o);if(this.pendingChunks.has(a))continue;let l=this.tileCache.upsert(a);(!l.data||l.selectorHash!==n)&&s.push(o)}if(s.length>0){let o=uHe(this.throttleState,this.throttleMs);if(o>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),IHe(this.throttleState,o,this.invalidate);return}pHe(this.throttleState);let a=this.pendingChunks.size===0;for(let g of s)this.pendingChunks.add(m3(g));a&&this.emitLoadingState();let l=this.selectorVersion;this.prefetchTileData(s,n,l).catch(g=>{console.error("Error prefetching tile data:",g);for(let h of s)this.pendingChunks.delete(m3(h));this.emitLoadingState()})}}render(A,t){if(!this.tileCache)return;let e=!!t.mapbox,i=A.getProgram(t.shaderData,t.customShaderConfig,e,!1);A.gl.useProgram(i.program),A.applyCommonUniforms(i,t.colormapTexture,t.uniforms,t.customShaderConfig,t.projectionData,t.mapbox,t.matrix,!1);let r=this.zarrStore.levels[this.maxLevelIndex],n=got(r,this.maxLevelIndex);A.renderTiles(i,this.visibleTiles,t.worldOffsets,this.tileCache,this.tileSize,this.vertexArr,this.pixCoordArr,Object.keys(this.tileBounds).length>0?this.tileBounds:void 0,t.customShaderConfig,!1,n,void 0,this.zarrStore.latIsAscending)}renderToTile(A,t,e){return yHe({renderer:A,mode:this,tileId:t,context:e})}onProjectionChange(A){this.updateGeometryForProjection(A)}getTiledState(){return this.tileCache?{tileCache:this.tileCache,visibleTiles:this.visibleTiles,tileSize:this.tileSize,vertexArr:this.vertexArr,pixCoordArr:this.pixCoordArr,tileBounds:Object.keys(this.tileBounds).length>0?this.tileBounds:void 0,latIsAscending:this.zarrStore.latIsAscending}:null}getSingleImageState(){return null}dispose(A){dHe(this.throttleState),X_t(this.requestCanceller),this.tileCache?.clear(),this.tileCache=null,this.pendingChunks.clear(),this.emitLoadingState()}setLoadingCallback(A){fHe(this.loadingManager,A)}getCRS(){return this.crs}getXYLimits(){return this.xyLimits}getMaxLevelIndex(){return this.maxLevelIndex}getLevels(){return this.zarrStore.levels}emitLoadingState(){this.loadingManager.chunksLoading=this.pendingChunks.size>0||this.throttleState.throttledPending,_He(this.loadingManager)}async setSelector(A){this.selector=A,this.selectorVersion++;let t=HT(this.variable,A);if(this.tileCache?.updateSelector(this.selector),this.tileCache?.updateBandNames(t),this.tileCache&&this.visibleTiles.length>0){let e=JSON.stringify(this.selector);await this.tileCache.reextractTileSlices(this.visibleTiles,e,this.selectorVersion)}this.invalidate()}updateGeometryForProjection(A){let t=A?Pci:1;if(this.currentSubdivisions===t)return;let e=XPe(t);this.vertexArr=e.vertexArr,this.pixCoordArr=e.texCoordArr,this.currentSubdivisions=t,this.tileCache?.markGeometryDirty()}getVisibleTilesWithContext(A){if(!A.getZoom||!A.getBounds)return{tiles:[],pyramidLevel:null,mapZoom:null,bounds:null};let t=A.getZoom(),e=_hi(t,this.maxLevelIndex),i=A.getBounds()?.toArray();if(!i)return{tiles:[],pyramidLevel:e,mapZoom:t,bounds:null};let r=this.zarrStore.levels[e],n=got(r,e);return this.crs==="EPSG:4326"&&this.xyLimits?{tiles:AHe(n,i,this.xyLimits),pyramidLevel:e,mapZoom:t,bounds:i}:{tiles:eHe(n,i),pyramidLevel:e,mapZoom:t,bounds:i}}computeTileBounds(A){if(this.crs!=="EPSG:4326"||!this.xyLimits)return{};let{xMin:t,xMax:e,yMin:i,yMax:r}=PKt(this.xyLimits),n=e-t,s=r-i,o={};for(let a of A){let[l,g,h]=a,p=Math.pow(2,l),d=n/p,E=s/p,f=t+g*d,Q=f+d,y=r-h*E,S=y-E,v=$1(f),M=$1(Q),H=C6(y),Y=C6(S);o[m3(a)]={x0:v,y0:H,x1:M,y1:Y,latMin:S,latMax:y,lonMin:f,lonMax:Q}}return o}async prefetchTileData(A,t,e){let i=new AbortController;this.requestCanceller.controllers.set(e,i);try{let r=A.map(n=>this.fetchTileData(n,t,e,i.signal));await Promise.all(r)}finally{this.requestCanceller.controllers.delete(e)}}async fetchTileData(A,t,e,i){if(!this.tileCache){let s=m3(A);return this.pendingChunks.delete(s),this.emitLoadingState(),null}let r=m3(A),n=dPe(this.tileBounds[r]);try{let s=await this.tileCache.fetchTile(A,t,e,i,n);return this.pendingChunks.delete(r),s?(BHe(this.requestCanceller,e),this.emitLoadingState(),this.invalidate(),s.data):(this.emitLoadingState(),null)}catch(s){if(this.pendingChunks.delete(r),this.emitLoadingState(),s instanceof DOMException&&s.name==="AbortError")return null;throw s}}async queryData(A,t){if(!this.tileCache||!this.xyLimits)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let e=t?aot(t):this.selector,i=this.currentLevel??this.maxLevelIndex,r=this.zarrStore.describe();return Yhi(this.variable,A,e,this.zarrStore,this.crs,this.xyLimits,i,this.tileSize,{scaleFactor:r.scaleFactor,addOffset:r.addOffset,fillValue:r.fill_value})}},tui=1e4,eui=1e3,Aui=270;function lot(A){return isFinite(A)?((A+180)%360+360)%360-180:A}function iui(A){let{bounds:t,width:e,height:i,latIsAscending:r,transformer:n}=A,s=e>1?e/(e-1):1,o=i>1?i/(i-1):1;return new Aot({forwardTransform:(a,l)=>i6t(a*s,l*o,t,e,i,r),inverseTransform:(a,l)=>{let[g,h]=YKt(a,l,t,e,i,r);return[g/s,h/o]},forwardReproject:(a,l)=>n.forward(a,l),inverseReproject:(a,l)=>n.inverse(a,l)},e,i)}function rui(A,t,e,i,r=!1){return{lon0:$1(A),lat0:(e+90)/180,lon1:$1(t),lat1:(i+90)/180,crossesAntimeridian:r}}function nui(A,t,e,i,r,n=!1){let s=A.length/2,o=new Float32Array(s*2),a=n?360-t+e||1:e-t||1,l=r-i||1;for(let g=0;g<s;g++){let h=A[g*2],p=A[g*2+1];h=lot(h),n&&h<t&&(h+=360),o[g*2]=(h-t)/a*2-1,o[g*2+1]=(p-i)/l*2-1}return o}function mKt(A,t){return Math.abs(A-t)>180}function CPe(A,t,e,i){let r=A,n=e;A>0&&e<0&&A-e>180?n+=360:e>0&&A<0&&e-A>180&&(r+=360);let s=(180-r)/(n-r);return{lat:t+s*(i-t),t:s}}function sui(A,t,e,i){let r=A.length/2,n=new Uint8Array(r);for(let l=0;l<r;l++){let g=A[l*2],h=A[l*2+1];n[l]=isFinite(g)&&isFinite(h)?1:0}if(!i){let l=[];for(let g=0;g<e.length;g+=3){let h=e[g],p=e[g+1],d=e[g+2];n[h]&&n[p]&&n[d]&&l.push(h,p,d)}return{positions:A,texCoords:t,indices:new Uint32Array(l)}}let s=new Array(A.length);for(let l=0;l<A.length;l++)s[l]=A[l];let o=new Array(t.length);for(let l=0;l<t.length;l++)o[l]=t[l];let a=[];for(let l=0;l<e.length;l+=3){let g=e[l],h=e[l+1],p=e[l+2];if(!n[g]||!n[h]||!n[p])continue;let d=A[g*2],E=A[g*2+1],f=t[g*2],Q=t[g*2+1],y=A[h*2],S=A[h*2+1],v=t[h*2],M=t[h*2+1],H=A[p*2],Y=A[p*2+1],z=t[p*2],F=t[p*2+1],N=lot(d),P=lot(y),K=lot(H),At=mKt(N,P),st=mKt(P,K),it=mKt(K,N),W=(At?1:0)+(st?1:0)+(it?1:0);if(W===0)a.push(g,h,p);else if(W===2){let X=At?st?[1,2,0]:[0,1,2]:[2,0,1],[rt,gt,ft]=X,mt=[g,h,p],St=[N,P,K],wt=[E,S,Y],kt=[f,v,z],Dt=[Q,M,F],Pt=mt[rt],ee=mt[gt],Ie=mt[ft],Tt=St[rt],$e=wt[rt],Ne=kt[rt],be=Dt[rt],xt=St[gt],Ue=wt[gt],OA=kt[gt],_e=Dt[gt],Ci=St[ft],_A=wt[ft],fA=kt[ft],Ee=Dt[ft],ai=CPe(Tt,$e,xt,Ue),ki=CPe(Tt,$e,Ci,_A),$i=Ne+ai.t*(OA-Ne),pA=be+ai.t*(_e-be),ye=Ne+ki.t*(fA-Ne),ei=be+ki.t*(Ee-be),zA=Tt>0,EA=zA?179.9999:-179.9999,rA=zA?-179.9999:179.9999,oA=s.length/2;s.push(EA,ai.lat,EA,ki.lat),s.push(rA,ai.lat,rA,ki.lat),o.push($i,pA,ye,ei),o.push($i,pA,ye,ei);let re=oA,te=oA+1,Pe=oA+2,iA=oA+3;a.push(Pt,re,te),a.push(Pe,ee,Ie),a.push(Pe,Ie,iA)}else a.push(g,h,p)}return{positions:new Float64Array(s),texCoords:new Float64Array(o),indices:new Uint32Array(a)}}function oui(A){let{geoBounds:t,width:e,height:i,subdivisions:r,transformer:n,latIsAscending:s,maxError:o=Hci}=A,{xMin:a,xMax:l,yMin:g,yMax:h}=t,d=iui({bounds:[a,g,l,h],width:e,height:i,latIsAscending:s,transformer:n});for(let rt=0;rt<eui&&d.getMaxError()>o;rt++){let gt=d.uvs.length/2;d.refine();let ft=d.uvs.length/2;if(ft>=tui||ft===gt)break}let E=d.uvs,f=(r+1)**2,Q=new Float64Array(E.length+f*2);Q.set(E);let y=E.length;for(let rt=0;rt<=r;rt++)for(let gt=0;gt<=r;gt++)Q[y++]=gt/r,Q[y++]=rt/r;let v=new eot(Q).triangles,M=Q.length/2,H=new Float64Array(M*2),Y=[],z=1/0,F=-1/0;for(let rt=0;rt<M;rt++){let gt=Q[rt*2],ft=Q[rt*2+1],mt=a+gt*(l-a),St=s?g+ft*(h-g):h-ft*(h-g),[wt,kt]=n.forward(mt,St);H[rt*2]=wt,H[rt*2+1]=kt,isFinite(wt)&&isFinite(kt)&&(Y.push(lot(wt)),z=Math.min(z,kt),F=Math.max(F,kt))}isFinite(z)||(z=-90),isFinite(F)||(F=90);let N=-180,P=180,K=!1;if(Y.length>0){Y.sort((gt,ft)=>gt-ft),N=Y[0],P=Y[Y.length-1];let rt=P-N;if(rt>0){let gt=0,ft=0;for(let St=0;St<Y.length-1;St++){let wt=Y[St+1]-Y[St];wt>gt&&(gt=wt,ft=St+1)}Y[0]+360-Y[Y.length-1]<gt&&rt<Aui&&(K=!0,N=Y[ft],P=Y[ft-1])}}K&&N>=180&&(N=N-360,N<=P&&(K=!1));let At=K||P-N>=180,st=new Float64Array(Q),it=sui(H,st,v,At),W=nui(it.positions,N,P,z,F,K),X=rui(N,P,z,F,K);return{positions:W,texCoords:new Float32Array(it.texCoords),indices:it.indices,wgs84Bounds:X}}var aui=128,lui=class{constructor(A,t,e,i,r=100,n=1){this.isMultiscale=!1,this.width=0,this.height=0,this.channels=1,this.mercatorBounds=null,this.bandNames=[],this.dimIndices={},this.xyLimits=null,this.crs="EPSG:4326",this.zarrArray=null,this.latIsAscending=!0,this.levels=[],this.currentLevelIndex=0,this.pendingLevelIndex=null,this.levelMetadataFetched=new Set,this.proj4def=null,this.cachedMercatorTransformer=null,this.cachedWGS84Transformer=null,this.cached4326Transformer=null,this.isRemoved=!1,this.throttleState=hHe(),this.requestCanceller=CHe(),this.loadingManager=EHe(),this.dimensionValues={},this.regionCache=new Map,this.visibleRegionKeys=new Set,this.lastVisibleRegions=[],this.lastVisibleRegionsLevel=-1,this.regionSize=null,this.lastViewportHash="",this.baseSliceArgs=[],this.selectorVersion=0,this.baseMultiValueDims=[],this.cachedGl=null,this.baseSliceArgsReady=!1,this.isGlobeProjection=!1,this.fixedDataScale=1,this.zarrStore=A,this.variable=t,this.selector=e,this.bandNames=HT(t,e),this.invalidate=i,this.throttleMs=r,this.fixedDataScale=n}async initialize(){this.loadingManager.metadataLoading=!0,this.emitLoadingState();try{let A=this.zarrStore.describe();if(this.dimIndices=A.dimIndices,this.crs=A.crs,this.xyLimits=A.xyLimits,this.latIsAscending=A.latIsAscending,this.proj4def=A.proj4??null,this.proj4def&&this.xyLimits){let t=[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax];this.cachedMercatorTransformer=khi(this.proj4def,t),this.cachedWGS84Transformer=hot(this.proj4def),this.cached4326Transformer=Rhi(this.proj4def,t)}this.crs!=="EPSG:4326"&&this.crs!=="EPSG:3857"&&console.warn(`Unsupported CRS "${this.crs}" - rendering may be incorrect. Supported: EPSG:4326, EPSG:3857`),A.untiledLevels&&A.untiledLevels.length>0?(this.levels=A.untiledLevels,this.isMultiscale=!0,await this.ensureAllLevelShapes(),this.currentLevelIndex=-1):(this.isMultiscale=!1,this.zarrArray=await this.zarrStore.getArray(),this.width=this.zarrArray.shape[this.dimIndices.lon.index],this.height=this.zarrArray.shape[this.dimIndices.lat.index]),this.xyLimits?this.proj4def?this.mercatorBounds=this.computeMercatorBoundsFromProjection():this.mercatorBounds=cPe(this.xyLimits,this.crs):console.warn("UntiledMode: No XY limits found")}finally{this.loadingManager.metadataLoading=!1,this.emitLoadingState()}}async ensureLevelMetadata(A){let t=this.levels[A];if(t&&!this.levelMetadataFetched.has(A)&&!(t.dtype!==void 0&&t.scaleFactor!==void 0&&t.addOffset!==void 0)){this.levelMetadataFetched.add(A);try{let e=await this.zarrStore.getUntiledLevelMetadata(t.asset);t.shape=e.shape,t.chunks=e.chunks,e.scaleFactor!==void 0&&(t.scaleFactor=e.scaleFactor),e.addOffset!==void 0&&(t.addOffset=e.addOffset),t.fillValue=e.fillValue,t.dtype=e.dtype}catch(e){console.warn(`Failed to load metadata for level ${t.asset}:`,e)}}}async ensureAllLevelShapes(){let A=this.levels.map((t,e)=>({level:t,index:e})).filter(({level:t})=>!t.shape);A.length!==0&&await Promise.all(A.map(async({level:t,index:e})=>{if(!this.levelMetadataFetched.has(e)){this.levelMetadataFetched.add(e);try{let i=await this.zarrStore.getUntiledLevelMetadata(t.asset);t.shape=i.shape,t.chunks=i.chunks,i.scaleFactor!==void 0&&(t.scaleFactor=i.scaleFactor),i.addOffset!==void 0&&(t.addOffset=i.addOffset),t.fillValue=i.fillValue,t.dtype=i.dtype}catch(i){console.warn(`Failed to load shape for level ${t.asset}:`,i)}}}))}getRegionSize(A){let t=this.dimIndices.lat?.index,e=this.dimIndices.lon?.index;if(t===void 0||e===void 0)return null;let i=A.codecs||[];for(let n of i)if(n.name==="sharding_indexed"&&n.configuration?.chunk_shape){let s=n.configuration.chunk_shape;return[s[t],s[e]]}let r=A.chunks;if(r&&r.length>Math.max(t,e)){let n=r[t],s=r[e],o=A.shape;if(n<o[t]||s<o[e])return[n,s]}return null}clearRegionCache(A){for(let t of this.regionCache.values())this.disposeRegion(t,A);this.regionCache.clear(),this.lastViewportHash=""}disposeRegion(A,t){A.texture&&t.deleteTexture(A.texture),A.vertexBuffer&&t.deleteBuffer(A.vertexBuffer),A.pixCoordBuffer&&t.deleteBuffer(A.pixCoordBuffer),A.indexBuffer&&t.deleteBuffer(A.indexBuffer);for(let e of A.bandTextures.values())t.deleteTexture(e)}evictOldRegions(A){for(;this.regionCache.size>aui;){let t=null;for(let i of this.regionCache.keys())if(!this.visibleRegionKeys.has(i)){t=i;break}if(!t)break;let e=this.regionCache.get(t);e&&this.disposeRegion(e,A),this.regionCache.delete(t)}}getVisibleRegions(A){let t=A.getBounds?.()?.toArray?.();if(!t||!this.xyLimits||!this.regionSize)return[];let[[e,i],[r,n]]=t,{xMin:s,xMax:o,yMin:a,yMax:l}=this.xyLimits,[g,h]=this.regionSize;if(this.proj4def&&this.cachedWGS84Transformer){let K=this.cachedWGS84Transformer,At=Math.ceil(this.width/h),st=Math.ceil(this.height/g),it=[];for(let W=0;W<st;W++)for(let X=0;X<At;X++){let rt=this.getRegionBounds(X,W),gt=(rt.xMin+rt.xMax)/2,ft=(rt.yMin+rt.yMax)/2,St=[K.inverse(rt.xMin,rt.yMin),K.inverse(rt.xMax,rt.yMin),K.inverse(rt.xMax,rt.yMax),K.inverse(rt.xMin,rt.yMax),K.inverse(gt,rt.yMin),K.inverse(gt,rt.yMax),K.inverse(rt.xMin,ft),K.inverse(rt.xMax,ft)].filter(ee=>isFinite(ee[0])&&isFinite(ee[1]));if(St.length===0)continue;let wt=Math.min(...St.map(ee=>ee[0])),kt=Math.max(...St.map(ee=>ee[0])),Dt=Math.min(...St.map(ee=>ee[1])),Pt=Math.max(...St.map(ee=>ee[1]));kt>=e&&wt<=r&&Pt>=i&&Dt<=n&&it.push({regionX:X,regionY:W})}return it}let p=T_t(e,s,o,this.width),d=T_t(r,s,o,this.width),E=T_t(i,a,l,this.height),f=T_t(n,a,l,this.height);this.latIsAscending===!1&&(E=this.height-1-E,f=this.height-1-f);let Q=Math.floor(Math.min(p,d)/h),y=Math.floor(Math.max(p,d)/h),S=Math.floor(Math.min(E,f)/g),v=Math.floor(Math.max(E,f)/g),M=Math.ceil(this.width/h),H=Math.ceil(this.height/g),Y=Math.max(0,Q),z=Math.min(M-1,y),F=Math.max(0,S),N=Math.min(H-1,v),P=[];for(let K=F;K<=N;K++)for(let At=Y;At<=z;At++)P.push({regionX:At,regionY:K});return P}makeRegionKey(A,t,e){return`${A}:${t},${e}`}createRegionState(A,t,e){return{key:this.makeRegionKey(A,t,e),levelIndex:A,regionX:t,regionY:e,data:null,width:0,height:0,loading:!1,channels:1,texture:null,textureUploaded:!1,vertexBuffer:null,pixCoordBuffer:null,indexBuffer:null,vertexArr:null,pixCoordArr:null,indexArr:null,vertexCount:0,useIndexedMesh:!1,mercatorBounds:null,wgs84Bounds:null,latIsAscending:this.latIsAscending,selectorVersion:this.selectorVersion,bandData:new Map,bandTextures:new Map,bandTexturesUploaded:new Set,bandTexturesConfigured:new Set,levelMeta:null}}isRegionValid(A){return!!(A.data&&A.textureUploaded&&A.texture&&A.vertexBuffer&&A.pixCoordBuffer&&A.vertexArr&&A.mercatorBounds)}clearBatchLoadingFlags(A,t){for(let{regionX:e,regionY:i}of A){let r=this.makeRegionKey(t,e,i),n=this.regionCache.get(r);n&&(n.loading=!1)}}getUniformsForRender(A){return{...A,scaleFactor:1,offset:0}}currentLevelCoversViewport(){if(this.lastVisibleRegionsLevel!==this.currentLevelIndex)return!1;let A=this.currentLevelIndex;for(let{regionX:t,regionY:e}of this.lastVisibleRegions){let i=this.makeRegionKey(A,t,e),r=this.regionCache.get(i);if(!r||!this.isRegionValid(r))return!1}return this.lastVisibleRegions.length>0}getProtectedFallbackRegions(){let A=[];for(let t of this.regionCache.values())t.levelIndex!==this.currentLevelIndex&&this.isRegionValid(t)&&this.visibleRegionKeys.has(t.key)&&A.push(t);return A}getLoadedRegions(){let A=this.currentLevelIndex,t=[];for(let i of this.regionCache.values())this.isRegionValid(i)&&i.levelIndex===A&&t.push(i);return this.currentLevelCoversViewport()?t:[...this.getProtectedFallbackRegions(),...t]}buildChannelCombinations(A){let t=[[]],e=[[]];for(let{values:i,labels:r}of A){let n=[],s=[];for(let o=0;o<i.length;o++)for(let a=0;a<t.length;a++)n.push([...t[a],i[o]]),s.push([...e[a],r[o]]);t=n,e=s}return{combinations:t,labelCombinations:e}}getRegionBounds(A,t,e){let i=e?.width??this.width,r=e?.height??this.height,n=e?.regionSize??this.regionSize;if(!this.xyLimits||!n)return{xMin:0,xMax:1,yMin:0,yMax:1};let[s,o]=n,{xMin:a,xMax:l,yMin:g,yMax:h}=this.xyLimits,p=A*o,d=Math.min(p+o,i),E=t*s,f=Math.min(E+s,r),Q=a+p/i*(l-a),y=a+d/i*(l-a),S,v;return this.latIsAscending===!1?(v=h-E/r*(h-g),S=h-f/r*(h-g)):(S=g+E/r*(h-g),v=g+f/r*(h-g)),{xMin:Q,xMax:y,yMin:S,yMax:v}}createRegionGeometry(A,t,e,i){if(!i.levelMeta&&!this.regionSize)return;let r=this.getRegionBounds(A,t,i.levelMeta??void 0),n=i.mercatorBounds??cPe(r,this.crs);if(i.mercatorBounds=n,this.proj4def&&this.cached4326Transformer){let s=(r.xMin+r.xMax)/2,o=(r.yMin+r.yMax)/2,l=[this.cached4326Transformer.forward(r.xMin,r.yMin),this.cached4326Transformer.forward(r.xMax,r.yMin),this.cached4326Transformer.forward(r.xMin,r.yMax),this.cached4326Transformer.forward(r.xMax,r.yMax),this.cached4326Transformer.forward(s,o)].map(d=>d[1]).filter(d=>isFinite(d)),g=l.length>0?Math.max(...l)-Math.min(...l):0,h=Math.max(tPe,Math.min(ePe,Math.ceil(g))),p=oui({geoBounds:r,width:i.width,height:i.height,subdivisions:h,transformer:this.cached4326Transformer,latIsAscending:this.latIsAscending});i.vertexArr=p.positions,i.pixCoordArr=p.texCoords,i.indexArr=p.indices,i.wgs84Bounds=p.wgs84Bounds,i.useIndexedMesh=!0,i.vertexCount=i.indexArr.length}else{let s;if(this.crs==="EPSG:3857"){let l=.5-r.yMin/(2*zC),g=.5-r.yMax/(2*zC);s=Math.abs(YT(g)-YT(l))}else s=Math.abs(r.yMax-r.yMin);let o=this.isGlobeProjection?Math.max(tPe,Math.min(ePe,Math.ceil(s))):Oci,a=XPe(o);if(i.vertexArr=a.vertexArr,i.useIndexedMesh=!1,i.vertexCount=a.vertexArr.length/2,this.crs==="EPSG:4326"){let l=r.yMin,g=r.yMax;i.mercatorBounds={x0:$1(r.xMin),x1:$1(r.xMax),y0:C6(g),y1:C6(l),latMin:l,latMax:g},i.latIsAscending=this.latIsAscending,i.pixCoordArr=a.texCoordArr}else i.pixCoordArr=this.latIsAscending?Qhi(a.texCoordArr):a.texCoordArr}i.vertexBuffer||(i.vertexBuffer=e.createBuffer()),i.pixCoordBuffer||(i.pixCoordBuffer=e.createBuffer()),e.bindBuffer(e.ARRAY_BUFFER,i.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,i.vertexArr,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,i.pixCoordBuffer),e.bufferData(e.ARRAY_BUFFER,i.pixCoordArr,e.STATIC_DRAW),i.useIndexedMesh&&i.indexArr&&(i.indexBuffer||(i.indexBuffer=e.createBuffer()),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,i.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,i.indexArr,e.STATIC_DRAW))}classifyDimension(A){let t=A.toLowerCase();return t==="lon"||t==="x"||t==="lng"||t.includes("lon")?"lon":t==="lat"||t==="y"||t.includes("lat")?"lat":t.includes("time")?"time":"other"}async buildSliceArgsForSelector(A,t){if(!this.zarrArray)return{sliceArgs:[],multiValueDims:[]};let e=new Array(this.zarrArray.shape.length).fill(0),i=[],r=Object.keys(this.dimIndices);for(let n of r){let s=this.dimIndices[n],o=this.classifyDimension(n);if(o==="lon")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.x:t.spatialBounds?.type==="bbox"?e[s.index]=aQ(t.spatialBounds.minX,t.spatialBounds.maxX):e[s.index]=t.includeSpatialSlices?aQ(0,this.width):0;else if(o==="lat")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.y:t.spatialBounds?.type==="bbox"?e[s.index]=aQ(t.spatialBounds.minY,t.spatialBounds.maxY):e[s.index]=t.includeSpatialSlices?aQ(0,this.height):0;else{let a=A[n]||(o==="time"?A.time:void 0);if(a!==void 0){let l=a.selected,g=a.type;if(t.trackMultiValue&&Array.isArray(l)&&l.length>1){let h=[],p=[];for(let d of l){let E=await this.resolveSelectionIndex(n,s,d,g);h.push(E),p.push(d)}i.push({dimIndex:s.index,dimName:n,values:h,labels:p}),e[s.index]=h[0]}else{let h=Array.isArray(l)?l[0]:l;e[s.index]=await this.resolveSelectionIndex(n,s,h,g)}}else e[s.index]=0}}return{sliceArgs:e,multiValueDims:i}}resetVisibleRegions(){this.lastVisibleRegions=[],this.lastVisibleRegionsLevel=-1,this.lastViewportHash=""}updateVisibleRegions(A,t){let e=this.getVisibleRegions(A);this.lastVisibleRegions=e,this.lastVisibleRegionsLevel=this.currentLevelIndex;let i=this.currentLevelIndex;for(let{regionX:a,regionY:l}of e)this.visibleRegionKeys.add(this.makeRegionKey(i,a,l));if(this.currentLevelCoversViewport()){let a=`${i}:`;for(let l of this.visibleRegionKeys)l.startsWith(a)||this.visibleRegionKeys.delete(l)}let r=[],n=[];for(let{regionX:a,regionY:l}of e){let g=this.makeRegionKey(i,a,l),h=this.regionCache.get(g);h?.loading||(h?.data?h.selectorVersion!==this.selectorVersion&&n.push({regionX:a,regionY:l}):r.push({regionX:a,regionY:l}))}let s=`${i}:${this.selectorVersion}:${e.map(a=>`${a.regionX},${a.regionY}`).join("|")}`,o=s!==this.lastViewportHash;this.lastViewportHash=s,!(r.length===0&&n.length===0&&!o)&&(r.length>0&&this.fetchRegions(r,t),n.length>0&&this.fetchRegionsThrottled(n,t))}fetchRegionsThrottled(A,t){let e=uHe(this.throttleState,this.throttleMs);if(e>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),IHe(this.throttleState,e,this.invalidate);return}pHe(this.throttleState),this.fetchRegions(A,t)}async fetchRegions(A,t){if(!this.zarrArray||!this.regionSize)return;let e={index:this.currentLevelIndex,zarrArray:this.zarrArray,baseSliceArgs:[...this.baseSliceArgs],width:this.width,height:this.height,regionSize:this.regionSize,selectorVersion:this.selectorVersion,baseMultiValueDims:this.baseMultiValueDims.map(n=>({dimIndex:n.dimIndex,dimName:n.dimName,values:[...n.values],labels:[...n.labels]}))};this.loadingManager.chunksLoading=!0,this.emitLoadingState();for(let{regionX:n,regionY:s}of A){let o=this.makeRegionKey(e.index,n,s),a=this.regionCache.get(o);a||(a=this.createRegionState(e.index,n,s),this.regionCache.set(o,a)),a.loading=!0}let i=32,r=[];for(let{regionX:n,regionY:s}of A){if(this.currentLevelIndex!==e.index){X_t(this.requestCanceller),this.clearBatchLoadingFlags(A,e.index);break}let o=this.fetchRegion(n,s,t,e).then(()=>{r.splice(r.indexOf(o),1)}).catch(()=>{r.splice(r.indexOf(o),1)});r.push(o),r.length>=i&&await Promise.race(r)}r.length>0&&await Promise.allSettled(r),jhi(this.requestCanceller)||(this.loadingManager.chunksLoading=!1,this.emitLoadingState(),this.evictOldRegions(t),this.invalidate())}async fetchRegion(A,t,e,i){if(this.currentLevelIndex!==i.index||this.isRemoved)return;let r=this.makeRegionKey(i.index,A,t),n=++this.requestCanceller.currentVersion,s=i.selectorVersion,o=new AbortController;this.requestCanceller.controllers.set(n,o);let a=this.regionCache.get(r);a||(a=this.createRegionState(i.index,A,t),this.regionCache.set(r,a)),a.loading=!0;let[l,g]=i.regionSize,h=t*l,p=Math.min(h+l,i.height),d=A*g,E=Math.min(d+g,i.width),f=E-d,Q=p-h;try{let y=[...i.baseSliceArgs],S=this.dimIndices.lat.index,v=this.dimIndices.lon.index;y[S]=aQ(h,p),y[v]=aQ(d,E);let M=this.zarrStore.describe(),H=this.levels[i.index],Y=H?.fillValue??M.fill_value,{combinations:z}=this.buildChannelCombinations(i.baseMultiValueDims),F=z.length||1,N=f*Q,P=[],K=new Float32Array(N*F);if(K.fill(Y??0),F===1){if(o.signal.aborted||this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let St=await X2(i.zarrArray,y,{opts:{signal:o.signal}});if(o.signal.aborted||this.isRemoved){a.loading=!1;return}if(this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let wt=new Float32Array(St.data);P.push(wt),K.set(wt)}else for(let St=0;St<F;St++){if(o.signal.aborted||this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let wt=[...y],kt=z[St];for(let ee=0;ee<i.baseMultiValueDims.length;ee++)wt[i.baseMultiValueDims[ee].dimIndex]=kt[ee];let Dt=await X2(i.zarrArray,wt,{opts:{signal:o.signal}});if(o.signal.aborted||this.isRemoved){a.loading=!1;return}if(this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let Pt=new Float32Array(Dt.data);P.push(Pt);for(let ee=0;ee<N;ee++)K[ee*F+St]=Pt[ee]}if(s<a.selectorVersion){a.loading=!1;return}a.selectorVersion=s,BHe(this.requestCanceller,n);let At=P,st=f,it=Q;if(this.proj4def&&this.cachedMercatorTransformer&&this.xyLimits&&!a.mercatorBounds){let St={width:i.width,height:i.height,regionSize:i.regionSize},wt=this.getRegionBounds(A,t,St);a.mercatorBounds=this.computeRegionMercatorBounds(wt)}let X=H?.scaleFactor??M.scaleFactor,rt=H?.addOffset??M.addOffset;a.bandData.clear(),a.bandTexturesUploaded.clear();let gt=[];for(let St=0;St<At.length;St++){let wt=this.bandNames[St]||`band_${St}`,kt=At[St];if(X!==1||rt!==0){let ee=new Float32Array(kt.length);for(let Ie=0;Ie<kt.length;Ie++){let Tt=kt[Ie];Number.isFinite(Tt)?ee[Ie]=Tt*X+rt:ee[Ie]=Tt}kt=ee}let Dt=Y!==null&&(X!==1||rt!==0)?Y*X+rt:Y,{normalized:Pt}=VPe(kt,Dt,this.fixedDataScale);a.bandData.set(wt,Pt),gt.push(Pt)}a.data=ZPe(gt,F);let ft=!a.vertexBuffer||a.width!==st||a.height!==it;a.width=st,a.height=it,a.channels=F,a.loading=!1,a.levelMeta={width:i.width,height:i.height,regionSize:[...i.regionSize]},a.texture||(a.texture=e.createTexture());let mt=Shi(e,{texture:a.texture,data:a.data,width:st,height:it,channels:F,configured:!1});a.textureUploaded=mt.uploaded,ft&&this.createRegionGeometry(A,t,e,a),this.invalidate()}catch(y){y instanceof DOMException&&y.name==="AbortError"||console.error(`[fetchRegion] Error fetching region ${r}:`,y),a.loading=!1}finally{this.requestCanceller.controllers.delete(n)}}update(A,t){if(this.cachedGl=t,!this.loadingManager.metadataLoading)if(this.isMultiscale&&this.levels.length>0){let e=A.getZoom?.()??0,i=this.selectLevelForZoom(e);if(this.currentLevelIndex===-1){this.initializeLevel(i);return}if(i!==this.currentLevelIndex){this.pendingLevelIndex===null?this.switchToLevel(i):this.pendingLevelIndex!==i&&(this.pendingLevelIndex=i,X_t(this.requestCanceller));return}this.regionSize&&this.baseSliceArgsReady&&this.updateVisibleRegions(A,t)}else{if(!this.regionSize&&this.zarrArray&&!this.loadingManager.chunksLoading){let e=this.getRegionSize(this.zarrArray);this.regionSize=e??[this.height,this.width],this.buildBaseSliceArgs().then(()=>{this.updateVisibleRegions(A,t)});return}this.regionSize&&this.baseSliceArgsReady&&this.updateVisibleRegions(A,t)}}async initializeLevel(A){if(A<0||A>=this.levels.length||this.loadingManager.chunksLoading)return;await this.ensureLevelMetadata(A);let t=this.levels[A];this.currentLevelIndex=A;try{this.zarrArray=await this.zarrStore.getLevelArray(t.asset),this.width=this.zarrArray.shape[this.dimIndices.lon.index],this.height=this.zarrArray.shape[this.dimIndices.lat.index];let e=this.getRegionSize(this.zarrArray);this.regionSize=e??[this.height,this.width],this.regionCache.clear(),await this.buildBaseSliceArgs(),this.invalidate()}catch(e){console.error(`Failed to initialize level ${t.asset}:`,e)}}async buildBaseSliceArgs(){if(!this.zarrArray)return;this.baseSliceArgsReady=!1;let{sliceArgs:A,multiValueDims:t}=await this.buildSliceArgsForSelector(this.selector,{includeSpatialSlices:!1,trackMultiValue:!0});this.baseSliceArgs=A,this.baseMultiValueDims=t,this.baseSliceArgsReady=!0}selectLevelForZoom(A){if(!this.xyLimits||this.levels.length===0)return 0;let t=256*Math.pow(2,A),e;if(this.proj4def&&this.cachedMercatorTransformer){let[r]=this.cachedMercatorTransformer.forward(this.xyLimits.xMin,this.xyLimits.yMin),[n]=this.cachedMercatorTransformer.forward(this.xyLimits.xMax,this.xyLimits.yMax),s=Math.abs(n-r),o=2*zC;e=s/o}else if(this.crs==="EPSG:3857"){let r=this.xyLimits.xMax-this.xyLimits.xMin,n=2*zC;e=r/n}else e=(this.xyLimits.xMax-this.xyLimits.xMin)/360;let i=[];for(let r=0;r<this.levels.length;r++){let n=this.levels[r];if(!n.shape)continue;let s=this.dimIndices.lon?.index??n.shape.length-1,o=n.shape[s]/e;i.push({index:r,effectivePixels:o})}if(i.length===0)return this.levels.length-1;i.sort((r,n)=>r.effectivePixels-n.effectivePixels);for(let{index:r,effectivePixels:n}of i)if(n>=t)return r;return i[i.length-1].index}async switchToLevel(A){if(A===this.currentLevelIndex||A<0||A>=this.levels.length)return;if(this.pendingLevelIndex=A,this.requestCanceller.controllers.size>0){for(let i of this.requestCanceller.controllers.values())i.abort();this.requestCanceller.controllers.clear(),this.loadingManager.chunksLoading=!1,this.emitLoadingState()}await this.ensureLevelMetadata(A);let e=this.levels[A];try{let i=await this.zarrStore.getLevelArray(e.asset),r=i.shape[this.dimIndices.lon.index],n=i.shape[this.dimIndices.lat.index],o=this.getRegionSize(i)??[n,r];if(this.pendingLevelIndex!==A){this.pendingLevelIndex=null,this.invalidate();return}this.currentLevelIndex=A,this.pendingLevelIndex=null,this.zarrArray=i,this.width=r,this.height=n,this.regionSize=o,this.resetVisibleRegions(),await this.buildBaseSliceArgs(),this.invalidate()}catch(i){this.pendingLevelIndex=null,console.error(`Failed to switch to level ${e.asset}:`,i)}}render(A,t){let e=!!t.mapbox,i=!!this.proj4def&&!!this.cached4326Transformer,r=A.getProgram(t.shaderData,t.customShaderConfig,e,i);A.gl.useProgram(r.program),A.applyCommonUniforms(r,t.colormapTexture,this.getUniformsForRender(t.uniforms),t.customShaderConfig,t.projectionData,t.mapbox,t.matrix,!1),this.renderRegions(A,r,t.worldOffsets,t.customShaderConfig)}regionToRenderable(A){return{mercatorBounds:A.mercatorBounds,vertexBuffer:A.vertexBuffer,pixCoordBuffer:A.pixCoordBuffer,vertexCount:A.useIndexedMesh?A.vertexCount:A.vertexArr.length/2,indexBuffer:A.indexBuffer,useIndexedMesh:A.useIndexedMesh,wgs84Bounds:A.wgs84Bounds??void 0,latIsAscending:A.latIsAscending,texture:A.texture,bandData:A.bandData,bandTextures:A.bandTextures,bandTexturesUploaded:A.bandTexturesUploaded,bandTexturesConfigured:A.bandTexturesConfigured,width:A.width,height:A.height}}renderRegions(A,t,e,i){let r=A.gl;HKt(r,t,i);for(let n of this.getLoadedRegions())A6t(r,t,this.regionToRenderable(n),e,i)}renderToTile(A,t,e){return yHe({renderer:A,mode:this,tileId:t,context:{...e,uniforms:this.getUniformsForRender(e.uniforms)},regions:this.getRegionStates()})}onProjectionChange(A){if(this.isGlobeProjection===A)return;this.isGlobeProjection=A;let t=this.cachedGl;if(t){for(let e of this.regionCache.values())e.data&&this.createRegionGeometry(e.regionX,e.regionY,t,e);this.invalidate()}}getTiledState(){return null}getRegionStates(){return this.regionSize?this.getLoadedRegions().map(A=>({texture:A.texture,vertexBuffer:A.vertexBuffer,pixCoordBuffer:A.pixCoordBuffer,vertexArr:A.vertexArr,mercatorBounds:A.mercatorBounds,width:A.width,height:A.height,channels:this.channels,bandData:A.bandData,bandTextures:A.bandTextures,bandTexturesUploaded:A.bandTexturesUploaded,bandTexturesConfigured:A.bandTexturesConfigured,indexBuffer:A.indexBuffer??void 0,vertexCount:A.vertexCount,useIndexedMesh:A.useIndexedMesh,wgs84Bounds:A.wgs84Bounds??void 0,latIsAscending:A.latIsAscending})):[]}dispose(A){this.isRemoved=!0,dHe(this.throttleState),X_t(this.requestCanceller),this.clearRegionCache(A),this.regionSize=null,this.cachedMercatorTransformer=null,this.cachedWGS84Transformer=null,this.cached4326Transformer=null,this.loadingManager.chunksLoading=!1,this.emitLoadingState()}setLoadingCallback(A){fHe(this.loadingManager,A)}getCRS(){return this.crs}getXYLimits(){return this.xyLimits}computeMercatorBoundsFromProjection(){if(!this.proj4def||!this.xyLimits||!this.cachedMercatorTransformer)return{x0:0,y0:0,x1:1,y1:1};let A=IPe(this.xyLimits,this.cachedMercatorTransformer,20);return A||(console.warn("computeMercatorBoundsFromProjection: No valid samples found"),{x0:0,y0:0,x1:1,y1:1})}computeRegionMercatorBounds(A){if(!this.proj4def||!this.cachedMercatorTransformer)return{x0:0,y0:0,x1:1,y1:1};let t=IPe(A,this.cachedMercatorTransformer,5);return t||(console.warn("computeRegionMercatorBounds: No valid samples found"),{x0:0,y0:0,x1:1,y1:1})}getMaxLevelIndex(){return this.levels.length>0?this.levels.length-1:0}getLevels(){return this.levels.map(A=>A.asset)}async setSelector(A){if(this.selector=A,this.bandNames=HT(this.variable,A),!this.cachedGl){this.invalidate();return}!this.regionSize&&this.zarrArray&&(this.regionSize=this.getRegionSize(this.zarrArray)??[this.height,this.width]),this.selectorVersion++,await this.buildBaseSliceArgs(),this.lastViewportHash="",this.invalidate()}emitLoadingState(){this.throttleState.throttledPending&&!this.loadingManager.chunksLoading&&(this.loadingManager.chunksLoading=!0),_He(this.loadingManager)}async resolveSelectionIndex(A,t,e,i){if(i==="index"||!this.zarrStore.root)return typeof e=="number"?e:0;try{let r=await JPe(this.dimensionValues,null,t,this.zarrStore.root,this.zarrStore.version);if(this.dimensionValues[A]=r,typeof e=="number"||typeof e=="string"){let n=r.indexOf(e);if(n>=0)return n;throw new Error(`[ZarrLayer] Selector value '${e}' not found in coordinate array for dimension '${A}'. Available values: [${r.slice(0,10).join(", ")}${r.length>10?", ...":""}]. Use { selected: <index>, type: 'index' } to select by array index instead.`)}}catch(r){console.debug(`Could not resolve coordinate for '${A}':`,r)}return typeof e=="number"?e:0}async fetchQueryData(A,t){if(!this.zarrArray)return null;try{let{sliceArgs:e,multiValueDims:i}=await this.buildSliceArgsForSelector(A,{includeSpatialSlices:t.type!=="bbox",trackMultiValue:!0,spatialBounds:t}),{combinations:r,labelCombinations:n}=this.buildChannelCombinations(i),s=r.length||1,o=i.map(h=>h.dimName);if(t.type==="point"){let h=[];if(s===1){let p=await X2(this.zarrArray,e),d=this.extractScalarValue(p);if(d===null)return null;h.push(d)}else for(let p=0;p<s;p++){let d=[...e],E=r[p];for(let y=0;y<i.length;y++)d[i[y].dimIndex]=E[y];let f=await X2(this.zarrArray,d),Q=this.extractScalarValue(f);Q!==null&&h.push(Q)}return{type:"point",values:h,data:new Float32Array(0),width:1,height:1,channels:s,channelLabels:n,multiValueDimNames:o}}let a=t.maxX-t.minX,l=t.maxY-t.minY;if(s===1){let h=await X2(this.zarrArray,e);return{type:"bbox",values:[],data:new Float32Array(h.data),width:a,height:l,channels:1,channelLabels:n,multiValueDimNames:o}}let g=new Float32Array(a*l*s);for(let h=0;h<s;h++){let p=[...e],d=r[h];for(let f=0;f<i.length;f++)p[i[f].dimIndex]=d[f];let E=await X2(this.zarrArray,p);for(let f=0;f<a*l;f++)g[f*s+h]=E.data[f]}return{type:"bbox",values:[],data:g,width:a,height:l,channels:s,channelLabels:n,multiValueDimNames:o}}catch(e){return console.error("Error fetching query data:",e),null}}extractScalarValue(A){if(A&&typeof A=="object"&&"data"in A){let t=A.data;return t[0]??t}else{if(typeof A=="number")return A;if(ArrayBuffer.isView(A))return A[0]}return console.warn("Unexpected zarr.get result format:",A),null}async queryData(A,t){if(!this.mercatorBounds)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let e=t?aot(t):this.selector,i=this.zarrStore.describe(),r=this.levels[this.currentLevelIndex],n=r?.scaleFactor??i.scaleFactor,s=r?.addOffset??i.addOffset,o=r?.fillValue??i.fill_value;if(A.type==="Point"){let[v,M]=A.coordinates,H={lat:[M],lon:[v]},Y=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,z=Hhi(v,M,this.mercatorBounds,this.width,this.height,this.crs??"EPSG:4326",this.latIsAscending,this.proj4def,Y,this.cachedWGS84Transformer??void 0);if(!z)return{[this.variable]:[],dimensions:["lat","lon"],coordinates:H};let F=await this.fetchQueryData(e,{type:"point",x:z.x,y:z.y});if(!F)return{[this.variable]:[],dimensions:["lat","lon"],coordinates:H};let{values:N,channelLabels:P,multiValueDimNames:K}=F,At=K.length>0,st=At?{}:[];for(let gt=0;gt<N.length;gt++){let ft=N[gt];if(!(ft==null||!Number.isFinite(ft))&&!(o!==null&&ft===o))if(n!==1&&(ft*=n),s!==0&&(ft+=s),At){let mt=P?.[gt];mt&&K.length>0&&mt.length===K.length?st=jKt(st,mt,ft):Array.isArray(st)&&st.push(ft)}else Array.isArray(st)&&st.push(ft)}let it=i.dimensions,W=it.map(gt=>{let ft=gt.toLowerCase();return["x","lon","longitude"].includes(ft)?"lon":["y","lat","latitude"].includes(ft)?"lat":gt}),X=At?W:["lat","lon"],rt={lat:H.lat,lon:H.lon};if(At)for(let gt of it){let ft=gt.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(ft))continue;let mt=e[gt];if(mt&&"selected"in mt){let St=mt.selected,wt=Array.isArray(St)?St:[St];rt[gt]=wt}else i.coordinates[gt]&&(rt[gt]=i.coordinates[gt])}return{[this.variable]:st,dimensions:X,coordinates:rt}}let a=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,l=Mhi(A,this.mercatorBounds,this.width,this.height,this.crs??"EPSG:4326",this.latIsAscending,this.proj4def,a,this.cachedWGS84Transformer??void 0);if(!l)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let g=await this.fetchQueryData(e,{type:"bbox",...l});if(!g)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let{minX:h,maxX:p,minY:d,maxY:E}=l,f=this.mercatorBounds.x1-this.mercatorBounds.x0,Q=this.mercatorBounds.y1-this.mercatorBounds.y0,y={x0:this.mercatorBounds.x0+h/this.width*f,x1:this.mercatorBounds.x0+p/this.width*f,y0:this.mercatorBounds.y0+d/this.height*Q,y1:this.mercatorBounds.y0+E/this.height*Q};if(this.mercatorBounds.latMin!==void 0&&this.mercatorBounds.latMax!==void 0){let v=this.mercatorBounds.latMax-this.mercatorBounds.latMin;this.latIsAscending?(y.latMin=this.mercatorBounds.latMin+d/this.height*v,y.latMax=this.mercatorBounds.latMin+E/this.height*v):(y.latMax=this.mercatorBounds.latMax-d/this.height*v,y.latMin=this.mercatorBounds.latMax-E/this.height*v)}let S=null;if(this.proj4def&&a){let[v,M]=i6t(h,d,a,this.width,this.height,this.latIsAscending),[H,Y]=i6t(p,E,a,this.width,this.height,this.latIsAscending);S=[Math.min(v,H),Math.min(M,Y),Math.max(v,H),Math.max(M,Y)]}return Jhi(this.variable,A,e,g.data,g.width,g.height,y,this.crs??"EPSG:4326",i.dimensions,i.coordinates,g.channels,g.channelLabels,g.multiValueDimNames,this.latIsAscending,{scaleFactor:n,addOffset:s,fillValue:o},this.proj4def,S)}},xHe=class{constructor({id:A,source:t,variable:e,selector:i={},colormap:r,clim:n,opacity:s=1,minzoom:o=0,maxzoom:a=1/0,zarrVersion:l,spatialDimensions:g={},bounds:h,crs:p,latIsAscending:d=null,fillValue:E,customFrag:f,uniforms:Q,renderingMode:y="3d",onLoadingStateChange:S,throttleMs:v=100,proj4:M,transformRequest:H}){if(this.type="custom",this.zarrVersion=null,this.latIsAscending=null,this.selectorHash="",this._fillValue=null,this.scaleFactor=1,this.offset=0,this.dataScaleLocked=!1,this.map=null,this.renderer=null,this.mode=null,this.tileNeedsRender=!0,this.projectionChangeHandler=null,this.zarrStore=null,this.levelInfos=[],this.dimIndices={},this.dimensionValues={},this.normalizedSelector={},this.isRemoved=!1,this.fragmentShaderSource=lhi,this.customUniforms={},this.bandNames=[],this.customShaderConfig=null,this.metadataLoading=!1,this.chunksLoading=!1,this.initError=null,this.lastIsGlobe=null,this.handleChunkLoadingChange=Y=>{this.chunksLoading=Y.chunks,this.emitLoadingState()},!A)throw new Error("[ZarrLayer] id is required");if(!t)throw new Error("[ZarrLayer] source is required");if(!e)throw new Error("[ZarrLayer] variable is required");if(!r||!Array.isArray(r)||r.length===0)throw new Error("[ZarrLayer] colormap is required and must be an array of [r, g, b] or hex string values");if(!n||!Array.isArray(n)||n.length!==2)throw new Error("[ZarrLayer] clim is required and must be [min, max]");M&&!h&&console.warn("[ZarrLayer] proj4 provided without explicit bounds. Bounds will be derived from coordinate arrays if available (see subsequent log for values). For best performance, provide bounds in source CRS units."),this.id=A,this.url=t,this.variable=e,this.zarrVersion=l??null,this.spatialDimensions=g,this.bounds=h,this.crs=p,this.latIsAscending=d??null,this.selector=i,this.normalizedSelector=aot(i),this.selectorHash=this.computeSelectorHash(this.normalizedSelector),this.renderingMode=y,this.invalidate=()=>{},this.colormap=new uhi(r),this.clim=n,this.fixedDataScale=Math.max(Math.abs(n[0]),Math.abs(n[1]),1),this.opacity=s,this.minZoom=o,this.maxZoom=a,this.customFrag=f,this.customUniforms=Q||{},this.bandNames=HT(e,this.normalizedSelector),(this.bandNames.length>1||f)&&(this.customShaderConfig={bands:this.bandNames,customFrag:f,customUniforms:this.customUniforms}),E!==void 0&&(this._fillValue=E),this.onLoadingStateChange=S,this.throttleMs=v,this.proj4=M,this.transformRequest=H}resolveGl(A,t){if(t&&typeof t.getUniformLocation=="function"&&typeof t.drawBuffers=="function")return t;let i=r=>r?{type:r.constructor?.name,keys:Object.keys(r)}:null;throw console.error("Invalid WebGL2 context passed to onAdd",{providedGl:i(t),painterGl:i(A?.painter?.context?.gl),rendererGl:i(A?.renderer?.getContext?.())}),new Error("`map` did not provide a valid WebGL2 context")}get fillValue(){return this._fillValue}isGlobeProjection(){let A=this.map?.getProjection?this.map.getProjection():null;return nHe(A)}syncProjectionState(){let A=this.isGlobeProjection();return this.lastIsGlobe!==null&&this.lastIsGlobe!==A&&this.mode?.onProjectionChange(A),this.lastIsGlobe=A,A}emitLoadingState(){this.onLoadingStateChange&&this.onLoadingStateChange({loading:this.metadataLoading||this.chunksLoading,metadata:this.metadataLoading,chunks:this.chunksLoading,error:this.initError})}setOpacity(A){this.opacity=A,this.invalidate()}setClim(A){this.clim=A,this.dataScaleLocked||(this.fixedDataScale=Math.max(Math.abs(A[0]),Math.abs(A[1]),1)),this.invalidate()}setColormap(A){this.colormap.apply(A),this.gl&&this.colormap.upload(this.gl),this.invalidate()}setUniforms(A){if(!this.customShaderConfig){console.warn("[ZarrLayer] setUniforms() called but layer was not created with customFrag. Uniforms will not be applied. Recreate the layer with customFrag and uniforms options.");return}this.customUniforms={...this.customUniforms,...A},this.customShaderConfig.customUniforms=this.customUniforms,this.invalidate()}async setVariable(A){if(A!==this.variable){this.metadataLoading=!0,this.emitLoadingState();try{this.initError=null,this.variable=A,this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null),this.dimensionValues={},this._fillValue=null,this.dataScaleLocked=!1,this.fixedDataScale=Math.max(Math.abs(this.clim[0]),Math.abs(this.clim[1]),1),await this.initialize(),await this.initializeMode(),this.invalidate()}catch(t){this.initError=t instanceof Error?t:new Error(String(t)),console.error("[zarr-layer] Failed to reset:",this.initError.message),this.mode&&this.gl&&(this.mode.dispose(this.gl),this.mode=null),this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null)}finally{this.metadataLoading=!1,this.emitLoadingState()}}}async setSelector(A){let t=aot(A),e=this.computeSelectorHash(t);e!==this.selectorHash&&(this.selectorHash=e,this.selector=A,this.normalizedSelector=t,this.bandNames=HT(this.variable,this.normalizedSelector),this.bandNames.length>1||this.customFrag?this.customShaderConfig={bands:this.bandNames,customFrag:this.customFrag,customUniforms:this.customUniforms}:this.customShaderConfig=null,this.mode&&await this.mode.setSelector(this.normalizedSelector),this.invalidate())}onAdd(A,t){this._onAddAsync(A,t)}async _onAddAsync(A,t){this.map=A;let e=this.resolveGl(A,t);this.gl=e,this.invalidate=()=>{this.tileNeedsRender=!0,A.triggerRepaint&&A.triggerRepaint()},this.initError=null,this.metadataLoading=!0,this.emitLoadingState();try{this.colormap.upload(e),this.renderer=new Dhi(e,this.fragmentShaderSource),this.projectionChangeHandler=()=>{let r=this.isGlobeProjection();this.mode?.onProjectionChange(r)},typeof A.on=="function"&&this.projectionChangeHandler&&(A.on("projectionchange",this.projectionChangeHandler),A.on("style.load",this.projectionChangeHandler)),await this.initialize(),await this.initializeMode();let i=this.isGlobeProjection();this.lastIsGlobe=i,this.mode?.onProjectionChange(i),this.mode?.update(this.map,this.gl)}catch(i){this.initError=i instanceof Error?i:new Error(String(i)),console.error(`[zarr-layer] Failed to initialize: ${this.initError.message}. Use onLoadingStateChange callback to handle errors and call map.removeLayer('${this.id}') to clean up.`),this._disposeResources(e)}finally{this.metadataLoading=!1,this.emitLoadingState()}this.initError||this.invalidate()}computeSelectorHash(A){let t=e=>{if(Array.isArray(e)||e===null||typeof e!="object")return e;let i=e,r={};return Object.keys(i).sort().forEach(n=>{r[n]=t(i[n])}),r};return JSON.stringify(t(A))}async initializeMode(){if(!this.zarrStore||!this.gl)return;this.mode&&this.mode.dispose(this.gl),this.zarrStore.describe().multiscaleType==="tiled"?this.mode=new $hi(this.zarrStore,this.variable,this.normalizedSelector,this.invalidate,this.throttleMs,this.fixedDataScale):this.mode=new lui(this.zarrStore,this.variable,this.normalizedSelector,this.invalidate,this.throttleMs,this.fixedDataScale),this.dataScaleLocked=!0,this.mode.setLoadingCallback(this.handleChunkLoadingChange),await this.mode.initialize(),this.map&&this.gl&&this.mode.update(this.map,this.gl)}async initialize(){try{this.zarrStore=new Vci({source:this.url,version:this.zarrVersion,variable:this.variable,spatialDimensions:this.spatialDimensions,bounds:this.bounds,crs:this.crs,latIsAscending:this.latIsAscending,coordinateKeys:Object.keys(this.selector),proj4:this.proj4,transformRequest:this.transformRequest}),await this.zarrStore.initialized;let A=this.zarrStore.describe();this.levelInfos=A.levels,this.dimIndices=A.dimIndices,this.scaleFactor=A.scaleFactor,this.offset=A.addOffset,this._fillValue===null&&A.fill_value!==null&&A.fill_value!==void 0&&(this._fillValue=A.fill_value),this.normalizedSelector=aot(this.selector),await this.loadInitialDimensionValues(),this.bandNames=HT(this.variable,this.normalizedSelector),this.bandNames.length>1||this.customFrag?this.customShaderConfig={bands:this.bandNames,customFrag:this.customFrag,customUniforms:this.customUniforms}:this.customShaderConfig=null}catch(A){throw this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null),A}}async loadInitialDimensionValues(){if(!this.zarrStore?.root)return;let A=this.levelInfos.length>0?this.levelInfos[0]:null;for(let[t,e]of Object.entries(this.selector))this.normalizedSelector[t]=jPe(e);for(let t of Object.keys(this.dimIndices))if(!Yci.has(t.toLowerCase()))try{this.dimensionValues[t]=await JPe(this.dimensionValues,A,this.dimIndices[t],this.zarrStore.root,this.zarrStore.version),this.normalizedSelector[t]||(this.normalizedSelector[t]={selected:0})}catch(e){console.warn(`Failed to load dimension values for ${t}:`,e)}}isZoomInRange(){if(!this.map?.getZoom)return!0;let A=this.map.getZoom();return A>=this.minZoom&&A<=this.maxZoom}prerender(A,t){this.isRemoved||!this.gl||!this.mode||!this.map||this.isZoomInRange()&&(this.syncProjectionState(),this.mode.update(this.map,this.gl))}render(A,t,e,i,r,n,s){if(this.isRemoved||!this.renderer||!this.gl||!this.mode||!this.map||!this.isZoomInRange())return;let o=yhi(t,e,i,r);if(!o.matrix)return;let a=!o.mapbox&&!o.shaderData?{projection:{name:"mercator"},globeToMercatorMatrix:$q,transition:1}:void 0,l=this.isGlobeProjection(),g=xhi(this.map,l),h=this.colormap.ensureTexture(this.gl),p={gl:this.gl,matrix:o.matrix,uniforms:{clim:this.clim,opacity:this.opacity,fillValue:this._fillValue,scaleFactor:this.scaleFactor,offset:this.offset,fixedDataScale:this.fixedDataScale},colormapTexture:h,worldOffsets:g,customShaderConfig:this.customShaderConfig||void 0,shaderData:o.shaderData,projectionData:o.projectionData,mapbox:o.mapbox??a};this.mode.render(this.renderer,p),this.tileNeedsRender=!1}renderToTile(A,t){if(this.isRemoved||!this.renderer||!this.gl||!this.mode||!this.map)return;let e=this.syncProjectionState();this.mode.update(this.map,this.gl);let i=this.colormap.ensureTexture(this.gl),r={gl:this.gl,matrix:new Float32Array(16),uniforms:{clim:this.clim,opacity:this.opacity,fillValue:this._fillValue,scaleFactor:this.scaleFactor,offset:this.offset,fixedDataScale:this.fixedDataScale},colormapTexture:i,worldOffsets:[0],customShaderConfig:this.customShaderConfig||void 0,isGlobe:e};this.tileNeedsRender=this.mode.renderToTile?.(this.renderer,t,r)??!1}shouldRerenderTiles(){let A=this.tileNeedsRender;return this.tileNeedsRender=!1,A}_disposeResources(A){this.isRemoved=!0,this.renderer?.dispose(),this.renderer=null,this.colormap.dispose(A),this.mode?.dispose(A),this.mode=null,this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null),this.map&&this.projectionChangeHandler&&typeof this.map.off=="function"&&(this.map.off("projectionchange",this.projectionChangeHandler),this.map.off("style.load",this.projectionChangeHandler))}onRemove(A,t){let e=this.gl??this.resolveGl(A,t);this._disposeResources(e)}async queryData(A,t){return this.mode?.queryData?this.mode.queryData(A,t):{[this.variable]:[],dimensions:["lat","lon"],coordinates:{lat:[],lon:[]}}}};var a6t=class{model;el;map=null;mapContainer=null;lastProcessedCallId=0;pendingCalls=[];eventQueue=[];isMapReady=!1;methodHandlers=new Map;modelListeners=[];constructor(t,e){this.model=t,this.el=e}createMapContainer(){let t=this.model.get("width")||"100%",e=this.model.get("height")||"400px";this.el.style.width="100%",this.el.style.display="block",e.endsWith("%")&&(this.el.style.height="100%");let i=document.createElement("div");return i.style.width=t,i.style.height=e,i.style.position="relative",i.style.minWidth="200px",this.el.appendChild(i),this.mapContainer=i,i}setupModelListeners(){let t=()=>this.processJsCalls(),e=()=>this.onCenterChange(),i=()=>this.onZoomChange(),r=()=>this.onStyleChange();this.model.on("change:_js_calls",t),this.model.on("change:center",e),this.model.on("change:zoom",i),this.model.on("change:style",r),this.modelListeners.push(()=>this.model.off("change:_js_calls",t),()=>this.model.off("change:center",e),()=>this.model.off("change:zoom",i),()=>this.model.off("change:style",r))}removeModelListeners(){this.modelListeners.forEach(t=>t()),this.modelListeners=[]}registerMethod(t,e){this.methodHandlers.set(t,e)}executeMethod(t,e,i){let r=this.methodHandlers.get(t);if(r)try{r(e,i)}catch(n){console.error(`Error executing method ${t}:`,n)}else console.warn(`Unknown method: ${t}`)}processJsCalls(){let e=(this.model.get("_js_calls")||[]).filter(i=>i.id>this.lastProcessedCallId);for(let i of e)this.isMapReady?this.executeMethod(i.method,i.args,i.kwargs):this.pendingCalls.push(i),this.lastProcessedCallId=i.id}processPendingCalls(){for(let t of this.pendingCalls)this.executeMethod(t.method,t.args,t.kwargs);this.pendingCalls=[]}sendEvent(t,e){let i={type:t,data:e,timestamp:Date.now()};this.eventQueue.push(i),this.model.set("_js_events",[...this.eventQueue]),this.model.save_changes()}restoreState(){let t=this.model.get("_sources")||{};for(let[g,h]of Object.entries(t))this.executeMethod("addSource",[g],h);let e=new Set(["fill","line","symbol","circle","heatmap","fill-extrusion","raster","hillshade","color-relief","background"]),i=this.model.get("_layers")||{},r=Object.entries(i).filter(([,g])=>e.has(g.type)),n=r.filter(([g,h])=>g.startsWith("basemap-")||h.type==="raster"),s=r.filter(([g,h])=>!(g.startsWith("basemap-")||h.type==="raster")),o=[...n,...s];for(let[g,h]of o)this.executeMethod("addLayer",[],h);let a=this.model.get("_controls")||{},l=Object.keys(i);for(let[g,h]of Object.entries(a)){let p=h;p.type==="layer-control"?this.executeMethod("addLayerControl",[],{position:p.position,layers:l,...p.options}):p.type==="draw-control"?this.executeMethod("addDrawControl",[],{position:p.position,...p.options}):p.type==="control-grid"?this.executeMethod("addControlGrid",[],{position:p.position,...p.options}):this.executeMethod("addControl",[p.type],{position:p.position,...p.options})}}getMap(){return this.map}getIsMapReady(){return this.isMapReady}getModel(){return this.model}};var l6t=class{model;constructor(t){this.model=t}addLayer(t,e){let i=this.model.get("_layers")||{},r={id:e.id,type:e.type,source:e.source,paint:e.paint,layout:e.layout,visible:!0,opacity:1};this.model.set("_layers",{...i,[t]:r}),this.model.save_changes()}removeLayer(t){let e={...this.model.get("_layers")};delete e[t],this.model.set("_layers",e),this.model.save_changes()}setLayerVisibility(t,e){let i={...this.model.get("_layers")};i[t]&&(i[t]={...i[t],visible:e},this.model.set("_layers",i),this.model.save_changes())}setLayerOpacity(t,e){let i={...this.model.get("_layers")};i[t]&&(i[t]={...i[t],opacity:e},this.model.set("_layers",i),this.model.save_changes())}setLayerFilter(t,e){let i={...this.model.get("_layers")};if(i[t]){let{filter:r,...n}=i[t];i[t]=e?{...n,filter:e}:{...n},this.model.set("_layers",i),this.model.save_changes()}}getLayer(t){return this.model.get("_layers")?.[t]}getLayers(){return this.model.get("_layers")||{}}addSource(t,e){let i=this.model.get("_sources")||{},r={type:e.type,data:e.data,url:e.url,urls:e.urls,tiles:e.tiles,tileSize:e.tileSize,attribution:e.attribution,coordinates:e.coordinates};this.model.set("_sources",{...i,[t]:r}),this.model.save_changes()}removeSource(t){let e={...this.model.get("_sources")};delete e[t],this.model.set("_sources",e),this.model.save_changes()}getSource(t){return this.model.get("_sources")?.[t]}getSources(){return this.model.get("_sources")||{}}addControl(t,e,i,r){let n=this.model.get("_controls")||{},s={type:e,position:i,options:r};this.model.set("_controls",{...n,[t]:s}),this.model.save_changes()}removeControl(t){let e={...this.model.get("_controls")};delete e[t],this.model.set("_controls",e),this.model.save_changes()}getControl(t){return this.model.get("_controls")?.[t]}getControls(){return this.model.get("_controls")||{}}};vVt();var EKe=xg(kx(),1),a1=63710088e-1,fKe={centimeters:a1*100,centimetres:a1*100,degrees:360/(2*Math.PI),feet:a1*3.28084,inches:a1*39.37,kilometers:a1/1e3,kilometres:a1/1e3,meters:a1,metres:a1,miles:a1/1609.344,millimeters:a1*1e3,millimetres:a1*1e3,nauticalmiles:a1/1852,radians:1,yards:a1*1.0936};function Xf(A,t,e={}){let i={type:"Feature"};return(e.id===0||e.id)&&(i.id=e.id),e.bbox&&(i.bbox=e.bbox),i.properties=t||{},i.geometry=A,i}function l9(A,t,e={}){if(!A)throw new Error("coordinates is required");if(!Array.isArray(A))throw new Error("coordinates must be an Array");if(A.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!yqe(A[0])||!yqe(A[1]))throw new Error("coordinates must contain numbers");return Xf({type:"Point",coordinates:A},t,e)}function DQ(A,t,e={}){for(let r of A){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let n=0;n<r[r.length-1].length;n++)if(r[r.length-1][n]!==r[0][n])throw new Error("First and last Position are not equivalent.")}return Xf({type:"Polygon",coordinates:A},t,e)}function $C(A,t,e={}){if(A.length<2)throw new Error("coordinates must be an array of two or more positions");return Xf({type:"LineString",coordinates:A},t,e)}function Xl(A,t={}){let e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=A,e}function _Ke(A,t,e={}){return Xf({type:"MultiLineString",coordinates:A},t,e)}function RQt(A,t,e={}){return Xf({type:"MultiPolygon",coordinates:A},t,e)}function cZt(A,t="kilometers"){let e=fKe[t];if(!e)throw new Error(t+" units is invalid");return A*e}function mKe(A,t="kilometers"){let e=fKe[t];if(!e)throw new Error(t+" units is invalid");return A/e}function oQt(A){return A%(2*Math.PI)*180/Math.PI}function QE(A){return A%360*Math.PI/180}function QKe(A,t="kilometers",e="kilometers"){if(!(A>=0))throw new Error("length must be a positive number");return cZt(mKe(A,t),e)}function yqe(A){return!isNaN(A)&&A!==null&&!Array.isArray(A)}function Dat(A){return A!==null&&typeof A=="object"&&!Array.isArray(A)}function g9(A){if(!A)throw new Error("coord is required");if(!Array.isArray(A)){if(A.type==="Feature"&&A.geometry!==null&&A.geometry.type==="Point")return[...A.geometry.coordinates];if(A.type==="Point")return[...A.coordinates]}if(Array.isArray(A)&&A.length>=2&&!Array.isArray(A[0])&&!Array.isArray(A[1]))return[...A];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function iC(A){if(Array.isArray(A))return A;if(A.type==="Feature"){if(A.geometry!==null)return A.geometry.coordinates}else if(A.coordinates)return A.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function kQ(A){return A.type==="Feature"?A.geometry:A}function aQt(A,t){return A.type==="FeatureCollection"?"FeatureCollection":A.type==="GeometryCollection"?"GeometryCollection":A.type==="Feature"&&A.geometry!==null?A.geometry.type:A.type}function yKe(A,t,e={}){if(e.final===!0)return c6i(A,t);let i=g9(A),r=g9(t),n=QE(i[0]),s=QE(r[0]),o=QE(i[1]),a=QE(r[1]),l=Math.sin(s-n)*Math.cos(a),g=Math.cos(o)*Math.sin(a)-Math.sin(o)*Math.cos(a)*Math.cos(s-n);return oQt(Math.atan2(l,g))}function c6i(A,t){let e=yKe(t,A);return e=(e+180)%360,e}function xat(A,t,e={}){var i=g9(A),r=g9(t),n=QE(r[1]-i[1]),s=QE(r[0]-i[0]),o=QE(i[1]),a=QE(r[1]),l=Math.pow(Math.sin(n/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(o)*Math.cos(a);return cZt(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),e.units)}function h6i(A,t,e={}){let i;return e.final?i=xqe(g9(t),g9(A)):i=xqe(g9(A),g9(t)),i>180?-(360-i):i}function xqe(A,t){let e=QE(A[1]),i=QE(t[1]),r=QE(t[0]-A[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);let n=Math.log(Math.tan(i/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(r,n);return(oQt(s)+360)%360}function rM(A,t,e){if(A!==null)for(var i,r,n,s,o,a,l,g=0,h=0,p,d=A.type,E=d==="FeatureCollection",f=d==="Feature",Q=E?A.features.length:1,y=0;y<Q;y++){l=E?A.features[y].geometry:f?A.geometry:A,p=l?l.type==="GeometryCollection":!1,o=p?l.geometries.length:1;for(var S=0;S<o;S++){var v=0,M=0;if(s=p?l.geometries[S]:l,s!==null){a=s.coordinates;var H=s.type;switch(g=e&&(H==="Polygon"||H==="MultiPolygon")?1:0,H){case null:break;case"Point":if(t(a,h,y,v,M)===!1)return!1;h++,v++;break;case"LineString":case"MultiPoint":for(i=0;i<a.length;i++){if(t(a[i],h,y,v,M)===!1)return!1;h++,H==="MultiPoint"&&v++}H==="LineString"&&v++;break;case"Polygon":case"MultiLineString":for(i=0;i<a.length;i++){for(r=0;r<a[i].length-g;r++){if(t(a[i][r],h,y,v,M)===!1)return!1;h++}H==="MultiLineString"&&v++,H==="Polygon"&&M++}H==="Polygon"&&v++;break;case"MultiPolygon":for(i=0;i<a.length;i++){for(M=0,r=0;r<a[i].length;r++){for(n=0;n<a[i][r].length-g;n++){if(t(a[i][r][n],h,y,v,M)===!1)return!1;h++}M++}v++}break;case"GeometryCollection":for(i=0;i<s.geometries.length;i++)if(rM(s.geometries[i],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function fv(A,t){if(A.type==="Feature")t(A,0);else if(A.type==="FeatureCollection")for(var e=0;e<A.features.length&&t(A.features[e],e)!==!1;e++);}function u6i(A,t,e){var i=e;return fv(A,function(r,n){n===0&&e===void 0?i=r:i=t(i,r,n)}),i}function I6i(A){var t=[];return rM(A,function(e){t.push(e)}),t}function nM(A,t){var e,i,r,n,s,o,a,l,g,h,p=0,d=A.type==="FeatureCollection",E=A.type==="Feature",f=d?A.features.length:1;for(e=0;e<f;e++){for(o=d?A.features[e].geometry:E?A.geometry:A,l=d?A.features[e].properties:E?A.properties:{},g=d?A.features[e].bbox:E?A.bbox:void 0,h=d?A.features[e].id:E?A.id:void 0,a=o?o.type==="GeometryCollection":!1,s=a?o.geometries.length:1,r=0;r<s;r++){if(n=a?o.geometries[r]:o,n===null){if(t(null,p,l,g,h)===!1)return!1;continue}switch(n.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(n,p,l,g,h)===!1)return!1;break}case"GeometryCollection":{for(i=0;i<n.geometries.length;i++)if(t(n.geometries[i],p,l,g,h)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}p++}}function p6i(A,t,e){var i=e;return nM(A,function(r,n,s,o,a){i=t(i,r,n,s,o,a)}),i}function _v(A,t){nM(A,function(e,i,r,n,s){var o=e===null?null:e.type;switch(o){case null:case"Point":case"LineString":case"Polygon":return t(Xf(e,r,{bbox:n,id:s}),i,0)===!1?!1:void 0}var a;switch(o){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon";break}for(var l=0;l<e.coordinates.length;l++){var g=e.coordinates[l],h={type:a,coordinates:g};if(t(Xf(h,r),i,l)===!1)return!1}})}function uat(A,t){_v(A,function(e,i,r){var n=0;if(e.geometry){var s=e.geometry.type;if(!(s==="Point"||s==="MultiPoint")){var o,a=0,l=0,g=0;if(rM(e,function(h,p,d,E,f){if(o===void 0||i>a||E>l||f>g){o=h,a=i,l=E,g=f,n=0;return}var Q=$C([o,h],e.properties);if(t(Q,i,r,f,n)===!1)return!1;n++,o=h})===!1)return!1}}})}function lQt(A){return p6i(A,(t,e)=>t+d6i(e),0)}function d6i(A){let t=0,e;switch(A.type){case"Polygon":return wqe(A.coordinates);case"MultiPolygon":for(e=0;e<A.coordinates.length;e++)t+=wqe(A.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function wqe(A){let t=0;if(A&&A.length>0){t+=Math.abs(bqe(A[0]));for(let e=1;e<A.length;e++)t-=Math.abs(bqe(A[e]))}return t}var C6i=a1*a1/2,DVt=Math.PI/180;function bqe(A){let t=A.length-1;if(t<=2)return 0;let e=0,i=0;for(;i<t;){let r=A[i],n=A[i+1===t?0:i+1],s=A[i+2>=t?(i+2)%t:i+2],o=r[0]*DVt,a=n[1]*DVt,l=s[0]*DVt;e+=(l-o)*Math.sin(a),i++}return e*C6i}function SI(A,t={}){if(A.bbox!=null&&t.recompute!==!0)return A.bbox;let e=[1/0,1/0,-1/0,-1/0];return rM(A,i=>{e[0]>i[0]&&(e[0]=i[0]),e[1]>i[1]&&(e[1]=i[1]),e[2]<i[0]&&(e[2]=i[0]),e[3]<i[1]&&(e[3]=i[1])}),e}function B6i(A,t,e){var i=A.length,r=YK(A[0],t),n=[],s,o,a;let l,g;for(e||(e=[]),s=1;s<i;s++){for(l=A[s-1],g=A[s],o=a=YK(g,t);;)if(r|o){if(r&o)break;r?(l=qVt(l,g,r,t),r=YK(l,t)):(g=qVt(l,g,o,t),o=YK(g,t))}else{n.push(l),o!==a?(n.push(g),s<i-1&&(e.push(n),n=[])):s===i-1&&n.push(g);break}r=a}return n.length&&e.push(n),e}function E6i(A,t){var e,i,r,n,s,o,a;for(i=1;i<=8;i*=2){for(e=[],r=A[A.length-1],n=!(YK(r,t)&i),s=0;s<A.length;s++)o=A[s],a=!(YK(o,t)&i),a!==n&&e.push(qVt(r,o,i,t)),a&&e.push(o),r=o,n=a;if(A=e,!A.length)break}return e}function qVt(A,t,e,i){return e&8?[A[0]+(t[0]-A[0])*(i[3]-A[1])/(t[1]-A[1]),i[3]]:e&4?[A[0]+(t[0]-A[0])*(i[1]-A[1])/(t[1]-A[1]),i[1]]:e&2?[i[2],A[1]+(t[1]-A[1])*(i[2]-A[0])/(t[0]-A[0])]:e&1?[i[0],A[1]+(t[1]-A[1])*(i[0]-A[0])/(t[0]-A[0])]:null}function YK(A,t){var e=0;return A[0]<t[0]?e|=1:A[0]>t[2]&&(e|=2),A[1]<t[1]?e|=4:A[1]>t[3]&&(e|=8),e}function f6i(A,t){let e=kQ(A),i=e.type,r=A.type==="Feature"?A.properties:{},n=e.coordinates;switch(i){case"LineString":case"MultiLineString":{let s=[];return i==="LineString"&&(n=[n]),n.forEach(o=>{B6i(o,t,s)}),s.length===1?$C(s[0],r):_Ke(s,r)}case"Polygon":return DQ(Sqe(n,t),r);case"MultiPolygon":return RQt(n.map(s=>Sqe(s,t)),r);default:throw new Error("geometry "+i+" not supported")}}function Sqe(A,t){let e=[];for(let i of A){let r=E6i(i,t);r.length>0&&((r[0][0]!==r[r.length-1][0]||r[0][1]!==r[r.length-1][1])&&r.push(r[0]),r.length>=4&&e.push(r))}return e}var Ev=11102230246251565e-32,XC=134217729,_6i=(3+8*Ev)*Ev;function kVt(A,t,e,i,r){let n,s,o,a,l=t[0],g=i[0],h=0,p=0;g>l==g>-l?(n=l,l=t[++h]):(n=g,g=i[++p]);let d=0;if(h<A&&p<e)for(g>l==g>-l?(s=l+n,o=n-(s-l),l=t[++h]):(s=g+n,o=n-(s-g),g=i[++p]),n=s,o!==0&&(r[d++]=o);h<A&&p<e;)g>l==g>-l?(s=n+l,a=s-n,o=n-(s-a)+(l-a),l=t[++h]):(s=n+g,a=s-n,o=n-(s-a)+(g-a),g=i[++p]),n=s,o!==0&&(r[d++]=o);for(;h<A;)s=n+l,a=s-n,o=n-(s-a)+(l-a),l=t[++h],n=s,o!==0&&(r[d++]=o);for(;p<e;)s=n+g,a=s-n,o=n-(s-a)+(g-a),g=i[++p],n=s,o!==0&&(r[d++]=o);return(n!==0||d===0)&&(r[d++]=n),d}function m6i(A,t){let e=t[0];for(let i=1;i<A;i++)e+=t[i];return e}function kat(A){return new Float64Array(A)}var Q6i=(3+16*Ev)*Ev,y6i=(2+12*Ev)*Ev,x6i=(9+64*Ev)*Ev*Ev,TK=kat(4),vqe=kat(8),Dqe=kat(12),kqe=kat(16),mE=kat(4);function w6i(A,t,e,i,r,n,s){let o,a,l,g,h,p,d,E,f,Q,y,S,v,M,H,Y,z,F,N=A-r,P=e-r,K=t-n,At=i-n;M=N*At,p=XC*N,d=p-(p-N),E=N-d,p=XC*At,f=p-(p-At),Q=At-f,H=E*Q-(M-d*f-E*f-d*Q),Y=K*P,p=XC*K,d=p-(p-K),E=K-d,p=XC*P,f=p-(p-P),Q=P-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,TK[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,TK[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,TK[2]=S-(F-h)+(y-h),TK[3]=F;let st=m6i(4,TK),it=y6i*s;if(st>=it||-st>=it||(h=A-N,o=A-(N+h)+(h-r),h=e-P,l=e-(P+h)+(h-r),h=t-K,a=t-(K+h)+(h-n),h=i-At,g=i-(At+h)+(h-n),o===0&&a===0&&l===0&&g===0)||(it=x6i*s+_6i*Math.abs(st),st+=N*g+At*o-(K*l+P*a),st>=it||-st>=it))return st;M=o*At,p=XC*o,d=p-(p-o),E=o-d,p=XC*At,f=p-(p-At),Q=At-f,H=E*Q-(M-d*f-E*f-d*Q),Y=a*P,p=XC*a,d=p-(p-a),E=a-d,p=XC*P,f=p-(p-P),Q=P-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,mE[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,mE[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,mE[2]=S-(F-h)+(y-h),mE[3]=F;let W=kVt(4,TK,4,mE,vqe);M=N*g,p=XC*N,d=p-(p-N),E=N-d,p=XC*g,f=p-(p-g),Q=g-f,H=E*Q-(M-d*f-E*f-d*Q),Y=K*l,p=XC*K,d=p-(p-K),E=K-d,p=XC*l,f=p-(p-l),Q=l-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,mE[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,mE[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,mE[2]=S-(F-h)+(y-h),mE[3]=F;let X=kVt(W,vqe,4,mE,Dqe);M=o*g,p=XC*o,d=p-(p-o),E=o-d,p=XC*g,f=p-(p-g),Q=g-f,H=E*Q-(M-d*f-E*f-d*Q),Y=a*l,p=XC*a,d=p-(p-a),E=a-d,p=XC*l,f=p-(p-l),Q=l-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,mE[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,mE[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,mE[2]=S-(F-h)+(y-h),mE[3]=F;let rt=kVt(X,Dqe,4,mE,kqe);return kqe[rt-1]}function b6i(A,t,e,i,r,n){let s=(t-n)*(e-r),o=(A-r)*(i-n),a=s-o,l=Math.abs(s+o);return Math.abs(a)>=Q6i*l?a:-w6i(A,t,e,i,r,n,l)}function S6i(A,t){var e,i,r=0,n,s,o,a,l,g,h,p=A[0],d=A[1],E=t.length;for(e=0;e<E;e++){i=0;var f=t[e],Q=f.length-1;if(g=f[0],g[0]!==f[Q][0]&&g[1]!==f[Q][1])throw new Error("First and last coordinates in a ring must be the same");for(s=g[0]-p,o=g[1]-d,i;i<Q;i++){if(h=f[i+1],a=h[0]-p,l=h[1]-d,o===0&&l===0){if(a<=0&&s>=0||s<=0&&a>=0)return 0}else if(l>=0&&o<=0||l<=0&&o>=0){if(n=b6i(s,a,o,l,0,0),n===0)return 0;(n>0&&l>0&&o<=0||n<0&&l<=0&&o>0)&&r++}g=h,o=l,s=a}}return r%2!==0}function c9(A,t,e={}){if(!A)throw new Error("point is required");if(!t)throw new Error("polygon is required");let i=g9(A),r=kQ(t),n=r.type,s=t.bbox,o=r.coordinates;if(s&&v6i(i,s)===!1)return!1;n==="Polygon"&&(o=[o]);let a=!1;for(var l=0;l<o.length;++l){let g=S6i(i,o[l]);if(g===0)return!e.ignoreBoundary;g&&(a=!0)}return a}function v6i(A,t){return t[0]<=A[0]&&t[1]<=A[1]&&t[2]>=A[0]&&t[3]>=A[1]}function yE(A,t,e={}){let i=g9(A),r=iC(t);for(let n=0;n<r.length-1;n++){let s=!1;if(e.ignoreEndVertices&&(n===0&&(s="start"),n===r.length-2&&(s="end"),n===0&&n+1===r.length-1&&(s="both")),D6i(r[n],r[n+1],i,s,typeof e.epsilon>"u"?null:e.epsilon))return!0}return!1}function D6i(A,t,e,i,r){let n=e[0],s=e[1],o=A[0],a=A[1],l=t[0],g=t[1],h=e[0]-o,p=e[1]-a,d=l-o,E=g-a,f=h*E-p*d;if(r!==null){if(Math.abs(f)>r)return!1}else if(f!==0)return!1;if(Math.abs(d)===Math.abs(E)&&Math.abs(d)===0)return i?!1:e[0]===A[0]&&e[1]===A[1];if(i){if(i==="start")return Math.abs(d)>=Math.abs(E)?d>0?o<n&&n<=l:l<=n&&n<o:E>0?a<s&&s<=g:g<=s&&s<a;if(i==="end")return Math.abs(d)>=Math.abs(E)?d>0?o<=n&&n<l:l<n&&n<=o:E>0?a<=s&&s<g:g<s&&s<=a;if(i==="both")return Math.abs(d)>=Math.abs(E)?d>0?o<n&&n<l:l<n&&n<o:E>0?a<s&&s<g:g<s&&s<a}else return Math.abs(d)>=Math.abs(E)?d>0?o<=n&&n<=l:l<=n&&n<=o:E>0?a<=s&&s<=g:g<=s&&s<=a;return!1}function k6i(A,t,e,i,r){xKe(A,t,e||0,i||A.length-1,r||R6i)}function xKe(A,t,e,i,r){for(;i>e;){if(i-e>600){var n=i-e+1,s=t-e+1,o=Math.log(n),a=.5*Math.exp(2*o/3),l=.5*Math.sqrt(o*a*(n-a)/n)*(s-n/2<0?-1:1),g=Math.max(e,Math.floor(t-s*a/n+l)),h=Math.min(i,Math.floor(t+(n-s)*a/n+l));xKe(A,t,g,h,r)}var p=A[t],d=e,E=i;for(lat(A,e,t),r(A[i],p)>0&&lat(A,e,i);d<E;){for(lat(A,d,E),d++,E--;r(A[d],p)<0;)d++;for(;r(A[E],p)>0;)E--}r(A[e],p)===0?lat(A,e,E):(E++,lat(A,E,i)),E<=t&&(e=E+1),t<=E&&(i=E-1)}}function lat(A,t,e){var i=A[t];A[t]=A[e],A[e]=i}function R6i(A,t){return A<t?-1:A>t?1:0}var hZt=class{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data,i=[];if(!Ymt(t,e))return i;let r=this.toBBox,n=[];for(;e;){for(let s=0;s<e.children.length;s++){let o=e.children[s],a=e.leaf?r(o):o;Ymt(t,a)&&(e.leaf?i.push(o):MVt(t,a)?this._all(o,i):n.push(o))}e=n.pop()}return i}collides(t){let e=this.data;if(!Ymt(t,e))return!1;let i=[];for(;e;){for(let r=0;r<e.children.length;r++){let n=e.children[r],s=e.leaf?this.toBBox(n):n;if(Ymt(t,s)){if(e.leaf||MVt(t,s))return!0;i.push(n)}}e=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){let i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=HK([]),this}remove(t,e){if(!t)return this;let i=this.data,r=this.toBBox(t),n=[],s=[],o,a,l;for(;i||n.length;){if(i||(i=n.pop(),a=n[n.length-1],o=s.pop(),l=!0),i.leaf){let g=M6i(t,i.children,e);if(g!==-1)return i.children.splice(g,1),n.push(i),this._condense(n),this}!l&&!i.leaf&&MVt(i,r)?(n.push(i),s.push(o),o=0,a=i,i=i.children[0]):a?(o++,i=a.children[o],l=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){let i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,r){let n=i-e+1,s=this._maxEntries,o;if(n<=s)return o=HK(t.slice(e,i+1)),UK(o,this.toBBox),o;r||(r=Math.ceil(Math.log(n)/Math.log(s)),s=Math.ceil(n/Math.pow(s,r-1))),o=HK([]),o.leaf=!1,o.height=r;let a=Math.ceil(n/s),l=a*Math.ceil(Math.sqrt(s));Rqe(t,e,i,l,this.compareMinX);for(let g=e;g<=i;g+=l){let h=Math.min(g+l-1,i);Rqe(t,g,h,a,this.compareMinY);for(let p=g;p<=h;p+=a){let d=Math.min(p+a-1,h);o.children.push(this._build(t,p,d,r-1))}}return UK(o,this.toBBox),o}_chooseSubtree(t,e,i,r){for(;r.push(e),!(e.leaf||r.length-1===i);){let n=1/0,s=1/0,o;for(let a=0;a<e.children.length;a++){let l=e.children[a],g=RVt(l),h=N6i(t,l)-g;h<s?(s=h,n=g<n?g:n,o=l):h===s&&g<n&&(n=g,o=l)}e=o||e.children[0]}return e}_insert(t,e,i){let r=i?t:this.toBBox(t),n=[],s=this._chooseSubtree(r,this.data,e,n);for(s.children.push(t),pat(s,r);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(r,n,e)}_split(t,e){let i=t[e],r=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,r);let s=this._chooseSplitIndex(i,n,r),o=HK(i.children.splice(s,i.children.length-s));o.height=i.height,o.leaf=i.leaf,UK(i,this.toBBox),UK(o,this.toBBox),e?t[e-1].children.push(o):this._splitRoot(i,o)}_splitRoot(t,e){this.data=HK([t,e]),this.data.height=t.height+1,this.data.leaf=!1,UK(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let r,n=1/0,s=1/0;for(let o=e;o<=i-e;o++){let a=Iat(t,0,o,this.toBBox),l=Iat(t,o,i,this.toBBox),g=L6i(a,l),h=RVt(a)+RVt(l);g<n?(n=g,r=o,s=h<s?h:s):g===n&&h<s&&(s=h,r=o)}return r||i-e}_chooseSplitAxis(t,e,i){let r=t.leaf?this.compareMinX:G6i,n=t.leaf?this.compareMinY:F6i,s=this._allDistMargin(t,e,i,r),o=this._allDistMargin(t,e,i,n);s<o&&t.children.sort(r)}_allDistMargin(t,e,i,r){t.children.sort(r);let n=this.toBBox,s=Iat(t,0,e,n),o=Iat(t,i-e,i,n),a=Omt(s)+Omt(o);for(let l=e;l<i-e;l++){let g=t.children[l];pat(s,t.leaf?n(g):g),a+=Omt(s)}for(let l=i-e-1;l>=e;l--){let g=t.children[l];pat(o,t.leaf?n(g):g),a+=Omt(o)}return a}_adjustParentBBoxes(t,e,i){for(let r=i;r>=0;r--)pat(e[r],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():UK(t[e],this.toBBox)}};function M6i(A,t,e){if(!e)return t.indexOf(A);for(let i=0;i<t.length;i++)if(e(A,t[i]))return i;return-1}function UK(A,t){Iat(A,0,A.children.length,t,A)}function Iat(A,t,e,i,r){r||(r=HK(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let n=t;n<e;n++){let s=A.children[n];pat(r,A.leaf?i(s):s)}return r}function pat(A,t){return A.minX=Math.min(A.minX,t.minX),A.minY=Math.min(A.minY,t.minY),A.maxX=Math.max(A.maxX,t.maxX),A.maxY=Math.max(A.maxY,t.maxY),A}function G6i(A,t){return A.minX-t.minX}function F6i(A,t){return A.minY-t.minY}function RVt(A){return(A.maxX-A.minX)*(A.maxY-A.minY)}function Omt(A){return A.maxX-A.minX+(A.maxY-A.minY)}function N6i(A,t){return(Math.max(t.maxX,A.maxX)-Math.min(t.minX,A.minX))*(Math.max(t.maxY,A.maxY)-Math.min(t.minY,A.minY))}function L6i(A,t){let e=Math.max(A.minX,t.minX),i=Math.max(A.minY,t.minY),r=Math.min(A.maxX,t.maxX),n=Math.min(A.maxY,t.maxY);return Math.max(0,r-e)*Math.max(0,n-i)}function MVt(A,t){return A.minX<=t.minX&&A.minY<=t.minY&&t.maxX<=A.maxX&&t.maxY<=A.maxY}function Ymt(A,t){return t.minX<=A.maxX&&t.minY<=A.maxY&&t.maxX>=A.minX&&t.maxY>=A.minY}function HK(A){return{children:A,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Rqe(A,t,e,i,r){let n=[t,e];for(;n.length;){if(e=n.pop(),t=n.pop(),e-t<=i)continue;let s=t+Math.ceil((e-t)/i/2)*i;k6i(A,s,t,e,r),n.push(t,s,s,e)}}function GVt(A){var t;if(A.bbox)t=A.bbox;else if(Array.isArray(A)&&A.length===4)t=A;else if(Array.isArray(A)&&A.length===6)t=[A[0],A[1],A[3],A[4]];else if(A.type==="Feature")t=SI(A);else if(A.type==="FeatureCollection")t=SI(A);else throw new Error("invalid geojson");return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}}var T6i=class{constructor(A=9){this.tree=new hZt(A),this.tree.toBBox=GVt}insert(A){if(A.type!=="Feature")throw new Error("invalid feature");return A.bbox=A.bbox?A.bbox:SI(A),this.tree.insert(A),this}load(A){var t=[];return Array.isArray(A)?A.forEach(function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:SI(e),t.push(e)}):fv(A,function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:SI(e),t.push(e)}),this.tree.load(t),this}remove(A,t){if(A.type!=="Feature")throw new Error("invalid feature");return A.bbox=A.bbox?A.bbox:SI(A),this.tree.remove(A,t),this}clear(){return this.tree.clear(),this}search(A){var t=this.tree.search(GVt(A));return Xl(t)}collides(A){return this.tree.collides(GVt(A))}all(){let A=this.tree.all();return Xl(A)}toJSON(){return this.tree.toJSON()}fromJSON(A){return this.tree.fromJSON(A),this}};function uZt(A){return new T6i(A)}function U6i(A,t){if(t=t??{},!Dat(t))throw new Error("options is invalid");var e=t.precision,i=t.coordinates,r=t.mutate;if(e=e==null||isNaN(e)?6:e,i=i==null||isNaN(i)?3:i,!A)throw new Error("<geojson> is required");if(typeof e!="number")throw new Error("<precision> must be a number");if(typeof i!="number")throw new Error("<coordinates> must be a number");(r===!1||r===void 0)&&(A=JSON.parse(JSON.stringify(A)));var n=Math.pow(10,e);return rM(A,function(s){P6i(s,n,i)}),A}function P6i(A,t,e){A.length>e&&A.splice(e,A.length);for(var i=0;i<A.length;i++)A[i]=Math.round(A[i]*t)/t;return A}function wKe(A){if(!A)throw new Error("geojson is required");let t=[];return _v(A,e=>{H6i(e,t)}),Xl(t)}function H6i(A,t){let e=[],i=A.geometry;if(i!==null){switch(i.type){case"Polygon":e=iC(i);break;case"LineString":e=[iC(i)]}e.forEach(r=>{O6i(r,A.properties).forEach(s=>{s.id=t.length,t.push(s)})})}}function O6i(A,t){let e=[];return A.reduce((i,r)=>{let n=$C([i,r],t);return n.bbox=Y6i(i,r),e.push(n),r}),e}function Y6i(A,t){let e=A[0],i=A[1],r=t[0],n=t[1],s=e<r?e:r,o=i<n?i:n,a=e>r?e:r,l=i>n?i:n;return[s,o,a,l]}var gQt=class{constructor(t=[],e=J6i){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;let t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){let{data:e,compare:i}=this,r=e[t];for(;t>0;){let n=t-1>>1,s=e[n];if(i(r,s)>=0)break;e[t]=s,t=n}e[t]=r}_down(t){let{data:e,compare:i}=this,r=this.length>>1,n=e[t];for(;t<r;){let s=(t<<1)+1,o=e[s],a=s+1;if(a<this.length&&i(e[a],o)<0&&(s=a,o=e[a]),i(o,n)>=0)break;e[t]=o,t=s}e[t]=n}};function J6i(A,t){return A<t?-1:A>t?1:0}function bKe(A,t){return A.p.x>t.p.x?1:A.p.x<t.p.x?-1:A.p.y!==t.p.y?A.p.y>t.p.y?1:-1:1}function j6i(A,t){return A.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:A.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:A.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?A.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}var cQt=class{constructor(t,e,i,r){this.p={x:t[0],y:t[1]},this.featureId=e,this.ringId=i,this.eventId=r,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(t){return this.p.x===t.p.x&&this.p.y===t.p.y}};function q6i(A,t){if(A.type==="FeatureCollection"){let e=A.features;for(let i=0;i<e.length;i++)Mqe(e[i],t)}else Mqe(A,t)}var Jmt=0,jmt=0,qmt=0;function Mqe(A,t){let e=A.type==="Feature"?A.geometry:A,i=e.coordinates;(e.type==="Polygon"||e.type==="MultiLineString")&&(i=[i]),e.type==="LineString"&&(i=[[i]]);for(let r=0;r<i.length;r++)for(let n=0;n<i[r].length;n++){let s=i[r][n][0],o=null;jmt=jmt+1;for(let a=0;a<i[r][n].length-1;a++){o=i[r][n][a+1];let l=new cQt(s,Jmt,jmt,qmt),g=new cQt(o,Jmt,jmt,qmt+1);l.otherEvent=g,g.otherEvent=l,bKe(l,g)>0?(g.isLeftEndpoint=!0,l.isLeftEndpoint=!1):(l.isLeftEndpoint=!0,g.isLeftEndpoint=!1),t.push(l),t.push(g),s=o,qmt=qmt+1}}Jmt=Jmt+1}var K6i=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function z6i(A,t){if(A===null||t===null||A.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(A.rightSweepEvent.isSamePoint(t.leftSweepEvent)||A.rightSweepEvent.isSamePoint(t.leftSweepEvent)||A.rightSweepEvent.isSamePoint(t.rightSweepEvent)||A.leftSweepEvent.isSamePoint(t.leftSweepEvent)||A.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;let e=A.leftSweepEvent.p.x,i=A.leftSweepEvent.p.y,r=A.rightSweepEvent.p.x,n=A.rightSweepEvent.p.y,s=t.leftSweepEvent.p.x,o=t.leftSweepEvent.p.y,a=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,g=(l-o)*(r-e)-(a-s)*(n-i),h=(a-s)*(i-o)-(l-o)*(e-s),p=(r-e)*(i-o)-(n-i)*(e-s);if(g===0)return!1;let d=h/g,E=p/g;if(d>=0&&d<=1&&E>=0&&E<=1){let f=e+d*(r-e),Q=i+d*(n-i);return[f,Q]}return!1}function W6i(A,t){t=t||!1;let e=[],i=new gQt([],j6i);for(;A.length;){let r=A.pop();if(r.isLeftEndpoint){let n=new K6i(r);for(let s=0;s<i.data.length;s++){let o=i.data[s];if(t&&o.leftSweepEvent.featureId===r.featureId)continue;let a=z6i(n,o);a!==!1&&e.push(a)}i.push(n)}else r.isLeftEndpoint===!1&&i.pop()}return e}function V6i(A,t){let e=new gQt([],bKe);return q6i(A,e),W6i(e,t)}var Z6i=V6i;function WK(A,t,e={}){let{removeDuplicates:i=!0,ignoreSelfIntersections:r=!0}=e,n=[];A.type==="FeatureCollection"?n=n.concat(A.features):A.type==="Feature"?n.push(A):(A.type==="LineString"||A.type==="Polygon"||A.type==="MultiLineString"||A.type==="MultiPolygon")&&n.push(Xf(A)),t.type==="FeatureCollection"?n=n.concat(t.features):t.type==="Feature"?n.push(t):(t.type==="LineString"||t.type==="Polygon"||t.type==="MultiLineString"||t.type==="MultiPolygon")&&n.push(Xf(t));let s=Z6i(Xl(n),r),o=[];if(i){let a={};s.forEach(l=>{let g=l.join(",");a[g]||(a[g]=!0,o.push(l))})}else o=s;return Xl(o.map(a=>l9(a)))}var X6i=Object.defineProperty,$6i=Object.defineProperties,tmi=Object.getOwnPropertyDescriptors,Gqe=Object.getOwnPropertySymbols,emi=Object.prototype.hasOwnProperty,Ami=Object.prototype.propertyIsEnumerable,Fqe=(A,t,e)=>t in A?X6i(A,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):A[t]=e,imi=(A,t)=>{for(var e in t||(t={}))emi.call(t,e)&&Fqe(A,e,t[e]);if(Gqe)for(var e of Gqe(t))Ami.call(t,e)&&Fqe(A,e,t[e]);return A},rmi=(A,t)=>$6i(A,tmi(t));function JK(A,t,e={}){if(!A||!t)throw new Error("lines and inputPoint are required arguments");let i=g9(t),r=l9([1/0,1/0],{lineStringIndex:-1,segmentIndex:-1,totalDistance:-1,lineDistance:-1,segmentDistance:-1,pointDistance:1/0,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),n=0,s=0,o=-1;return _v(A,function(a,l,g){o!==g&&(o=g,s=0);let h=iC(a);for(let p=0;p<h.length-1;p++){let d=l9(h[p]),E=g9(d),f=l9(h[p+1]),Q=g9(f),y=xat(d,f,e),S,v;Q[0]===i[0]&&Q[1]===i[1]?[S,v]=[Q,!0]:E[0]===i[0]&&E[1]===i[1]?[S,v]=[E,!1]:[S,v]=omi(E,Q,i);let M=xat(t,S,e);if(M<r.properties.pointDistance){let H=xat(d,S,e);r=l9(S,{lineStringIndex:g,segmentIndex:v?p+1:p,totalDistance:n+H,lineDistance:s+H,segmentDistance:H,pointDistance:M,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),r.properties=rmi(imi({},r.properties),{multiFeatureIndex:r.properties.lineStringIndex,index:r.properties.segmentIndex,location:r.properties.totalDistance,dist:r.properties.pointDistance})}n+=y,s+=y}}),r}function hU(A,t){let[e,i,r]=A,[n,s,o]=t;return e*n+i*s+r*o}function gat(A,t){let[e,i,r]=A,[n,s,o]=t;return[i*o-r*s,r*n-e*o,e*s-i*n]}function nmi(A){return Math.sqrt(Math.pow(A[0],2)+Math.pow(A[1],2)+Math.pow(A[2],2))}function Nqe(A){let t=nmi(A);return[A[0]/t,A[1]/t,A[2]/t]}function FVt(A){let t=QE(A[1]),e=QE(A[0]);return[Math.cos(t)*Math.cos(e),Math.cos(t)*Math.sin(e),Math.sin(t)]}function smi(A){let[t,e,i]=A,r=Math.min(Math.max(i,-1),1),n=oQt(Math.asin(r));return[oQt(Math.atan2(e,t)),n]}function omi(A,t,e){let i=FVt(A),r=FVt(t),n=FVt(e),s=gat(i,r);if(s[0]===0&&s[1]===0&&s[2]===0)return hU(i,r)>0?[[...t],!0]:[[...e],!1];let o=gat(s,n);if(o[0]===0&&o[1]===0&&o[2]===0)return[[...t],!0];let a=gat(o,s),l=Nqe(a),g=[-l[0],-l[1],-l[2]],h=hU(n,l)>hU(n,g)?l:g,p=Nqe(s),d=hU(gat(i,h),p),E=hU(gat(h,r),p);return d>=0&&E>=0?[smi(h),!1]:hU(i,n)>hU(r,n)?[[...A],!1]:[[...t],!0]}function IZt(A,t){if(!A)throw new Error("line is required");if(!t)throw new Error("splitter is required");let e=aQt(A),i=aQt(t);if(e!=="LineString")throw new Error("line must be LineString");if(i==="FeatureCollection")throw new Error("splitter cannot be a FeatureCollection");if(i==="GeometryCollection")throw new Error("splitter cannot be a GeometryCollection");var r=U6i(t,{precision:7});switch(A.type!=="Feature"&&(A=Xf(A)),i){case"Point":return KVt(A,r);case"MultiPoint":return Lqe(A,r);case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":return Lqe(A,WK(A,r,{ignoreSelfIntersections:!0}))}}function Lqe(A,t){var e=[],i=uZt();return _v(t,function(r){if(e.forEach(function(o,a){o.id=a}),!e.length)e=KVt(A,r).features,i.load(Xl(e));else{var n=i.search(r);if(n.features.length){var s=SKe(r,n);e=e.filter(function(o){return o.id!==s.id}),i.remove(s),fv(KVt(s,r),function(o){e.push(o),i.insert(o)})}}}),Xl(e)}function KVt(A,t){var e=[],i=iC(A)[0],r=iC(A)[A.geometry.coordinates.length-1];if(NVt(i,g9(t))||NVt(r,g9(t)))return Xl([A]);var n=uZt(),s=wKe(A);n.load(s);var o=n.search(t);if(!o.features.length)return Xl([A]);var a=SKe(t,o),l=[i],g=u6i(s,function(h,p,d){var E=iC(p)[1],f=g9(t);return d===a.id?(h.push(f),e.push($C(h)),NVt(f,E)?[f]:[f,E]):(h.push(E),h)},l);return g.length>1&&e.push($C(g)),Xl(e)}function SKe(A,t){if(!t.features.length)throw new Error("lines must contain features");if(t.features.length===1)return t.features[0];var e,i=1/0;return fv(t,function(r){var n=JK(r,A),s=n.properties.dist;s<i&&(e=r,i=s)}),e}function NVt(A,t){return A[0]===t[0]&&A[1]===t[1]}function Tqe(A,t){let e=kQ(A),i=kQ(t),r=e.type,n=i.type,s=e.coordinates,o=i.coordinates;switch(r){case"Point":if(n==="Point")return dZt(s,o);throw new Error("feature2 "+n+" geometry not supported");case"MultiPoint":switch(n){case"Point":return gmi(e,i);case"MultiPoint":return cmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"Point":return yE(i,e,{ignoreEndVertices:!0});case"LineString":return Imi(e,i);case"MultiPoint":return hmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Point":return c9(i,e,{ignoreBoundary:!0});case"LineString":return dmi(e,i);case"Polygon":return pZt(e,i);case"MultiPoint":return umi(e,i);case"MultiPolygon":return lmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPolygon":if(n==="Polygon")return ami(e,i);throw new Error("feature2 "+n+" geometry not supported");default:throw new Error("feature1 "+r+" geometry not supported")}}function ami(A,t){return A.coordinates.some(e=>pZt({type:"Polygon",coordinates:e},t))}function lmi(A,t){return t.coordinates.every(e=>pZt(A,{type:"Polygon",coordinates:e}))}function gmi(A,t){let e,i=!1;for(e=0;e<A.coordinates.length;e++)if(dZt(A.coordinates[e],t.coordinates)){i=!0;break}return i}function cmi(A,t){for(let e of t.coordinates){let i=!1;for(let r of A.coordinates)if(dZt(e,r)){i=!0;break}if(!i)return!1}return!0}function hmi(A,t){let e=!1;for(let i of t.coordinates)if(yE(i,A,{ignoreEndVertices:!0})&&(e=!0),!yE(i,A))return!1;return!!e}function umi(A,t){for(let e of t.coordinates)if(!c9(e,A,{ignoreBoundary:!0}))return!1;return!0}function Imi(A,t){let e=!1;for(let i of t.coordinates)if(yE({type:"Point",coordinates:i},A,{ignoreEndVertices:!0})&&(e=!0),!yE({type:"Point",coordinates:i},A,{ignoreEndVertices:!1}))return!1;return e}function pmi(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=$C([e[r],e[r+1]]),s=IZt(n,Xf(t));s.features.length===0?i.push(n):i.push(...s.features)}return Xl(i)}function dmi(A,t){let e=SI(A),i=SI(t);if(!vKe(e,i))return!1;for(let s of t.coordinates)if(!c9(s,A))return!1;let r=!1,n=pmi(t,A);for(let s of n.features){let o=Cmi(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!c9(o,A))return!1;!r&&c9(o,A,{ignoreBoundary:!0})&&(r=!0)}return r}function pZt(A,t){if(A.type==="Feature"&&A.geometry===null||t.type==="Feature"&&t.geometry===null)return!1;let e=SI(A),i=SI(t);if(!vKe(e,i))return!1;let r=kQ(t).coordinates;for(let n of r)for(let s of n)if(!c9(s,A))return!1;return!0}function vKe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function dZt(A,t){return A[0]===t[0]&&A[1]===t[1]}function Cmi(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function hQt(A,t={}){let e=kQ(A);switch(!t.properties&&A.type==="Feature"&&(t.properties=A.properties),e.type){case"Polygon":return Bmi(e,t);case"MultiPolygon":return Emi(e,t);default:throw new Error("invalid poly")}}function Bmi(A,t={}){let i=kQ(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{};return DKe(i,r)}function Emi(A,t={}){let i=kQ(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{},n=[];return i.forEach(s=>{n.push(DKe(s,r))}),Xl(n)}function DKe(A,t){return A.length>1?_Ke(A,t):$C(A[0],t)}var fmi=Object.defineProperty,VK=(A,t)=>fmi(A,"name",{value:t,configurable:!0}),kKe=class{constructor(t){this.direction=!1,this.compareProperties=!0;var e,i,r;this.precision=10**-((e=t?.precision)!=null?e:17),this.direction=(i=t?.direction)!=null?i:!1,this.compareProperties=(r=t?.compareProperties)!=null?r:!0}compare(t,e){if(t.type!==e.type||!dat(t,e))return!1;switch(t.type){case"Point":return this.compareCoord(t.coordinates,e.coordinates);case"LineString":return this.compareLine(t.coordinates,e.coordinates);case"Polygon":return this.comparePolygon(t,e);case"GeometryCollection":return this.compareGeometryCollection(t,e);case"Feature":return this.compareFeature(t,e);case"FeatureCollection":return this.compareFeatureCollection(t,e);default:if(t.type.startsWith("Multi")){let i=zVt(t),r=zVt(e);return i.every(n=>r.some(s=>this.compare(n,s)))}}return!1}compareCoord(t,e){return t.length===e.length&&t.every((i,r)=>Math.abs(i-e[r])<this.precision)}compareLine(t,e,i=0,r=!1){if(!dat(t,e))return!1;let n=t,s=e;if(r&&!this.compareCoord(n[0],s[0])){let a=this.fixStartIndex(s,n);if(a)s=a;else return!1}let o=this.compareCoord(n[i],s[i]);return this.direction||o?this.comparePath(n,s):this.compareCoord(n[i],s[s.length-(1+i)])?this.comparePath(n.slice().reverse(),s):!1}fixStartIndex(t,e){let i,r=-1;for(let n=0;n<t.length;n++)if(this.compareCoord(t[n],e[0])){r=n;break}return r>=0&&(i=[].concat(t.slice(r,t.length),t.slice(1,r+1))),i}comparePath(t,e){return t.every((i,r)=>this.compareCoord(i,e[r]))}comparePolygon(t,e){if(this.compareLine(t.coordinates[0],e.coordinates[0],1,!0)){let i=t.coordinates.slice(1,t.coordinates.length),r=e.coordinates.slice(1,e.coordinates.length);return i.every(n=>r.some(s=>this.compareLine(n,s,1,!0)))}return!1}compareGeometryCollection(t,e){return dat(t.geometries,e.geometries)&&this.compareBBox(t,e)&&t.geometries.every((i,r)=>this.compare(i,e.geometries[r]))}compareFeature(t,e){return t.id===e.id&&(this.compareProperties?CZt(t.properties,e.properties):!0)&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return dat(t.features,e.features)&&this.compareBBox(t,e)&&t.features.every((i,r)=>this.compare(i,e.features[r]))}compareBBox(t,e){return!t.bbox&&!e.bbox||(t.bbox&&e.bbox?this.compareCoord(t.bbox,e.bbox):!1)}};VK(kKe,"GeojsonEquality");var _mi=kKe;function dat(A,t){return A.coordinates?A.coordinates.length===t.coordinates.length:A.length===t.length}VK(dat,"sameLength");function zVt(A){return A.coordinates.map(t=>({type:A.type.replace("Multi",""),coordinates:t}))}VK(zVt,"explode");function RKe(A,t,e){return new _mi(e).compare(A,t)}VK(RKe,"geojsonEquality");function CZt(A,t){if(A===null&&t===null)return!0;if(A===null||t===null)return!1;let e=Object.keys(A),i=Object.keys(t);if(e.length!==i.length)return!1;for(var r of e){let n=A[r],s=t[r],o=Uqe(n)&&Uqe(s);if(o&&!CZt(n,s)||!o&&n!==s)return!1}return!0}VK(CZt,"equal");var Uqe=VK(A=>A!=null&&typeof A=="object","isObject");function MKe(A,t={}){var e=typeof t=="object"?t.mutate:t;if(!A)throw new Error("geojson is required");var i=aQt(A),r=[];switch(i){case"LineString":r=LVt(A,i);break;case"MultiLineString":case"Polygon":iC(A).forEach(function(s){r.push(LVt(s,i))});break;case"MultiPolygon":iC(A).forEach(function(s){var o=[];s.forEach(function(a){o.push(LVt(a,i))}),r.push(o)});break;case"Point":return A;case"MultiPoint":var n={};iC(A).forEach(function(s){var o=s.join("-");Object.prototype.hasOwnProperty.call(n,o)||(r.push(s),n[o]=!0)});break;default:throw new Error(i+" geometry not supported")}return A.coordinates?e===!0?(A.coordinates=r,A):{type:i,coordinates:r}:e===!0?(A.geometry.coordinates=r,A):Xf({type:i,coordinates:r},A.properties,{bbox:A.bbox,id:A.id})}function LVt(A,t){let e=iC(A);if(e.length===2&&!Pqe(e[0],e[1]))return e;let i=[],r=0,n=1,s=2;for(i.push(e[r]);s<e.length;)yE(e[n],$C([e[r],e[s]]))?n=s:(i.push(e[n]),r=n,n++,s=n),s++;if(i.push(e[n]),t==="Polygon"||t==="MultiPolygon"){if(yE(i[0],$C([i[1],i[i.length-2]]))&&(i.shift(),i.pop(),i.push(i[0])),i.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!Pqe(i[0],i[i.length-1]))throw new Error("invalid polygon, first and last points not equal")}return i}function Pqe(A,t){return A[0]===t[0]&&A[1]===t[1]}function mmi(A,t,{ignoreSelfIntersections:e=!0}={ignoreSelfIntersections:!0}){let i=!0;return _v(A,r=>{_v(t,n=>{if(i===!1)return!1;i=Qmi(r.geometry,n.geometry,e)})}),i}function Qmi(A,t,e){switch(A.type){case"Point":switch(t.type){case"Point":return!bmi(A.coordinates,t.coordinates);case"LineString":return!Hqe(t,A);case"Polygon":return!c9(A,t)}break;case"LineString":switch(t.type){case"Point":return!Hqe(A,t);case"LineString":return!ymi(A,t,e);case"Polygon":return!Oqe(t,A,e)}break;case"Polygon":switch(t.type){case"Point":return!c9(t,A);case"LineString":return!Oqe(A,t,e);case"Polygon":return!xmi(t,A,e)}}return!1}function Hqe(A,t){for(let e=0;e<A.coordinates.length-1;e++)if(wmi(A.coordinates[e],A.coordinates[e+1],t.coordinates))return!0;return!1}function ymi(A,t,e){return WK(A,t,{ignoreSelfIntersections:e}).features.length>0}function Oqe(A,t,e){for(let r of t.coordinates)if(c9(r,A))return!0;return WK(t,hQt(A),{ignoreSelfIntersections:e}).features.length>0}function xmi(A,t,e){for(let r of A.coordinates[0])if(c9(r,t))return!0;for(let r of t.coordinates[0])if(c9(r,A))return!0;return WK(hQt(A),hQt(t),{ignoreSelfIntersections:e}).features.length>0}function wmi(A,t,e){let i=e[0]-A[0],r=e[1]-A[1],n=t[0]-A[0],s=t[1]-A[1];return i*s-r*n!==0?!1:Math.abs(n)>=Math.abs(s)?n>0?A[0]<=e[0]&&e[0]<=t[0]:t[0]<=e[0]&&e[0]<=A[0]:s>0?A[1]<=e[1]&&e[1]<=t[1]:t[1]<=e[1]&&e[1]<=A[1]}function bmi(A,t){return A[0]===t[0]&&A[1]===t[1]}function BZt(A,t,{ignoreSelfIntersections:e=!0}={}){let i=!1;return _v(A,r=>{_v(t,n=>{if(i===!0)return!0;i=!mmi(r.geometry,n.geometry,{ignoreSelfIntersections:e})})}),i}function GKe(A){return A&&A.__esModule&&Object.prototype.hasOwnProperty.call(A,"default")?A.default:A}var TVt,Yqe;function Smi(){return Yqe||(Yqe=1,TVt=function A(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){if(t.constructor!==e.constructor)return!1;var i,r,n;if(Array.isArray(t)){if(i=t.length,i!=e.length)return!1;for(r=i;r--!==0;)if(!A(t[r],e[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===e.source&&t.flags===e.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===e.toString();if(n=Object.keys(t),i=n.length,i!==Object.keys(e).length)return!1;for(r=i;r--!==0;)if(!Object.prototype.hasOwnProperty.call(e,n[r]))return!1;for(r=i;r--!==0;){var s=n[r];if(!A(t[s],e[s]))return!1}return!0}return t!==t&&e!==e}),TVt}var vmi=Smi(),Cat=GKe(vmi);function Dmi(A,t,e={}){if(e=e||{},!Dat(e))throw new Error("options is invalid");var i=e.tolerance||0,r=[],n=uZt();let s=wKe(A);n.load(s);var o;let a=[];return uat(t,function(l){var g=!1;l&&(fv(n.search(l),function(h){if(g===!1){var p=iC(l).sort(),d=iC(h).sort();if(Cat(p,d))g=!0,o?o=UVt(o,l)||o:o=l;else if(i===0?yE(p[0],h)&&yE(p[1],h):JK(h,p[0]).properties.dist<=i&&JK(h,p[1]).properties.dist<=i)g=!0,o?o=UVt(o,l)||o:o=l;else if(i===0?yE(d[0],l)&&yE(d[1],l):JK(l,d[0]).properties.dist<=i&&JK(l,d[1]).properties.dist<=i)if(o){let E=UVt(o,h);E?o=E:a.push(h)}else o=h}}),g===!1&&o&&(r.push(o),a.length&&(r=r.concat(a),a=[]),o=void 0))}),o&&r.push(o),Xl(r)}function UVt(A,t){var e=iC(t),i=iC(A),r=i[0],n=i[i.length-1],s=A.geometry.coordinates;if(Cat(e[0],r))s.unshift(e[1]);else if(Cat(e[0],n))s.push(e[1]);else if(Cat(e[1],r))s.unshift(e[0]);else if(Cat(e[1],n))s.push(e[0]);else return;return A}function FKe(A,t){let e=kQ(A),i=kQ(t),r=e.type,n=i.type;if(r==="MultiPoint"&&n!=="MultiPoint"||(r==="LineString"||r==="MultiLineString")&&n!=="LineString"&&n!=="MultiLineString"||(r==="Polygon"||r==="MultiPolygon")&&n!=="Polygon"&&n!=="MultiPolygon")throw new Error("features must be of the same type");if(r==="Point")throw new Error("Point geometry not supported");if(RKe(A,t,{precision:6}))return!1;let s=0;switch(r){case"MultiPoint":for(var o=0;o<e.coordinates.length;o++)for(var a=0;a<i.coordinates.length;a++){var l=e.coordinates[o],g=i.coordinates[a];if(l[0]===g[0]&&l[1]===g[1])return!0}return!1;case"LineString":case"MultiLineString":uat(A,h=>{uat(t,p=>{Dmi(h,p).features.length&&s++})});break;case"Polygon":case"MultiPolygon":uat(A,h=>{uat(t,p=>{WK(h,p).features.length&&s++})});break}return s>0}function kmi(A,t){var e=kQ(A),i=kQ(t),r=e.type,n=i.type;switch(r){case"Point":switch(n){case"MultiPoint":return Rmi(e,i);case"LineString":return yE(e,i,{ignoreEndVertices:!0});case"Polygon":case"MultiPolygon":return c9(e,i,{ignoreBoundary:!0});default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPoint":switch(n){case"MultiPoint":return Mmi(e,i);case"LineString":return Gmi(e,i);case"Polygon":case"MultiPolygon":return Fmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"LineString":return Nmi(e,i);case"Polygon":case"MultiPolygon":return Tmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Polygon":case"MultiPolygon":return Umi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}default:throw new Error("feature1 "+r+" geometry not supported")}}function Rmi(A,t){var e,i=!1;for(e=0;e<t.coordinates.length;e++)if(LKe(t.coordinates[e],A.coordinates)){i=!0;break}return i}function Mmi(A,t){for(var e=0;e<A.coordinates.length;e++){for(var i=!1,r=0;r<t.coordinates.length;r++)LKe(A.coordinates[e],t.coordinates[r])&&(i=!0);if(!i)return!1}return!0}function Gmi(A,t){for(var e=!1,i=0;i<A.coordinates.length;i++){if(!yE(A.coordinates[i],t))return!1;e||(e=yE(A.coordinates[i],t,{ignoreEndVertices:!0}))}return e}function Fmi(A,t){for(var e=!0,i=!1,r=0;r<A.coordinates.length;r++){if(i=c9(A.coordinates[r],t),!i){e=!1;break}i=c9(A.coordinates[r],t,{ignoreBoundary:!0})}return e&&i}function Nmi(A,t){for(var e=0;e<A.coordinates.length;e++)if(!yE(A.coordinates[e],t))return!1;return!0}function Lmi(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=$C([e[r],e[r+1]]),s=IZt(n,Xf(t));s.features.length===0?i.push(n):i.push(...s.features)}return Xl(i)}function Tmi(A,t){let e=SI(t),i=SI(A);if(!NKe(e,i))return!1;for(let s of A.coordinates)if(!c9(s,t))return!1;let r=!1,n=Lmi(A,t);for(let s of n.features){let o=Pmi(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!c9(o,t))return!1;!r&&c9(o,t,{ignoreBoundary:!0})&&(r=!0)}return r}function Umi(A,t){var e=SI(A),i=SI(t);if(!NKe(i,e))return!1;for(var r=0;r<A.coordinates[0].length;r++)if(!c9(A.coordinates[0][r],t))return!1;return!0}function NKe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function LKe(A,t){return A[0]===t[0]&&A[1]===t[1]}function Pmi(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function TKe(A,t={}){let e=SI(A),i=(e[0]+e[2])/2,r=(e[1]+e[3])/2;return l9([i,r],t.properties,t)}var tQt={exports:{}},Hmi=tQt.exports,Jqe;function Omi(){return Jqe||(Jqe=1,(function(A,t){(function(e,i){A.exports=i()})(Hmi,(function(){function e(C,c){(c==null||c>C.length)&&(c=C.length);for(var u=0,B=Array(c);u<c;u++)B[u]=C[u];return B}function i(C,c,u){return c=g(c),(function(B,b){if(b&&(typeof b=="object"||typeof b=="function"))return b;if(b!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return(function(T){if(T===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return T})(B)})(C,p()?Reflect.construct(c,u||[],g(C).constructor):c.apply(C,u))}function r(C,c){if(!(C instanceof c))throw new TypeError("Cannot call a class as a function")}function n(C,c,u){if(p())return Reflect.construct.apply(null,arguments);var B=[null];B.push.apply(B,c);var b=new(C.bind.apply(C,B));return u&&d(b,u.prototype),b}function s(C,c){for(var u=0;u<c.length;u++){var B=c[u];B.enumerable=B.enumerable||!1,B.configurable=!0,"value"in B&&(B.writable=!0),Object.defineProperty(C,Q(B.key),B)}}function o(C,c,u){return c&&s(C.prototype,c),u&&s(C,u),Object.defineProperty(C,"prototype",{writable:!1}),C}function a(C,c){var u=typeof Symbol<"u"&&C[Symbol.iterator]||C["@@iterator"];if(!u){if(Array.isArray(C)||(u=y(C))||c){u&&(C=u);var B=0,b=function(){};return{s:b,n:function(){return B>=C.length?{done:!0}:{done:!1,value:C[B++]}},e:function(_t){throw _t},f:b}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
26822
|
+
`}function sPe(A,t,e){let i=A.createShader(t);return i?(A.shaderSource(i,e),A.compileShader(i),A.getShaderParameter(i,A.COMPILE_STATUS)?i:(console.error("Shader compile error:",A.getShaderInfoLog(i)),A.deleteShader(i),null)):null}function chi(A,t,e){let i=A.createProgram();return i?(A.attachShader(i,t),A.attachShader(i,e),A.linkProgram(i),A.getProgramParameter(i,A.LINK_STATUS)?i:(console.error("Program link error:",A.getProgramInfoLog(i)),A.deleteProgram(i),null)):null}function Rx(A,t,e){let i=A.getUniformLocation(t,e);if(!i)throw new Error(`Failed to get uniform location for ${e}`);return i}function wKt(A){let t=A.createTexture();if(!t)throw new Error("Failed to create texture");return t}function oPe(A){let t=A.createBuffer();if(!t)throw new Error("Failed to create buffer");return t}function WPe(A,t){let e=t===2?A.RG:t===3?A.RGB:t>=4?A.RGBA:A.RED,i=t===2?A.RG32F:t===3?A.RGB32F:t>=4?A.RGBA32F:A.R32F;return{format:e,internalFormat:i}}function LKt(A){A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MIN_FILTER,A.NEAREST),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MAG_FILTER,A.NEAREST),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE)}function VPe(A,t,e){let i=new Float32Array(A.length);for(let r=0;r<A.length;r++){let n=A[r];t!==null&&n===t||n!==n?i[r]=NaN:i[r]=n/e}return{normalized:i,scale:e}}function ZPe(A,t){if(t===1&&A.length===1)return A[0];let e=A[0].length,i=new Float32Array(e*t);for(let r=0;r<e;r++)for(let n=0;n<t;n++)i[r*t+n]=A[n][r];return i}function XPe(A){let t=[],e=[],i=2/A,r=1/A,n=(s,o)=>{let a=-1+s*i,l=1-o*i,g=s*r,h=o*r;t.push(a,l),e.push(g,h)};for(let s=0;s<A;s++){for(let o=0;o<=A;o++)n(o,s),n(o,s+1);s<A-1&&(n(A,s+1),n(0,s+1))}return{vertexArr:new Float32Array(t),texCoordArr:new Float32Array(e)}}function hhi(A){let t=A.replace("#","");if(t.length!==6)throw new Error(`Invalid hex color: ${A}`);let e=parseInt(t,16);return[e>>16&255,e>>8&255,e&255]}var uhi=class{constructor(A){this.texture=null,this.dirty=!0;let{colors:t,floatData:e,length:i}=this.build(A);this.colors=t,this.floatData=e,this.length=i,this.dirty=!0}apply(A){let{colors:t,floatData:e,length:i}=this.build(A);this.colors=t,this.floatData=e,this.length=i,this.dirty=!0}ensureTexture(A){return(!this.texture||this.dirty)&&this.upload(A),this.texture}upload(A){this.texture||(this.texture=wKt(A)),A.bindTexture(A.TEXTURE_2D,this.texture),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MIN_FILTER,A.LINEAR),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MAG_FILTER,A.LINEAR),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_S,A.CLAMP_TO_EDGE),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_T,A.CLAMP_TO_EDGE),A.texImage2D(A.TEXTURE_2D,0,A.RGB16F,this.length,1,0,A.RGB,A.FLOAT,this.floatData),A.bindTexture(A.TEXTURE_2D,null),this.dirty=!1}dispose(A){this.texture&&(A.deleteTexture(this.texture),this.texture=null)}build(A){if(!Array.isArray(A)||A.length===0)throw new Error("colormap must be a non-empty array of [r, g, b] values or hex strings");let t=[];for(let n of A)if(typeof n=="string")t.push(hhi(n));else if(Array.isArray(n)&&n.length>=3)t.push([n[0],n[1],n[2]]);else throw new Error("colormap entries must be arrays shaped like [r, g, b] or hex strings");let e=t.flat(),i=e.some(n=>n>1),r=new Float32Array(e.map(n=>i?n/255:n));return{colors:t,floatData:r,length:t.length}}};function Ihi(A=!1,t=!1){return A&&t?"mapbox-wgs84":A?"mapbox":t?"wgs84-globe":"maplibre-globe"}function $Pe(A){let{projectionMode:t,shaderData:e,customShaderConfig:i}=A,r=i&&i.bands.length>0,n=e?.variantName??"base";return[r&&i?["custom",i.bands.join("_"),n].join("_"):n,t].join("_")}var phi=A=>A instanceof Float32Array?A:new Float32Array(A),tHe=A=>A==="mapbox"||A==="mapbox-wgs84",dhi=A=>A==="maplibre-globe"||A==="wgs84-globe";function Chi(A){let t=A.includes("wgs84")?"wgs84":"mercator",e=tHe(A)?"mapbox-globe":"maplibre-globe";return{inputSpace:t,projection:e}}function Bhi(A,t){let{fragmentShaderSource:e,shaderData:i,customShaderConfig:r,projectionMode:n}=t,s=r||void 0,o=s&&s.bands.length>0,a=t.variantName||$Pe({projectionMode:n,shaderData:i,customShaderConfig:r}),{inputSpace:l,projection:g}=Chi(n),h=ahi({inputSpace:l,projection:g,shaderData:i}),p=o&&s?ghi({bands:s.bands,customUniforms:s.customUniforms?Object.keys(s.customUniforms):[],customFrag:s.customFrag}):e,d=sPe(A,A.VERTEX_SHADER,h),E=sPe(A,A.FRAGMENT_SHADER,p);if(!d||!E)throw new Error(`Failed to create shaders for variant: ${a}`);let f=chi(A,d,E);if(!f)throw new Error(`Failed to create program for variant: ${a}`);let Q=new Map,y=new Map;if(o&&s){for(let z of s.bands){let F=A.getUniformLocation(f,z);F&&Q.set(z,F)}if(s.customUniforms)for(let z of Object.keys(s.customUniforms)){let F=A.getUniformLocation(f,z);F&&y.set(z,F)}}let S=dhi(n),v=tHe(n),M=z=>S?A.getUniformLocation(f,z):null,H=z=>v?A.getUniformLocation(f,z):null,Y={program:f,scaleLoc:Rx(A,f,"scale"),scaleXLoc:Rx(A,f,"scale_x"),scaleYLoc:Rx(A,f,"scale_y"),shiftXLoc:Rx(A,f,"shift_x"),shiftYLoc:Rx(A,f,"shift_y"),worldXOffsetLoc:Rx(A,f,"u_worldXOffset"),matrixLoc:S?null:Rx(A,f,"matrix"),projMatrixLoc:M("u_projection_matrix"),fallbackMatrixLoc:M("u_projection_fallback_matrix"),tileMercatorCoordsLoc:M("u_projection_tile_mercator_coords"),clippingPlaneLoc:M("u_projection_clipping_plane"),projectionTransitionLoc:M("u_projection_transition"),opacityLoc:Rx(A,f,"opacity"),texScaleLoc:Rx(A,f,"u_texScale"),texOffsetLoc:Rx(A,f,"u_texOffset"),vertexLoc:A.getAttribLocation(f,"vertex"),pixCoordLoc:A.getAttribLocation(f,"pix_coord_in"),climLoc:A.getUniformLocation(f,"clim"),fillValueLoc:A.getUniformLocation(f,"fillValue"),scaleFactorLoc:A.getUniformLocation(f,"u_scaleFactor"),addOffsetLoc:A.getUniformLocation(f,"u_addOffset"),cmapLoc:o?null:A.getUniformLocation(f,"cmap"),colormapLoc:A.getUniformLocation(f,"colormap"),texLoc:o?null:A.getUniformLocation(f,"tex"),projectionMode:n,useCustomShader:!!o,bandTexLocs:Q,customUniformLocs:y,globeToMercMatrixLoc:H("u_globe_to_merc"),globeTransitionLoc:H("u_globe_transition"),tileRenderLoc:H("u_tile_render"),dataScaleLoc:A.getUniformLocation(f,"u_dataScale"),reprojectLoc:A.getUniformLocation(f,"u_reproject"),latBoundsLoc:A.getUniformLocation(f,"u_latBounds"),latIsAscendingLoc:A.getUniformLocation(f,"u_latIsAscending")};return A.deleteShader(d),A.deleteShader(E),{shaderProgram:Y,variantName:a}}function Ehi(A,t,e,i,r,n){let s=(l,g)=>{l&&g&&A.uniformMatrix4fv(l,!1,phi(g))},o=(l,g)=>{l&&g&&A.uniform4f(l,...g)},a=(l,g)=>{l&&g!==void 0&&A.uniform1f(l,g)};switch(t.projectionMode){case"maplibre-globe":case"wgs84-globe":{if(!i)return;s(t.projMatrixLoc,i.mainMatrix),s(t.fallbackMatrixLoc,i.fallbackMatrix),o(t.tileMercatorCoordsLoc,i.tileMercatorCoords),o(t.clippingPlaneLoc,i.clippingPlane),a(t.projectionTransitionLoc,i.projectionTransition);break}case"mapbox":case"mapbox-wgs84":{s(t.matrixLoc,e),s(t.globeToMercMatrixLoc,r?.globeToMercatorMatrix),a(t.globeTransitionLoc,r?.transition??1),t.tileRenderLoc&&A.uniform1i(t.tileRenderLoc,n?1:0);break}default:{s(t.matrixLoc,e);break}}}var $q=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function TKt(A,t,e,i){let r=Math.max(0,A),n=Math.min(1,e),s=Math.max(0,t),o=Math.min(1,i),a=n-r,l=o-s;return new Float32Array([2/a,0,0,0,0,2/l,0,0,0,0,1,0,-(r+n)/a,-(s+o)/l,0,1])}function UKt(A){let t=2**A.z;return{x0:A.x/t,x1:(A.x+1)/t,y0:A.y/t,y1:(A.y+1)/t}}function fhi(A,t){return A.x0<t.x1&&A.x1>t.x0&&A.y0<t.y1&&A.y1>t.y0}function PKt(A){if(!A)return{xMin:-180,xMax:180,yMin:-90,yMax:90};let t=A.xMax-A.xMin,e=A.yMax-A.yMin,i=t>=350&&e>=170;return{xMin:i?-180:A.xMin,xMax:i?180:A.xMax,yMin:i?-90:A.yMin,yMax:i?90:A.yMax}}function aPe(A,t){return Math.floor($1(A)*Math.pow(2,t))}function lPe(A,t){let e=Math.max(-Xq,Math.min(Xq,A)),i=Math.pow(2,t);return Math.floor((1-Math.log(Math.tan(e*Math.PI/180)+1/Math.cos(e*Math.PI/180))/Math.PI)/2*i)}function eHe(A,t){let[[e,i],[r,n]]=t,s=Math.max(-Xq,i),o=Math.min(Xq,n),a=aPe(e,A),l=aPe(r,A),g=lPe(o,A),h=lPe(s,A),p=Math.pow(2,A),d=[],E=new Set;a>l&&(l+=p);for(let f=a;f<=l;f++){let Q=(f%p+p)%p;for(let y=g;y<=h;y++){let S=Math.max(0,Math.min(p-1,y)),v=`${A},${Q},${S}`;E.has(v)||(E.add(v),d.push([A,Q,S]))}}return d}function AHe(A,t,e){let[[i,r],[n,s]]=t,{xMin:o,xMax:a,yMin:l,yMax:g}=PKt(e),h=a-o,p=g-l,d=Math.pow(2,A),E=Y=>Math.floor((Y-o)/h*d),f=Y=>{let z=Math.max(Math.min(Y,g),l),F=(g-z)/p;return Math.floor(F*d)},Q=E(i),y=E(n),S=f(s),v=f(r),M=[],H=new Set;Q>y&&(y+=d);for(let Y=Q;Y<=y;Y++){let z=(Y%d+d)%d;for(let F=S;F<=v;F++){let N=Math.max(0,Math.min(d-1,F)),P=`${A},${z},${N}`;H.has(P)||(H.add(P),M.push([A,z,N]))}}return M}function m3(A){return A.join(",")}function gPe(A){let[t,e,i]=A,r=1/2**(t+1),n=(2*e+1)*r,s=(2*i+1)*r;return[r,n,s]}function _hi(A,t){return t?Math.min(Math.max(0,Math.floor(A)),t):Math.max(0,Math.floor(A))}function got(A,t=0){let e=parseInt(A,10);if(!isNaN(e))return e;let i=A.match(/(\d+)$/);return i?parseInt(i[1],10):t}function $1(A){let t=A;return A>180?t=A-360:A<-180&&(t=A+360),(t+180)/360}function C6(A){let t=Math.max(-Xq,Math.min(Xq,A));return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2}function YT(A){let t=Math.PI*(1-2*A);return 180/Math.PI*Math.atan(Math.sinh(t))}function oot(A){return A*360-180}function mhi(A,t,e,i){let r=Math.pow(2,A),{xMin:n,xMax:s,yMin:o,yMax:a}=PKt(i),l=s-n,g=a-o,h=n+t/r*l,p=n+(t+1)/r*l,d=a-e/r*g,E=a-(e+1)/r*g;return{west:h,east:p,south:E,north:d}}function iHe(A,t,e,i){let r=t-1,n=Math.floor(e/2),s=Math.floor(i/2);for(;r>=0;){let o=m3([r,n,s]),a=A.get(o);if(a&&a.data)return{tile:a,ancestorZ:r,ancestorX:n,ancestorY:s};r--,n=Math.floor(n/2),s=Math.floor(s/2)}return null}function rHe(A,t,e,i,r,n=2){let s=0,o=[];for(let a=1;a<=n;a++){let l=t+a;if(l>r)break;let g=Math.pow(2,a),h=e*g,p=i*g,d=g*g,E=[];for(let Q=0;Q<g;Q++)for(let y=0;y<g;y++){let S=h+y,v=p+Q,M=m3([l,S,v]),H=A.get(M);H&&H.data&&E.push({tile:H,childZ:l,childX:S,childY:v})}let f=E.length/d;if(f===1)return E;f>s&&(s=f,o=E)}return o.length>0?o:null}function cPe(A,t){if(t==="EPSG:3857")return{x0:(A.xMin+zC)/(2*zC),y0:(zC-A.yMax)/(2*zC),x1:(A.xMax+zC)/(2*zC),y1:(zC-A.yMin)/(2*zC)};let e=A.yMin,i=A.yMax;e>i&&([e,i]=[i,e]);let r={x0:$1(A.xMin),y0:C6(i),x1:$1(A.xMax),y1:C6(e)};return t==="EPSG:4326"&&(r.latMin=e,r.latMax=i),r}function T_t(A,t,e,i){let r=(A-t)/(e-t);return Math.floor(Math.max(0,Math.min(i-1,r*i)))}function Qhi(A){let t=new Float32Array(A.length);for(let e=0;e<A.length;e+=2)t[e]=A[e],t[e+1]=1-A[e+1];return t}function nHe(A){return A?.type==="globe"||A?.name==="globe"}function yhi(A,t,e,i){let r=A&&typeof A=="object"&&!Array.isArray(A)&&!ArrayBuffer.isView(A)?A:null,n=r?.shaderData,s,o=r?.defaultProjectionData;o&&o.mainMatrix&&o.fallbackMatrix&&o.tileMercatorCoords&&o.clippingPlane&&typeof o.projectionTransition=="number"&&(s={mainMatrix:o.mainMatrix,fallbackMatrix:o.fallbackMatrix,tileMercatorCoords:o.tileMercatorCoords,clippingPlane:o.clippingPlane,projectionTransition:o.projectionTransition});let a=null;s?.mainMatrix&&s.mainMatrix.length?a=s.mainMatrix:Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array?a=A:r?.modelViewProjectionMatrix?a=r.modelViewProjectionMatrix:r?.projectionMatrix&&(a=r.projectionMatrix);let l=Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array;return{matrix:a,shaderData:n,projectionData:s,mapbox:!!t||l?{projection:t??{name:"mercator"},globeToMercatorMatrix:e??$q,transition:typeof i=="number"?i:1}:void 0}}function xhi(A,t){if(!A)return[0];let e=A.getBounds?A.getBounds():null;if(!e)return[0];let i=typeof A.getRenderWorldCopies=="function"?A.getRenderWorldCopies():!0;if(t||!i)return[0];let r=e.getWest(),n=e.getEast(),s=n;r>n&&(s=n+360);let o=Math.floor((r+180)/360),a=Math.floor((s+180)/360),l=[];for(let g=o;g<=a;g++)l.push(g);return l.length>0?l:[0]}function HKt(A,t,e){if(!t.useCustomShader||!e)return;let i=2;for(let r of e.bands){let n=t.bandTexLocs.get(r);n&&A.uniform1i(n,i),i++}}function whi(A,t){let{bandData:e,bandTextures:i,bandTexturesUploaded:r,bandTexturesConfigured:n,customShaderConfig:s,width:o,height:a,ensureTexture:l}=t,g=2;for(let h of s.bands){let p=e.get(h);if(!p)return!1;let d=i.get(h);if(!d)if(l){let E=l(h);E&&(d=E,i.set(h,d))}else d=A.createTexture(),d&&i.set(h,d);if(!d)return!1;A.activeTexture(A.TEXTURE0+g),A.bindTexture(A.TEXTURE_2D,d),n.has(h)||(LKt(A),n.add(h)),r.has(h)||(A.texImage2D(A.TEXTURE_2D,0,A.R32F,o,a,0,A.RED,A.FLOAT,p),r.add(h)),g++}return!0}function bhi(A,t,e,i){A.bindBuffer(A.ARRAY_BUFFER,e),A.enableVertexAttribArray(t.vertexLoc),A.vertexAttribPointer(t.vertexLoc,2,A.FLOAT,!1,0,0),A.bindBuffer(A.ARRAY_BUFFER,i),A.enableVertexAttribArray(t.pixCoordLoc),A.vertexAttribPointer(t.pixCoordLoc,2,A.FLOAT,!1,0,0)}function Shi(A,t){let{texture:e,data:i,width:r,height:n,channels:s,configured:o}=t;A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,e),o||LKt(A);let{format:a,internalFormat:l}=WPe(A,s);return A.texImage2D(A.TEXTURE_2D,0,l,r,n,0,a,A.FLOAT,i),{configured:!0,uploaded:!0}}function A6t(A,t,e,i,r){let n=e.wgs84Bounds??null,s,o,a,l;n?(s=(n.lon1-n.lon0)/2,o=(n.lat1-n.lat0)/2,a=(n.lon0+n.lon1)/2,l=(n.lat0+n.lat1)/2):(s=(e.mercatorBounds.x1-e.mercatorBounds.x0)/2,o=(e.mercatorBounds.y1-e.mercatorBounds.y0)/2,a=(e.mercatorBounds.x0+e.mercatorBounds.x1)/2,l=(e.mercatorBounds.y0+e.mercatorBounds.y1)/2),A.uniform1f(t.scaleLoc,0),A.uniform1f(t.scaleXLoc,s),A.uniform1f(t.scaleYLoc,o),A.uniform1f(t.shiftXLoc,a),A.uniform1f(t.shiftYLoc,l);let g=e.texScale??[1,1],h=e.texOffset??[0,0];A.uniform2f(t.texScaleLoc,g[0],g[1]),A.uniform2f(t.texOffsetLoc,h[0],h[1]);let p=e.mercatorBounds.latMin!==void 0&&e.mercatorBounds.latMax!==void 0,d=p&&!n;if(t.reprojectLoc!==null&&A.uniform1i(t.reprojectLoc,d?1:0),d&&t.latBoundsLoc!==null&&p&&A.uniform2f(t.latBoundsLoc,e.mercatorBounds.latMin,e.mercatorBounds.latMax),d&&t.latIsAscendingLoc!==null&&A.uniform1i(t.latIsAscendingLoc,e.latIsAscending?1:0),bhi(A,t,e.vertexBuffer,e.pixCoordBuffer),e.useIndexedMesh&&e.indexBuffer&&A.bindBuffer(A.ELEMENT_ARRAY_BUFFER,e.indexBuffer),t.useCustomShader&&r){if(!whi(A,{bandData:e.bandData,bandTextures:e.bandTextures,bandTexturesUploaded:e.bandTexturesUploaded,bandTexturesConfigured:e.bandTexturesConfigured,customShaderConfig:r,width:e.width,height:e.height,ensureTexture:e.ensureBandTexture}))return!1}else A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,e.texture),t.texLoc!==null&&A.uniform1i(t.texLoc,0);for(let E of i)A.uniform1f(t.worldXOffsetLoc,E),e.useIndexedMesh&&e.indexBuffer?A.drawElements(A.TRIANGLES,e.vertexCount,A.UNSIGNED_INT,0):A.drawArrays(A.TRIANGLE_STRIP,0,e.vertexCount);return!0}function hPe(A,t,e,i){return A.bindBuffer(A.ARRAY_BUFFER,t.vertexBuffer),t.geometryUploaded||A.bufferData(A.ARRAY_BUFFER,e,A.STATIC_DRAW),A.bindBuffer(A.ARRAY_BUFFER,t.pixCoordBuffer),t.geometryUploaded||(A.bufferData(A.ARRAY_BUFFER,i,A.STATIC_DRAW),t.geometryUploaded=!0),t.pixCoordBuffer}function uPe(A,t,e,i,r,n,s,o,a,l){return{mercatorBounds:t,vertexBuffer:A.vertexBuffer,pixCoordBuffer:e,vertexCount:i,texture:A.tileTexture,bandData:A.bandData,bandTextures:A.bandTextures,bandTexturesUploaded:A.bandTexturesUploaded,bandTexturesConfigured:A.bandTexturesConfigured,width:r,height:r,texScale:n,texOffset:s,ensureBandTexture:g=>o.ensureBandTexture(a,g),latIsAscending:l}}function vhi(A,t,e,i,r,n,s,o,a,l,g=!1,h,p,d=!0){HKt(A,t,l);let E=s.length/2;for(let f of e){let[Q,y,S]=f,v=m3(f),M=r.get(v),H=a?.[v],Y=null,z=v,F=[1,1],N=[0,0];if(M&&M.data)Y=M;else{let st=iHe(r,Q,y,S);if(st){Y=st.tile,z=m3([st.ancestorZ,st.ancestorX,st.ancestorY]);let it=Q-st.ancestorZ,W=Math.pow(2,it),X=y%W,rt=S%W;F=[1/W,1/W],N=[X/W,rt/W]}else if(h!==void 0){let it=rHe(r,Q,y,S,h);if(it&&it.length>0){let W;if(H)W=H;else{let[X,rt,gt]=gPe(f);W={x0:rt-X,x1:rt+X,y0:gt-X,y1:gt+X}}for(let X of it){if(!X.tile.data||!X.tile.vertexBuffer||!X.tile.pixCoordBuffer||!X.tile.tileTexture)continue;let rt=X.childZ-Q,gt=Math.pow(2,rt),ft=X.childX%gt,mt=X.childY%gt,St=W.x1-W.x0,wt=W.y1-W.y0,kt={x0:W.x0+ft/gt*St,x1:W.x0+(ft+1)/gt*St,y0:W.y0+mt/gt*wt,y1:W.y0+(mt+1)/gt*wt};if(H?.latMin!==void 0&&H?.latMax!==void 0){let Ie=H.latMax-H.latMin;kt.latMin=H.latMin+mt/gt*Ie,kt.latMax=H.latMin+(mt+1)/gt*Ie}if(H?.lonMin!==void 0&&H?.lonMax!==void 0){let Ie=H.lonMax-H.lonMin;kt.lonMin=H.lonMin+ft/gt*Ie,kt.lonMax=H.lonMin+(ft+1)/gt*Ie}let Dt=hPe(A,X.tile,s,o),Pt=m3([X.childZ,X.childX,X.childY]),ee=uPe(X.tile,kt,Dt,E,n,[1,1],[0,0],r,Pt,d);A6t(A,t,ee,g?[0]:i,l)}continue}}}if(!Y||!Y.data||!Y.vertexBuffer||!Y.pixCoordBuffer||!Y.tileTexture)continue;if(g&&p?.[v]){let st=p[v];F=st.texScale,N=st.texOffset}let P=hPe(A,Y,s,o),K;if(H)K=H;else{let[st,it,W]=gPe(f);K={x0:it-st,x1:it+st,y0:W-st,y1:W+st}}let At=uPe(Y,K,P,E,n,F,N,r,z,d);A6t(A,t,At,g?[0]:i,l)}}var Dhi=class sHe{constructor(t,e,i){this.shaderCache=new Map,this.customShaderConfig=null,this.gl=sHe.resolveGl(t),this.fragmentShaderSource=e,this.customShaderConfig=i||null}updateMultiBandConfig(t){if(t&&this.customShaderConfig){let e=JSON.stringify(t.bands)!==JSON.stringify(this.customShaderConfig.bands),i=t.customFrag!==this.customShaderConfig.customFrag;(e||i)&&this.shaderCache.clear()}else t!==this.customShaderConfig&&this.shaderCache.clear();this.customShaderConfig=t}static resolveGl(t){if(t&&typeof t.getUniformLocation=="function"&&typeof t.drawBuffers=="function")return t.getExtension("EXT_color_buffer_float"),t.getExtension("OES_texture_float_linear"),t;throw new Error("Invalid WebGL2 context: missing required WebGL2 methods")}getProgram(t,e,i=!1,r=!1){let n=Ihi(i,r),s=e||this.customShaderConfig,o=$Pe({projectionMode:n,shaderData:t,customShaderConfig:s}),a=this.shaderCache.get(o);if(a)return a;let{shaderProgram:l}=Bhi(this.gl,{fragmentShaderSource:this.fragmentShaderSource,shaderData:t,customShaderConfig:s,projectionMode:n,variantName:o});return this.shaderCache.set(o,l),l}applyCommonUniforms(t,e,i,r,n,s,o,a=!1){let l=this.gl;if(l.enable(l.BLEND),l.blendFunc(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA),l.activeTexture(l.TEXTURE1),l.bindTexture(l.TEXTURE_2D,e),t.cmapLoc&&l.uniform1i(t.cmapLoc,1),t.colormapLoc&&l.uniform1i(t.colormapLoc,1),t.climLoc&&l.uniform2f(t.climLoc,i.clim[0],i.clim[1]),l.uniform1f(t.opacityLoc,i.opacity),t.fillValueLoc&&l.uniform1f(t.fillValueLoc,i.fillValue??NaN),t.scaleFactorLoc&&l.uniform1f(t.scaleFactorLoc,i.scaleFactor),t.addOffsetLoc&&l.uniform1f(t.addOffsetLoc,i.offset),t.dataScaleLoc&&l.uniform1f(t.dataScaleLoc,i.fixedDataScale),l.uniform2f(t.texScaleLoc,1,1),l.uniform2f(t.texOffsetLoc,0,0),r?.customUniforms)for(let[g,h]of Object.entries(r.customUniforms)){let p=t.customUniformLocs.get(g);p&&l.uniform1f(p,h)}o&&Ehi(l,t,o,n,s,a)}renderTiles(t,e,i,r,n,s,o,a,l,g=!1,h,p,d=!0){vhi(this.gl,t,e,i,r,n,s,o,a,l,g,h,p,d)}dispose(){let t=this.gl;for(let[,e]of this.shaderCache)t.deleteProgram(e.program);this.shaderCache.clear()}};function OKt(A,t){let e=t instanceof Error?t.message:String(t);return`[zarr-layer] Invalid proj4 string: "${A.slice(0,50)}${A.length>50?"...":""}". Error: ${e}. Check your dataset metadata or find CRS definitions at https://epsg.io/`}function khi(A,t){let e;try{e=V1(A,"EPSG:3857")}catch(i){throw new Error(OKt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function Rhi(A,t){let e;try{e=V1(A,"EPSG:4326")}catch(i){throw new Error(OKt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function oHe(A,t){let[e,i,r,n]=A;return r<=e||n<=i?(console.warn(`[zarr-layer] Invalid bounds in ${t}: max must be greater than min`),!1):!0}function YKt(A,t,e,i,r,n=!0){if(!oHe(e,"sourceCRSToPixel"))return[i/2,r/2];let[s,o,a,l]=e,g=(A-s)/(a-s),h=(t-o)/(l-o),p=g*i,d=n?h*r:(1-h)*r;return[p,d]}function i6t(A,t,e,i,r,n=!0){let[s,o,a,l]=e;if(!oHe(e,"pixelToSourceCRS"))return[(s+a)/2,(o+l)/2];let g=i<=1?.5:A/i,h=r<=1?.5:t/r,p=s+g*(a-s),d=n?o+h*(l-o):l-h*(l-o);return[p,d]}function hot(A){let t;try{t=V1("EPSG:4326",A)}catch(e){throw new Error(OKt(A,e))}return{forward:(e,i)=>t.forward([e,i]),inverse:(e,i)=>t.inverse([e,i])}}function IPe(A,t,e){let{xMin:i,yMin:r,xMax:n,yMax:s}=A,o=1/0,a=-1/0,l=1/0,g=-1/0;for(let h=0;h<=e;h++){let p=h/e,d=[[i+p*(n-i),r],[i+p*(n-i),s],[i,r+p*(s-r)],[n,r+p*(s-r)]];for(let[E,f]of d){let[Q,y]=t.forward(E,f);if(!isFinite(Q)||!isFinite(y))continue;let S=(Q+zC)/(2*zC),v=(zC-y)/(2*zC);o=Math.min(o,S),a=Math.max(a,S),l=Math.min(l,v),g=Math.max(g,v)}}return isFinite(o)?{x0:o,y0:l,x1:a,y1:g}:null}function aHe(A,t,e,i,r,n,s,o,a,l,g=!0){if(o&&a){let v=l??hot(o),M=g?A+.5:A,H=g?t+.5:t,[Y,z]=i6t(M,H,a,i,r,s),[F,N]=v.inverse(Y,z);return{lat:N,lon:F}}let h=i<=1?.5:g?(A+.5)/i:A/i,p=r<=1?.5:g?(t+.5)/r:t/r,d=e.x0+h*(e.x1-e.x0),E=e.y0+p*(e.y1-e.y0),f=oot(d),Q=e.y1-e.y0,y=Q===0?.5:(E-e.y0)/Q;return{lat:n==="EPSG:4326"&&e.latMin!==void 0&&e.latMax!==void 0?s?e.latMin+y*(e.latMax-e.latMin):e.latMax-y*(e.latMax-e.latMin):YT(E),lon:f}}function lHe(A,t,e,i,r,n){let[s,o,a]=A,l=Math.pow(2,s),g=(o+t/i)/l,h=(a+e/i)/l;if(r==="EPSG:4326"){let{xMin:f,xMax:Q,yMin:y,yMax:S}=n,v=f+g*(Q-f);return{lat:S-h*(S-y),lon:v}}let p=g*360-180,d=180-h*360;return{lat:360/Math.PI*Math.atan(Math.exp(d*Math.PI/180))-90,lon:p}}function JKt(A){let t=1/0,e=-1/0,i=1/0,r=-1/0;if(A.type==="Point"){let[s,o]=A.coordinates;return{west:s,east:s,south:o,north:o}}let n=s=>{for(let[o,a]of s)o<t&&(t=o),o>e&&(e=o),a<i&&(i=a),a>r&&(r=a)};return A.type==="Polygon"?A.coordinates.forEach(n):A.coordinates.forEach(s=>s.forEach(n)),{west:t,east:e,south:i,north:r}}function Mhi(A,t,e,i,r,n,s,o,a){let l=JKt(A);if(s&&o){let M=a??hot(s),H=5,Y=[];for(let W=0;W<=H;W++){let X=W/H,rt=l.west+X*(l.east-l.west),gt=l.south+X*(l.north-l.south);Y.push([rt,l.south]),Y.push([rt,l.north]),Y.push([l.west,gt]),Y.push([l.east,gt])}let z=1/0,F=-1/0,N=1/0,P=-1/0;for(let[W,X]of Y){let[rt,gt]=M.forward(W,X);if(!isFinite(rt)||!isFinite(gt))continue;let[ft,mt]=YKt(rt,gt,o,e,i,n);z=Math.min(z,ft),F=Math.max(F,ft),N=Math.min(N,mt),P=Math.max(P,mt)}if(!isFinite(z)||!isFinite(F)||!isFinite(N)||!isFinite(P))return null;let K=Math.max(0,Math.floor(z)),At=Math.min(e,Math.floor(F)+1),st=Math.max(0,Math.floor(N)),it=Math.min(i,Math.floor(P)+1);return At<=K||it<=st?null:{minX:K,maxX:At,minY:st,maxY:it}}let g=$1(l.west),h=$1(l.east),p=C6(l.north),d=C6(l.south),E=Math.max(t.x0,Math.min(g,h)),f=Math.min(t.x1,Math.max(g,h)),Q,y,S,v;if(r==="EPSG:4326"&&t.latMin!==void 0&&t.latMax!==void 0){let M=t.latMax,H=t.latMin,Y=Math.min(Math.max(l.north,H),M),z=Math.min(Math.max(l.south,H),M),F=M-H;if(F===0)return null;let N=X=>n?(X-H)/F:(M-X)/F,P=N(Y),K=N(z),At=Math.min(P,K),st=Math.max(P,K);if(f<=E||st<=At)return null;let it=(E-t.x0)/(t.x1-t.x0)*e,W=(f-t.x0)/(t.x1-t.x0)*e;Q=Math.max(0,Math.floor(it)),y=Math.min(e,Math.ceil(W)),S=Math.max(0,Math.floor(At*i)),v=Math.min(i,Math.ceil(st*i))}else{let M=Math.max(t.y0,Math.min(p,d)),H=Math.min(t.y1,Math.max(p,d));if(f<=E||H<=M)return null;let Y=(E-t.x0)/(t.x1-t.x0)*e,z=(f-t.x0)/(t.x1-t.x0)*e,F=(M-t.y0)/(t.y1-t.y0)*i,N=(H-t.y0)/(t.y1-t.y0)*i;Q=Math.max(0,Math.floor(Y)),y=Math.min(e,Math.ceil(z)),S=Math.max(0,Math.floor(F)),v=Math.min(i,Math.ceil(N))}return y<=Q||v<=S?null:{minX:Q,maxX:y,minY:S,maxY:v}}function U_t(A,t){let e=!1,[i,r]=A;for(let n=0,s=t.length-1;n<t.length;s=n++){let o=t[n][0],a=t[n][1],l=t[s][0],g=t[s][1];a>r!=g>r&&i<(l-o)*(r-a)/(g-a)+o&&(e=!e)}return e}function Ghi(A,t){if(t.type==="Point")return A[0]===t.coordinates[0]&&A[1]===t.coordinates[1];if(t.type==="Polygon"){if(!U_t(A,t.coordinates[0]))return!1;for(let e=1;e<t.coordinates.length;e++)if(U_t(A,t.coordinates[e]))return!1;return!0}for(let e of t.coordinates)if(U_t(A,e[0])){let i=!1;for(let r=1;r<e.length;r++)if(U_t(A,e[r])){i=!0;break}if(!i)return!0}return!1}function gHe(A,t){let e=Math.min(...A.map(h=>h[0])),i=Math.max(...A.map(h=>h[0])),r=Math.min(...A.map(h=>h[1])),n=Math.max(...A.map(h=>h[1])),s=h=>h[0]>=e&&h[0]<=i&&h[1]>=r&&h[1]<=n;for(let h of A)if(Ghi(h,t))return!0;if(t.type==="Point"&&s([t.coordinates[0],t.coordinates[1]]))return!0;if(t.type!=="Point"){let h=t.type==="Polygon"?t.coordinates:t.coordinates.flatMap(p=>p);for(let p of h)for(let[d,E]of p)if(s([d,E]))return!0}let o=[[A[0],A[1]],[A[1],A[2]],[A[2],A[3]],[A[3],A[0]]],a=h=>h.slice(0,-1).map((p,d)=>[h[d],h[d+1]]),l=t.type==="Polygon"?a(t.coordinates[0]):t.type==="MultiPolygon"?t.coordinates.flatMap(h=>a(h[0])):[],g=(h,p,d,E)=>{let f=(Y,z)=>Y[0]*z[1]-Y[1]*z[0],Q=(Y,z)=>[Y[0]-z[0],Y[1]-z[1]],y=Q(p,h),S=Q(E,d),v=f(y,S);if(v===0)return!1;let M=f(Q(d,h),S)/v,H=f(Q(d,h),y)/v;return M>=0&&M<=1&&H>=0&&H<=1};for(let h of o)for(let p of l)if(g(h[0],h[1],p[0],p[1]))return!0;return!1}function Fhi(A,t,e,i,r,n){let s=[],o=[[0,0],[1,0],[1,1],[0,1]];for(let[a,l]of o){let g=lHe(A,t+a,e+l,i,r,n);s.push([g.lon,g.lat])}return s}function Nhi(A,t,e,i,r,n,s,o,a,l){let g=[[0,0],[1,0],[1,1],[0,1]],h=[];for(let[p,d]of g){let{lon:E,lat:f}=aHe(i+p,r+d,A,t,e,n,s,o,a,l,!1);h.push([E,f])}return h}function Lhi(A,t,e,i,r,n,s){let o=Fhi(A,t,e,i,r,n);return gHe(o,s)}function Thi(A,t,e,i,r,n,s,o,a,l,g){let h=Nhi(A,t,e,i,r,n,o,a,l,g);return gHe(h,s)}function Uhi(A,t,e,i){let r=[[A.west,A.south],[A.east,A.north]];return e==="EPSG:4326"?AHe(t,r,i):eHe(t,r)}function Phi(A,t,e,i){let r=JKt(A);return Uhi(r,t,e,i)}function Hhi(A,t,e,i,r,n,s,o,a,l){if(o&&a){let E=l??hot(o),[f,Q]=E.forward(A,t),[y,S,v,M]=a;if(f<y||f>v||Q<S||Q>M)return null;let[H,Y]=YKt(f,Q,a,i,r,s),z=Math.floor(H),F=Math.floor(Y);return z<0||z>=i||F<0||F>=r?null:{x:z,y:F}}let g,h;if(n==="EPSG:4326"&&e.latMin!==void 0&&e.latMax!==void 0){g=($1(A)-e.x0)/(e.x1-e.x0);let E=e.latMax-e.latMin;if(E===0)return null;h=s?(t-e.latMin)/E:(e.latMax-t)/E}else g=($1(A)-e.x0)/(e.x1-e.x0),h=(C6(t)-e.y0)/(e.y1-e.y0);if(g<0||g>1||h<0||h>1)return null;let p=Math.floor(g*i),d=Math.floor(h*r);return{x:Math.min(p,i-1),y:Math.min(d,r-1)}}function Ohi(A,t,e,i,r,n,s,o,a){let l=[],g=[[]],h=[[]];for(let p=0;p<r.length;p++){let d=r[p],E=d.toLowerCase(),f=a[p]*o[p],Q=n[d];if(["x","lon","longitude"].includes(E))g=g.map(y=>[...y,t]);else if(["y","lat","latitude"].includes(E))g=g.map(y=>[...y,e]);else{let y=i[d],S,v;if(y===void 0){S=[],v=[];for(let Y=0;Y<o[p];Y++){let z=f+Y;z<s[p]&&(S.push(z),Q&&v.push(Q[z]))}}else if(Array.isArray(y)){S=[],v=[];for(let Y of y){let z;Q?(z=Q.indexOf(Y),z<0&&(z=typeof Y=="number"?Y:0)):z=typeof Y=="number"?Y:0,z>=f&&z<f+o[p]&&(S.push(z),v.push(Y))}}else if(typeof y=="object"&&"selected"in y){let Y=y.selected,z=y.type,F=Array.isArray(Y)?Y:[Y];S=[],v=[];for(let N of F){let P;z==="index"?P=typeof N=="number"?N:0:Q?(P=Q.indexOf(N),P<0&&(P=typeof N=="number"?N:0)):P=typeof N=="number"?N:0,P>=f&&P<f+o[p]&&(S.push(P),Array.isArray(Y)&&v.push(N))}}else{let Y;Q?(Y=Q.indexOf(y),Y<0&&(Y=typeof y=="number"?y:0)):Y=typeof y=="number"?y:0,S=[Y],v=[]}let M=[],H=[];for(let Y=0;Y<S.length;Y++)for(let z=0;z<g.length;z++)M.push([...g[z],S[Y]]),v.length>0?H.push([...h[z],v[Y]]):H.push([...h[z]]);g=M.length>0?M:g.map(Y=>[...Y,0]),h.length=0,h.push(...H.length>0?H:h.map(()=>[]))}}for(let p=0;p<g.length;p++){let d=g[p],E=h[p]||[],f=d.map((v,M)=>{let H=r[M].toLowerCase();return["x","lon","longitude","y","lat","latitude"].includes(H)?v:v-a[M]*o[M]}),Q=new Array(r.length);Q[r.length-1]=1;for(let v=r.length-2;v>=0;v--)Q[v]=Q[v+1]*o[v+1];let y=0;for(let v=0;v<r.length;v++)y+=f[v]*Q[v];let S=A[y];l.push({keys:E,value:S})}return l}function jKt(A,t,e){if(t.length===0)return Array.isArray(A)&&A.push(e),A;let i=A;for(let r=0;r<t.length;r++){let n=t[r];if(r===t.length-1){i[n]||(i[n]=[]);let s=i[n];Array.isArray(s)&&s.push(e)}else i[n]||(i[n]={}),i=i[n]}return A}function pPe(A,t,e,i,r,n,s){let o=t.map((l,g)=>{let h=l.toLowerCase();if(["x","lon","longitude"].includes(h))return[n];if(["y","lat","latitude"].includes(h))return[s];let p=A[l],d=e[l],E=r[g],f;if(p===void 0)f=Array(i[g]).fill(null).map((y,S)=>S);else if(Array.isArray(p))f=p.map(y=>{let S=d?d.indexOf(y):typeof y=="number"?y:0;return S>=0?S:typeof y=="number"?y:0});else if(typeof p=="object"&&"selected"in p){let y=p.selected,S=p.type;f=(Array.isArray(y)?y:[y]).map(M=>{if(S==="index")return typeof M=="number"?M:0;if(d){let H=d.indexOf(M);return H>=0?H:typeof M=="number"?M:0}return typeof M=="number"?M:0})}else if(d){let y=d.indexOf(p);f=[y>=0?y:typeof p=="number"?p:0]}else f=[typeof p=="number"?p:0];return f.map(y=>Math.floor(y/E)).filter((y,S,v)=>v.indexOf(y)===S)}),a=[[]];return o.forEach(l=>{let g=[];l.forEach(h=>{a.forEach(p=>{g.push([...p,h])})}),a=g}),a}function cHe(A,t){if(!Number.isFinite(A)||t?.fillValue!==void 0&&t.fillValue!==null&&A===t.fillValue)return null;let e=A;return t?.scaleFactor!==void 0&&t.scaleFactor!==1&&(e*=t.scaleFactor),t?.addOffset!==void 0&&t.addOffset!==0&&(e+=t.addOffset),e}async function Yhi(A,t,e,i,r,n,s,o,a){let l=i.describe(),g=l.dimensions,h=l.coordinates,p=l.shape||[],d=l.chunks||[],E=st=>Array.isArray(st)?!0:st&&typeof st=="object"&&"selected"in st?Array.isArray(st.selected):!1,f=Object.keys(e).filter(st=>!E(e[st])).length,y=g.length-f>2,S=y?{}:[],v=[],M=[],H=g.map(st=>{let it=st.toLowerCase();return["x","lon","longitude"].includes(it)?"lon":["y","lat","latitude"].includes(it)?"lat":st}),Y=y?H:["lat","lon"],z=()=>{let st={lat:v,lon:M};if(y){let it=W=>{let X=W.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(X))return;let rt=e[W],gt;if(Array.isArray(rt))gt=rt;else if(rt&&typeof rt=="object"&&"selected"in rt){let ft=rt.selected;gt=Array.isArray(ft)?ft:[ft]}else rt!==void 0&&typeof rt!="object"?gt=[rt]:h[W]&&(gt=h[W]);gt&&(st[W]=gt)};g.forEach(it)}return st},F=i.levels[s];if(!F)throw new Error(`No level path found for level index ${s}`);let N=got(F,s),P=Phi(t,N,r,n);if(P.length===0)return{[A]:S,dimensions:Y,coordinates:z()};let K=new Map;await Promise.all(P.map(async st=>{let[,it,W]=st,X=pPe(e,g,h,p,d,it,W),rt=m3(st),gt=new Map;await Promise.all(X.map(async ft=>{try{let mt=await i.getChunk(F,ft),St=new Float32Array(mt.data),wt=ft.join(",");gt.set(wt,St)}catch(mt){console.warn(`Failed to fetch chunk ${ft} for tile ${rt}:`,mt)}})),K.set(rt,gt)}));for(let st of P){let it=m3(st),W=K.get(it);if(!W||W.size===0)continue;let[,X,rt]=st,gt=pPe(e,g,h,p,d,X,rt);for(let ft=0;ft<o;ft++)for(let mt=0;mt<o;mt++){if(!Lhi(st,mt,ft,o,r,n,t))continue;let St=[];for(let kt of gt){let Dt=kt.join(","),Pt=W.get(Dt);if(!Pt)continue;let ee=Ohi(Pt,mt,ft,e,g,h,p,d,kt);for(let{keys:Ie,value:Tt}of ee){let $e=cHe(Tt,a);$e!==null&&St.push({keys:Ie,value:$e})}}if(St.length===0)continue;let wt=lHe(st,mt+.5,ft+.5,o,r,n);v.push(wt.lat),M.push(wt.lon);for(let{keys:kt,value:Dt}of St)kt.length>0?jKt(S,kt,Dt):Array.isArray(S)&&S.push(Dt)}}return{[A]:S,dimensions:Y,coordinates:z()}}async function Jhi(A,t,e,i,r,n,s,o,a,l,g=1,h,p,d,E,f,Q){let y=rt=>Array.isArray(rt)?!0:rt&&typeof rt=="object"&&"selected"in rt?Array.isArray(rt.selected):!1,S=Object.keys(e).filter(rt=>!y(e[rt])).length,M=a.length-S>2,H=M?{}:[],Y=[],z=[],F=a.map(rt=>{let gt=rt.toLowerCase();return["x","lon","longitude"].includes(gt)?"lon":["y","lat","latitude"].includes(gt)?"lat":rt}),N=M?F:["lat","lon"],P=()=>{let rt={lat:Y,lon:z};if(M){let gt=ft=>{let mt=ft.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(mt))return;let St=e[ft],wt;if(Array.isArray(St))wt=St;else if(St&&typeof St=="object"&&"selected"in St){let kt=St.selected;wt=Array.isArray(kt)?kt:[kt]}else St!==void 0&&typeof St!="object"?wt=[St]:l[ft]&&(wt=l[ft]);wt&&(rt[ft]=wt)};a.forEach(gt)}return rt};if(!i)return{[A]:H,dimensions:N,coordinates:P()};let K=0,At=r,st=0,it=n;if(!f){let rt=JKt(t),gt=$1(rt.west),ft=$1(rt.east),mt=C6(rt.north),St=C6(rt.south),wt=Math.max(s.x0,Math.min(gt,ft)),kt=Math.min(s.x1,Math.max(gt,ft));if(o==="EPSG:4326"&&s.latMin!==void 0&&s.latMax!==void 0){let Dt=s.latMax,Pt=s.latMin,ee=Math.min(Math.max(rt.north,Pt),Dt),Ie=Math.min(Math.max(rt.south,Pt),Dt),Tt=Dt-Pt;if(Tt===0)return{[A]:H,dimensions:N,coordinates:P()};let $e=Ci=>d?(Ci-Pt)/Tt:(Dt-Ci)/Tt,Ne=$e(ee),be=$e(Ie),xt=Math.min(Ne,be),Ue=Math.max(Ne,be);if(kt<=wt||Ue<=xt)return{[A]:H,dimensions:N,coordinates:P()};let OA=(wt-s.x0)/(s.x1-s.x0)*r,_e=(kt-s.x0)/(s.x1-s.x0)*r;K=Math.max(0,Math.floor(OA)),At=Math.min(r,Math.ceil(_e+1)),st=Math.max(0,Math.floor(xt*n)),it=Math.min(n,Math.ceil(Ue*n))}else{let Dt=Math.max(s.y0,Math.min(mt,St)),Pt=Math.min(s.y1,Math.max(mt,St));if(kt<=wt||Pt<=Dt)return{[A]:H,dimensions:N,coordinates:P()};let ee=(wt-s.x0)/(s.x1-s.x0)*r,Ie=(kt-s.x0)/(s.x1-s.x0)*r,Tt=(Dt-s.y0)/(s.y1-s.y0)*n,$e=(Pt-s.y0)/(s.y1-s.y0)*n;K=Math.max(0,Math.floor(ee)),At=Math.min(r,Math.ceil(Ie+1)),st=Math.max(0,Math.floor(Tt)),it=Math.min(n,Math.ceil($e+1))}if(At<=K||it<=st)return{[A]:H,dimensions:N,coordinates:P()}}let W=f?hot(f):void 0;for(let rt=st;rt<it;rt++)for(let gt=K;gt<At;gt++){if(!Thi(s,r,n,gt,rt,o,t,d,f,Q,W))continue;let{lat:ft,lon:mt}=aHe(gt,rt,s,r,n,o,d,f,Q,W),St=(rt*r+gt)*g,wt=[];for(let kt=0;kt<g;kt++){let Dt=i[St+kt],Pt=cHe(Dt,E);if(Pt!==null)if(M&&p){let ee=h?.[kt],Ie=ee&&ee.length===p.length?ee:[kt];wt.push({keys:Ie,value:Pt})}else wt.push({keys:[],value:Pt})}if(wt.length!==0){Y.push(ft),z.push(mt);for(let{keys:kt,value:Dt}of wt)kt.length>0?jKt(H,kt,Dt):Array.isArray(H)&&H.push(Dt)}}return{[A]:H,dimensions:N,coordinates:P()}}function hHe(){return{lastFetchTime:0,throttleTimeout:null,throttledPending:!1}}function uHe(A,t){if(t<=0)return 0;let i=Date.now()-A.lastFetchTime;return i<t?t-i:0}function IHe(A,t,e){A.throttleTimeout||(A.throttledPending=!0,A.throttleTimeout=setTimeout(()=>{A.throttleTimeout=null,A.throttledPending=!1,e()},t))}function pHe(A){A.lastFetchTime=Date.now()}function dHe(A){A.throttleTimeout&&(clearTimeout(A.throttleTimeout),A.throttleTimeout=null),A.throttledPending=!1}function CHe(){return{controllers:new Map,currentVersion:0}}function BHe(A,t){for(let[e,i]of A.controllers)e<t&&(i.abort(),A.controllers.delete(e))}function X_t(A){for(let t of A.controllers.values())t.abort();A.controllers.clear()}function jhi(A){for(let t of A.controllers.values())if(!t.signal.aborted)return!0;return!1}function EHe(){return{callback:void 0,metadataLoading:!1,chunksLoading:!1}}function fHe(A,t){A.callback=t}function _He(A){if(!A.callback)return;let t={loading:A.metadataLoading||A.chunksLoading,metadata:A.metadataLoading,chunks:A.chunksLoading,error:null};A.callback(t)}var qhi=class{constructor({store:A,selector:t,fillValue:e,dimIndices:i,coordinates:r,maxCachedTiles:n=64,bandNames:s=[],fixedDataScale:o=1}){this.tiles=new Map,this.gl=null,this.store=A,this.selector=t,this.fillValue=e,this.dimIndices=i,this.coordinates=r,this.maxCachedTiles=n,this.bandNames=s,this.fixedDataScale=o}setGL(A){this.gl=A}updateBandNames(A){this.bandNames=A}updateSelector(A){this.selector=A}getDimKeyForName(A){let t=A.toLowerCase();return["lat","latitude","y"].includes(t)?"lat":["lon","longitude","x","lng"].includes(t)?"lon":["time","t","time_counter"].includes(t)?"time":["depth","z","level","lev","elevation"].includes(t)?"elevation":A}arraysEqual(A,t){if(!A||!t||A.length!==t.length)return!1;for(let e=0;e<A.length;e++)if(A[e]!==t[e])return!1;return!0}normalizeSelection(A,t){if(A===void 0)return[0];let e=t?this.coordinates[t]:void 0,i=r=>{let n=typeof r=="object"&&r!==null&&!Array.isArray(r)&&"selected"in r,s=n?r.selected:r;if((n&&r.type?r.type:"value")!=="index"&&e&&(typeof s=="number"||typeof s=="string")){let a=e.indexOf(s);if(a>=0)return a}return typeof s=="number"?s:0};return typeof A=="object"&&A!==null&&!Array.isArray(A)&&"selected"in A?(Array.isArray(A.selected)?A.selected:[A.selected]).map(n=>i({selected:n,type:A.type})):Array.isArray(A)?A.map(r=>i(r)):[i(A)]}computeChunkIndices(A,t){let[e,i,r]=t,n=this.store.dimensions||[],s=A.chunks,o=new Array(n.length).fill(0);for(let a=0;a<n.length;a++){let l=n[a],g=this.getDimKeyForName(l);if(g==="lon")o[a]=i;else if(g==="lat")o[a]=r;else{let h=APe(this.selector,g,l,this.dimIndices),d=this.normalizeSelection(h,l).map(y=>Math.max(0,Math.min(y,A.shape[a]-1))),E=Math.floor(d[0]/s[a]);d.some(y=>Math.floor(y/s[a])!==E)&&console.warn(`Selector for dimension '${l}' spans multiple chunks \u2013 using chunk index ${E} for tile ${t.join(",")}`);let Q=Math.max(0,Math.ceil(A.shape[a]/s[a])-1);o[a]=Math.min(E,Q)}}return o}extractSliceFromChunk(A,t,e,i){let r=this.store.tileSize,n=this.store.tileSize,s=1,o=this.store.dimensions||[],a=e.chunks,l=[],g=-1,h=-1,p=n,d=r,E=[],f=[];for(let M=0;M<o.length;M++){let H=o[M],Y=this.getDimKeyForName(H);if(Y==="lat")g=M,p=Math.min(t[M],n),l.push(-1);else if(Y==="lon")h=M,d=Math.min(t[M],r),l.push(-1);else{let z=APe(this.selector,Y,H,this.dimIndices),F=this.normalizeSelection(z,H),N=i[M]*a[M],P=F.map(K=>Math.max(0,Math.min(K-N,t[M]-1)));E[M]=P,l.push(P[0]),P.length>1&&f.push(M)}}let Q=M=>{let H=0,Y=1;for(let z=M.length-1;z>=0;z--)H+=M[z]*Y,Y*=t[z];return H},y=[[]];f.forEach(M=>{let H=E[M],Y=[];y.forEach(z=>{H.forEach(F=>{Y.push([...z,F])})}),y=Y}),s=y.length||1;let S=new Map,v=[];for(let M=0;M<s;M++){let H=new Float32Array(r*n);H.fill(this.fillValue),v.push(H)}for(let M=0;M<p;M++)for(let H=0;H<d;H++)g>=0&&(l[g]=M),h>=0&&(l[h]=H),y.forEach((Y,z)=>{let F=[...l],N=0;for(let At=0;At<f.length;At++)F[f[At]]=Y[N++];let P=Q(F),K=M*r+H;P<A.length&&(v[z][K]=A[P])});for(let M=0;M<s;M++){let H=this.bandNames[M]||`band_${M}`;S.set(H,v[M])}return{channels:s,bandData:S}}applyNormalization(A,t){let e=t.bandData;A.bandData=new Map,A.bandTexturesUploaded.clear();let i=[];for(let[r,n]of e){let{normalized:s}=VPe(n,this.fillValue,this.fixedDataScale);A.bandData.set(r,s),i.push(s)}A.data=ZPe(i,t.channels),A.channels=t.channels,this.gl&&A.tileTexture&&this.uploadTileTexture(A)}uploadTileTexture(A){if(!this.gl||!A.tileTexture||!A.data)return;let t=this.gl;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,A.tileTexture),A.textureConfigured||(LKt(t),A.textureConfigured=!0);let{format:e,internalFormat:i}=WPe(t,A.channels),r=this.store.tileSize;t.texImage2D(t.TEXTURE_2D,0,i,r,r,0,e,t.FLOAT,A.data),A.textureUploaded=!0}getOrCreateTile(A){let t=this.tiles.get(A);return t?(this.tiles.delete(A),this.tiles.set(A,t),t):(t={chunkData:null,chunkShape:null,chunkIndices:void 0,data:null,bandData:new Map,channels:1,selectorHash:null,selectorVersion:0,loading:!1,latBounds:null,geoBounds:null,mercatorBounds:null,tileTexture:this.gl?wKt(this.gl):null,bandTextures:new Map,bandTexturesUploaded:new Set,bandTexturesConfigured:new Set,textureUploaded:!1,textureConfigured:!1,vertexBuffer:this.gl?oPe(this.gl):null,pixCoordBuffer:this.gl?oPe(this.gl):null,geometryUploaded:!1},this.tiles.set(A,t),this.evictOldTiles(),t)}evictOldTiles(){for(;this.tiles.size>this.maxCachedTiles;){let A=this.tiles.keys().next().value;if(!A)break;let t=this.tiles.get(A);if(t&&this.gl){t.tileTexture&&this.gl.deleteTexture(t.tileTexture);for(let e of t.bandTextures.values())this.gl.deleteTexture(e);t.vertexBuffer&&this.gl.deleteBuffer(t.vertexBuffer),t.pixCoordBuffer&&this.gl.deleteBuffer(t.pixCoordBuffer)}this.tiles.delete(A)}}get(A){let t=this.tiles.get(A);return t&&(this.tiles.delete(A),this.tiles.set(A,t)),t}upsert(A){return this.getOrCreateTile(A)}ensureBandTexture(A,t){let e=this.tiles.get(A);if(!e||!this.gl)return null;let i=e.bandTextures.get(t);return i||(i=wKt(this.gl),e.bandTextures.set(t,i)),i}getTile(A){return this.tiles.get(m3(A))}setTileBounds(A,t){let e=this.tiles.get(A);if(!e)return;let i={min:t.latMin,max:t.latMax},r={west:t.lonMin,south:t.latMin,east:t.lonMax,north:t.latMax},n={x0:t.x0,y0:t.y0,x1:t.x1,y1:t.y1};(e.latBounds?.min!==i.min||e.latBounds?.max!==i.max||e.geoBounds?.west!==r.west||e.geoBounds?.east!==r.east||e.mercatorBounds?.x0!==n.x0||e.mercatorBounds?.x1!==n.x1||e.mercatorBounds?.y0!==n.y0||e.mercatorBounds?.y1!==n.y1)&&(e.latBounds=i,e.geoBounds=r,e.mercatorBounds=n)}async reextractTileSlices(A,t,e){for(let i of A){let r=m3(i),n=this.tiles.get(r);if(!n)continue;let s=this.store.levels[i[0]];if(!s)continue;let o=await this.store.getLevelArray(s),a=this.computeChunkIndices(o,i);if(n.chunkData&&n.chunkShape&&this.arraysEqual(n.chunkIndices,a)){if(e<n.selectorVersion)continue;let g=this.extractSliceFromChunk(n.chunkData,n.chunkShape,o,a);this.applyNormalization(n,g),n.selectorHash=t,n.selectorVersion=e}else n.selectorHash=null,n.chunkData=null,n.chunkShape=null,n.chunkIndices=void 0}}async fetchTile(A,t,e,i,r){let[n]=A,s=this.store.levels[n];if(!s)return null;let o=await this.store.getLevelArray(s),a=m3(A),l=this.getOrCreateTile(a);if(r&&(l.latBounds={min:r.latMin,max:r.latMax},l.geoBounds={west:r.lonMin,south:r.latMin,east:r.lonMax,north:r.latMax},l.mercatorBounds={x0:r.x0,y0:r.y0,x1:r.x1,y1:r.y1}),l.data&&l.selectorHash===t)return l;if(l.loading)return null;l.loading=!0;try{let g=this.computeChunkIndices(o,A);if(l.chunkData&&l.chunkShape&&this.arraysEqual(l.chunkIndices,g)){if(e<l.selectorVersion)return l.loading=!1,null;let Q=this.extractSliceFromChunk(l.chunkData,l.chunkShape,o,g);return this.applyNormalization(l,Q),l.selectorHash=t,l.selectorVersion=e,l.loading=!1,l}let p=await this.store.getChunk(s,g,{signal:i}),d=p.shape.map(Q=>Number(Q)),E=p.data instanceof Float32Array?new Float32Array(p.data.buffer):Float32Array.from(p.data);if(e<l.selectorVersion)return l.loading=!1,null;l.chunkData=E,l.chunkShape=d,l.chunkIndices=g;let f=this.extractSliceFromChunk(E,d,o,g);return this.applyNormalization(l,f),l.selectorHash=t,l.selectorVersion=e,l.loading=!1,l}catch(g){return l.loading=!1,g instanceof DOMException&&g.name==="AbortError"||console.error("Error fetching tile data:",g),null}}markGeometryDirty(){for(let A of this.tiles.values())A.geometryUploaded=!1}clear(){if(this.gl)for(let A of this.tiles.values()){A.tileTexture&&this.gl.deleteTexture(A.tileTexture);for(let t of A.bandTextures.values())this.gl.deleteTexture(t);A.vertexBuffer&&this.gl.deleteBuffer(A.vertexBuffer),A.pixCoordBuffer&&this.gl.deleteBuffer(A.pixCoordBuffer)}this.tiles.clear()}};function mHe(A,t,e,i,r){let n=m3([A,t,e]),s=i?.[n];if(s)return s;let o=mhi(A,t,e,r);return{x0:$1(o.west),x1:$1(o.east),y0:C6(o.north),y1:C6(o.south),latMin:o.south,latMax:o.north,lonMin:o.west,lonMax:o.east}}function QHe(A,t){let e=Math.max(A.x0,t.x0),i=Math.min(A.x1,t.x1),r=Math.max(A.y0,t.y0),n=Math.min(A.y1,t.y1);if(i<=e||n<=r)return null;let s=A.lonMin??oot(A.x0),o=A.lonMax??oot(A.x1),a=A.latMin??YT(A.y1),l=A.latMax??YT(A.y0),g=o-s,h=oot(e),p=oot(i),d=g>0?(p-h)/g:1,E=g>0?(h-s)/g:0;return{overlap:{x0:e,y0:r,x1:i,y1:n},latBounds:{min:a,max:l},texScale:[d,1],texOffset:[E,0]}}function yHe({renderer:A,mode:t,tileId:e,context:i,regions:r}){return r?Khi(A,e,i,r):zhi(A,t,e,i)}function Khi(A,t,e,i){if(i.length===0)return!0;let r=UKt(t),n={lon0:r.x0,lon1:r.x1,lat0:(YT(r.y1)+90)/180,lat1:(YT(r.y0)+90)/180},s=TKt(r.x0,r.y0,r.x1,r.y1),{colormapTexture:o,uniforms:a,customShaderConfig:l}=e,g=e.isGlobe??!0,h=i.some(E=>!!E.wgs84Bounds),p=A.getProgram(e.shaderData,l,!0,h);A.gl.useProgram(p.program),A.applyCommonUniforms(p,o,a,l,e.projectionData,{projection:{name:g?"globe":"mercator"},globeToMercatorMatrix:$q,transition:g?0:1},s,!0),HKt(A.gl,p,l);let d=!1;for(let E of i){let f;if(E.wgs84Bounds){let v=E.wgs84Bounds,M=v.lat0<n.lat1&&v.lat1>n.lat0,H;if(v.crossesAntimeridian){let z=v.lon0<1&&n.lon0<1&&n.lon1>v.lon0,F=n.lon0<v.lon1&&n.lon1>0;H=z||F}else H=v.lon0<n.lon1&&v.lon1>n.lon0;f=M&&H}else f=fhi(E.mercatorBounds,r);if(!f)continue;let Q=!!E.useIndexedMesh&&!!E.indexBuffer,y={mercatorBounds:E.mercatorBounds,vertexBuffer:E.vertexBuffer,pixCoordBuffer:E.pixCoordBuffer,vertexCount:Q?E.vertexCount??E.vertexArr.length/2:E.vertexArr.length/2,texture:E.texture,bandData:E.bandData??new Map,bandTextures:E.bandTextures??new Map,bandTexturesUploaded:E.bandTexturesUploaded??new Set,bandTexturesConfigured:E.bandTexturesConfigured??new Set,width:E.width,height:E.height,indexBuffer:Q?E.indexBuffer:void 0,useIndexedMesh:Q,wgs84Bounds:E.wgs84Bounds,latIsAscending:E.latIsAscending};A6t(A.gl,p,y,[0],l)||(d=!0)}return d}function zhi(A,t,e,i){let r=t.getTiledState?.();return r?.tileCache?t.getCRS()==="EPSG:4326"?Whi(A,t,e,i,r):Xhi(A,t,e,i,r):!0}function Whi(A,t,e,i,r){let{customShaderConfig:n}=i,{visibleTiles:s,tileBounds:o}=r,a=t.getXYLimits(),l=t.getMaxLevelIndex(),g=t.getLevels();if(!a||s.length===0)return!0;let h=UKt(e),p=TKt(h.x0,h.y0,h.x1,h.y1),d=[];for(let v of s){let M=m3(v),H=o?.[M];H&&H.x0<h.x1&&H.x1>h.x0&&H.y0<h.y1&&H.y1>h.y0&&d.push(v)}if(d.length===0)return!1;let E=A.getProgram(i.shaderData,n,!0,!1);A.gl.useProgram(E.program);let f=g[l]??"",Q=got(f,l),y=!1,S=!1;for(let v of d){let M=Vhi(A,E,v,h,p,r,i,a,Q);M.rendered&&(y=!0),M.missing&&(S=!0)}return S||!y}function Vhi(A,t,e,i,r,n,s,o,a){let{tileCache:l,vertexArr:g,pixCoordArr:h,tileSize:p,tileBounds:d}=n,{colormapTexture:E,uniforms:f,customShaderConfig:Q}=s,y=m3(e),S=l.get(y),v=e,M=!1;if(!S?.data){M=!0;let rt=iHe(l,e[0],e[1],e[2]);if(rt)S=rt.tile,v=[rt.ancestorZ,rt.ancestorX,rt.ancestorY];else{let gt=rHe(l,e[0],e[1],e[2],a);if(gt&>.length>0){let ft=!1;for(let mt of gt){if(!mt.tile.data)continue;Zhi(A,t,mt,i,r,n,s,o)&&(ft=!0)}return{rendered:ft,missing:!0}}return{rendered:!1,missing:!0}}}let[H,Y,z]=v,F=m3(v),N=mHe(H,Y,z,d,o),P=QHe(N,i);if(!P)return{rendered:!1,missing:M};let{overlap:K,latBounds:At,texScale:st,texOffset:it}=P,W={[F]:{x0:K.x0,y0:K.y0,x1:K.x1,y1:K.y1,latMin:At.min,latMax:At.max}},X=s.isGlobe??!0;return A.applyCommonUniforms(t,E,f,Q,s.projectionData,{projection:{name:X?"globe":"mercator"},globeToMercatorMatrix:$q,transition:X?0:1},r,!0),A.renderTiles(t,[v],[0],l,p,g,h,W,Q,!0,void 0,{[F]:{texScale:st,texOffset:it}},n.latIsAscending),{rendered:!0,missing:M}}function Zhi(A,t,e,i,r,n,s,o){let{tileCache:a,vertexArr:l,pixCoordArr:g,tileSize:h,tileBounds:p}=n,{colormapTexture:d,uniforms:E,customShaderConfig:f}=s,Q=[e.childZ,e.childX,e.childY],y=m3(Q),S=mHe(e.childZ,e.childX,e.childY,p,o),v=QHe(S,i);if(!v)return!1;let{overlap:M,latBounds:H,texScale:Y,texOffset:z}=v,F={[y]:{x0:M.x0,y0:M.y0,x1:M.x1,y1:M.y1,latMin:H.min,latMax:H.max}},N=s.isGlobe??!0;return A.applyCommonUniforms(t,d,E,f,s.projectionData,{projection:{name:N?"globe":"mercator"},globeToMercatorMatrix:$q,transition:N?0:1},r,!0),A.renderTiles(t,[Q],[0],a,h,l,g,F,f,!0,void 0,{[y]:{texScale:Y,texOffset:z}},n.latIsAscending),!0}function Xhi(A,t,e,i,r){let{tileCache:n,vertexArr:s,pixCoordArr:o,tileSize:a,tileBounds:l}=r,{colormapTexture:g,uniforms:h,customShaderConfig:p}=i,d=t.getLevels(),E=t.getMaxLevelIndex(),f=UKt(e),Q=TKt(f.x0,f.y0,f.x1,f.y1),y=[e.z,e.x,e.y],S=y.join(","),v=l?.[S],M={[S]:{x0:f.x0,y0:f.y0,x1:f.x1,y1:f.y1,latMin:v?.latMin,latMax:v?.latMax}},H=d[E]??"",Y=got(H,E),z=A.getProgram(i.shaderData,p,!0);A.gl.useProgram(z.program);let F=i.isGlobe??!0;return A.applyCommonUniforms(z,g,h,p,i.projectionData,{projection:{name:F?"globe":"mercator"},globeToMercatorMatrix:$q,transition:F?0:1},Q,!0),A.renderTiles(z,[y],[0],n,a,s,o,M,p,!0,Y),!n.get(S)?.data}function dPe(A){if(!(!A||A.latMin===void 0||A.latMax===void 0||A.lonMin===void 0||A.lonMax===void 0))return{latMin:A.latMin,latMax:A.latMax,lonMin:A.lonMin,lonMax:A.lonMax,x0:A.x0,y0:A.y0,x1:A.x1,y1:A.y1}}var $hi=class{constructor(A,t,e,i,r=100,n=1){this.isMultiscale=!0,this.tileCache=null,this.vertexArr=new Float32Array,this.pixCoordArr=new Float32Array,this.currentSubdivisions=0,this.maxLevelIndex=0,this.tileSize=$Ue,this.visibleTiles=[],this.crs="EPSG:4326",this.xyLimits=null,this.tileBounds={},this.pendingChunks=new Set,this.currentLevel=null,this.selectorVersion=0,this.throttleState=hHe(),this.requestCanceller=CHe(),this.loadingManager=EHe(),this.zarrStore=A,this.variable=t,this.selector=e,this.invalidate=i,this.throttleMs=r,this.fixedDataScale=n}async initialize(){this.loadingManager.metadataLoading=!0,this.emitLoadingState();try{let A=this.zarrStore.describe();this.maxLevelIndex=A.levels.length-1,this.tileSize=A.tileSize||$Ue,this.crs=A.crs,this.xyLimits=A.xyLimits;let t=HT(this.variable,this.selector);this.tileCache=new qhi({store:this.zarrStore,selector:this.selector,fillValue:A.fill_value??0,dimIndices:A.dimIndices,coordinates:A.coordinates,maxCachedTiles:Uci,bandNames:t,crs:this.crs,fixedDataScale:this.fixedDataScale}),this.updateGeometryForProjection(!1)}finally{this.loadingManager.metadataLoading=!1,this.emitLoadingState()}}update(A,t){if(!this.tileCache)return;this.tileCache.setGL(t);let e=A.getProjection?A.getProjection():null,i=nHe(e);this.updateGeometryForProjection(i);let r=this.getVisibleTilesWithContext(A);this.visibleTiles=r.tiles,this.tileBounds=this.computeTileBounds(this.visibleTiles),r.pyramidLevel!==null&&(this.currentLevel=r.pyramidLevel);for(let[o,a]of Object.entries(this.tileBounds)){let l=dPe(a);l&&this.tileCache.setTileBounds(o,l)}let n=JSON.stringify(this.selector),s=[];for(let o of this.visibleTiles){let a=m3(o);if(this.pendingChunks.has(a))continue;let l=this.tileCache.upsert(a);(!l.data||l.selectorHash!==n)&&s.push(o)}if(s.length>0){let o=uHe(this.throttleState,this.throttleMs);if(o>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),IHe(this.throttleState,o,this.invalidate);return}pHe(this.throttleState);let a=this.pendingChunks.size===0;for(let g of s)this.pendingChunks.add(m3(g));a&&this.emitLoadingState();let l=this.selectorVersion;this.prefetchTileData(s,n,l).catch(g=>{console.error("Error prefetching tile data:",g);for(let h of s)this.pendingChunks.delete(m3(h));this.emitLoadingState()})}}render(A,t){if(!this.tileCache)return;let e=!!t.mapbox,i=A.getProgram(t.shaderData,t.customShaderConfig,e,!1);A.gl.useProgram(i.program),A.applyCommonUniforms(i,t.colormapTexture,t.uniforms,t.customShaderConfig,t.projectionData,t.mapbox,t.matrix,!1);let r=this.zarrStore.levels[this.maxLevelIndex],n=got(r,this.maxLevelIndex);A.renderTiles(i,this.visibleTiles,t.worldOffsets,this.tileCache,this.tileSize,this.vertexArr,this.pixCoordArr,Object.keys(this.tileBounds).length>0?this.tileBounds:void 0,t.customShaderConfig,!1,n,void 0,this.zarrStore.latIsAscending)}renderToTile(A,t,e){return yHe({renderer:A,mode:this,tileId:t,context:e})}onProjectionChange(A){this.updateGeometryForProjection(A)}getTiledState(){return this.tileCache?{tileCache:this.tileCache,visibleTiles:this.visibleTiles,tileSize:this.tileSize,vertexArr:this.vertexArr,pixCoordArr:this.pixCoordArr,tileBounds:Object.keys(this.tileBounds).length>0?this.tileBounds:void 0,latIsAscending:this.zarrStore.latIsAscending}:null}getSingleImageState(){return null}dispose(A){dHe(this.throttleState),X_t(this.requestCanceller),this.tileCache?.clear(),this.tileCache=null,this.pendingChunks.clear(),this.emitLoadingState()}setLoadingCallback(A){fHe(this.loadingManager,A)}getCRS(){return this.crs}getXYLimits(){return this.xyLimits}getMaxLevelIndex(){return this.maxLevelIndex}getLevels(){return this.zarrStore.levels}emitLoadingState(){this.loadingManager.chunksLoading=this.pendingChunks.size>0||this.throttleState.throttledPending,_He(this.loadingManager)}async setSelector(A){this.selector=A,this.selectorVersion++;let t=HT(this.variable,A);if(this.tileCache?.updateSelector(this.selector),this.tileCache?.updateBandNames(t),this.tileCache&&this.visibleTiles.length>0){let e=JSON.stringify(this.selector);await this.tileCache.reextractTileSlices(this.visibleTiles,e,this.selectorVersion)}this.invalidate()}updateGeometryForProjection(A){let t=A?Pci:1;if(this.currentSubdivisions===t)return;let e=XPe(t);this.vertexArr=e.vertexArr,this.pixCoordArr=e.texCoordArr,this.currentSubdivisions=t,this.tileCache?.markGeometryDirty()}getVisibleTilesWithContext(A){if(!A.getZoom||!A.getBounds)return{tiles:[],pyramidLevel:null,mapZoom:null,bounds:null};let t=A.getZoom(),e=_hi(t,this.maxLevelIndex),i=A.getBounds()?.toArray();if(!i)return{tiles:[],pyramidLevel:e,mapZoom:t,bounds:null};let r=this.zarrStore.levels[e],n=got(r,e);return this.crs==="EPSG:4326"&&this.xyLimits?{tiles:AHe(n,i,this.xyLimits),pyramidLevel:e,mapZoom:t,bounds:i}:{tiles:eHe(n,i),pyramidLevel:e,mapZoom:t,bounds:i}}computeTileBounds(A){if(this.crs!=="EPSG:4326"||!this.xyLimits)return{};let{xMin:t,xMax:e,yMin:i,yMax:r}=PKt(this.xyLimits),n=e-t,s=r-i,o={};for(let a of A){let[l,g,h]=a,p=Math.pow(2,l),d=n/p,E=s/p,f=t+g*d,Q=f+d,y=r-h*E,S=y-E,v=$1(f),M=$1(Q),H=C6(y),Y=C6(S);o[m3(a)]={x0:v,y0:H,x1:M,y1:Y,latMin:S,latMax:y,lonMin:f,lonMax:Q}}return o}async prefetchTileData(A,t,e){let i=new AbortController;this.requestCanceller.controllers.set(e,i);try{let r=A.map(n=>this.fetchTileData(n,t,e,i.signal));await Promise.all(r)}finally{this.requestCanceller.controllers.delete(e)}}async fetchTileData(A,t,e,i){if(!this.tileCache){let s=m3(A);return this.pendingChunks.delete(s),this.emitLoadingState(),null}let r=m3(A),n=dPe(this.tileBounds[r]);try{let s=await this.tileCache.fetchTile(A,t,e,i,n);return this.pendingChunks.delete(r),s?(BHe(this.requestCanceller,e),this.emitLoadingState(),this.invalidate(),s.data):(this.emitLoadingState(),null)}catch(s){if(this.pendingChunks.delete(r),this.emitLoadingState(),s instanceof DOMException&&s.name==="AbortError")return null;throw s}}async queryData(A,t){if(!this.tileCache||!this.xyLimits)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let e=t?aot(t):this.selector,i=this.currentLevel??this.maxLevelIndex,r=this.zarrStore.describe();return Yhi(this.variable,A,e,this.zarrStore,this.crs,this.xyLimits,i,this.tileSize,{scaleFactor:r.scaleFactor,addOffset:r.addOffset,fillValue:r.fill_value})}},tui=1e4,eui=1e3,Aui=270;function lot(A){return isFinite(A)?((A+180)%360+360)%360-180:A}function iui(A){let{bounds:t,width:e,height:i,latIsAscending:r,transformer:n}=A,s=e>1?e/(e-1):1,o=i>1?i/(i-1):1;return new Aot({forwardTransform:(a,l)=>i6t(a*s,l*o,t,e,i,r),inverseTransform:(a,l)=>{let[g,h]=YKt(a,l,t,e,i,r);return[g/s,h/o]},forwardReproject:(a,l)=>n.forward(a,l),inverseReproject:(a,l)=>n.inverse(a,l)},e,i)}function rui(A,t,e,i,r=!1){return{lon0:$1(A),lat0:(e+90)/180,lon1:$1(t),lat1:(i+90)/180,crossesAntimeridian:r}}function nui(A,t,e,i,r,n=!1){let s=A.length/2,o=new Float32Array(s*2),a=n?360-t+e||1:e-t||1,l=r-i||1;for(let g=0;g<s;g++){let h=A[g*2],p=A[g*2+1];h=lot(h),n&&h<t&&(h+=360),o[g*2]=(h-t)/a*2-1,o[g*2+1]=(p-i)/l*2-1}return o}function mKt(A,t){return Math.abs(A-t)>180}function CPe(A,t,e,i){let r=A,n=e;A>0&&e<0&&A-e>180?n+=360:e>0&&A<0&&e-A>180&&(r+=360);let s=(180-r)/(n-r);return{lat:t+s*(i-t),t:s}}function sui(A,t,e,i){let r=A.length/2,n=new Uint8Array(r);for(let l=0;l<r;l++){let g=A[l*2],h=A[l*2+1];n[l]=isFinite(g)&&isFinite(h)?1:0}if(!i){let l=[];for(let g=0;g<e.length;g+=3){let h=e[g],p=e[g+1],d=e[g+2];n[h]&&n[p]&&n[d]&&l.push(h,p,d)}return{positions:A,texCoords:t,indices:new Uint32Array(l)}}let s=new Array(A.length);for(let l=0;l<A.length;l++)s[l]=A[l];let o=new Array(t.length);for(let l=0;l<t.length;l++)o[l]=t[l];let a=[];for(let l=0;l<e.length;l+=3){let g=e[l],h=e[l+1],p=e[l+2];if(!n[g]||!n[h]||!n[p])continue;let d=A[g*2],E=A[g*2+1],f=t[g*2],Q=t[g*2+1],y=A[h*2],S=A[h*2+1],v=t[h*2],M=t[h*2+1],H=A[p*2],Y=A[p*2+1],z=t[p*2],F=t[p*2+1],N=lot(d),P=lot(y),K=lot(H),At=mKt(N,P),st=mKt(P,K),it=mKt(K,N),W=(At?1:0)+(st?1:0)+(it?1:0);if(W===0)a.push(g,h,p);else if(W===2){let X=At?st?[1,2,0]:[0,1,2]:[2,0,1],[rt,gt,ft]=X,mt=[g,h,p],St=[N,P,K],wt=[E,S,Y],kt=[f,v,z],Dt=[Q,M,F],Pt=mt[rt],ee=mt[gt],Ie=mt[ft],Tt=St[rt],$e=wt[rt],Ne=kt[rt],be=Dt[rt],xt=St[gt],Ue=wt[gt],OA=kt[gt],_e=Dt[gt],Ci=St[ft],_A=wt[ft],fA=kt[ft],Ee=Dt[ft],ai=CPe(Tt,$e,xt,Ue),ki=CPe(Tt,$e,Ci,_A),$i=Ne+ai.t*(OA-Ne),pA=be+ai.t*(_e-be),ye=Ne+ki.t*(fA-Ne),ei=be+ki.t*(Ee-be),zA=Tt>0,EA=zA?179.9999:-179.9999,rA=zA?-179.9999:179.9999,oA=s.length/2;s.push(EA,ai.lat,EA,ki.lat),s.push(rA,ai.lat,rA,ki.lat),o.push($i,pA,ye,ei),o.push($i,pA,ye,ei);let re=oA,te=oA+1,Pe=oA+2,iA=oA+3;a.push(Pt,re,te),a.push(Pe,ee,Ie),a.push(Pe,Ie,iA)}else a.push(g,h,p)}return{positions:new Float64Array(s),texCoords:new Float64Array(o),indices:new Uint32Array(a)}}function oui(A){let{geoBounds:t,width:e,height:i,subdivisions:r,transformer:n,latIsAscending:s,maxError:o=Hci}=A,{xMin:a,xMax:l,yMin:g,yMax:h}=t,d=iui({bounds:[a,g,l,h],width:e,height:i,latIsAscending:s,transformer:n});for(let rt=0;rt<eui&&d.getMaxError()>o;rt++){let gt=d.uvs.length/2;d.refine();let ft=d.uvs.length/2;if(ft>=tui||ft===gt)break}let E=d.uvs,f=(r+1)**2,Q=new Float64Array(E.length+f*2);Q.set(E);let y=E.length;for(let rt=0;rt<=r;rt++)for(let gt=0;gt<=r;gt++)Q[y++]=gt/r,Q[y++]=rt/r;let v=new eot(Q).triangles,M=Q.length/2,H=new Float64Array(M*2),Y=[],z=1/0,F=-1/0;for(let rt=0;rt<M;rt++){let gt=Q[rt*2],ft=Q[rt*2+1],mt=a+gt*(l-a),St=s?g+ft*(h-g):h-ft*(h-g),[wt,kt]=n.forward(mt,St);H[rt*2]=wt,H[rt*2+1]=kt,isFinite(wt)&&isFinite(kt)&&(Y.push(lot(wt)),z=Math.min(z,kt),F=Math.max(F,kt))}isFinite(z)||(z=-90),isFinite(F)||(F=90);let N=-180,P=180,K=!1;if(Y.length>0){Y.sort((gt,ft)=>gt-ft),N=Y[0],P=Y[Y.length-1];let rt=P-N;if(rt>0){let gt=0,ft=0;for(let St=0;St<Y.length-1;St++){let wt=Y[St+1]-Y[St];wt>gt&&(gt=wt,ft=St+1)}Y[0]+360-Y[Y.length-1]<gt&&rt<Aui&&(K=!0,N=Y[ft],P=Y[ft-1])}}K&&N>=180&&(N=N-360,N<=P&&(K=!1));let At=K||P-N>=180,st=new Float64Array(Q),it=sui(H,st,v,At),W=nui(it.positions,N,P,z,F,K),X=rui(N,P,z,F,K);return{positions:W,texCoords:new Float32Array(it.texCoords),indices:it.indices,wgs84Bounds:X}}var aui=128,lui=class{constructor(A,t,e,i,r=100,n=1){this.isMultiscale=!1,this.width=0,this.height=0,this.channels=1,this.mercatorBounds=null,this.bandNames=[],this.dimIndices={},this.xyLimits=null,this.crs="EPSG:4326",this.zarrArray=null,this.latIsAscending=!0,this.levels=[],this.currentLevelIndex=0,this.pendingLevelIndex=null,this.levelMetadataFetched=new Set,this.proj4def=null,this.cachedMercatorTransformer=null,this.cachedWGS84Transformer=null,this.cached4326Transformer=null,this.isRemoved=!1,this.throttleState=hHe(),this.requestCanceller=CHe(),this.loadingManager=EHe(),this.dimensionValues={},this.regionCache=new Map,this.visibleRegionKeys=new Set,this.lastVisibleRegions=[],this.lastVisibleRegionsLevel=-1,this.regionSize=null,this.lastViewportHash="",this.baseSliceArgs=[],this.selectorVersion=0,this.baseMultiValueDims=[],this.cachedGl=null,this.baseSliceArgsReady=!1,this.isGlobeProjection=!1,this.fixedDataScale=1,this.zarrStore=A,this.variable=t,this.selector=e,this.bandNames=HT(t,e),this.invalidate=i,this.throttleMs=r,this.fixedDataScale=n}async initialize(){this.loadingManager.metadataLoading=!0,this.emitLoadingState();try{let A=this.zarrStore.describe();if(this.dimIndices=A.dimIndices,this.crs=A.crs,this.xyLimits=A.xyLimits,this.latIsAscending=A.latIsAscending,this.proj4def=A.proj4??null,this.proj4def&&this.xyLimits){let t=[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax];this.cachedMercatorTransformer=khi(this.proj4def,t),this.cachedWGS84Transformer=hot(this.proj4def),this.cached4326Transformer=Rhi(this.proj4def,t)}this.crs!=="EPSG:4326"&&this.crs!=="EPSG:3857"&&console.warn(`Unsupported CRS "${this.crs}" - rendering may be incorrect. Supported: EPSG:4326, EPSG:3857`),A.untiledLevels&&A.untiledLevels.length>0?(this.levels=A.untiledLevels,this.isMultiscale=!0,await this.ensureAllLevelShapes(),this.currentLevelIndex=-1):(this.isMultiscale=!1,this.zarrArray=await this.zarrStore.getArray(),this.width=this.zarrArray.shape[this.dimIndices.lon.index],this.height=this.zarrArray.shape[this.dimIndices.lat.index]),this.xyLimits?this.proj4def?this.mercatorBounds=this.computeMercatorBoundsFromProjection():this.mercatorBounds=cPe(this.xyLimits,this.crs):console.warn("UntiledMode: No XY limits found")}finally{this.loadingManager.metadataLoading=!1,this.emitLoadingState()}}async ensureLevelMetadata(A){let t=this.levels[A];if(t&&!this.levelMetadataFetched.has(A)&&!(t.dtype!==void 0&&t.scaleFactor!==void 0&&t.addOffset!==void 0)){this.levelMetadataFetched.add(A);try{let e=await this.zarrStore.getUntiledLevelMetadata(t.asset);t.shape=e.shape,t.chunks=e.chunks,e.scaleFactor!==void 0&&(t.scaleFactor=e.scaleFactor),e.addOffset!==void 0&&(t.addOffset=e.addOffset),t.fillValue=e.fillValue,t.dtype=e.dtype}catch(e){console.warn(`Failed to load metadata for level ${t.asset}:`,e)}}}async ensureAllLevelShapes(){let A=this.levels.map((t,e)=>({level:t,index:e})).filter(({level:t})=>!t.shape);A.length!==0&&await Promise.all(A.map(async({level:t,index:e})=>{if(!this.levelMetadataFetched.has(e)){this.levelMetadataFetched.add(e);try{let i=await this.zarrStore.getUntiledLevelMetadata(t.asset);t.shape=i.shape,t.chunks=i.chunks,i.scaleFactor!==void 0&&(t.scaleFactor=i.scaleFactor),i.addOffset!==void 0&&(t.addOffset=i.addOffset),t.fillValue=i.fillValue,t.dtype=i.dtype}catch(i){console.warn(`Failed to load shape for level ${t.asset}:`,i)}}}))}getRegionSize(A){let t=this.dimIndices.lat?.index,e=this.dimIndices.lon?.index;if(t===void 0||e===void 0)return null;let i=A.codecs||[];for(let n of i)if(n.name==="sharding_indexed"&&n.configuration?.chunk_shape){let s=n.configuration.chunk_shape;return[s[t],s[e]]}let r=A.chunks;if(r&&r.length>Math.max(t,e)){let n=r[t],s=r[e],o=A.shape;if(n<o[t]||s<o[e])return[n,s]}return null}clearRegionCache(A){for(let t of this.regionCache.values())this.disposeRegion(t,A);this.regionCache.clear(),this.lastViewportHash=""}disposeRegion(A,t){A.texture&&t.deleteTexture(A.texture),A.vertexBuffer&&t.deleteBuffer(A.vertexBuffer),A.pixCoordBuffer&&t.deleteBuffer(A.pixCoordBuffer),A.indexBuffer&&t.deleteBuffer(A.indexBuffer);for(let e of A.bandTextures.values())t.deleteTexture(e)}evictOldRegions(A){for(;this.regionCache.size>aui;){let t=null;for(let i of this.regionCache.keys())if(!this.visibleRegionKeys.has(i)){t=i;break}if(!t)break;let e=this.regionCache.get(t);e&&this.disposeRegion(e,A),this.regionCache.delete(t)}}getVisibleRegions(A){let t=A.getBounds?.()?.toArray?.();if(!t||!this.xyLimits||!this.regionSize)return[];let[[e,i],[r,n]]=t,{xMin:s,xMax:o,yMin:a,yMax:l}=this.xyLimits,[g,h]=this.regionSize;if(this.proj4def&&this.cachedWGS84Transformer){let K=this.cachedWGS84Transformer,At=Math.ceil(this.width/h),st=Math.ceil(this.height/g),it=[];for(let W=0;W<st;W++)for(let X=0;X<At;X++){let rt=this.getRegionBounds(X,W),gt=(rt.xMin+rt.xMax)/2,ft=(rt.yMin+rt.yMax)/2,St=[K.inverse(rt.xMin,rt.yMin),K.inverse(rt.xMax,rt.yMin),K.inverse(rt.xMax,rt.yMax),K.inverse(rt.xMin,rt.yMax),K.inverse(gt,rt.yMin),K.inverse(gt,rt.yMax),K.inverse(rt.xMin,ft),K.inverse(rt.xMax,ft)].filter(ee=>isFinite(ee[0])&&isFinite(ee[1]));if(St.length===0)continue;let wt=Math.min(...St.map(ee=>ee[0])),kt=Math.max(...St.map(ee=>ee[0])),Dt=Math.min(...St.map(ee=>ee[1])),Pt=Math.max(...St.map(ee=>ee[1]));kt>=e&&wt<=r&&Pt>=i&&Dt<=n&&it.push({regionX:X,regionY:W})}return it}let p=T_t(e,s,o,this.width),d=T_t(r,s,o,this.width),E=T_t(i,a,l,this.height),f=T_t(n,a,l,this.height);this.latIsAscending===!1&&(E=this.height-1-E,f=this.height-1-f);let Q=Math.floor(Math.min(p,d)/h),y=Math.floor(Math.max(p,d)/h),S=Math.floor(Math.min(E,f)/g),v=Math.floor(Math.max(E,f)/g),M=Math.ceil(this.width/h),H=Math.ceil(this.height/g),Y=Math.max(0,Q),z=Math.min(M-1,y),F=Math.max(0,S),N=Math.min(H-1,v),P=[];for(let K=F;K<=N;K++)for(let At=Y;At<=z;At++)P.push({regionX:At,regionY:K});return P}makeRegionKey(A,t,e){return`${A}:${t},${e}`}createRegionState(A,t,e){return{key:this.makeRegionKey(A,t,e),levelIndex:A,regionX:t,regionY:e,data:null,width:0,height:0,loading:!1,channels:1,texture:null,textureUploaded:!1,vertexBuffer:null,pixCoordBuffer:null,indexBuffer:null,vertexArr:null,pixCoordArr:null,indexArr:null,vertexCount:0,useIndexedMesh:!1,mercatorBounds:null,wgs84Bounds:null,latIsAscending:this.latIsAscending,selectorVersion:this.selectorVersion,bandData:new Map,bandTextures:new Map,bandTexturesUploaded:new Set,bandTexturesConfigured:new Set,levelMeta:null}}isRegionValid(A){return!!(A.data&&A.textureUploaded&&A.texture&&A.vertexBuffer&&A.pixCoordBuffer&&A.vertexArr&&A.mercatorBounds)}clearBatchLoadingFlags(A,t){for(let{regionX:e,regionY:i}of A){let r=this.makeRegionKey(t,e,i),n=this.regionCache.get(r);n&&(n.loading=!1)}}getUniformsForRender(A){return{...A,scaleFactor:1,offset:0}}currentLevelCoversViewport(){if(this.lastVisibleRegionsLevel!==this.currentLevelIndex)return!1;let A=this.currentLevelIndex;for(let{regionX:t,regionY:e}of this.lastVisibleRegions){let i=this.makeRegionKey(A,t,e),r=this.regionCache.get(i);if(!r||!this.isRegionValid(r))return!1}return this.lastVisibleRegions.length>0}getProtectedFallbackRegions(){let A=[];for(let t of this.regionCache.values())t.levelIndex!==this.currentLevelIndex&&this.isRegionValid(t)&&this.visibleRegionKeys.has(t.key)&&A.push(t);return A}getLoadedRegions(){let A=this.currentLevelIndex,t=[];for(let i of this.regionCache.values())this.isRegionValid(i)&&i.levelIndex===A&&t.push(i);return this.currentLevelCoversViewport()?t:[...this.getProtectedFallbackRegions(),...t]}buildChannelCombinations(A){let t=[[]],e=[[]];for(let{values:i,labels:r}of A){let n=[],s=[];for(let o=0;o<i.length;o++)for(let a=0;a<t.length;a++)n.push([...t[a],i[o]]),s.push([...e[a],r[o]]);t=n,e=s}return{combinations:t,labelCombinations:e}}getRegionBounds(A,t,e){let i=e?.width??this.width,r=e?.height??this.height,n=e?.regionSize??this.regionSize;if(!this.xyLimits||!n)return{xMin:0,xMax:1,yMin:0,yMax:1};let[s,o]=n,{xMin:a,xMax:l,yMin:g,yMax:h}=this.xyLimits,p=A*o,d=Math.min(p+o,i),E=t*s,f=Math.min(E+s,r),Q=a+p/i*(l-a),y=a+d/i*(l-a),S,v;return this.latIsAscending===!1?(v=h-E/r*(h-g),S=h-f/r*(h-g)):(S=g+E/r*(h-g),v=g+f/r*(h-g)),{xMin:Q,xMax:y,yMin:S,yMax:v}}createRegionGeometry(A,t,e,i){if(!i.levelMeta&&!this.regionSize)return;let r=this.getRegionBounds(A,t,i.levelMeta??void 0),n=i.mercatorBounds??cPe(r,this.crs);if(i.mercatorBounds=n,this.proj4def&&this.cached4326Transformer){let s=(r.xMin+r.xMax)/2,o=(r.yMin+r.yMax)/2,l=[this.cached4326Transformer.forward(r.xMin,r.yMin),this.cached4326Transformer.forward(r.xMax,r.yMin),this.cached4326Transformer.forward(r.xMin,r.yMax),this.cached4326Transformer.forward(r.xMax,r.yMax),this.cached4326Transformer.forward(s,o)].map(d=>d[1]).filter(d=>isFinite(d)),g=l.length>0?Math.max(...l)-Math.min(...l):0,h=Math.max(tPe,Math.min(ePe,Math.ceil(g))),p=oui({geoBounds:r,width:i.width,height:i.height,subdivisions:h,transformer:this.cached4326Transformer,latIsAscending:this.latIsAscending});i.vertexArr=p.positions,i.pixCoordArr=p.texCoords,i.indexArr=p.indices,i.wgs84Bounds=p.wgs84Bounds,i.useIndexedMesh=!0,i.vertexCount=i.indexArr.length}else{let s;if(this.crs==="EPSG:3857"){let l=.5-r.yMin/(2*zC),g=.5-r.yMax/(2*zC);s=Math.abs(YT(g)-YT(l))}else s=Math.abs(r.yMax-r.yMin);let o=this.isGlobeProjection?Math.max(tPe,Math.min(ePe,Math.ceil(s))):Oci,a=XPe(o);if(i.vertexArr=a.vertexArr,i.useIndexedMesh=!1,i.vertexCount=a.vertexArr.length/2,this.crs==="EPSG:4326"){let l=r.yMin,g=r.yMax;i.mercatorBounds={x0:$1(r.xMin),x1:$1(r.xMax),y0:C6(g),y1:C6(l),latMin:l,latMax:g},i.latIsAscending=this.latIsAscending,i.pixCoordArr=a.texCoordArr}else i.pixCoordArr=this.latIsAscending?Qhi(a.texCoordArr):a.texCoordArr}i.vertexBuffer||(i.vertexBuffer=e.createBuffer()),i.pixCoordBuffer||(i.pixCoordBuffer=e.createBuffer()),e.bindBuffer(e.ARRAY_BUFFER,i.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,i.vertexArr,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,i.pixCoordBuffer),e.bufferData(e.ARRAY_BUFFER,i.pixCoordArr,e.STATIC_DRAW),i.useIndexedMesh&&i.indexArr&&(i.indexBuffer||(i.indexBuffer=e.createBuffer()),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,i.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,i.indexArr,e.STATIC_DRAW))}classifyDimension(A){let t=A.toLowerCase();return t==="lon"||t==="x"||t==="lng"||t.includes("lon")?"lon":t==="lat"||t==="y"||t.includes("lat")?"lat":t.includes("time")?"time":"other"}async buildSliceArgsForSelector(A,t){if(!this.zarrArray)return{sliceArgs:[],multiValueDims:[]};let e=new Array(this.zarrArray.shape.length).fill(0),i=[],r=Object.keys(this.dimIndices);for(let n of r){let s=this.dimIndices[n],o=this.classifyDimension(n);if(o==="lon")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.x:t.spatialBounds?.type==="bbox"?e[s.index]=aQ(t.spatialBounds.minX,t.spatialBounds.maxX):e[s.index]=t.includeSpatialSlices?aQ(0,this.width):0;else if(o==="lat")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.y:t.spatialBounds?.type==="bbox"?e[s.index]=aQ(t.spatialBounds.minY,t.spatialBounds.maxY):e[s.index]=t.includeSpatialSlices?aQ(0,this.height):0;else{let a=A[n]||(o==="time"?A.time:void 0);if(a!==void 0){let l=a.selected,g=a.type;if(t.trackMultiValue&&Array.isArray(l)&&l.length>1){let h=[],p=[];for(let d of l){let E=await this.resolveSelectionIndex(n,s,d,g);h.push(E),p.push(d)}i.push({dimIndex:s.index,dimName:n,values:h,labels:p}),e[s.index]=h[0]}else{let h=Array.isArray(l)?l[0]:l;e[s.index]=await this.resolveSelectionIndex(n,s,h,g)}}else e[s.index]=0}}return{sliceArgs:e,multiValueDims:i}}resetVisibleRegions(){this.lastVisibleRegions=[],this.lastVisibleRegionsLevel=-1,this.lastViewportHash=""}updateVisibleRegions(A,t){let e=this.getVisibleRegions(A);this.lastVisibleRegions=e,this.lastVisibleRegionsLevel=this.currentLevelIndex;let i=this.currentLevelIndex;for(let{regionX:a,regionY:l}of e)this.visibleRegionKeys.add(this.makeRegionKey(i,a,l));if(this.currentLevelCoversViewport()){let a=`${i}:`;for(let l of this.visibleRegionKeys)l.startsWith(a)||this.visibleRegionKeys.delete(l)}let r=[],n=[];for(let{regionX:a,regionY:l}of e){let g=this.makeRegionKey(i,a,l),h=this.regionCache.get(g);h?.loading||(h?.data?h.selectorVersion!==this.selectorVersion&&n.push({regionX:a,regionY:l}):r.push({regionX:a,regionY:l}))}let s=`${i}:${this.selectorVersion}:${e.map(a=>`${a.regionX},${a.regionY}`).join("|")}`,o=s!==this.lastViewportHash;this.lastViewportHash=s,!(r.length===0&&n.length===0&&!o)&&(r.length>0&&this.fetchRegions(r,t),n.length>0&&this.fetchRegionsThrottled(n,t))}fetchRegionsThrottled(A,t){let e=uHe(this.throttleState,this.throttleMs);if(e>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),IHe(this.throttleState,e,this.invalidate);return}pHe(this.throttleState),this.fetchRegions(A,t)}async fetchRegions(A,t){if(!this.zarrArray||!this.regionSize)return;let e={index:this.currentLevelIndex,zarrArray:this.zarrArray,baseSliceArgs:[...this.baseSliceArgs],width:this.width,height:this.height,regionSize:this.regionSize,selectorVersion:this.selectorVersion,baseMultiValueDims:this.baseMultiValueDims.map(n=>({dimIndex:n.dimIndex,dimName:n.dimName,values:[...n.values],labels:[...n.labels]}))};this.loadingManager.chunksLoading=!0,this.emitLoadingState();for(let{regionX:n,regionY:s}of A){let o=this.makeRegionKey(e.index,n,s),a=this.regionCache.get(o);a||(a=this.createRegionState(e.index,n,s),this.regionCache.set(o,a)),a.loading=!0}let i=32,r=[];for(let{regionX:n,regionY:s}of A){if(this.currentLevelIndex!==e.index){X_t(this.requestCanceller),this.clearBatchLoadingFlags(A,e.index);break}let o=this.fetchRegion(n,s,t,e).then(()=>{r.splice(r.indexOf(o),1)}).catch(()=>{r.splice(r.indexOf(o),1)});r.push(o),r.length>=i&&await Promise.race(r)}r.length>0&&await Promise.allSettled(r),jhi(this.requestCanceller)||(this.loadingManager.chunksLoading=!1,this.emitLoadingState(),this.evictOldRegions(t),this.invalidate())}async fetchRegion(A,t,e,i){if(this.currentLevelIndex!==i.index||this.isRemoved)return;let r=this.makeRegionKey(i.index,A,t),n=++this.requestCanceller.currentVersion,s=i.selectorVersion,o=new AbortController;this.requestCanceller.controllers.set(n,o);let a=this.regionCache.get(r);a||(a=this.createRegionState(i.index,A,t),this.regionCache.set(r,a)),a.loading=!0;let[l,g]=i.regionSize,h=t*l,p=Math.min(h+l,i.height),d=A*g,E=Math.min(d+g,i.width),f=E-d,Q=p-h;try{let y=[...i.baseSliceArgs],S=this.dimIndices.lat.index,v=this.dimIndices.lon.index;y[S]=aQ(h,p),y[v]=aQ(d,E);let M=this.zarrStore.describe(),H=this.levels[i.index],Y=H?.fillValue??M.fill_value,{combinations:z}=this.buildChannelCombinations(i.baseMultiValueDims),F=z.length||1,N=f*Q,P=[],K=new Float32Array(N*F);if(K.fill(Y??0),F===1){if(o.signal.aborted||this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let St=await X2(i.zarrArray,y,{opts:{signal:o.signal}});if(o.signal.aborted||this.isRemoved){a.loading=!1;return}if(this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let wt=new Float32Array(St.data);P.push(wt),K.set(wt)}else for(let St=0;St<F;St++){if(o.signal.aborted||this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let wt=[...y],kt=z[St];for(let ee=0;ee<i.baseMultiValueDims.length;ee++)wt[i.baseMultiValueDims[ee].dimIndex]=kt[ee];let Dt=await X2(i.zarrArray,wt,{opts:{signal:o.signal}});if(o.signal.aborted||this.isRemoved){a.loading=!1;return}if(this.currentLevelIndex!==i.index){a.loading=!1,this.requestCanceller.controllers.delete(n);return}let Pt=new Float32Array(Dt.data);P.push(Pt);for(let ee=0;ee<N;ee++)K[ee*F+St]=Pt[ee]}if(s<a.selectorVersion){a.loading=!1;return}a.selectorVersion=s,BHe(this.requestCanceller,n);let At=P,st=f,it=Q;if(this.proj4def&&this.cachedMercatorTransformer&&this.xyLimits&&!a.mercatorBounds){let St={width:i.width,height:i.height,regionSize:i.regionSize},wt=this.getRegionBounds(A,t,St);a.mercatorBounds=this.computeRegionMercatorBounds(wt)}let X=H?.scaleFactor??M.scaleFactor,rt=H?.addOffset??M.addOffset;a.bandData.clear(),a.bandTexturesUploaded.clear();let gt=[];for(let St=0;St<At.length;St++){let wt=this.bandNames[St]||`band_${St}`,kt=At[St];if(X!==1||rt!==0){let ee=new Float32Array(kt.length);for(let Ie=0;Ie<kt.length;Ie++){let Tt=kt[Ie];Number.isFinite(Tt)?ee[Ie]=Tt*X+rt:ee[Ie]=Tt}kt=ee}let Dt=Y!==null&&(X!==1||rt!==0)?Y*X+rt:Y,{normalized:Pt}=VPe(kt,Dt,this.fixedDataScale);a.bandData.set(wt,Pt),gt.push(Pt)}a.data=ZPe(gt,F);let ft=!a.vertexBuffer||a.width!==st||a.height!==it;a.width=st,a.height=it,a.channels=F,a.loading=!1,a.levelMeta={width:i.width,height:i.height,regionSize:[...i.regionSize]},a.texture||(a.texture=e.createTexture());let mt=Shi(e,{texture:a.texture,data:a.data,width:st,height:it,channels:F,configured:!1});a.textureUploaded=mt.uploaded,ft&&this.createRegionGeometry(A,t,e,a),this.invalidate()}catch(y){y instanceof DOMException&&y.name==="AbortError"||console.error(`[fetchRegion] Error fetching region ${r}:`,y),a.loading=!1}finally{this.requestCanceller.controllers.delete(n)}}update(A,t){if(this.cachedGl=t,!this.loadingManager.metadataLoading)if(this.isMultiscale&&this.levels.length>0){let e=A.getZoom?.()??0,i=this.selectLevelForZoom(e);if(this.currentLevelIndex===-1){this.initializeLevel(i);return}if(i!==this.currentLevelIndex){this.pendingLevelIndex===null?this.switchToLevel(i):this.pendingLevelIndex!==i&&(this.pendingLevelIndex=i,X_t(this.requestCanceller));return}this.regionSize&&this.baseSliceArgsReady&&this.updateVisibleRegions(A,t)}else{if(!this.regionSize&&this.zarrArray&&!this.loadingManager.chunksLoading){let e=this.getRegionSize(this.zarrArray);this.regionSize=e??[this.height,this.width],this.buildBaseSliceArgs().then(()=>{this.updateVisibleRegions(A,t)});return}this.regionSize&&this.baseSliceArgsReady&&this.updateVisibleRegions(A,t)}}async initializeLevel(A){if(A<0||A>=this.levels.length||this.loadingManager.chunksLoading)return;await this.ensureLevelMetadata(A);let t=this.levels[A];this.currentLevelIndex=A;try{this.zarrArray=await this.zarrStore.getLevelArray(t.asset),this.width=this.zarrArray.shape[this.dimIndices.lon.index],this.height=this.zarrArray.shape[this.dimIndices.lat.index];let e=this.getRegionSize(this.zarrArray);this.regionSize=e??[this.height,this.width],this.regionCache.clear(),await this.buildBaseSliceArgs(),this.invalidate()}catch(e){console.error(`Failed to initialize level ${t.asset}:`,e)}}async buildBaseSliceArgs(){if(!this.zarrArray)return;this.baseSliceArgsReady=!1;let{sliceArgs:A,multiValueDims:t}=await this.buildSliceArgsForSelector(this.selector,{includeSpatialSlices:!1,trackMultiValue:!0});this.baseSliceArgs=A,this.baseMultiValueDims=t,this.baseSliceArgsReady=!0}selectLevelForZoom(A){if(!this.xyLimits||this.levels.length===0)return 0;let t=256*Math.pow(2,A),e;if(this.proj4def&&this.cachedMercatorTransformer){let[r]=this.cachedMercatorTransformer.forward(this.xyLimits.xMin,this.xyLimits.yMin),[n]=this.cachedMercatorTransformer.forward(this.xyLimits.xMax,this.xyLimits.yMax),s=Math.abs(n-r),o=2*zC;e=s/o}else if(this.crs==="EPSG:3857"){let r=this.xyLimits.xMax-this.xyLimits.xMin,n=2*zC;e=r/n}else e=(this.xyLimits.xMax-this.xyLimits.xMin)/360;let i=[];for(let r=0;r<this.levels.length;r++){let n=this.levels[r];if(!n.shape)continue;let s=this.dimIndices.lon?.index??n.shape.length-1,o=n.shape[s]/e;i.push({index:r,effectivePixels:o})}if(i.length===0)return this.levels.length-1;i.sort((r,n)=>r.effectivePixels-n.effectivePixels);for(let{index:r,effectivePixels:n}of i)if(n>=t)return r;return i[i.length-1].index}async switchToLevel(A){if(A===this.currentLevelIndex||A<0||A>=this.levels.length)return;if(this.pendingLevelIndex=A,this.requestCanceller.controllers.size>0){for(let i of this.requestCanceller.controllers.values())i.abort();this.requestCanceller.controllers.clear(),this.loadingManager.chunksLoading=!1,this.emitLoadingState()}await this.ensureLevelMetadata(A);let e=this.levels[A];try{let i=await this.zarrStore.getLevelArray(e.asset),r=i.shape[this.dimIndices.lon.index],n=i.shape[this.dimIndices.lat.index],o=this.getRegionSize(i)??[n,r];if(this.pendingLevelIndex!==A){this.pendingLevelIndex=null,this.invalidate();return}this.currentLevelIndex=A,this.pendingLevelIndex=null,this.zarrArray=i,this.width=r,this.height=n,this.regionSize=o,this.resetVisibleRegions(),await this.buildBaseSliceArgs(),this.invalidate()}catch(i){this.pendingLevelIndex=null,console.error(`Failed to switch to level ${e.asset}:`,i)}}render(A,t){let e=!!t.mapbox,i=!!this.proj4def&&!!this.cached4326Transformer,r=A.getProgram(t.shaderData,t.customShaderConfig,e,i);A.gl.useProgram(r.program),A.applyCommonUniforms(r,t.colormapTexture,this.getUniformsForRender(t.uniforms),t.customShaderConfig,t.projectionData,t.mapbox,t.matrix,!1),this.renderRegions(A,r,t.worldOffsets,t.customShaderConfig)}regionToRenderable(A){return{mercatorBounds:A.mercatorBounds,vertexBuffer:A.vertexBuffer,pixCoordBuffer:A.pixCoordBuffer,vertexCount:A.useIndexedMesh?A.vertexCount:A.vertexArr.length/2,indexBuffer:A.indexBuffer,useIndexedMesh:A.useIndexedMesh,wgs84Bounds:A.wgs84Bounds??void 0,latIsAscending:A.latIsAscending,texture:A.texture,bandData:A.bandData,bandTextures:A.bandTextures,bandTexturesUploaded:A.bandTexturesUploaded,bandTexturesConfigured:A.bandTexturesConfigured,width:A.width,height:A.height}}renderRegions(A,t,e,i){let r=A.gl;HKt(r,t,i);for(let n of this.getLoadedRegions())A6t(r,t,this.regionToRenderable(n),e,i)}renderToTile(A,t,e){return yHe({renderer:A,mode:this,tileId:t,context:{...e,uniforms:this.getUniformsForRender(e.uniforms)},regions:this.getRegionStates()})}onProjectionChange(A){if(this.isGlobeProjection===A)return;this.isGlobeProjection=A;let t=this.cachedGl;if(t){for(let e of this.regionCache.values())e.data&&this.createRegionGeometry(e.regionX,e.regionY,t,e);this.invalidate()}}getTiledState(){return null}getRegionStates(){return this.regionSize?this.getLoadedRegions().map(A=>({texture:A.texture,vertexBuffer:A.vertexBuffer,pixCoordBuffer:A.pixCoordBuffer,vertexArr:A.vertexArr,mercatorBounds:A.mercatorBounds,width:A.width,height:A.height,channels:this.channels,bandData:A.bandData,bandTextures:A.bandTextures,bandTexturesUploaded:A.bandTexturesUploaded,bandTexturesConfigured:A.bandTexturesConfigured,indexBuffer:A.indexBuffer??void 0,vertexCount:A.vertexCount,useIndexedMesh:A.useIndexedMesh,wgs84Bounds:A.wgs84Bounds??void 0,latIsAscending:A.latIsAscending})):[]}dispose(A){this.isRemoved=!0,dHe(this.throttleState),X_t(this.requestCanceller),this.clearRegionCache(A),this.regionSize=null,this.cachedMercatorTransformer=null,this.cachedWGS84Transformer=null,this.cached4326Transformer=null,this.loadingManager.chunksLoading=!1,this.emitLoadingState()}setLoadingCallback(A){fHe(this.loadingManager,A)}getCRS(){return this.crs}getXYLimits(){return this.xyLimits}computeMercatorBoundsFromProjection(){if(!this.proj4def||!this.xyLimits||!this.cachedMercatorTransformer)return{x0:0,y0:0,x1:1,y1:1};let A=IPe(this.xyLimits,this.cachedMercatorTransformer,20);return A||(console.warn("computeMercatorBoundsFromProjection: No valid samples found"),{x0:0,y0:0,x1:1,y1:1})}computeRegionMercatorBounds(A){if(!this.proj4def||!this.cachedMercatorTransformer)return{x0:0,y0:0,x1:1,y1:1};let t=IPe(A,this.cachedMercatorTransformer,5);return t||(console.warn("computeRegionMercatorBounds: No valid samples found"),{x0:0,y0:0,x1:1,y1:1})}getMaxLevelIndex(){return this.levels.length>0?this.levels.length-1:0}getLevels(){return this.levels.map(A=>A.asset)}async setSelector(A){if(this.selector=A,this.bandNames=HT(this.variable,A),!this.cachedGl){this.invalidate();return}!this.regionSize&&this.zarrArray&&(this.regionSize=this.getRegionSize(this.zarrArray)??[this.height,this.width]),this.selectorVersion++,await this.buildBaseSliceArgs(),this.lastViewportHash="",this.invalidate()}emitLoadingState(){this.throttleState.throttledPending&&!this.loadingManager.chunksLoading&&(this.loadingManager.chunksLoading=!0),_He(this.loadingManager)}async resolveSelectionIndex(A,t,e,i){if(i==="index"||!this.zarrStore.root)return typeof e=="number"?e:0;try{let r=await JPe(this.dimensionValues,null,t,this.zarrStore.root,this.zarrStore.version);if(this.dimensionValues[A]=r,typeof e=="number"||typeof e=="string"){let n=r.indexOf(e);if(n>=0)return n;throw new Error(`[ZarrLayer] Selector value '${e}' not found in coordinate array for dimension '${A}'. Available values: [${r.slice(0,10).join(", ")}${r.length>10?", ...":""}]. Use { selected: <index>, type: 'index' } to select by array index instead.`)}}catch(r){console.debug(`Could not resolve coordinate for '${A}':`,r)}return typeof e=="number"?e:0}async fetchQueryData(A,t){if(!this.zarrArray)return null;try{let{sliceArgs:e,multiValueDims:i}=await this.buildSliceArgsForSelector(A,{includeSpatialSlices:t.type!=="bbox",trackMultiValue:!0,spatialBounds:t}),{combinations:r,labelCombinations:n}=this.buildChannelCombinations(i),s=r.length||1,o=i.map(h=>h.dimName);if(t.type==="point"){let h=[];if(s===1){let p=await X2(this.zarrArray,e),d=this.extractScalarValue(p);if(d===null)return null;h.push(d)}else for(let p=0;p<s;p++){let d=[...e],E=r[p];for(let y=0;y<i.length;y++)d[i[y].dimIndex]=E[y];let f=await X2(this.zarrArray,d),Q=this.extractScalarValue(f);Q!==null&&h.push(Q)}return{type:"point",values:h,data:new Float32Array(0),width:1,height:1,channels:s,channelLabels:n,multiValueDimNames:o}}let a=t.maxX-t.minX,l=t.maxY-t.minY;if(s===1){let h=await X2(this.zarrArray,e);return{type:"bbox",values:[],data:new Float32Array(h.data),width:a,height:l,channels:1,channelLabels:n,multiValueDimNames:o}}let g=new Float32Array(a*l*s);for(let h=0;h<s;h++){let p=[...e],d=r[h];for(let f=0;f<i.length;f++)p[i[f].dimIndex]=d[f];let E=await X2(this.zarrArray,p);for(let f=0;f<a*l;f++)g[f*s+h]=E.data[f]}return{type:"bbox",values:[],data:g,width:a,height:l,channels:s,channelLabels:n,multiValueDimNames:o}}catch(e){return console.error("Error fetching query data:",e),null}}extractScalarValue(A){if(A&&typeof A=="object"&&"data"in A){let t=A.data;return t[0]??t}else{if(typeof A=="number")return A;if(ArrayBuffer.isView(A))return A[0]}return console.warn("Unexpected zarr.get result format:",A),null}async queryData(A,t){if(!this.mercatorBounds)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let e=t?aot(t):this.selector,i=this.zarrStore.describe(),r=this.levels[this.currentLevelIndex],n=r?.scaleFactor??i.scaleFactor,s=r?.addOffset??i.addOffset,o=r?.fillValue??i.fill_value;if(A.type==="Point"){let[v,M]=A.coordinates,H={lat:[M],lon:[v]},Y=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,z=Hhi(v,M,this.mercatorBounds,this.width,this.height,this.crs??"EPSG:4326",this.latIsAscending,this.proj4def,Y,this.cachedWGS84Transformer??void 0);if(!z)return{[this.variable]:[],dimensions:["lat","lon"],coordinates:H};let F=await this.fetchQueryData(e,{type:"point",x:z.x,y:z.y});if(!F)return{[this.variable]:[],dimensions:["lat","lon"],coordinates:H};let{values:N,channelLabels:P,multiValueDimNames:K}=F,At=K.length>0,st=At?{}:[];for(let gt=0;gt<N.length;gt++){let ft=N[gt];if(!(ft==null||!Number.isFinite(ft))&&!(o!==null&&ft===o))if(n!==1&&(ft*=n),s!==0&&(ft+=s),At){let mt=P?.[gt];mt&&K.length>0&&mt.length===K.length?st=jKt(st,mt,ft):Array.isArray(st)&&st.push(ft)}else Array.isArray(st)&&st.push(ft)}let it=i.dimensions,W=it.map(gt=>{let ft=gt.toLowerCase();return["x","lon","longitude"].includes(ft)?"lon":["y","lat","latitude"].includes(ft)?"lat":gt}),X=At?W:["lat","lon"],rt={lat:H.lat,lon:H.lon};if(At)for(let gt of it){let ft=gt.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(ft))continue;let mt=e[gt];if(mt&&"selected"in mt){let St=mt.selected,wt=Array.isArray(St)?St:[St];rt[gt]=wt}else i.coordinates[gt]&&(rt[gt]=i.coordinates[gt])}return{[this.variable]:st,dimensions:X,coordinates:rt}}let a=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,l=Mhi(A,this.mercatorBounds,this.width,this.height,this.crs??"EPSG:4326",this.latIsAscending,this.proj4def,a,this.cachedWGS84Transformer??void 0);if(!l)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let g=await this.fetchQueryData(e,{type:"bbox",...l});if(!g)return{[this.variable]:[],dimensions:[],coordinates:{lat:[],lon:[]}};let{minX:h,maxX:p,minY:d,maxY:E}=l,f=this.mercatorBounds.x1-this.mercatorBounds.x0,Q=this.mercatorBounds.y1-this.mercatorBounds.y0,y={x0:this.mercatorBounds.x0+h/this.width*f,x1:this.mercatorBounds.x0+p/this.width*f,y0:this.mercatorBounds.y0+d/this.height*Q,y1:this.mercatorBounds.y0+E/this.height*Q};if(this.mercatorBounds.latMin!==void 0&&this.mercatorBounds.latMax!==void 0){let v=this.mercatorBounds.latMax-this.mercatorBounds.latMin;this.latIsAscending?(y.latMin=this.mercatorBounds.latMin+d/this.height*v,y.latMax=this.mercatorBounds.latMin+E/this.height*v):(y.latMax=this.mercatorBounds.latMax-d/this.height*v,y.latMin=this.mercatorBounds.latMax-E/this.height*v)}let S=null;if(this.proj4def&&a){let[v,M]=i6t(h,d,a,this.width,this.height,this.latIsAscending),[H,Y]=i6t(p,E,a,this.width,this.height,this.latIsAscending);S=[Math.min(v,H),Math.min(M,Y),Math.max(v,H),Math.max(M,Y)]}return Jhi(this.variable,A,e,g.data,g.width,g.height,y,this.crs??"EPSG:4326",i.dimensions,i.coordinates,g.channels,g.channelLabels,g.multiValueDimNames,this.latIsAscending,{scaleFactor:n,addOffset:s,fillValue:o},this.proj4def,S)}},xHe=class{constructor({id:A,source:t,variable:e,selector:i={},colormap:r,clim:n,opacity:s=1,minzoom:o=0,maxzoom:a=1/0,zarrVersion:l,spatialDimensions:g={},bounds:h,crs:p,latIsAscending:d=null,fillValue:E,customFrag:f,uniforms:Q,renderingMode:y="3d",onLoadingStateChange:S,throttleMs:v=100,proj4:M,transformRequest:H}){if(this.type="custom",this.zarrVersion=null,this.latIsAscending=null,this.selectorHash="",this._fillValue=null,this.scaleFactor=1,this.offset=0,this.dataScaleLocked=!1,this.map=null,this.renderer=null,this.mode=null,this.tileNeedsRender=!0,this.projectionChangeHandler=null,this.zarrStore=null,this.levelInfos=[],this.dimIndices={},this.dimensionValues={},this.normalizedSelector={},this.isRemoved=!1,this.fragmentShaderSource=lhi,this.customUniforms={},this.bandNames=[],this.customShaderConfig=null,this.metadataLoading=!1,this.chunksLoading=!1,this.initError=null,this.lastIsGlobe=null,this.handleChunkLoadingChange=Y=>{this.chunksLoading=Y.chunks,this.emitLoadingState()},!A)throw new Error("[ZarrLayer] id is required");if(!t)throw new Error("[ZarrLayer] source is required");if(!e)throw new Error("[ZarrLayer] variable is required");if(!r||!Array.isArray(r)||r.length===0)throw new Error("[ZarrLayer] colormap is required and must be an array of [r, g, b] or hex string values");if(!n||!Array.isArray(n)||n.length!==2)throw new Error("[ZarrLayer] clim is required and must be [min, max]");M&&!h&&console.warn("[ZarrLayer] proj4 provided without explicit bounds. Bounds will be derived from coordinate arrays if available (see subsequent log for values). For best performance, provide bounds in source CRS units."),this.id=A,this.url=t,this.variable=e,this.zarrVersion=l??null,this.spatialDimensions=g,this.bounds=h,this.crs=p,this.latIsAscending=d??null,this.selector=i,this.normalizedSelector=aot(i),this.selectorHash=this.computeSelectorHash(this.normalizedSelector),this.renderingMode=y,this.invalidate=()=>{},this.colormap=new uhi(r),this.clim=n,this.fixedDataScale=Math.max(Math.abs(n[0]),Math.abs(n[1]),1),this.opacity=s,this.minZoom=o,this.maxZoom=a,this.customFrag=f,this.customUniforms=Q||{},this.bandNames=HT(e,this.normalizedSelector),(this.bandNames.length>1||f)&&(this.customShaderConfig={bands:this.bandNames,customFrag:f,customUniforms:this.customUniforms}),E!==void 0&&(this._fillValue=E),this.onLoadingStateChange=S,this.throttleMs=v,this.proj4=M,this.transformRequest=H}resolveGl(A,t){if(t&&typeof t.getUniformLocation=="function"&&typeof t.drawBuffers=="function")return t;let i=r=>r?{type:r.constructor?.name,keys:Object.keys(r)}:null;throw console.error("Invalid WebGL2 context passed to onAdd",{providedGl:i(t),painterGl:i(A?.painter?.context?.gl),rendererGl:i(A?.renderer?.getContext?.())}),new Error("`map` did not provide a valid WebGL2 context")}get fillValue(){return this._fillValue}isGlobeProjection(){let A=this.map?.getProjection?this.map.getProjection():null;return nHe(A)}syncProjectionState(){let A=this.isGlobeProjection();return this.lastIsGlobe!==null&&this.lastIsGlobe!==A&&this.mode?.onProjectionChange(A),this.lastIsGlobe=A,A}emitLoadingState(){this.onLoadingStateChange&&this.onLoadingStateChange({loading:this.metadataLoading||this.chunksLoading,metadata:this.metadataLoading,chunks:this.chunksLoading,error:this.initError})}setOpacity(A){this.opacity=A,this.invalidate()}setClim(A){this.clim=A,this.dataScaleLocked||(this.fixedDataScale=Math.max(Math.abs(A[0]),Math.abs(A[1]),1)),this.invalidate()}setColormap(A){this.colormap.apply(A),this.gl&&this.colormap.upload(this.gl),this.invalidate()}setUniforms(A){if(!this.customShaderConfig){console.warn("[ZarrLayer] setUniforms() called but layer was not created with customFrag. Uniforms will not be applied. Recreate the layer with customFrag and uniforms options.");return}this.customUniforms={...this.customUniforms,...A},this.customShaderConfig.customUniforms=this.customUniforms,this.invalidate()}async setVariable(A){if(A!==this.variable){this.metadataLoading=!0,this.emitLoadingState();try{this.initError=null,this.variable=A,this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null),this.dimensionValues={},this._fillValue=null,this.dataScaleLocked=!1,this.fixedDataScale=Math.max(Math.abs(this.clim[0]),Math.abs(this.clim[1]),1),await this.initialize(),await this.initializeMode(),this.invalidate()}catch(t){this.initError=t instanceof Error?t:new Error(String(t)),console.error("[zarr-layer] Failed to reset:",this.initError.message),this.mode&&this.gl&&(this.mode.dispose(this.gl),this.mode=null),this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null)}finally{this.metadataLoading=!1,this.emitLoadingState()}}}async setSelector(A){let t=aot(A),e=this.computeSelectorHash(t);e!==this.selectorHash&&(this.selectorHash=e,this.selector=A,this.normalizedSelector=t,this.bandNames=HT(this.variable,this.normalizedSelector),this.bandNames.length>1||this.customFrag?this.customShaderConfig={bands:this.bandNames,customFrag:this.customFrag,customUniforms:this.customUniforms}:this.customShaderConfig=null,this.mode&&await this.mode.setSelector(this.normalizedSelector),this.invalidate())}onAdd(A,t){this._onAddAsync(A,t)}async _onAddAsync(A,t){this.map=A;let e=this.resolveGl(A,t);this.gl=e,this.invalidate=()=>{this.tileNeedsRender=!0,A.triggerRepaint&&A.triggerRepaint()},this.initError=null,this.metadataLoading=!0,this.emitLoadingState();try{this.colormap.upload(e),this.renderer=new Dhi(e,this.fragmentShaderSource),this.projectionChangeHandler=()=>{let r=this.isGlobeProjection();this.mode?.onProjectionChange(r)},typeof A.on=="function"&&this.projectionChangeHandler&&(A.on("projectionchange",this.projectionChangeHandler),A.on("style.load",this.projectionChangeHandler)),await this.initialize(),await this.initializeMode();let i=this.isGlobeProjection();this.lastIsGlobe=i,this.mode?.onProjectionChange(i),this.mode?.update(this.map,this.gl)}catch(i){this.initError=i instanceof Error?i:new Error(String(i)),console.error(`[zarr-layer] Failed to initialize: ${this.initError.message}. Use onLoadingStateChange callback to handle errors and call map.removeLayer('${this.id}') to clean up.`),this._disposeResources(e)}finally{this.metadataLoading=!1,this.emitLoadingState()}this.initError||this.invalidate()}computeSelectorHash(A){let t=e=>{if(Array.isArray(e)||e===null||typeof e!="object")return e;let i=e,r={};return Object.keys(i).sort().forEach(n=>{r[n]=t(i[n])}),r};return JSON.stringify(t(A))}async initializeMode(){if(!this.zarrStore||!this.gl)return;this.mode&&this.mode.dispose(this.gl),this.zarrStore.describe().multiscaleType==="tiled"?this.mode=new $hi(this.zarrStore,this.variable,this.normalizedSelector,this.invalidate,this.throttleMs,this.fixedDataScale):this.mode=new lui(this.zarrStore,this.variable,this.normalizedSelector,this.invalidate,this.throttleMs,this.fixedDataScale),this.dataScaleLocked=!0,this.mode.setLoadingCallback(this.handleChunkLoadingChange),await this.mode.initialize(),this.map&&this.gl&&this.mode.update(this.map,this.gl)}async initialize(){try{this.zarrStore=new Vci({source:this.url,version:this.zarrVersion,variable:this.variable,spatialDimensions:this.spatialDimensions,bounds:this.bounds,crs:this.crs,latIsAscending:this.latIsAscending,coordinateKeys:Object.keys(this.selector),proj4:this.proj4,transformRequest:this.transformRequest}),await this.zarrStore.initialized;let A=this.zarrStore.describe();this.levelInfos=A.levels,this.dimIndices=A.dimIndices,this.scaleFactor=A.scaleFactor,this.offset=A.addOffset,this._fillValue===null&&A.fill_value!==null&&A.fill_value!==void 0&&(this._fillValue=A.fill_value),this.normalizedSelector=aot(this.selector),await this.loadInitialDimensionValues(),this.bandNames=HT(this.variable,this.normalizedSelector),this.bandNames.length>1||this.customFrag?this.customShaderConfig={bands:this.bandNames,customFrag:this.customFrag,customUniforms:this.customUniforms}:this.customShaderConfig=null}catch(A){throw this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null),A}}async loadInitialDimensionValues(){if(!this.zarrStore?.root)return;let A=this.levelInfos.length>0?this.levelInfos[0]:null;for(let[t,e]of Object.entries(this.selector))this.normalizedSelector[t]=jPe(e);for(let t of Object.keys(this.dimIndices))if(!Yci.has(t.toLowerCase()))try{this.dimensionValues[t]=await JPe(this.dimensionValues,A,this.dimIndices[t],this.zarrStore.root,this.zarrStore.version),this.normalizedSelector[t]||(this.normalizedSelector[t]={selected:0})}catch(e){console.warn(`Failed to load dimension values for ${t}:`,e)}}isZoomInRange(){if(!this.map?.getZoom)return!0;let A=this.map.getZoom();return A>=this.minZoom&&A<=this.maxZoom}prerender(A,t){this.isRemoved||!this.gl||!this.mode||!this.map||this.isZoomInRange()&&(this.syncProjectionState(),this.mode.update(this.map,this.gl))}render(A,t,e,i,r,n,s){if(this.isRemoved||!this.renderer||!this.gl||!this.mode||!this.map||!this.isZoomInRange())return;let o=yhi(t,e,i,r);if(!o.matrix)return;let a=!o.mapbox&&!o.shaderData?{projection:{name:"mercator"},globeToMercatorMatrix:$q,transition:1}:void 0,l=this.isGlobeProjection(),g=xhi(this.map,l),h=this.colormap.ensureTexture(this.gl),p={gl:this.gl,matrix:o.matrix,uniforms:{clim:this.clim,opacity:this.opacity,fillValue:this._fillValue,scaleFactor:this.scaleFactor,offset:this.offset,fixedDataScale:this.fixedDataScale},colormapTexture:h,worldOffsets:g,customShaderConfig:this.customShaderConfig||void 0,shaderData:o.shaderData,projectionData:o.projectionData,mapbox:o.mapbox??a};this.mode.render(this.renderer,p),this.tileNeedsRender=!1}renderToTile(A,t){if(this.isRemoved||!this.renderer||!this.gl||!this.mode||!this.map)return;let e=this.syncProjectionState();this.mode.update(this.map,this.gl);let i=this.colormap.ensureTexture(this.gl),r={gl:this.gl,matrix:new Float32Array(16),uniforms:{clim:this.clim,opacity:this.opacity,fillValue:this._fillValue,scaleFactor:this.scaleFactor,offset:this.offset,fixedDataScale:this.fixedDataScale},colormapTexture:i,worldOffsets:[0],customShaderConfig:this.customShaderConfig||void 0,isGlobe:e};this.tileNeedsRender=this.mode.renderToTile?.(this.renderer,t,r)??!1}shouldRerenderTiles(){let A=this.tileNeedsRender;return this.tileNeedsRender=!1,A}_disposeResources(A){this.isRemoved=!0,this.renderer?.dispose(),this.renderer=null,this.colormap.dispose(A),this.mode?.dispose(A),this.mode=null,this.zarrStore&&(this.zarrStore.cleanup(),this.zarrStore=null),this.map&&this.projectionChangeHandler&&typeof this.map.off=="function"&&(this.map.off("projectionchange",this.projectionChangeHandler),this.map.off("style.load",this.projectionChangeHandler))}onRemove(A,t){let e=this.gl??this.resolveGl(A,t);this._disposeResources(e)}async queryData(A,t){return this.mode?.queryData?this.mode.queryData(A,t):{[this.variable]:[],dimensions:["lat","lon"],coordinates:{lat:[],lon:[]}}}};var a6t=class{model;el;map=null;mapContainer=null;lastProcessedCallId=0;pendingCalls=[];eventQueue=[];isMapReady=!1;methodHandlers=new Map;modelListeners=[];constructor(t,e){this.model=t,this.el=e}createMapContainer(){let t=this.model.get("width")||"100%",e=this.model.get("height")||"400px";this.el.style.width="100%",this.el.style.display="block",e.endsWith("%")&&(this.el.style.height="100%");let i=document.createElement("div");return i.style.width=t,i.style.height=e,i.style.position="relative",i.style.minWidth="200px",this.el.appendChild(i),this.mapContainer=i,i}setupModelListeners(){let t=()=>this.processJsCalls(),e=()=>this.onCenterChange(),i=()=>this.onZoomChange(),r=()=>this.onStyleChange();this.model.on("change:_js_calls",t),this.model.on("change:center",e),this.model.on("change:zoom",i),this.model.on("change:style",r),this.modelListeners.push(()=>this.model.off("change:_js_calls",t),()=>this.model.off("change:center",e),()=>this.model.off("change:zoom",i),()=>this.model.off("change:style",r))}removeModelListeners(){this.modelListeners.forEach(t=>t()),this.modelListeners=[]}registerMethod(t,e){this.methodHandlers.set(t,e)}executeMethod(t,e,i){let r=this.methodHandlers.get(t);if(r)try{r(e,i)}catch(n){console.error(`Error executing method ${t}:`,n)}else console.warn(`Unknown method: ${t}`)}processJsCalls(){let e=(this.model.get("_js_calls")||[]).filter(i=>i.id>this.lastProcessedCallId);for(let i of e)this.isMapReady?this.executeMethod(i.method,i.args,i.kwargs):this.pendingCalls.push(i),this.lastProcessedCallId=i.id}processPendingCalls(){for(let t of this.pendingCalls)this.executeMethod(t.method,t.args,t.kwargs);this.pendingCalls=[]}sendEvent(t,e){let i={type:t,data:e,timestamp:Date.now()};this.eventQueue.push(i),this.model.set("_js_events",[...this.eventQueue]),this.model.save_changes()}restoreState(){let t=this.model.get("_sources")||{};for(let[a,l]of Object.entries(t))this.executeMethod("addSource",[a],l);let e=new Set(["fill","line","symbol","circle","heatmap","fill-extrusion","raster","hillshade","color-relief","background"]),i=this.model.get("_layers")||{},r=Object.entries(i).filter(([,a])=>e.has(a.type)),n=r.filter(([a,l])=>a.startsWith("basemap-")||l.type==="raster"),s=r.filter(([a,l])=>!(a.startsWith("basemap-")||l.type==="raster")),o=[...n,...s];for(let[a,l]of o)this.executeMethod("addLayer",[],l)}getMap(){return this.map}getIsMapReady(){return this.isMapReady}getModel(){return this.model}};var l6t=class{model;constructor(t){this.model=t}addLayer(t,e){let i=this.model.get("_layers")||{},r={id:e.id,type:e.type,source:e.source,paint:e.paint,layout:e.layout,visible:!0,opacity:1};this.model.set("_layers",{...i,[t]:r}),this.model.save_changes()}removeLayer(t){let e={...this.model.get("_layers")};delete e[t],this.model.set("_layers",e),this.model.save_changes()}setLayerVisibility(t,e){let i={...this.model.get("_layers")};i[t]&&(i[t]={...i[t],visible:e},this.model.set("_layers",i),this.model.save_changes())}setLayerOpacity(t,e){let i={...this.model.get("_layers")};i[t]&&(i[t]={...i[t],opacity:e},this.model.set("_layers",i),this.model.save_changes())}setLayerFilter(t,e){let i={...this.model.get("_layers")};if(i[t]){let{filter:r,...n}=i[t];i[t]=e?{...n,filter:e}:{...n},this.model.set("_layers",i),this.model.save_changes()}}getLayer(t){return this.model.get("_layers")?.[t]}getLayers(){return this.model.get("_layers")||{}}addSource(t,e){let i=this.model.get("_sources")||{},r={type:e.type,data:e.data,url:e.url,urls:e.urls,tiles:e.tiles,tileSize:e.tileSize,attribution:e.attribution,coordinates:e.coordinates};this.model.set("_sources",{...i,[t]:r}),this.model.save_changes()}removeSource(t){let e={...this.model.get("_sources")};delete e[t],this.model.set("_sources",e),this.model.save_changes()}getSource(t){return this.model.get("_sources")?.[t]}getSources(){return this.model.get("_sources")||{}}addControl(t,e,i,r){let n=this.model.get("_controls")||{},s={type:e,position:i,options:r};this.model.set("_controls",{...n,[t]:s}),this.model.save_changes()}removeControl(t){let e={...this.model.get("_controls")};delete e[t],this.model.set("_controls",e),this.model.save_changes()}getControl(t){return this.model.get("_controls")?.[t]}getControls(){return this.model.get("_controls")||{}}};vVt();var EKe=xg(kx(),1),a1=63710088e-1,fKe={centimeters:a1*100,centimetres:a1*100,degrees:360/(2*Math.PI),feet:a1*3.28084,inches:a1*39.37,kilometers:a1/1e3,kilometres:a1/1e3,meters:a1,metres:a1,miles:a1/1609.344,millimeters:a1*1e3,millimetres:a1*1e3,nauticalmiles:a1/1852,radians:1,yards:a1*1.0936};function Xf(A,t,e={}){let i={type:"Feature"};return(e.id===0||e.id)&&(i.id=e.id),e.bbox&&(i.bbox=e.bbox),i.properties=t||{},i.geometry=A,i}function l9(A,t,e={}){if(!A)throw new Error("coordinates is required");if(!Array.isArray(A))throw new Error("coordinates must be an Array");if(A.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!yqe(A[0])||!yqe(A[1]))throw new Error("coordinates must contain numbers");return Xf({type:"Point",coordinates:A},t,e)}function DQ(A,t,e={}){for(let r of A){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let n=0;n<r[r.length-1].length;n++)if(r[r.length-1][n]!==r[0][n])throw new Error("First and last Position are not equivalent.")}return Xf({type:"Polygon",coordinates:A},t,e)}function $C(A,t,e={}){if(A.length<2)throw new Error("coordinates must be an array of two or more positions");return Xf({type:"LineString",coordinates:A},t,e)}function Xl(A,t={}){let e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=A,e}function _Ke(A,t,e={}){return Xf({type:"MultiLineString",coordinates:A},t,e)}function RQt(A,t,e={}){return Xf({type:"MultiPolygon",coordinates:A},t,e)}function cZt(A,t="kilometers"){let e=fKe[t];if(!e)throw new Error(t+" units is invalid");return A*e}function mKe(A,t="kilometers"){let e=fKe[t];if(!e)throw new Error(t+" units is invalid");return A/e}function oQt(A){return A%(2*Math.PI)*180/Math.PI}function QE(A){return A%360*Math.PI/180}function QKe(A,t="kilometers",e="kilometers"){if(!(A>=0))throw new Error("length must be a positive number");return cZt(mKe(A,t),e)}function yqe(A){return!isNaN(A)&&A!==null&&!Array.isArray(A)}function Dat(A){return A!==null&&typeof A=="object"&&!Array.isArray(A)}function g9(A){if(!A)throw new Error("coord is required");if(!Array.isArray(A)){if(A.type==="Feature"&&A.geometry!==null&&A.geometry.type==="Point")return[...A.geometry.coordinates];if(A.type==="Point")return[...A.coordinates]}if(Array.isArray(A)&&A.length>=2&&!Array.isArray(A[0])&&!Array.isArray(A[1]))return[...A];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function iC(A){if(Array.isArray(A))return A;if(A.type==="Feature"){if(A.geometry!==null)return A.geometry.coordinates}else if(A.coordinates)return A.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function kQ(A){return A.type==="Feature"?A.geometry:A}function aQt(A,t){return A.type==="FeatureCollection"?"FeatureCollection":A.type==="GeometryCollection"?"GeometryCollection":A.type==="Feature"&&A.geometry!==null?A.geometry.type:A.type}function yKe(A,t,e={}){if(e.final===!0)return c6i(A,t);let i=g9(A),r=g9(t),n=QE(i[0]),s=QE(r[0]),o=QE(i[1]),a=QE(r[1]),l=Math.sin(s-n)*Math.cos(a),g=Math.cos(o)*Math.sin(a)-Math.sin(o)*Math.cos(a)*Math.cos(s-n);return oQt(Math.atan2(l,g))}function c6i(A,t){let e=yKe(t,A);return e=(e+180)%360,e}function xat(A,t,e={}){var i=g9(A),r=g9(t),n=QE(r[1]-i[1]),s=QE(r[0]-i[0]),o=QE(i[1]),a=QE(r[1]),l=Math.pow(Math.sin(n/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(o)*Math.cos(a);return cZt(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),e.units)}function h6i(A,t,e={}){let i;return e.final?i=xqe(g9(t),g9(A)):i=xqe(g9(A),g9(t)),i>180?-(360-i):i}function xqe(A,t){let e=QE(A[1]),i=QE(t[1]),r=QE(t[0]-A[0]);r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI);let n=Math.log(Math.tan(i/2+Math.PI/4)/Math.tan(e/2+Math.PI/4)),s=Math.atan2(r,n);return(oQt(s)+360)%360}function rM(A,t,e){if(A!==null)for(var i,r,n,s,o,a,l,g=0,h=0,p,d=A.type,E=d==="FeatureCollection",f=d==="Feature",Q=E?A.features.length:1,y=0;y<Q;y++){l=E?A.features[y].geometry:f?A.geometry:A,p=l?l.type==="GeometryCollection":!1,o=p?l.geometries.length:1;for(var S=0;S<o;S++){var v=0,M=0;if(s=p?l.geometries[S]:l,s!==null){a=s.coordinates;var H=s.type;switch(g=e&&(H==="Polygon"||H==="MultiPolygon")?1:0,H){case null:break;case"Point":if(t(a,h,y,v,M)===!1)return!1;h++,v++;break;case"LineString":case"MultiPoint":for(i=0;i<a.length;i++){if(t(a[i],h,y,v,M)===!1)return!1;h++,H==="MultiPoint"&&v++}H==="LineString"&&v++;break;case"Polygon":case"MultiLineString":for(i=0;i<a.length;i++){for(r=0;r<a[i].length-g;r++){if(t(a[i][r],h,y,v,M)===!1)return!1;h++}H==="MultiLineString"&&v++,H==="Polygon"&&M++}H==="Polygon"&&v++;break;case"MultiPolygon":for(i=0;i<a.length;i++){for(M=0,r=0;r<a[i].length;r++){for(n=0;n<a[i][r].length-g;n++){if(t(a[i][r][n],h,y,v,M)===!1)return!1;h++}M++}v++}break;case"GeometryCollection":for(i=0;i<s.geometries.length;i++)if(rM(s.geometries[i],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function fv(A,t){if(A.type==="Feature")t(A,0);else if(A.type==="FeatureCollection")for(var e=0;e<A.features.length&&t(A.features[e],e)!==!1;e++);}function u6i(A,t,e){var i=e;return fv(A,function(r,n){n===0&&e===void 0?i=r:i=t(i,r,n)}),i}function I6i(A){var t=[];return rM(A,function(e){t.push(e)}),t}function nM(A,t){var e,i,r,n,s,o,a,l,g,h,p=0,d=A.type==="FeatureCollection",E=A.type==="Feature",f=d?A.features.length:1;for(e=0;e<f;e++){for(o=d?A.features[e].geometry:E?A.geometry:A,l=d?A.features[e].properties:E?A.properties:{},g=d?A.features[e].bbox:E?A.bbox:void 0,h=d?A.features[e].id:E?A.id:void 0,a=o?o.type==="GeometryCollection":!1,s=a?o.geometries.length:1,r=0;r<s;r++){if(n=a?o.geometries[r]:o,n===null){if(t(null,p,l,g,h)===!1)return!1;continue}switch(n.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(n,p,l,g,h)===!1)return!1;break}case"GeometryCollection":{for(i=0;i<n.geometries.length;i++)if(t(n.geometries[i],p,l,g,h)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}p++}}function p6i(A,t,e){var i=e;return nM(A,function(r,n,s,o,a){i=t(i,r,n,s,o,a)}),i}function _v(A,t){nM(A,function(e,i,r,n,s){var o=e===null?null:e.type;switch(o){case null:case"Point":case"LineString":case"Polygon":return t(Xf(e,r,{bbox:n,id:s}),i,0)===!1?!1:void 0}var a;switch(o){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon";break}for(var l=0;l<e.coordinates.length;l++){var g=e.coordinates[l],h={type:a,coordinates:g};if(t(Xf(h,r),i,l)===!1)return!1}})}function uat(A,t){_v(A,function(e,i,r){var n=0;if(e.geometry){var s=e.geometry.type;if(!(s==="Point"||s==="MultiPoint")){var o,a=0,l=0,g=0;if(rM(e,function(h,p,d,E,f){if(o===void 0||i>a||E>l||f>g){o=h,a=i,l=E,g=f,n=0;return}var Q=$C([o,h],e.properties);if(t(Q,i,r,f,n)===!1)return!1;n++,o=h})===!1)return!1}}})}function lQt(A){return p6i(A,(t,e)=>t+d6i(e),0)}function d6i(A){let t=0,e;switch(A.type){case"Polygon":return wqe(A.coordinates);case"MultiPolygon":for(e=0;e<A.coordinates.length;e++)t+=wqe(A.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function wqe(A){let t=0;if(A&&A.length>0){t+=Math.abs(bqe(A[0]));for(let e=1;e<A.length;e++)t-=Math.abs(bqe(A[e]))}return t}var C6i=a1*a1/2,DVt=Math.PI/180;function bqe(A){let t=A.length-1;if(t<=2)return 0;let e=0,i=0;for(;i<t;){let r=A[i],n=A[i+1===t?0:i+1],s=A[i+2>=t?(i+2)%t:i+2],o=r[0]*DVt,a=n[1]*DVt,l=s[0]*DVt;e+=(l-o)*Math.sin(a),i++}return e*C6i}function SI(A,t={}){if(A.bbox!=null&&t.recompute!==!0)return A.bbox;let e=[1/0,1/0,-1/0,-1/0];return rM(A,i=>{e[0]>i[0]&&(e[0]=i[0]),e[1]>i[1]&&(e[1]=i[1]),e[2]<i[0]&&(e[2]=i[0]),e[3]<i[1]&&(e[3]=i[1])}),e}function B6i(A,t,e){var i=A.length,r=YK(A[0],t),n=[],s,o,a;let l,g;for(e||(e=[]),s=1;s<i;s++){for(l=A[s-1],g=A[s],o=a=YK(g,t);;)if(r|o){if(r&o)break;r?(l=qVt(l,g,r,t),r=YK(l,t)):(g=qVt(l,g,o,t),o=YK(g,t))}else{n.push(l),o!==a?(n.push(g),s<i-1&&(e.push(n),n=[])):s===i-1&&n.push(g);break}r=a}return n.length&&e.push(n),e}function E6i(A,t){var e,i,r,n,s,o,a;for(i=1;i<=8;i*=2){for(e=[],r=A[A.length-1],n=!(YK(r,t)&i),s=0;s<A.length;s++)o=A[s],a=!(YK(o,t)&i),a!==n&&e.push(qVt(r,o,i,t)),a&&e.push(o),r=o,n=a;if(A=e,!A.length)break}return e}function qVt(A,t,e,i){return e&8?[A[0]+(t[0]-A[0])*(i[3]-A[1])/(t[1]-A[1]),i[3]]:e&4?[A[0]+(t[0]-A[0])*(i[1]-A[1])/(t[1]-A[1]),i[1]]:e&2?[i[2],A[1]+(t[1]-A[1])*(i[2]-A[0])/(t[0]-A[0])]:e&1?[i[0],A[1]+(t[1]-A[1])*(i[0]-A[0])/(t[0]-A[0])]:null}function YK(A,t){var e=0;return A[0]<t[0]?e|=1:A[0]>t[2]&&(e|=2),A[1]<t[1]?e|=4:A[1]>t[3]&&(e|=8),e}function f6i(A,t){let e=kQ(A),i=e.type,r=A.type==="Feature"?A.properties:{},n=e.coordinates;switch(i){case"LineString":case"MultiLineString":{let s=[];return i==="LineString"&&(n=[n]),n.forEach(o=>{B6i(o,t,s)}),s.length===1?$C(s[0],r):_Ke(s,r)}case"Polygon":return DQ(Sqe(n,t),r);case"MultiPolygon":return RQt(n.map(s=>Sqe(s,t)),r);default:throw new Error("geometry "+i+" not supported")}}function Sqe(A,t){let e=[];for(let i of A){let r=E6i(i,t);r.length>0&&((r[0][0]!==r[r.length-1][0]||r[0][1]!==r[r.length-1][1])&&r.push(r[0]),r.length>=4&&e.push(r))}return e}var Ev=11102230246251565e-32,XC=134217729,_6i=(3+8*Ev)*Ev;function kVt(A,t,e,i,r){let n,s,o,a,l=t[0],g=i[0],h=0,p=0;g>l==g>-l?(n=l,l=t[++h]):(n=g,g=i[++p]);let d=0;if(h<A&&p<e)for(g>l==g>-l?(s=l+n,o=n-(s-l),l=t[++h]):(s=g+n,o=n-(s-g),g=i[++p]),n=s,o!==0&&(r[d++]=o);h<A&&p<e;)g>l==g>-l?(s=n+l,a=s-n,o=n-(s-a)+(l-a),l=t[++h]):(s=n+g,a=s-n,o=n-(s-a)+(g-a),g=i[++p]),n=s,o!==0&&(r[d++]=o);for(;h<A;)s=n+l,a=s-n,o=n-(s-a)+(l-a),l=t[++h],n=s,o!==0&&(r[d++]=o);for(;p<e;)s=n+g,a=s-n,o=n-(s-a)+(g-a),g=i[++p],n=s,o!==0&&(r[d++]=o);return(n!==0||d===0)&&(r[d++]=n),d}function m6i(A,t){let e=t[0];for(let i=1;i<A;i++)e+=t[i];return e}function kat(A){return new Float64Array(A)}var Q6i=(3+16*Ev)*Ev,y6i=(2+12*Ev)*Ev,x6i=(9+64*Ev)*Ev*Ev,TK=kat(4),vqe=kat(8),Dqe=kat(12),kqe=kat(16),mE=kat(4);function w6i(A,t,e,i,r,n,s){let o,a,l,g,h,p,d,E,f,Q,y,S,v,M,H,Y,z,F,N=A-r,P=e-r,K=t-n,At=i-n;M=N*At,p=XC*N,d=p-(p-N),E=N-d,p=XC*At,f=p-(p-At),Q=At-f,H=E*Q-(M-d*f-E*f-d*Q),Y=K*P,p=XC*K,d=p-(p-K),E=K-d,p=XC*P,f=p-(p-P),Q=P-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,TK[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,TK[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,TK[2]=S-(F-h)+(y-h),TK[3]=F;let st=m6i(4,TK),it=y6i*s;if(st>=it||-st>=it||(h=A-N,o=A-(N+h)+(h-r),h=e-P,l=e-(P+h)+(h-r),h=t-K,a=t-(K+h)+(h-n),h=i-At,g=i-(At+h)+(h-n),o===0&&a===0&&l===0&&g===0)||(it=x6i*s+_6i*Math.abs(st),st+=N*g+At*o-(K*l+P*a),st>=it||-st>=it))return st;M=o*At,p=XC*o,d=p-(p-o),E=o-d,p=XC*At,f=p-(p-At),Q=At-f,H=E*Q-(M-d*f-E*f-d*Q),Y=a*P,p=XC*a,d=p-(p-a),E=a-d,p=XC*P,f=p-(p-P),Q=P-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,mE[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,mE[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,mE[2]=S-(F-h)+(y-h),mE[3]=F;let W=kVt(4,TK,4,mE,vqe);M=N*g,p=XC*N,d=p-(p-N),E=N-d,p=XC*g,f=p-(p-g),Q=g-f,H=E*Q-(M-d*f-E*f-d*Q),Y=K*l,p=XC*K,d=p-(p-K),E=K-d,p=XC*l,f=p-(p-l),Q=l-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,mE[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,mE[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,mE[2]=S-(F-h)+(y-h),mE[3]=F;let X=kVt(W,vqe,4,mE,Dqe);M=o*g,p=XC*o,d=p-(p-o),E=o-d,p=XC*g,f=p-(p-g),Q=g-f,H=E*Q-(M-d*f-E*f-d*Q),Y=a*l,p=XC*a,d=p-(p-a),E=a-d,p=XC*l,f=p-(p-l),Q=l-f,z=E*Q-(Y-d*f-E*f-d*Q),y=H-z,h=H-y,mE[0]=H-(y+h)+(h-z),S=M+y,h=S-M,v=M-(S-h)+(y-h),y=v-Y,h=v-y,mE[1]=v-(y+h)+(h-Y),F=S+y,h=F-S,mE[2]=S-(F-h)+(y-h),mE[3]=F;let rt=kVt(X,Dqe,4,mE,kqe);return kqe[rt-1]}function b6i(A,t,e,i,r,n){let s=(t-n)*(e-r),o=(A-r)*(i-n),a=s-o,l=Math.abs(s+o);return Math.abs(a)>=Q6i*l?a:-w6i(A,t,e,i,r,n,l)}function S6i(A,t){var e,i,r=0,n,s,o,a,l,g,h,p=A[0],d=A[1],E=t.length;for(e=0;e<E;e++){i=0;var f=t[e],Q=f.length-1;if(g=f[0],g[0]!==f[Q][0]&&g[1]!==f[Q][1])throw new Error("First and last coordinates in a ring must be the same");for(s=g[0]-p,o=g[1]-d,i;i<Q;i++){if(h=f[i+1],a=h[0]-p,l=h[1]-d,o===0&&l===0){if(a<=0&&s>=0||s<=0&&a>=0)return 0}else if(l>=0&&o<=0||l<=0&&o>=0){if(n=b6i(s,a,o,l,0,0),n===0)return 0;(n>0&&l>0&&o<=0||n<0&&l<=0&&o>0)&&r++}g=h,o=l,s=a}}return r%2!==0}function c9(A,t,e={}){if(!A)throw new Error("point is required");if(!t)throw new Error("polygon is required");let i=g9(A),r=kQ(t),n=r.type,s=t.bbox,o=r.coordinates;if(s&&v6i(i,s)===!1)return!1;n==="Polygon"&&(o=[o]);let a=!1;for(var l=0;l<o.length;++l){let g=S6i(i,o[l]);if(g===0)return!e.ignoreBoundary;g&&(a=!0)}return a}function v6i(A,t){return t[0]<=A[0]&&t[1]<=A[1]&&t[2]>=A[0]&&t[3]>=A[1]}function yE(A,t,e={}){let i=g9(A),r=iC(t);for(let n=0;n<r.length-1;n++){let s=!1;if(e.ignoreEndVertices&&(n===0&&(s="start"),n===r.length-2&&(s="end"),n===0&&n+1===r.length-1&&(s="both")),D6i(r[n],r[n+1],i,s,typeof e.epsilon>"u"?null:e.epsilon))return!0}return!1}function D6i(A,t,e,i,r){let n=e[0],s=e[1],o=A[0],a=A[1],l=t[0],g=t[1],h=e[0]-o,p=e[1]-a,d=l-o,E=g-a,f=h*E-p*d;if(r!==null){if(Math.abs(f)>r)return!1}else if(f!==0)return!1;if(Math.abs(d)===Math.abs(E)&&Math.abs(d)===0)return i?!1:e[0]===A[0]&&e[1]===A[1];if(i){if(i==="start")return Math.abs(d)>=Math.abs(E)?d>0?o<n&&n<=l:l<=n&&n<o:E>0?a<s&&s<=g:g<=s&&s<a;if(i==="end")return Math.abs(d)>=Math.abs(E)?d>0?o<=n&&n<l:l<n&&n<=o:E>0?a<=s&&s<g:g<s&&s<=a;if(i==="both")return Math.abs(d)>=Math.abs(E)?d>0?o<n&&n<l:l<n&&n<o:E>0?a<s&&s<g:g<s&&s<a}else return Math.abs(d)>=Math.abs(E)?d>0?o<=n&&n<=l:l<=n&&n<=o:E>0?a<=s&&s<=g:g<=s&&s<=a;return!1}function k6i(A,t,e,i,r){xKe(A,t,e||0,i||A.length-1,r||R6i)}function xKe(A,t,e,i,r){for(;i>e;){if(i-e>600){var n=i-e+1,s=t-e+1,o=Math.log(n),a=.5*Math.exp(2*o/3),l=.5*Math.sqrt(o*a*(n-a)/n)*(s-n/2<0?-1:1),g=Math.max(e,Math.floor(t-s*a/n+l)),h=Math.min(i,Math.floor(t+(n-s)*a/n+l));xKe(A,t,g,h,r)}var p=A[t],d=e,E=i;for(lat(A,e,t),r(A[i],p)>0&&lat(A,e,i);d<E;){for(lat(A,d,E),d++,E--;r(A[d],p)<0;)d++;for(;r(A[E],p)>0;)E--}r(A[e],p)===0?lat(A,e,E):(E++,lat(A,E,i)),E<=t&&(e=E+1),t<=E&&(i=E-1)}}function lat(A,t,e){var i=A[t];A[t]=A[e],A[e]=i}function R6i(A,t){return A<t?-1:A>t?1:0}var hZt=class{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data,i=[];if(!Ymt(t,e))return i;let r=this.toBBox,n=[];for(;e;){for(let s=0;s<e.children.length;s++){let o=e.children[s],a=e.leaf?r(o):o;Ymt(t,a)&&(e.leaf?i.push(o):MVt(t,a)?this._all(o,i):n.push(o))}e=n.pop()}return i}collides(t){let e=this.data;if(!Ymt(t,e))return!1;let i=[];for(;e;){for(let r=0;r<e.children.length;r++){let n=e.children[r],s=e.leaf?this.toBBox(n):n;if(Ymt(t,s)){if(e.leaf||MVt(t,s))return!0;i.push(n)}}e=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){let i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=HK([]),this}remove(t,e){if(!t)return this;let i=this.data,r=this.toBBox(t),n=[],s=[],o,a,l;for(;i||n.length;){if(i||(i=n.pop(),a=n[n.length-1],o=s.pop(),l=!0),i.leaf){let g=M6i(t,i.children,e);if(g!==-1)return i.children.splice(g,1),n.push(i),this._condense(n),this}!l&&!i.leaf&&MVt(i,r)?(n.push(i),s.push(o),o=0,a=i,i=i.children[0]):a?(o++,i=a.children[o],l=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){let i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,r){let n=i-e+1,s=this._maxEntries,o;if(n<=s)return o=HK(t.slice(e,i+1)),UK(o,this.toBBox),o;r||(r=Math.ceil(Math.log(n)/Math.log(s)),s=Math.ceil(n/Math.pow(s,r-1))),o=HK([]),o.leaf=!1,o.height=r;let a=Math.ceil(n/s),l=a*Math.ceil(Math.sqrt(s));Rqe(t,e,i,l,this.compareMinX);for(let g=e;g<=i;g+=l){let h=Math.min(g+l-1,i);Rqe(t,g,h,a,this.compareMinY);for(let p=g;p<=h;p+=a){let d=Math.min(p+a-1,h);o.children.push(this._build(t,p,d,r-1))}}return UK(o,this.toBBox),o}_chooseSubtree(t,e,i,r){for(;r.push(e),!(e.leaf||r.length-1===i);){let n=1/0,s=1/0,o;for(let a=0;a<e.children.length;a++){let l=e.children[a],g=RVt(l),h=N6i(t,l)-g;h<s?(s=h,n=g<n?g:n,o=l):h===s&&g<n&&(n=g,o=l)}e=o||e.children[0]}return e}_insert(t,e,i){let r=i?t:this.toBBox(t),n=[],s=this._chooseSubtree(r,this.data,e,n);for(s.children.push(t),pat(s,r);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(r,n,e)}_split(t,e){let i=t[e],r=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,r);let s=this._chooseSplitIndex(i,n,r),o=HK(i.children.splice(s,i.children.length-s));o.height=i.height,o.leaf=i.leaf,UK(i,this.toBBox),UK(o,this.toBBox),e?t[e-1].children.push(o):this._splitRoot(i,o)}_splitRoot(t,e){this.data=HK([t,e]),this.data.height=t.height+1,this.data.leaf=!1,UK(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let r,n=1/0,s=1/0;for(let o=e;o<=i-e;o++){let a=Iat(t,0,o,this.toBBox),l=Iat(t,o,i,this.toBBox),g=L6i(a,l),h=RVt(a)+RVt(l);g<n?(n=g,r=o,s=h<s?h:s):g===n&&h<s&&(s=h,r=o)}return r||i-e}_chooseSplitAxis(t,e,i){let r=t.leaf?this.compareMinX:G6i,n=t.leaf?this.compareMinY:F6i,s=this._allDistMargin(t,e,i,r),o=this._allDistMargin(t,e,i,n);s<o&&t.children.sort(r)}_allDistMargin(t,e,i,r){t.children.sort(r);let n=this.toBBox,s=Iat(t,0,e,n),o=Iat(t,i-e,i,n),a=Omt(s)+Omt(o);for(let l=e;l<i-e;l++){let g=t.children[l];pat(s,t.leaf?n(g):g),a+=Omt(s)}for(let l=i-e-1;l>=e;l--){let g=t.children[l];pat(o,t.leaf?n(g):g),a+=Omt(o)}return a}_adjustParentBBoxes(t,e,i){for(let r=i;r>=0;r--)pat(e[r],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():UK(t[e],this.toBBox)}};function M6i(A,t,e){if(!e)return t.indexOf(A);for(let i=0;i<t.length;i++)if(e(A,t[i]))return i;return-1}function UK(A,t){Iat(A,0,A.children.length,t,A)}function Iat(A,t,e,i,r){r||(r=HK(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let n=t;n<e;n++){let s=A.children[n];pat(r,A.leaf?i(s):s)}return r}function pat(A,t){return A.minX=Math.min(A.minX,t.minX),A.minY=Math.min(A.minY,t.minY),A.maxX=Math.max(A.maxX,t.maxX),A.maxY=Math.max(A.maxY,t.maxY),A}function G6i(A,t){return A.minX-t.minX}function F6i(A,t){return A.minY-t.minY}function RVt(A){return(A.maxX-A.minX)*(A.maxY-A.minY)}function Omt(A){return A.maxX-A.minX+(A.maxY-A.minY)}function N6i(A,t){return(Math.max(t.maxX,A.maxX)-Math.min(t.minX,A.minX))*(Math.max(t.maxY,A.maxY)-Math.min(t.minY,A.minY))}function L6i(A,t){let e=Math.max(A.minX,t.minX),i=Math.max(A.minY,t.minY),r=Math.min(A.maxX,t.maxX),n=Math.min(A.maxY,t.maxY);return Math.max(0,r-e)*Math.max(0,n-i)}function MVt(A,t){return A.minX<=t.minX&&A.minY<=t.minY&&t.maxX<=A.maxX&&t.maxY<=A.maxY}function Ymt(A,t){return t.minX<=A.maxX&&t.minY<=A.maxY&&t.maxX>=A.minX&&t.maxY>=A.minY}function HK(A){return{children:A,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Rqe(A,t,e,i,r){let n=[t,e];for(;n.length;){if(e=n.pop(),t=n.pop(),e-t<=i)continue;let s=t+Math.ceil((e-t)/i/2)*i;k6i(A,s,t,e,r),n.push(t,s,s,e)}}function GVt(A){var t;if(A.bbox)t=A.bbox;else if(Array.isArray(A)&&A.length===4)t=A;else if(Array.isArray(A)&&A.length===6)t=[A[0],A[1],A[3],A[4]];else if(A.type==="Feature")t=SI(A);else if(A.type==="FeatureCollection")t=SI(A);else throw new Error("invalid geojson");return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}}var T6i=class{constructor(A=9){this.tree=new hZt(A),this.tree.toBBox=GVt}insert(A){if(A.type!=="Feature")throw new Error("invalid feature");return A.bbox=A.bbox?A.bbox:SI(A),this.tree.insert(A),this}load(A){var t=[];return Array.isArray(A)?A.forEach(function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:SI(e),t.push(e)}):fv(A,function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:SI(e),t.push(e)}),this.tree.load(t),this}remove(A,t){if(A.type!=="Feature")throw new Error("invalid feature");return A.bbox=A.bbox?A.bbox:SI(A),this.tree.remove(A,t),this}clear(){return this.tree.clear(),this}search(A){var t=this.tree.search(GVt(A));return Xl(t)}collides(A){return this.tree.collides(GVt(A))}all(){let A=this.tree.all();return Xl(A)}toJSON(){return this.tree.toJSON()}fromJSON(A){return this.tree.fromJSON(A),this}};function uZt(A){return new T6i(A)}function U6i(A,t){if(t=t??{},!Dat(t))throw new Error("options is invalid");var e=t.precision,i=t.coordinates,r=t.mutate;if(e=e==null||isNaN(e)?6:e,i=i==null||isNaN(i)?3:i,!A)throw new Error("<geojson> is required");if(typeof e!="number")throw new Error("<precision> must be a number");if(typeof i!="number")throw new Error("<coordinates> must be a number");(r===!1||r===void 0)&&(A=JSON.parse(JSON.stringify(A)));var n=Math.pow(10,e);return rM(A,function(s){P6i(s,n,i)}),A}function P6i(A,t,e){A.length>e&&A.splice(e,A.length);for(var i=0;i<A.length;i++)A[i]=Math.round(A[i]*t)/t;return A}function wKe(A){if(!A)throw new Error("geojson is required");let t=[];return _v(A,e=>{H6i(e,t)}),Xl(t)}function H6i(A,t){let e=[],i=A.geometry;if(i!==null){switch(i.type){case"Polygon":e=iC(i);break;case"LineString":e=[iC(i)]}e.forEach(r=>{O6i(r,A.properties).forEach(s=>{s.id=t.length,t.push(s)})})}}function O6i(A,t){let e=[];return A.reduce((i,r)=>{let n=$C([i,r],t);return n.bbox=Y6i(i,r),e.push(n),r}),e}function Y6i(A,t){let e=A[0],i=A[1],r=t[0],n=t[1],s=e<r?e:r,o=i<n?i:n,a=e>r?e:r,l=i>n?i:n;return[s,o,a,l]}var gQt=class{constructor(t=[],e=J6i){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;let t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){let{data:e,compare:i}=this,r=e[t];for(;t>0;){let n=t-1>>1,s=e[n];if(i(r,s)>=0)break;e[t]=s,t=n}e[t]=r}_down(t){let{data:e,compare:i}=this,r=this.length>>1,n=e[t];for(;t<r;){let s=(t<<1)+1,o=e[s],a=s+1;if(a<this.length&&i(e[a],o)<0&&(s=a,o=e[a]),i(o,n)>=0)break;e[t]=o,t=s}e[t]=n}};function J6i(A,t){return A<t?-1:A>t?1:0}function bKe(A,t){return A.p.x>t.p.x?1:A.p.x<t.p.x?-1:A.p.y!==t.p.y?A.p.y>t.p.y?1:-1:1}function j6i(A,t){return A.rightSweepEvent.p.x>t.rightSweepEvent.p.x?1:A.rightSweepEvent.p.x<t.rightSweepEvent.p.x?-1:A.rightSweepEvent.p.y!==t.rightSweepEvent.p.y?A.rightSweepEvent.p.y<t.rightSweepEvent.p.y?1:-1:1}var cQt=class{constructor(t,e,i,r){this.p={x:t[0],y:t[1]},this.featureId=e,this.ringId=i,this.eventId=r,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(t){return this.p.x===t.p.x&&this.p.y===t.p.y}};function q6i(A,t){if(A.type==="FeatureCollection"){let e=A.features;for(let i=0;i<e.length;i++)Mqe(e[i],t)}else Mqe(A,t)}var Jmt=0,jmt=0,qmt=0;function Mqe(A,t){let e=A.type==="Feature"?A.geometry:A,i=e.coordinates;(e.type==="Polygon"||e.type==="MultiLineString")&&(i=[i]),e.type==="LineString"&&(i=[[i]]);for(let r=0;r<i.length;r++)for(let n=0;n<i[r].length;n++){let s=i[r][n][0],o=null;jmt=jmt+1;for(let a=0;a<i[r][n].length-1;a++){o=i[r][n][a+1];let l=new cQt(s,Jmt,jmt,qmt),g=new cQt(o,Jmt,jmt,qmt+1);l.otherEvent=g,g.otherEvent=l,bKe(l,g)>0?(g.isLeftEndpoint=!0,l.isLeftEndpoint=!1):(l.isLeftEndpoint=!0,g.isLeftEndpoint=!1),t.push(l),t.push(g),s=o,qmt=qmt+1}}Jmt=Jmt+1}var K6i=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function z6i(A,t){if(A===null||t===null||A.leftSweepEvent.ringId===t.leftSweepEvent.ringId&&(A.rightSweepEvent.isSamePoint(t.leftSweepEvent)||A.rightSweepEvent.isSamePoint(t.leftSweepEvent)||A.rightSweepEvent.isSamePoint(t.rightSweepEvent)||A.leftSweepEvent.isSamePoint(t.leftSweepEvent)||A.leftSweepEvent.isSamePoint(t.rightSweepEvent)))return!1;let e=A.leftSweepEvent.p.x,i=A.leftSweepEvent.p.y,r=A.rightSweepEvent.p.x,n=A.rightSweepEvent.p.y,s=t.leftSweepEvent.p.x,o=t.leftSweepEvent.p.y,a=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,g=(l-o)*(r-e)-(a-s)*(n-i),h=(a-s)*(i-o)-(l-o)*(e-s),p=(r-e)*(i-o)-(n-i)*(e-s);if(g===0)return!1;let d=h/g,E=p/g;if(d>=0&&d<=1&&E>=0&&E<=1){let f=e+d*(r-e),Q=i+d*(n-i);return[f,Q]}return!1}function W6i(A,t){t=t||!1;let e=[],i=new gQt([],j6i);for(;A.length;){let r=A.pop();if(r.isLeftEndpoint){let n=new K6i(r);for(let s=0;s<i.data.length;s++){let o=i.data[s];if(t&&o.leftSweepEvent.featureId===r.featureId)continue;let a=z6i(n,o);a!==!1&&e.push(a)}i.push(n)}else r.isLeftEndpoint===!1&&i.pop()}return e}function V6i(A,t){let e=new gQt([],bKe);return q6i(A,e),W6i(e,t)}var Z6i=V6i;function WK(A,t,e={}){let{removeDuplicates:i=!0,ignoreSelfIntersections:r=!0}=e,n=[];A.type==="FeatureCollection"?n=n.concat(A.features):A.type==="Feature"?n.push(A):(A.type==="LineString"||A.type==="Polygon"||A.type==="MultiLineString"||A.type==="MultiPolygon")&&n.push(Xf(A)),t.type==="FeatureCollection"?n=n.concat(t.features):t.type==="Feature"?n.push(t):(t.type==="LineString"||t.type==="Polygon"||t.type==="MultiLineString"||t.type==="MultiPolygon")&&n.push(Xf(t));let s=Z6i(Xl(n),r),o=[];if(i){let a={};s.forEach(l=>{let g=l.join(",");a[g]||(a[g]=!0,o.push(l))})}else o=s;return Xl(o.map(a=>l9(a)))}var X6i=Object.defineProperty,$6i=Object.defineProperties,tmi=Object.getOwnPropertyDescriptors,Gqe=Object.getOwnPropertySymbols,emi=Object.prototype.hasOwnProperty,Ami=Object.prototype.propertyIsEnumerable,Fqe=(A,t,e)=>t in A?X6i(A,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):A[t]=e,imi=(A,t)=>{for(var e in t||(t={}))emi.call(t,e)&&Fqe(A,e,t[e]);if(Gqe)for(var e of Gqe(t))Ami.call(t,e)&&Fqe(A,e,t[e]);return A},rmi=(A,t)=>$6i(A,tmi(t));function JK(A,t,e={}){if(!A||!t)throw new Error("lines and inputPoint are required arguments");let i=g9(t),r=l9([1/0,1/0],{lineStringIndex:-1,segmentIndex:-1,totalDistance:-1,lineDistance:-1,segmentDistance:-1,pointDistance:1/0,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),n=0,s=0,o=-1;return _v(A,function(a,l,g){o!==g&&(o=g,s=0);let h=iC(a);for(let p=0;p<h.length-1;p++){let d=l9(h[p]),E=g9(d),f=l9(h[p+1]),Q=g9(f),y=xat(d,f,e),S,v;Q[0]===i[0]&&Q[1]===i[1]?[S,v]=[Q,!0]:E[0]===i[0]&&E[1]===i[1]?[S,v]=[E,!1]:[S,v]=omi(E,Q,i);let M=xat(t,S,e);if(M<r.properties.pointDistance){let H=xat(d,S,e);r=l9(S,{lineStringIndex:g,segmentIndex:v?p+1:p,totalDistance:n+H,lineDistance:s+H,segmentDistance:H,pointDistance:M,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),r.properties=rmi(imi({},r.properties),{multiFeatureIndex:r.properties.lineStringIndex,index:r.properties.segmentIndex,location:r.properties.totalDistance,dist:r.properties.pointDistance})}n+=y,s+=y}}),r}function hU(A,t){let[e,i,r]=A,[n,s,o]=t;return e*n+i*s+r*o}function gat(A,t){let[e,i,r]=A,[n,s,o]=t;return[i*o-r*s,r*n-e*o,e*s-i*n]}function nmi(A){return Math.sqrt(Math.pow(A[0],2)+Math.pow(A[1],2)+Math.pow(A[2],2))}function Nqe(A){let t=nmi(A);return[A[0]/t,A[1]/t,A[2]/t]}function FVt(A){let t=QE(A[1]),e=QE(A[0]);return[Math.cos(t)*Math.cos(e),Math.cos(t)*Math.sin(e),Math.sin(t)]}function smi(A){let[t,e,i]=A,r=Math.min(Math.max(i,-1),1),n=oQt(Math.asin(r));return[oQt(Math.atan2(e,t)),n]}function omi(A,t,e){let i=FVt(A),r=FVt(t),n=FVt(e),s=gat(i,r);if(s[0]===0&&s[1]===0&&s[2]===0)return hU(i,r)>0?[[...t],!0]:[[...e],!1];let o=gat(s,n);if(o[0]===0&&o[1]===0&&o[2]===0)return[[...t],!0];let a=gat(o,s),l=Nqe(a),g=[-l[0],-l[1],-l[2]],h=hU(n,l)>hU(n,g)?l:g,p=Nqe(s),d=hU(gat(i,h),p),E=hU(gat(h,r),p);return d>=0&&E>=0?[smi(h),!1]:hU(i,n)>hU(r,n)?[[...A],!1]:[[...t],!0]}function IZt(A,t){if(!A)throw new Error("line is required");if(!t)throw new Error("splitter is required");let e=aQt(A),i=aQt(t);if(e!=="LineString")throw new Error("line must be LineString");if(i==="FeatureCollection")throw new Error("splitter cannot be a FeatureCollection");if(i==="GeometryCollection")throw new Error("splitter cannot be a GeometryCollection");var r=U6i(t,{precision:7});switch(A.type!=="Feature"&&(A=Xf(A)),i){case"Point":return KVt(A,r);case"MultiPoint":return Lqe(A,r);case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":return Lqe(A,WK(A,r,{ignoreSelfIntersections:!0}))}}function Lqe(A,t){var e=[],i=uZt();return _v(t,function(r){if(e.forEach(function(o,a){o.id=a}),!e.length)e=KVt(A,r).features,i.load(Xl(e));else{var n=i.search(r);if(n.features.length){var s=SKe(r,n);e=e.filter(function(o){return o.id!==s.id}),i.remove(s),fv(KVt(s,r),function(o){e.push(o),i.insert(o)})}}}),Xl(e)}function KVt(A,t){var e=[],i=iC(A)[0],r=iC(A)[A.geometry.coordinates.length-1];if(NVt(i,g9(t))||NVt(r,g9(t)))return Xl([A]);var n=uZt(),s=wKe(A);n.load(s);var o=n.search(t);if(!o.features.length)return Xl([A]);var a=SKe(t,o),l=[i],g=u6i(s,function(h,p,d){var E=iC(p)[1],f=g9(t);return d===a.id?(h.push(f),e.push($C(h)),NVt(f,E)?[f]:[f,E]):(h.push(E),h)},l);return g.length>1&&e.push($C(g)),Xl(e)}function SKe(A,t){if(!t.features.length)throw new Error("lines must contain features");if(t.features.length===1)return t.features[0];var e,i=1/0;return fv(t,function(r){var n=JK(r,A),s=n.properties.dist;s<i&&(e=r,i=s)}),e}function NVt(A,t){return A[0]===t[0]&&A[1]===t[1]}function Tqe(A,t){let e=kQ(A),i=kQ(t),r=e.type,n=i.type,s=e.coordinates,o=i.coordinates;switch(r){case"Point":if(n==="Point")return dZt(s,o);throw new Error("feature2 "+n+" geometry not supported");case"MultiPoint":switch(n){case"Point":return gmi(e,i);case"MultiPoint":return cmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"Point":return yE(i,e,{ignoreEndVertices:!0});case"LineString":return Imi(e,i);case"MultiPoint":return hmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Point":return c9(i,e,{ignoreBoundary:!0});case"LineString":return dmi(e,i);case"Polygon":return pZt(e,i);case"MultiPoint":return umi(e,i);case"MultiPolygon":return lmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPolygon":if(n==="Polygon")return ami(e,i);throw new Error("feature2 "+n+" geometry not supported");default:throw new Error("feature1 "+r+" geometry not supported")}}function ami(A,t){return A.coordinates.some(e=>pZt({type:"Polygon",coordinates:e},t))}function lmi(A,t){return t.coordinates.every(e=>pZt(A,{type:"Polygon",coordinates:e}))}function gmi(A,t){let e,i=!1;for(e=0;e<A.coordinates.length;e++)if(dZt(A.coordinates[e],t.coordinates)){i=!0;break}return i}function cmi(A,t){for(let e of t.coordinates){let i=!1;for(let r of A.coordinates)if(dZt(e,r)){i=!0;break}if(!i)return!1}return!0}function hmi(A,t){let e=!1;for(let i of t.coordinates)if(yE(i,A,{ignoreEndVertices:!0})&&(e=!0),!yE(i,A))return!1;return!!e}function umi(A,t){for(let e of t.coordinates)if(!c9(e,A,{ignoreBoundary:!0}))return!1;return!0}function Imi(A,t){let e=!1;for(let i of t.coordinates)if(yE({type:"Point",coordinates:i},A,{ignoreEndVertices:!0})&&(e=!0),!yE({type:"Point",coordinates:i},A,{ignoreEndVertices:!1}))return!1;return e}function pmi(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=$C([e[r],e[r+1]]),s=IZt(n,Xf(t));s.features.length===0?i.push(n):i.push(...s.features)}return Xl(i)}function dmi(A,t){let e=SI(A),i=SI(t);if(!vKe(e,i))return!1;for(let s of t.coordinates)if(!c9(s,A))return!1;let r=!1,n=pmi(t,A);for(let s of n.features){let o=Cmi(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!c9(o,A))return!1;!r&&c9(o,A,{ignoreBoundary:!0})&&(r=!0)}return r}function pZt(A,t){if(A.type==="Feature"&&A.geometry===null||t.type==="Feature"&&t.geometry===null)return!1;let e=SI(A),i=SI(t);if(!vKe(e,i))return!1;let r=kQ(t).coordinates;for(let n of r)for(let s of n)if(!c9(s,A))return!1;return!0}function vKe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function dZt(A,t){return A[0]===t[0]&&A[1]===t[1]}function Cmi(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function hQt(A,t={}){let e=kQ(A);switch(!t.properties&&A.type==="Feature"&&(t.properties=A.properties),e.type){case"Polygon":return Bmi(e,t);case"MultiPolygon":return Emi(e,t);default:throw new Error("invalid poly")}}function Bmi(A,t={}){let i=kQ(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{};return DKe(i,r)}function Emi(A,t={}){let i=kQ(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{},n=[];return i.forEach(s=>{n.push(DKe(s,r))}),Xl(n)}function DKe(A,t){return A.length>1?_Ke(A,t):$C(A[0],t)}var fmi=Object.defineProperty,VK=(A,t)=>fmi(A,"name",{value:t,configurable:!0}),kKe=class{constructor(t){this.direction=!1,this.compareProperties=!0;var e,i,r;this.precision=10**-((e=t?.precision)!=null?e:17),this.direction=(i=t?.direction)!=null?i:!1,this.compareProperties=(r=t?.compareProperties)!=null?r:!0}compare(t,e){if(t.type!==e.type||!dat(t,e))return!1;switch(t.type){case"Point":return this.compareCoord(t.coordinates,e.coordinates);case"LineString":return this.compareLine(t.coordinates,e.coordinates);case"Polygon":return this.comparePolygon(t,e);case"GeometryCollection":return this.compareGeometryCollection(t,e);case"Feature":return this.compareFeature(t,e);case"FeatureCollection":return this.compareFeatureCollection(t,e);default:if(t.type.startsWith("Multi")){let i=zVt(t),r=zVt(e);return i.every(n=>r.some(s=>this.compare(n,s)))}}return!1}compareCoord(t,e){return t.length===e.length&&t.every((i,r)=>Math.abs(i-e[r])<this.precision)}compareLine(t,e,i=0,r=!1){if(!dat(t,e))return!1;let n=t,s=e;if(r&&!this.compareCoord(n[0],s[0])){let a=this.fixStartIndex(s,n);if(a)s=a;else return!1}let o=this.compareCoord(n[i],s[i]);return this.direction||o?this.comparePath(n,s):this.compareCoord(n[i],s[s.length-(1+i)])?this.comparePath(n.slice().reverse(),s):!1}fixStartIndex(t,e){let i,r=-1;for(let n=0;n<t.length;n++)if(this.compareCoord(t[n],e[0])){r=n;break}return r>=0&&(i=[].concat(t.slice(r,t.length),t.slice(1,r+1))),i}comparePath(t,e){return t.every((i,r)=>this.compareCoord(i,e[r]))}comparePolygon(t,e){if(this.compareLine(t.coordinates[0],e.coordinates[0],1,!0)){let i=t.coordinates.slice(1,t.coordinates.length),r=e.coordinates.slice(1,e.coordinates.length);return i.every(n=>r.some(s=>this.compareLine(n,s,1,!0)))}return!1}compareGeometryCollection(t,e){return dat(t.geometries,e.geometries)&&this.compareBBox(t,e)&&t.geometries.every((i,r)=>this.compare(i,e.geometries[r]))}compareFeature(t,e){return t.id===e.id&&(this.compareProperties?CZt(t.properties,e.properties):!0)&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return dat(t.features,e.features)&&this.compareBBox(t,e)&&t.features.every((i,r)=>this.compare(i,e.features[r]))}compareBBox(t,e){return!t.bbox&&!e.bbox||(t.bbox&&e.bbox?this.compareCoord(t.bbox,e.bbox):!1)}};VK(kKe,"GeojsonEquality");var _mi=kKe;function dat(A,t){return A.coordinates?A.coordinates.length===t.coordinates.length:A.length===t.length}VK(dat,"sameLength");function zVt(A){return A.coordinates.map(t=>({type:A.type.replace("Multi",""),coordinates:t}))}VK(zVt,"explode");function RKe(A,t,e){return new _mi(e).compare(A,t)}VK(RKe,"geojsonEquality");function CZt(A,t){if(A===null&&t===null)return!0;if(A===null||t===null)return!1;let e=Object.keys(A),i=Object.keys(t);if(e.length!==i.length)return!1;for(var r of e){let n=A[r],s=t[r],o=Uqe(n)&&Uqe(s);if(o&&!CZt(n,s)||!o&&n!==s)return!1}return!0}VK(CZt,"equal");var Uqe=VK(A=>A!=null&&typeof A=="object","isObject");function MKe(A,t={}){var e=typeof t=="object"?t.mutate:t;if(!A)throw new Error("geojson is required");var i=aQt(A),r=[];switch(i){case"LineString":r=LVt(A,i);break;case"MultiLineString":case"Polygon":iC(A).forEach(function(s){r.push(LVt(s,i))});break;case"MultiPolygon":iC(A).forEach(function(s){var o=[];s.forEach(function(a){o.push(LVt(a,i))}),r.push(o)});break;case"Point":return A;case"MultiPoint":var n={};iC(A).forEach(function(s){var o=s.join("-");Object.prototype.hasOwnProperty.call(n,o)||(r.push(s),n[o]=!0)});break;default:throw new Error(i+" geometry not supported")}return A.coordinates?e===!0?(A.coordinates=r,A):{type:i,coordinates:r}:e===!0?(A.geometry.coordinates=r,A):Xf({type:i,coordinates:r},A.properties,{bbox:A.bbox,id:A.id})}function LVt(A,t){let e=iC(A);if(e.length===2&&!Pqe(e[0],e[1]))return e;let i=[],r=0,n=1,s=2;for(i.push(e[r]);s<e.length;)yE(e[n],$C([e[r],e[s]]))?n=s:(i.push(e[n]),r=n,n++,s=n),s++;if(i.push(e[n]),t==="Polygon"||t==="MultiPolygon"){if(yE(i[0],$C([i[1],i[i.length-2]]))&&(i.shift(),i.pop(),i.push(i[0])),i.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!Pqe(i[0],i[i.length-1]))throw new Error("invalid polygon, first and last points not equal")}return i}function Pqe(A,t){return A[0]===t[0]&&A[1]===t[1]}function mmi(A,t,{ignoreSelfIntersections:e=!0}={ignoreSelfIntersections:!0}){let i=!0;return _v(A,r=>{_v(t,n=>{if(i===!1)return!1;i=Qmi(r.geometry,n.geometry,e)})}),i}function Qmi(A,t,e){switch(A.type){case"Point":switch(t.type){case"Point":return!bmi(A.coordinates,t.coordinates);case"LineString":return!Hqe(t,A);case"Polygon":return!c9(A,t)}break;case"LineString":switch(t.type){case"Point":return!Hqe(A,t);case"LineString":return!ymi(A,t,e);case"Polygon":return!Oqe(t,A,e)}break;case"Polygon":switch(t.type){case"Point":return!c9(t,A);case"LineString":return!Oqe(A,t,e);case"Polygon":return!xmi(t,A,e)}}return!1}function Hqe(A,t){for(let e=0;e<A.coordinates.length-1;e++)if(wmi(A.coordinates[e],A.coordinates[e+1],t.coordinates))return!0;return!1}function ymi(A,t,e){return WK(A,t,{ignoreSelfIntersections:e}).features.length>0}function Oqe(A,t,e){for(let r of t.coordinates)if(c9(r,A))return!0;return WK(t,hQt(A),{ignoreSelfIntersections:e}).features.length>0}function xmi(A,t,e){for(let r of A.coordinates[0])if(c9(r,t))return!0;for(let r of t.coordinates[0])if(c9(r,A))return!0;return WK(hQt(A),hQt(t),{ignoreSelfIntersections:e}).features.length>0}function wmi(A,t,e){let i=e[0]-A[0],r=e[1]-A[1],n=t[0]-A[0],s=t[1]-A[1];return i*s-r*n!==0?!1:Math.abs(n)>=Math.abs(s)?n>0?A[0]<=e[0]&&e[0]<=t[0]:t[0]<=e[0]&&e[0]<=A[0]:s>0?A[1]<=e[1]&&e[1]<=t[1]:t[1]<=e[1]&&e[1]<=A[1]}function bmi(A,t){return A[0]===t[0]&&A[1]===t[1]}function BZt(A,t,{ignoreSelfIntersections:e=!0}={}){let i=!1;return _v(A,r=>{_v(t,n=>{if(i===!0)return!0;i=!mmi(r.geometry,n.geometry,{ignoreSelfIntersections:e})})}),i}function GKe(A){return A&&A.__esModule&&Object.prototype.hasOwnProperty.call(A,"default")?A.default:A}var TVt,Yqe;function Smi(){return Yqe||(Yqe=1,TVt=function A(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){if(t.constructor!==e.constructor)return!1;var i,r,n;if(Array.isArray(t)){if(i=t.length,i!=e.length)return!1;for(r=i;r--!==0;)if(!A(t[r],e[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===e.source&&t.flags===e.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===e.toString();if(n=Object.keys(t),i=n.length,i!==Object.keys(e).length)return!1;for(r=i;r--!==0;)if(!Object.prototype.hasOwnProperty.call(e,n[r]))return!1;for(r=i;r--!==0;){var s=n[r];if(!A(t[s],e[s]))return!1}return!0}return t!==t&&e!==e}),TVt}var vmi=Smi(),Cat=GKe(vmi);function Dmi(A,t,e={}){if(e=e||{},!Dat(e))throw new Error("options is invalid");var i=e.tolerance||0,r=[],n=uZt();let s=wKe(A);n.load(s);var o;let a=[];return uat(t,function(l){var g=!1;l&&(fv(n.search(l),function(h){if(g===!1){var p=iC(l).sort(),d=iC(h).sort();if(Cat(p,d))g=!0,o?o=UVt(o,l)||o:o=l;else if(i===0?yE(p[0],h)&&yE(p[1],h):JK(h,p[0]).properties.dist<=i&&JK(h,p[1]).properties.dist<=i)g=!0,o?o=UVt(o,l)||o:o=l;else if(i===0?yE(d[0],l)&&yE(d[1],l):JK(l,d[0]).properties.dist<=i&&JK(l,d[1]).properties.dist<=i)if(o){let E=UVt(o,h);E?o=E:a.push(h)}else o=h}}),g===!1&&o&&(r.push(o),a.length&&(r=r.concat(a),a=[]),o=void 0))}),o&&r.push(o),Xl(r)}function UVt(A,t){var e=iC(t),i=iC(A),r=i[0],n=i[i.length-1],s=A.geometry.coordinates;if(Cat(e[0],r))s.unshift(e[1]);else if(Cat(e[0],n))s.push(e[1]);else if(Cat(e[1],r))s.unshift(e[0]);else if(Cat(e[1],n))s.push(e[0]);else return;return A}function FKe(A,t){let e=kQ(A),i=kQ(t),r=e.type,n=i.type;if(r==="MultiPoint"&&n!=="MultiPoint"||(r==="LineString"||r==="MultiLineString")&&n!=="LineString"&&n!=="MultiLineString"||(r==="Polygon"||r==="MultiPolygon")&&n!=="Polygon"&&n!=="MultiPolygon")throw new Error("features must be of the same type");if(r==="Point")throw new Error("Point geometry not supported");if(RKe(A,t,{precision:6}))return!1;let s=0;switch(r){case"MultiPoint":for(var o=0;o<e.coordinates.length;o++)for(var a=0;a<i.coordinates.length;a++){var l=e.coordinates[o],g=i.coordinates[a];if(l[0]===g[0]&&l[1]===g[1])return!0}return!1;case"LineString":case"MultiLineString":uat(A,h=>{uat(t,p=>{Dmi(h,p).features.length&&s++})});break;case"Polygon":case"MultiPolygon":uat(A,h=>{uat(t,p=>{WK(h,p).features.length&&s++})});break}return s>0}function kmi(A,t){var e=kQ(A),i=kQ(t),r=e.type,n=i.type;switch(r){case"Point":switch(n){case"MultiPoint":return Rmi(e,i);case"LineString":return yE(e,i,{ignoreEndVertices:!0});case"Polygon":case"MultiPolygon":return c9(e,i,{ignoreBoundary:!0});default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPoint":switch(n){case"MultiPoint":return Mmi(e,i);case"LineString":return Gmi(e,i);case"Polygon":case"MultiPolygon":return Fmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"LineString":return Nmi(e,i);case"Polygon":case"MultiPolygon":return Tmi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Polygon":case"MultiPolygon":return Umi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}default:throw new Error("feature1 "+r+" geometry not supported")}}function Rmi(A,t){var e,i=!1;for(e=0;e<t.coordinates.length;e++)if(LKe(t.coordinates[e],A.coordinates)){i=!0;break}return i}function Mmi(A,t){for(var e=0;e<A.coordinates.length;e++){for(var i=!1,r=0;r<t.coordinates.length;r++)LKe(A.coordinates[e],t.coordinates[r])&&(i=!0);if(!i)return!1}return!0}function Gmi(A,t){for(var e=!1,i=0;i<A.coordinates.length;i++){if(!yE(A.coordinates[i],t))return!1;e||(e=yE(A.coordinates[i],t,{ignoreEndVertices:!0}))}return e}function Fmi(A,t){for(var e=!0,i=!1,r=0;r<A.coordinates.length;r++){if(i=c9(A.coordinates[r],t),!i){e=!1;break}i=c9(A.coordinates[r],t,{ignoreBoundary:!0})}return e&&i}function Nmi(A,t){for(var e=0;e<A.coordinates.length;e++)if(!yE(A.coordinates[e],t))return!1;return!0}function Lmi(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=$C([e[r],e[r+1]]),s=IZt(n,Xf(t));s.features.length===0?i.push(n):i.push(...s.features)}return Xl(i)}function Tmi(A,t){let e=SI(t),i=SI(A);if(!NKe(e,i))return!1;for(let s of A.coordinates)if(!c9(s,t))return!1;let r=!1,n=Lmi(A,t);for(let s of n.features){let o=Pmi(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!c9(o,t))return!1;!r&&c9(o,t,{ignoreBoundary:!0})&&(r=!0)}return r}function Umi(A,t){var e=SI(A),i=SI(t);if(!NKe(i,e))return!1;for(var r=0;r<A.coordinates[0].length;r++)if(!c9(A.coordinates[0][r],t))return!1;return!0}function NKe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function LKe(A,t){return A[0]===t[0]&&A[1]===t[1]}function Pmi(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function TKe(A,t={}){let e=SI(A),i=(e[0]+e[2])/2,r=(e[1]+e[3])/2;return l9([i,r],t.properties,t)}var tQt={exports:{}},Hmi=tQt.exports,Jqe;function Omi(){return Jqe||(Jqe=1,(function(A,t){(function(e,i){A.exports=i()})(Hmi,(function(){function e(C,c){(c==null||c>C.length)&&(c=C.length);for(var u=0,B=Array(c);u<c;u++)B[u]=C[u];return B}function i(C,c,u){return c=g(c),(function(B,b){if(b&&(typeof b=="object"||typeof b=="function"))return b;if(b!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return(function(T){if(T===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return T})(B)})(C,p()?Reflect.construct(c,u||[],g(C).constructor):c.apply(C,u))}function r(C,c){if(!(C instanceof c))throw new TypeError("Cannot call a class as a function")}function n(C,c,u){if(p())return Reflect.construct.apply(null,arguments);var B=[null];B.push.apply(B,c);var b=new(C.bind.apply(C,B));return u&&d(b,u.prototype),b}function s(C,c){for(var u=0;u<c.length;u++){var B=c[u];B.enumerable=B.enumerable||!1,B.configurable=!0,"value"in B&&(B.writable=!0),Object.defineProperty(C,Q(B.key),B)}}function o(C,c,u){return c&&s(C.prototype,c),u&&s(C,u),Object.defineProperty(C,"prototype",{writable:!1}),C}function a(C,c){var u=typeof Symbol<"u"&&C[Symbol.iterator]||C["@@iterator"];if(!u){if(Array.isArray(C)||(u=y(C))||c){u&&(C=u);var B=0,b=function(){};return{s:b,n:function(){return B>=C.length?{done:!0}:{done:!1,value:C[B++]}},e:function(_t){throw _t},f:b}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
26823
26823
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var T,O=!0,nt=!1;return{s:function(){u=u.call(C)},n:function(){var _t=u.next();return O=_t.done,_t},e:function(_t){nt=!0,T=_t},f:function(){try{O||u.return==null||u.return()}finally{if(nt)throw T}}}}function l(){return l=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(C,c,u){var B=(function(T,O){for(;!{}.hasOwnProperty.call(T,O)&&(T=g(T))!==null;);return T})(C,c);if(B){var b=Object.getOwnPropertyDescriptor(B,c);return b.get?b.get.call(arguments.length<3?C:u):b.value}},l.apply(null,arguments)}function g(C){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(c){return c.__proto__||Object.getPrototypeOf(c)},g(C)}function h(C,c){if(typeof c!="function"&&c!==null)throw new TypeError("Super expression must either be null or a function");C.prototype=Object.create(c&&c.prototype,{constructor:{value:C,writable:!0,configurable:!0}}),Object.defineProperty(C,"prototype",{writable:!1}),c&&d(C,c)}function p(){try{var C=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch{}return(p=function(){return!!C})()}function d(C,c){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(u,B){return u.__proto__=B,u},d(C,c)}function E(C,c,u,B){var b=l(g(1&B?C.prototype:C),c,u);return 2&B&&typeof b=="function"?function(T){return b.apply(u,T)}:b}function f(C){return(function(c){if(Array.isArray(c))return e(c)})(C)||(function(c){if(typeof Symbol<"u"&&c[Symbol.iterator]!=null||c["@@iterator"]!=null)return Array.from(c)})(C)||y(C)||(function(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
26824
26824
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})()}function Q(C){var c=(function(u,B){if(typeof u!="object"||!u)return u;var b=u[Symbol.toPrimitive];if(b!==void 0){var T=b.call(u,B);if(typeof T!="object")return T;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(u)})(C,"string");return typeof c=="symbol"?c:c+""}function y(C,c){if(C){if(typeof C=="string")return e(C,c);var u={}.toString.call(C).slice(8,-1);return u==="Object"&&C.constructor&&(u=C.constructor.name),u==="Map"||u==="Set"?Array.from(C):u==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(u)?e(C,c):void 0}}function S(C){var c=typeof Map=="function"?new Map:void 0;return S=function(u){if(u===null||!(function(b){try{return Function.toString.call(b).indexOf("[native code]")!==-1}catch{return typeof b=="function"}})(u))return u;if(typeof u!="function")throw new TypeError("Super expression must either be null or a function");if(c!==void 0){if(c.has(u))return c.get(u);c.set(u,B)}function B(){return n(u,arguments,g(this).constructor)}return B.prototype=Object.create(u.prototype,{constructor:{value:B,enumerable:!1,writable:!0,configurable:!0}}),d(B,u)},S(C)}var v=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"getEndCapStyle",value:function(){return this._endCapStyle}},{key:"isSingleSided",value:function(){return this._isSingleSided}},{key:"setQuadrantSegments",value:function(c){this._quadrantSegments=c,this._quadrantSegments===0&&(this._joinStyle=C.JOIN_BEVEL),this._quadrantSegments<0&&(this._joinStyle=C.JOIN_MITRE,this._mitreLimit=Math.abs(this._quadrantSegments)),c<=0&&(this._quadrantSegments=1),this._joinStyle!==C.JOIN_ROUND&&(this._quadrantSegments=C.DEFAULT_QUADRANT_SEGMENTS)}},{key:"getJoinStyle",value:function(){return this._joinStyle}},{key:"setJoinStyle",value:function(c){this._joinStyle=c}},{key:"setSimplifyFactor",value:function(c){this._simplifyFactor=c<0?0:c}},{key:"getSimplifyFactor",value:function(){return this._simplifyFactor}},{key:"getQuadrantSegments",value:function(){return this._quadrantSegments}},{key:"setEndCapStyle",value:function(c){this._endCapStyle=c}},{key:"getMitreLimit",value:function(){return this._mitreLimit}},{key:"setMitreLimit",value:function(c){this._mitreLimit=c}},{key:"setSingleSided",value:function(c){this._isSingleSided=c}}],[{key:"constructor_",value:function(){if(this._quadrantSegments=C.DEFAULT_QUADRANT_SEGMENTS,this._endCapStyle=C.CAP_ROUND,this._joinStyle=C.JOIN_ROUND,this._mitreLimit=C.DEFAULT_MITRE_LIMIT,this._isSingleSided=!1,this._simplifyFactor=C.DEFAULT_SIMPLIFY_FACTOR,arguments.length!==0){if(arguments.length===1){var c=arguments[0];this.setQuadrantSegments(c)}else if(arguments.length===2){var u=arguments[0],B=arguments[1];this.setQuadrantSegments(u),this.setEndCapStyle(B)}else if(arguments.length===4){var b=arguments[0],T=arguments[1],O=arguments[2],nt=arguments[3];this.setQuadrantSegments(b),this.setEndCapStyle(T),this.setJoinStyle(O),this.setMitreLimit(nt)}}}},{key:"bufferDistanceError",value:function(c){var u=Math.PI/2/c;return 1-Math.cos(u/2)}}])})();v.CAP_ROUND=1,v.CAP_FLAT=2,v.CAP_SQUARE=3,v.JOIN_ROUND=1,v.JOIN_MITRE=2,v.JOIN_BEVEL=3,v.DEFAULT_QUADRANT_SEGMENTS=8,v.DEFAULT_MITRE_LIMIT=5,v.DEFAULT_SIMPLIFY_FACTOR=.01;var M=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({Exception:c})[0],B}return h(c,C),o(c,[{key:"toString",value:function(){return this.message}}])})(S(Error)),H=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({IllegalArgumentException:c})[0],B}return h(c,C),o(c)})(M),Y=(function(){return o((function C(){r(this,C)}),[{key:"filter",value:function(C){}}])})();function z(){}function F(){}function N(){}var P,K,At,st,it,W,X,rt,gt=(function(){return o((function C(){r(this,C)}),null,[{key:"equalsWithTolerance",value:function(C,c,u){return Math.abs(C-c)<=u}}])})(),ft=(function(){return o((function C(c,u){r(this,C),this.low=u||0,this.high=c||0}),null,[{key:"toBinaryString",value:function(C){var c,u="";for(c=2147483648;c>0;c>>>=1)u+=(C.high&c)===c?"1":"0";for(c=2147483648;c>0;c>>>=1)u+=(C.low&c)===c?"1":"0";return u}}])})();function mt(){}function St(){}mt.NaN=NaN,mt.isNaN=function(C){return Number.isNaN(C)},mt.isInfinite=function(C){return!Number.isFinite(C)},mt.MAX_VALUE=Number.MAX_VALUE,mt.POSITIVE_INFINITY=Number.POSITIVE_INFINITY,mt.NEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,typeof Float64Array=="function"&&typeof Int32Array=="function"?(W=2146435072,X=new Float64Array(1),rt=new Int32Array(X.buffer),mt.doubleToLongBits=function(C){X[0]=C;var c=0|rt[0],u=0|rt[1];return(u&W)===W&&1048575&u&&c!==0&&(c=0,u=2146959360),new ft(u,c)},mt.longBitsToDouble=function(C){return rt[0]=C.low,rt[1]=C.high,X[0]}):(P=1023,K=Math.log2,At=Math.floor,st=Math.pow,it=(function(){for(var C=53;C>0;C--){var c=st(2,C)-1;if(At(K(c))+1===C)return c}return 0})(),mt.doubleToLongBits=function(C){var c,u,B,b,T,O,nt,_t,Lt;if(C<0||1/C===Number.NEGATIVE_INFINITY?(O=1<<31,C=-C):O=0,C===0)return new ft(_t=O,Lt=0);if(C===1/0)return new ft(_t=2146435072|O,Lt=0);if(C!=C)return new ft(_t=2146959360,Lt=0);if(b=0,Lt=0,(c=At(C))>1)if(c<=it)(b=At(K(c)))<=20?(Lt=0,_t=c<<20-b&1048575):(Lt=c%(u=st(2,B=b-20))<<32-B,_t=c/u&1048575);else for(B=c,Lt=0;(B=At(u=B/2))!==0;)b++,Lt>>>=1,Lt|=(1&_t)<<31,_t>>>=1,u!==B&&(_t|=524288);if(nt=b+P,T=c===0,c=C-c,b<52&&c!==0)for(B=0;;){if((u=2*c)>=1?(c=u-1,T?(nt--,T=!1):(B<<=1,B|=1,b++)):(c=u,T?--nt==0&&(b++,T=!1):(B<<=1,b++)),b===20)_t|=B,B=0;else if(b===52){Lt|=B;break}if(u===1){b<20?_t|=B<<20-b:b<52&&(Lt|=B<<52-b);break}}return _t|=nt<<20,new ft(_t|=O,Lt)},mt.longBitsToDouble=function(C){var c,u,B,b,T=C.high,O=C.low,nt=T&1<<31?-1:1;for(B=((2146435072&T)>>20)-P,b=0,u=1<<19,c=1;c<=20;c++)T&u&&(b+=st(2,-c)),u>>>=1;for(u=1<<31,c=21;c<=52;c++)O&u&&(b+=st(2,-c)),u>>>=1;if(B===-1023){if(b===0)return 0*nt;B=-1022}else{if(B===1024)return b===0?nt/0:NaN;b+=1}return nt*b*st(2,B)});var wt=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({RuntimeException:c})[0],B}return h(c,C),o(c)})(M),kt=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,null,[{key:"constructor_",value:function(){if(arguments.length===0)wt.constructor_.call(this);else if(arguments.length===1){var u=arguments[0];wt.constructor_.call(this,u)}}}])})(wt),Dt=(function(){function C(){r(this,C)}return o(C,null,[{key:"shouldNeverReachHere",value:function(){if(arguments.length===0)C.shouldNeverReachHere(null);else if(arguments.length===1){var c=arguments[0];throw new kt("Should never reach here"+(c!==null?": "+c:""))}}},{key:"isTrue",value:function(){if(arguments.length===1){var c=arguments[0];C.isTrue(c,null)}else if(arguments.length===2){var u=arguments[1];if(!arguments[0])throw u===null?new kt:new kt(u)}}},{key:"equals",value:function(){if(arguments.length===2){var c=arguments[0],u=arguments[1];C.equals(c,u,null)}else if(arguments.length===3){var B=arguments[0],b=arguments[1],T=arguments[2];if(!b.equals(B))throw new kt("Expected "+B+" but encountered "+b+(T!==null?": "+T:""))}}}])})(),Pt=new ArrayBuffer(8),ee=new Float64Array(Pt),Ie=new Int32Array(Pt),Tt=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"getM",value:function(){return mt.NaN}},{key:"setOrdinate",value:function(c,u){switch(c){case C.X:this.x=u;break;case C.Y:this.y=u;break;case C.Z:this.setZ(u);break;default:throw new H("Invalid ordinate index: "+c)}}},{key:"equals2D",value:function(){if(arguments.length===1){var c=arguments[0];return this.x===c.x&&this.y===c.y}if(arguments.length===2){var u=arguments[0],B=arguments[1];return!!gt.equalsWithTolerance(this.x,u.x,B)&&!!gt.equalsWithTolerance(this.y,u.y,B)}}},{key:"setM",value:function(c){throw new H("Invalid ordinate index: "+C.M)}},{key:"getZ",value:function(){return this.z}},{key:"getOrdinate",value:function(c){switch(c){case C.X:return this.x;case C.Y:return this.y;case C.Z:return this.getZ()}throw new H("Invalid ordinate index: "+c)}},{key:"equals3D",value:function(c){return this.x===c.x&&this.y===c.y&&(this.getZ()===c.getZ()||mt.isNaN(this.getZ())&&mt.isNaN(c.getZ()))}},{key:"equals",value:function(c){return c instanceof C&&this.equals2D(c)}},{key:"equalInZ",value:function(c,u){return gt.equalsWithTolerance(this.getZ(),c.getZ(),u)}},{key:"setX",value:function(c){this.x=c}},{key:"compareTo",value:function(c){var u=c;return this.x<u.x?-1:this.x>u.x?1:this.y<u.y?-1:this.y>u.y?1:0}},{key:"getX",value:function(){return this.x}},{key:"setZ",value:function(c){this.z=c}},{key:"clone",value:function(){try{return null}catch(c){if(c instanceof CloneNotSupportedException)return Dt.shouldNeverReachHere("this shouldn't happen because this class is Cloneable"),null;throw c}}},{key:"copy",value:function(){return new C(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+")"}},{key:"distance3D",value:function(c){var u=this.x-c.x,B=this.y-c.y,b=this.getZ()-c.getZ();return Math.sqrt(u*u+B*B+b*b)}},{key:"getY",value:function(){return this.y}},{key:"setY",value:function(c){this.y=c}},{key:"distance",value:function(c){var u=this.x-c.x,B=this.y-c.y;return Math.sqrt(u*u+B*B)}},{key:"hashCode",value:function(){var c=17;return c=37*(c=37*c+C.hashCode(this.x))+C.hashCode(this.y)}},{key:"setCoordinate",value:function(c){this.x=c.x,this.y=c.y,this.z=c.getZ()}},{key:"interfaces_",get:function(){return[z,F,N]}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.z=null,arguments.length===0)C.constructor_.call(this,0,0);else if(arguments.length===1){var c=arguments[0];C.constructor_.call(this,c.x,c.y,c.getZ())}else if(arguments.length===2){var u=arguments[0],B=arguments[1];C.constructor_.call(this,u,B,C.NULL_ORDINATE)}else if(arguments.length===3){var b=arguments[0],T=arguments[1],O=arguments[2];this.x=b,this.y=T,this.z=O}}},{key:"hashCode",value:function(c){return ee[0]=c,Ie[0]^Ie[1]}}])})(),$e=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"compare",value:function(c,u){var B=C.compare(c.x,u.x);if(B!==0)return B;var b=C.compare(c.y,u.y);return b!==0?b:this._dimensionsToTest<=2?0:C.compare(c.getZ(),u.getZ())}},{key:"interfaces_",get:function(){return[St]}}],[{key:"constructor_",value:function(){if(this._dimensionsToTest=2,arguments.length===0)C.constructor_.call(this,2);else if(arguments.length===1){var c=arguments[0];if(c!==2&&c!==3)throw new H("only 2 or 3 dimensions may be specified");this._dimensionsToTest=c}}},{key:"compare",value:function(c,u){return c<u?-1:c>u?1:mt.isNaN(c)?mt.isNaN(u)?0:-1:mt.isNaN(u)?1:0}}])})();Tt.DimensionalComparator=$e,Tt.NULL_ORDINATE=mt.NaN,Tt.X=0,Tt.Y=1,Tt.Z=2,Tt.M=3;var Ne=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"getArea",value:function(){return this.getWidth()*this.getHeight()}},{key:"equals",value:function(c){if(!(c instanceof C))return!1;var u=c;return this.isNull()?u.isNull():this._maxx===u.getMaxX()&&this._maxy===u.getMaxY()&&this._minx===u.getMinX()&&this._miny===u.getMinY()}},{key:"intersection",value:function(c){if(this.isNull()||c.isNull()||!this.intersects(c))return new C;var u=this._minx>c._minx?this._minx:c._minx,B=this._miny>c._miny?this._miny:c._miny;return new C(u,this._maxx<c._maxx?this._maxx:c._maxx,B,this._maxy<c._maxy?this._maxy:c._maxy)}},{key:"isNull",value:function(){return this._maxx<this._minx}},{key:"getMaxX",value:function(){return this._maxx}},{key:"covers",value:function(){if(arguments.length===1){if(arguments[0]instanceof Tt){var c=arguments[0];return this.covers(c.x,c.y)}if(arguments[0]instanceof C){var u=arguments[0];return!this.isNull()&&!u.isNull()&&u.getMinX()>=this._minx&&u.getMaxX()<=this._maxx&&u.getMinY()>=this._miny&&u.getMaxY()<=this._maxy}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];return!this.isNull()&&B>=this._minx&&B<=this._maxx&&b>=this._miny&&b<=this._maxy}}},{key:"intersects",value:function(){if(arguments.length===1){if(arguments[0]instanceof C){var c=arguments[0];return!this.isNull()&&!c.isNull()&&!(c._minx>this._maxx||c._maxx<this._minx||c._miny>this._maxy||c._maxy<this._miny)}if(arguments[0]instanceof Tt){var u=arguments[0];return this.intersects(u.x,u.y)}}else if(arguments.length===2){if(arguments[0]instanceof Tt&&arguments[1]instanceof Tt){var B=arguments[0],b=arguments[1];return!this.isNull()&&!((B.x<b.x?B.x:b.x)>this._maxx)&&!((B.x>b.x?B.x:b.x)<this._minx)&&!((B.y<b.y?B.y:b.y)>this._maxy)&&!((B.y>b.y?B.y:b.y)<this._miny)}if(typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var T=arguments[0],O=arguments[1];return!this.isNull()&&!(T>this._maxx||T<this._minx||O>this._maxy||O<this._miny)}}}},{key:"getMinY",value:function(){return this._miny}},{key:"getDiameter",value:function(){if(this.isNull())return 0;var c=this.getWidth(),u=this.getHeight();return Math.sqrt(c*c+u*u)}},{key:"getMinX",value:function(){return this._minx}},{key:"expandToInclude",value:function(){if(arguments.length===1){if(arguments[0]instanceof Tt){var c=arguments[0];this.expandToInclude(c.x,c.y)}else if(arguments[0]instanceof C){var u=arguments[0];if(u.isNull())return null;this.isNull()?(this._minx=u.getMinX(),this._maxx=u.getMaxX(),this._miny=u.getMinY(),this._maxy=u.getMaxY()):(u._minx<this._minx&&(this._minx=u._minx),u._maxx>this._maxx&&(this._maxx=u._maxx),u._miny<this._miny&&(this._miny=u._miny),u._maxy>this._maxy&&(this._maxy=u._maxy))}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];this.isNull()?(this._minx=B,this._maxx=B,this._miny=b,this._maxy=b):(B<this._minx&&(this._minx=B),B>this._maxx&&(this._maxx=B),b<this._miny&&(this._miny=b),b>this._maxy&&(this._maxy=b))}}},{key:"minExtent",value:function(){if(this.isNull())return 0;var c=this.getWidth(),u=this.getHeight();return c<u?c:u}},{key:"getWidth",value:function(){return this.isNull()?0:this._maxx-this._minx}},{key:"compareTo",value:function(c){var u=c;return this.isNull()?u.isNull()?0:-1:u.isNull()?1:this._minx<u._minx?-1:this._minx>u._minx?1:this._miny<u._miny?-1:this._miny>u._miny?1:this._maxx<u._maxx?-1:this._maxx>u._maxx?1:this._maxy<u._maxy?-1:this._maxy>u._maxy?1:0}},{key:"translate",value:function(c,u){if(this.isNull())return null;this.init(this.getMinX()+c,this.getMaxX()+c,this.getMinY()+u,this.getMaxY()+u)}},{key:"copy",value:function(){return new C(this)}},{key:"toString",value:function(){return"Env["+this._minx+" : "+this._maxx+", "+this._miny+" : "+this._maxy+"]"}},{key:"setToNull",value:function(){this._minx=0,this._maxx=-1,this._miny=0,this._maxy=-1}},{key:"disjoint",value:function(c){return!(!this.isNull()&&!c.isNull())||c._minx>this._maxx||c._maxx<this._minx||c._miny>this._maxy||c._maxy<this._miny}},{key:"getHeight",value:function(){return this.isNull()?0:this._maxy-this._miny}},{key:"maxExtent",value:function(){if(this.isNull())return 0;var c=this.getWidth(),u=this.getHeight();return c>u?c:u}},{key:"expandBy",value:function(){if(arguments.length===1){var c=arguments[0];this.expandBy(c,c)}else if(arguments.length===2){var u=arguments[0],B=arguments[1];if(this.isNull())return null;this._minx-=u,this._maxx+=u,this._miny-=B,this._maxy+=B,(this._minx>this._maxx||this._miny>this._maxy)&&this.setToNull()}}},{key:"contains",value:function(){if(arguments.length===1){if(arguments[0]instanceof C){var c=arguments[0];return this.covers(c)}if(arguments[0]instanceof Tt){var u=arguments[0];return this.covers(u)}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];return this.covers(B,b)}}},{key:"centre",value:function(){return this.isNull()?null:new Tt((this.getMinX()+this.getMaxX())/2,(this.getMinY()+this.getMaxY())/2)}},{key:"init",value:function(){if(arguments.length===0)this.setToNull();else if(arguments.length===1){if(arguments[0]instanceof Tt){var c=arguments[0];this.init(c.x,c.x,c.y,c.y)}else if(arguments[0]instanceof C){var u=arguments[0];this._minx=u._minx,this._maxx=u._maxx,this._miny=u._miny,this._maxy=u._maxy}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];this.init(B.x,b.x,B.y,b.y)}else if(arguments.length===4){var T=arguments[0],O=arguments[1],nt=arguments[2],_t=arguments[3];T<O?(this._minx=T,this._maxx=O):(this._minx=O,this._maxx=T),nt<_t?(this._miny=nt,this._maxy=_t):(this._miny=_t,this._maxy=nt)}}},{key:"getMaxY",value:function(){return this._maxy}},{key:"distance",value:function(c){if(this.intersects(c))return 0;var u=0;this._maxx<c._minx?u=c._minx-this._maxx:this._minx>c._maxx&&(u=this._minx-c._maxx);var B=0;return this._maxy<c._miny?B=c._miny-this._maxy:this._miny>c._maxy&&(B=this._miny-c._maxy),u===0?B:B===0?u:Math.sqrt(u*u+B*B)}},{key:"hashCode",value:function(){var c=17;return c=37*(c=37*(c=37*(c=37*c+Tt.hashCode(this._minx))+Tt.hashCode(this._maxx))+Tt.hashCode(this._miny))+Tt.hashCode(this._maxy)}},{key:"interfaces_",get:function(){return[z,N]}}],[{key:"constructor_",value:function(){if(this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,arguments.length===0)this.init();else if(arguments.length===1){if(arguments[0]instanceof Tt){var c=arguments[0];this.init(c.x,c.x,c.y,c.y)}else if(arguments[0]instanceof C){var u=arguments[0];this.init(u)}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];this.init(B.x,b.x,B.y,b.y)}else if(arguments.length===4){var T=arguments[0],O=arguments[1],nt=arguments[2],_t=arguments[3];this.init(T,O,nt,_t)}}},{key:"intersects",value:function(){if(arguments.length===3){var c=arguments[0],u=arguments[1],B=arguments[2];return B.x>=(c.x<u.x?c.x:u.x)&&B.x<=(c.x>u.x?c.x:u.x)&&B.y>=(c.y<u.y?c.y:u.y)&&B.y<=(c.y>u.y?c.y:u.y)}if(arguments.length===4){var b=arguments[0],T=arguments[1],O=arguments[2],nt=arguments[3],_t=Math.min(O.x,nt.x),Lt=Math.max(O.x,nt.x),ge=Math.min(b.x,T.x),Se=Math.max(b.x,T.x);return!(ge>Lt)&&!(Se<_t)&&(_t=Math.min(O.y,nt.y),Lt=Math.max(O.y,nt.y),ge=Math.min(b.y,T.y),Se=Math.max(b.y,T.y),!(ge>Lt)&&!(Se<_t))}}}])})(),be=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"isGeometryCollection",value:function(){return this.getTypeCode()===C.TYPECODE_GEOMETRYCOLLECTION}},{key:"getFactory",value:function(){return this._factory}},{key:"getGeometryN",value:function(c){return this}},{key:"getArea",value:function(){return 0}},{key:"isRectangle",value:function(){return!1}},{key:"equalsExact",value:function(c){return this===c||this.equalsExact(c,0)}},{key:"geometryChanged",value:function(){this.apply(C.geometryChangedFilter)}},{key:"geometryChangedAction",value:function(){this._envelope=null}},{key:"equalsNorm",value:function(c){return c!==null&&this.norm().equalsExact(c.norm())}},{key:"getLength",value:function(){return 0}},{key:"getNumGeometries",value:function(){return 1}},{key:"compareTo",value:function(){var c;if(arguments.length===1){var u=arguments[0];return c=u,this.getTypeCode()!==c.getTypeCode()?this.getTypeCode()-c.getTypeCode():this.isEmpty()&&c.isEmpty()?0:this.isEmpty()?-1:c.isEmpty()?1:this.compareToSameClass(u)}if(arguments.length===2){var B=arguments[0],b=arguments[1];return c=B,this.getTypeCode()!==c.getTypeCode()?this.getTypeCode()-c.getTypeCode():this.isEmpty()&&c.isEmpty()?0:this.isEmpty()?-1:c.isEmpty()?1:this.compareToSameClass(B,b)}}},{key:"getUserData",value:function(){return this._userData}},{key:"getSRID",value:function(){return this._SRID}},{key:"getEnvelope",value:function(){return this.getFactory().toGeometry(this.getEnvelopeInternal())}},{key:"checkNotGeometryCollection",value:function(c){if(c.getTypeCode()===C.TYPECODE_GEOMETRYCOLLECTION)throw new H("This method does not support GeometryCollection arguments")}},{key:"equal",value:function(c,u,B){return B===0?c.equals(u):c.distance(u)<=B}},{key:"norm",value:function(){var c=this.copy();return c.normalize(),c}},{key:"reverse",value:function(){var c=this.reverseInternal();return this.envelope!=null&&(c.envelope=this.envelope.copy()),c.setSRID(this.getSRID()),c}},{key:"copy",value:function(){var c=this.copyInternal();return c.envelope=this._envelope==null?null:this._envelope.copy(),c._SRID=this._SRID,c._userData=this._userData,c}},{key:"getPrecisionModel",value:function(){return this._factory.getPrecisionModel()}},{key:"getEnvelopeInternal",value:function(){return this._envelope===null&&(this._envelope=this.computeEnvelopeInternal()),new Ne(this._envelope)}},{key:"setSRID",value:function(c){this._SRID=c}},{key:"setUserData",value:function(c){this._userData=c}},{key:"compare",value:function(c,u){for(var B=c.iterator(),b=u.iterator();B.hasNext()&&b.hasNext();){var T=B.next(),O=b.next(),nt=T.compareTo(O);if(nt!==0)return nt}return B.hasNext()?1:b.hasNext()?-1:0}},{key:"hashCode",value:function(){return this.getEnvelopeInternal().hashCode()}},{key:"isEquivalentClass",value:function(c){return this.getClass()===c.getClass()}},{key:"isGeometryCollectionOrDerived",value:function(){return this.getTypeCode()===C.TYPECODE_GEOMETRYCOLLECTION||this.getTypeCode()===C.TYPECODE_MULTIPOINT||this.getTypeCode()===C.TYPECODE_MULTILINESTRING||this.getTypeCode()===C.TYPECODE_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[F,z,N]}},{key:"getClass",value:function(){return C}}],[{key:"hasNonEmptyElements",value:function(c){for(var u=0;u<c.length;u++)if(!c[u].isEmpty())return!0;return!1}},{key:"hasNullElements",value:function(c){for(var u=0;u<c.length;u++)if(c[u]===null)return!0;return!1}}])})();be.constructor_=function(C){C&&(this._envelope=null,this._userData=null,this._factory=C,this._SRID=C.getSRID())},be.TYPECODE_POINT=0,be.TYPECODE_MULTIPOINT=1,be.TYPECODE_LINESTRING=2,be.TYPECODE_LINEARRING=3,be.TYPECODE_MULTILINESTRING=4,be.TYPECODE_POLYGON=5,be.TYPECODE_MULTIPOLYGON=6,be.TYPECODE_GEOMETRYCOLLECTION=7,be.TYPENAME_POINT="Point",be.TYPENAME_MULTIPOINT="MultiPoint",be.TYPENAME_LINESTRING="LineString",be.TYPENAME_LINEARRING="LinearRing",be.TYPENAME_MULTILINESTRING="MultiLineString",be.TYPENAME_POLYGON="Polygon",be.TYPENAME_MULTIPOLYGON="MultiPolygon",be.TYPENAME_GEOMETRYCOLLECTION="GeometryCollection",be.geometryChangedFilter={get interfaces_(){return[Y]},filter:function(C){C.geometryChangedAction()}};var xt=(function(){function C(){r(this,C)}return o(C,null,[{key:"toLocationSymbol",value:function(c){switch(c){case C.EXTERIOR:return"e";case C.BOUNDARY:return"b";case C.INTERIOR:return"i";case C.NONE:return"-"}throw new H("Unknown location value: "+c)}}])})();xt.INTERIOR=0,xt.BOUNDARY=1,xt.EXTERIOR=2,xt.NONE=-1;var Ue=(function(){return o((function C(){r(this,C)}),[{key:"add",value:function(){}},{key:"addAll",value:function(){}},{key:"isEmpty",value:function(){}},{key:"iterator",value:function(){}},{key:"size",value:function(){}},{key:"toArray",value:function(){}},{key:"remove",value:function(){}}])})(),OA=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({NoSuchElementException:c})[0],B}return h(c,C),o(c)})(M),_e=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({UnsupportedOperationException:c})[0],B}return h(c,C),o(c)})(M),Ci=(function(C){function c(){return r(this,c),i(this,c,arguments)}return h(c,C),o(c,[{key:"contains",value:function(){}}])})(Ue),_A=(function(C){function c(u){var B;return r(this,c),(B=i(this,c)).map=new Map,u instanceof Ue&&B.addAll(u),B}return h(c,C),o(c,[{key:"contains",value:function(u){var B=u.hashCode?u.hashCode():u;return!!this.map.has(B)}},{key:"add",value:function(u){var B=u.hashCode?u.hashCode():u;return!this.map.has(B)&&!!this.map.set(B,u)}},{key:"addAll",value:function(u){var B,b=a(u);try{for(b.s();!(B=b.n()).done;){var T=B.value;this.add(T)}}catch(O){b.e(O)}finally{b.f()}return!0}},{key:"remove",value:function(){throw new _e}},{key:"size",value:function(){return this.map.size}},{key:"isEmpty",value:function(){return this.map.size===0}},{key:"toArray",value:function(){return Array.from(this.map.values())}},{key:"iterator",value:function(){return new fA(this.map)}},{key:Symbol.iterator,value:function(){return this.map}}])})(Ci),fA=(function(){return o((function C(c){r(this,C),this.iterator=c.values();var u=this.iterator.next(),B=u.done,b=u.value;this.done=B,this.value=b}),[{key:"next",value:function(){if(this.done)throw new OA;var C=this.value,c=this.iterator.next(),u=c.done,B=c.value;return this.done=u,this.value=B,C}},{key:"hasNext",value:function(){return!this.done}},{key:"remove",value:function(){throw new _e}}])})(),Ee=(function(){function C(){r(this,C)}return o(C,null,[{key:"opposite",value:function(c){return c===C.LEFT?C.RIGHT:c===C.RIGHT?C.LEFT:c}}])})();Ee.ON=0,Ee.LEFT=1,Ee.RIGHT=2;var ai=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({EmptyStackException:c})[0],B}return h(c,C),o(c)})(M),ki=(function(C){function c(u){var B;return r(this,c),(B=i(this,c,[u])).name=Object.keys({IndexOutOfBoundsException:c})[0],B}return h(c,C),o(c)})(M),$i=(function(C){function c(){return r(this,c),i(this,c,arguments)}return h(c,C),o(c,[{key:"get",value:function(){}},{key:"set",value:function(){}},{key:"isEmpty",value:function(){}}])})(Ue),pA=(function(C){function c(){var u;return r(this,c),(u=i(this,c)).array=[],u}return h(c,C),o(c,[{key:"add",value:function(u){return this.array.push(u),!0}},{key:"get",value:function(u){if(u<0||u>=this.size())throw new ki;return this.array[u]}},{key:"push",value:function(u){return this.array.push(u),u}},{key:"pop",value:function(){if(this.array.length===0)throw new ai;return this.array.pop()}},{key:"peek",value:function(){if(this.array.length===0)throw new ai;return this.array[this.array.length-1]}},{key:"empty",value:function(){return this.array.length===0}},{key:"isEmpty",value:function(){return this.empty()}},{key:"search",value:function(u){return this.array.indexOf(u)}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}}])})($i);function ye(C,c){return C.interfaces_&&C.interfaces_.indexOf(c)>-1}var ei=(function(){return o((function C(c){r(this,C),this.str=c}),[{key:"append",value:function(C){this.str+=C}},{key:"setCharAt",value:function(C,c){this.str=this.str.substr(0,C)+c+this.str.substr(C+1)}},{key:"toString",value:function(){return this.str}}])})(),zA=(function(){function C(c){r(this,C),this.value=c}return o(C,[{key:"intValue",value:function(){return this.value}},{key:"compareTo",value:function(c){return this.value<c?-1:this.value>c?1:0}}],[{key:"compare",value:function(c,u){return c<u?-1:c>u?1:0}},{key:"isNan",value:function(c){return Number.isNaN(c)}},{key:"valueOf",value:function(c){return new C(c)}}])})(),EA=(function(){return o((function C(){r(this,C)}),null,[{key:"isWhitespace",value:function(C){return C<=32&&C>=0||C===127}},{key:"toUpperCase",value:function(C){return C.toUpperCase()}}])})(),rA=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"le",value:function(c){return this._hi<c._hi||this._hi===c._hi&&this._lo<=c._lo}},{key:"extractSignificantDigits",value:function(c,u){var B=this.abs(),b=C.magnitude(B._hi),T=C.TEN.pow(b);(B=B.divide(T)).gt(C.TEN)?(B=B.divide(C.TEN),b+=1):B.lt(C.ONE)&&(B=B.multiply(C.TEN),b-=1);for(var O=b+1,nt=new ei,_t=C.MAX_PRINT_DIGITS-1,Lt=0;Lt<=_t;Lt++){c&&Lt===O&&nt.append(".");var ge=Math.trunc(B._hi);if(ge<0)break;var Se=!1,hA=0;ge>9?(Se=!0,hA="9"):hA="0"+ge,nt.append(hA),B=B.subtract(C.valueOf(ge)).multiply(C.TEN),Se&&B.selfAdd(C.TEN);var $A=!0,Li=C.magnitude(B._hi);if(Li<0&&Math.abs(Li)>=_t-Lt&&($A=!1),!$A)break}return u[0]=b,nt.toString()}},{key:"sqr",value:function(){return this.multiply(this)}},{key:"doubleValue",value:function(){return this._hi+this._lo}},{key:"subtract",value:function(){if(arguments[0]instanceof C){var c=arguments[0];return this.add(c.negate())}if(typeof arguments[0]=="number"){var u=arguments[0];return this.add(-u)}}},{key:"equals",value:function(){if(arguments.length===1&&arguments[0]instanceof C){var c=arguments[0];return this._hi===c._hi&&this._lo===c._lo}}},{key:"isZero",value:function(){return this._hi===0&&this._lo===0}},{key:"selfSubtract",value:function(){if(arguments[0]instanceof C){var c=arguments[0];return this.isNaN()?this:this.selfAdd(-c._hi,-c._lo)}if(typeof arguments[0]=="number"){var u=arguments[0];return this.isNaN()?this:this.selfAdd(-u,0)}}},{key:"getSpecialNumberString",value:function(){return this.isZero()?"0.0":this.isNaN()?"NaN ":null}},{key:"min",value:function(c){return this.le(c)?this:c}},{key:"selfDivide",value:function(){if(arguments.length===1){if(arguments[0]instanceof C){var c=arguments[0];return this.selfDivide(c._hi,c._lo)}if(typeof arguments[0]=="number"){var u=arguments[0];return this.selfDivide(u,0)}}else if(arguments.length===2){var B,b,T,O,nt=arguments[0],_t=arguments[1],Lt=null,ge=null,Se=null,hA=null;return T=this._hi/nt,hA=(Lt=(Se=C.SPLIT*T)-(Lt=Se-T))*(ge=(hA=C.SPLIT*nt)-(ge=hA-nt))-(O=T*nt)+Lt*(b=nt-ge)+(B=T-Lt)*ge+B*b,hA=T+(Se=(this._hi-O-hA+this._lo-T*_t)/nt),this._hi=hA,this._lo=T-hA+Se,this}}},{key:"dump",value:function(){return"DD<"+this._hi+", "+this._lo+">"}},{key:"divide",value:function(){if(arguments[0]instanceof C){var c,u,B,b,T=arguments[0],O=null,nt=null,_t=null,Lt=null;return c=(B=this._hi/T._hi)-(O=(_t=C.SPLIT*B)-(O=_t-B)),Lt=O*(nt=(Lt=C.SPLIT*T._hi)-(nt=Lt-T._hi))-(b=B*T._hi)+O*(u=T._hi-nt)+c*nt+c*u,new C(Lt=B+(_t=(this._hi-b-Lt+this._lo-B*T._lo)/T._hi),B-Lt+_t)}if(typeof arguments[0]=="number"){var ge=arguments[0];return mt.isNaN(ge)?C.createNaN():C.copy(this).selfDivide(ge,0)}}},{key:"ge",value:function(c){return this._hi>c._hi||this._hi===c._hi&&this._lo>=c._lo}},{key:"pow",value:function(c){if(c===0)return C.valueOf(1);var u=new C(this),B=C.valueOf(1),b=Math.abs(c);if(b>1)for(;b>0;)b%2==1&&B.selfMultiply(u),(b/=2)>0&&(u=u.sqr());else B=u;return c<0?B.reciprocal():B}},{key:"ceil",value:function(){if(this.isNaN())return C.NaN;var c=Math.ceil(this._hi),u=0;return c===this._hi&&(u=Math.ceil(this._lo)),new C(c,u)}},{key:"compareTo",value:function(c){var u=c;return this._hi<u._hi?-1:this._hi>u._hi?1:this._lo<u._lo?-1:this._lo>u._lo?1:0}},{key:"rint",value:function(){return this.isNaN()?this:this.add(.5).floor()}},{key:"setValue",value:function(){if(arguments[0]instanceof C){var c=arguments[0];return this.init(c),this}if(typeof arguments[0]=="number"){var u=arguments[0];return this.init(u),this}}},{key:"max",value:function(c){return this.ge(c)?this:c}},{key:"sqrt",value:function(){if(this.isZero())return C.valueOf(0);if(this.isNegative())return C.NaN;var c=1/Math.sqrt(this._hi),u=this._hi*c,B=C.valueOf(u),b=this.subtract(B.sqr())._hi*(.5*c);return B.add(b)}},{key:"selfAdd",value:function(){if(arguments.length===1){if(arguments[0]instanceof C){var c=arguments[0];return this.selfAdd(c._hi,c._lo)}if(typeof arguments[0]=="number"){var u,B,b,T,O,nt=arguments[0],_t=null;return _t=(b=this._hi+nt)-(T=b-this._hi),B=(O=(_t=nt-T+(this._hi-_t))+this._lo)+(b-(u=b+O)),this._hi=u+B,this._lo=B+(u-this._hi),this}}else if(arguments.length===2){var Lt,ge,Se,hA,$A=arguments[0],Li=arguments[1],Vi=null,Xr=null,Vr=null;Se=this._hi+$A,ge=this._lo+Li,Xr=Se-(Vr=Se-this._hi),Vi=ge-(hA=ge-this._lo);var yn=(Lt=Se+(Vr=(Xr=$A-Vr+(this._hi-Xr))+ge))+(Vr=(Vi=Li-hA+(this._lo-Vi))+(Vr+(Se-Lt))),hs=Vr+(Lt-yn);return this._hi=yn,this._lo=hs,this}}},{key:"selfMultiply",value:function(){if(arguments.length===1){if(arguments[0]instanceof C){var c=arguments[0];return this.selfMultiply(c._hi,c._lo)}if(typeof arguments[0]=="number"){var u=arguments[0];return this.selfMultiply(u,0)}}else if(arguments.length===2){var B,b,T=arguments[0],O=arguments[1],nt=null,_t=null,Lt=null,ge=null;nt=(Lt=C.SPLIT*this._hi)-this._hi,ge=C.SPLIT*T,nt=Lt-nt,B=this._hi-nt,_t=ge-T;var Se=(Lt=this._hi*T)+(ge=nt*(_t=ge-_t)-Lt+nt*(b=T-_t)+B*_t+B*b+(this._hi*O+this._lo*T)),hA=ge+(nt=Lt-Se);return this._hi=Se,this._lo=hA,this}}},{key:"selfSqr",value:function(){return this.selfMultiply(this)}},{key:"floor",value:function(){if(this.isNaN())return C.NaN;var c=Math.floor(this._hi),u=0;return c===this._hi&&(u=Math.floor(this._lo)),new C(c,u)}},{key:"negate",value:function(){return this.isNaN()?this:new C(-this._hi,-this._lo)}},{key:"clone",value:function(){try{return null}catch(c){if(c instanceof CloneNotSupportedException)return null;throw c}}},{key:"multiply",value:function(){if(arguments[0]instanceof C){var c=arguments[0];return c.isNaN()?C.createNaN():C.copy(this).selfMultiply(c)}if(typeof arguments[0]=="number"){var u=arguments[0];return mt.isNaN(u)?C.createNaN():C.copy(this).selfMultiply(u,0)}}},{key:"isNaN",value:function(){return mt.isNaN(this._hi)}},{key:"intValue",value:function(){return Math.trunc(this._hi)}},{key:"toString",value:function(){var c=C.magnitude(this._hi);return c>=-3&&c<=20?this.toStandardNotation():this.toSciNotation()}},{key:"toStandardNotation",value:function(){var c=this.getSpecialNumberString();if(c!==null)return c;var u=new Array(1).fill(null),B=this.extractSignificantDigits(!0,u),b=u[0]+1,T=B;if(B.charAt(0)===".")T="0"+B;else if(b<0)T="0."+C.stringOfChar("0",-b)+B;else if(B.indexOf(".")===-1){var O=b-B.length;T=B+C.stringOfChar("0",O)+".0"}return this.isNegative()?"-"+T:T}},{key:"reciprocal",value:function(){var c,u,B,b,T=null,O=null,nt=null,_t=null;c=(B=1/this._hi)-(T=(nt=C.SPLIT*B)-(T=nt-B)),O=(_t=C.SPLIT*this._hi)-this._hi;var Lt=B+(nt=(1-(b=B*this._hi)-(_t=T*(O=_t-O)-b+T*(u=this._hi-O)+c*O+c*u)-B*this._lo)/this._hi);return new C(Lt,B-Lt+nt)}},{key:"toSciNotation",value:function(){if(this.isZero())return C.SCI_NOT_ZERO;var c=this.getSpecialNumberString();if(c!==null)return c;var u=new Array(1).fill(null),B=this.extractSignificantDigits(!1,u),b=C.SCI_NOT_EXPONENT_CHAR+u[0];if(B.charAt(0)==="0")throw new IllegalStateException("Found leading zero: "+B);var T="";B.length>1&&(T=B.substring(1));var O=B.charAt(0)+"."+T;return this.isNegative()?"-"+O+b:O+b}},{key:"abs",value:function(){return this.isNaN()?C.NaN:this.isNegative()?this.negate():new C(this)}},{key:"isPositive",value:function(){return this._hi>0||this._hi===0&&this._lo>0}},{key:"lt",value:function(c){return this._hi<c._hi||this._hi===c._hi&&this._lo<c._lo}},{key:"add",value:function(){if(arguments[0]instanceof C){var c=arguments[0];return C.copy(this).selfAdd(c)}if(typeof arguments[0]=="number"){var u=arguments[0];return C.copy(this).selfAdd(u)}}},{key:"init",value:function(){if(arguments.length===1){if(typeof arguments[0]=="number"){var c=arguments[0];this._hi=c,this._lo=0}else if(arguments[0]instanceof C){var u=arguments[0];this._hi=u._hi,this._lo=u._lo}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];this._hi=B,this._lo=b}}},{key:"gt",value:function(c){return this._hi>c._hi||this._hi===c._hi&&this._lo>c._lo}},{key:"isNegative",value:function(){return this._hi<0||this._hi===0&&this._lo<0}},{key:"trunc",value:function(){return this.isNaN()?C.NaN:this.isPositive()?this.floor():this.ceil()}},{key:"signum",value:function(){return this._hi>0?1:this._hi<0?-1:this._lo>0?1:this._lo<0?-1:0}},{key:"interfaces_",get:function(){return[N,z,F]}}],[{key:"constructor_",value:function(){if(this._hi=0,this._lo=0,arguments.length===0)this.init(0);else if(arguments.length===1){if(typeof arguments[0]=="number"){var c=arguments[0];this.init(c)}else if(arguments[0]instanceof C){var u=arguments[0];this.init(u)}else if(typeof arguments[0]=="string"){var B=arguments[0];C.constructor_.call(this,C.parse(B))}}else if(arguments.length===2){var b=arguments[0],T=arguments[1];this.init(b,T)}}},{key:"determinant",value:function(){if(typeof arguments[3]=="number"&&typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var c=arguments[0],u=arguments[1],B=arguments[2],b=arguments[3];return C.determinant(C.valueOf(c),C.valueOf(u),C.valueOf(B),C.valueOf(b))}if(arguments[3]instanceof C&&arguments[2]instanceof C&&arguments[0]instanceof C&&arguments[1]instanceof C){var T=arguments[1],O=arguments[2],nt=arguments[3];return arguments[0].multiply(nt).selfSubtract(T.multiply(O))}}},{key:"sqr",value:function(c){return C.valueOf(c).selfMultiply(c)}},{key:"valueOf",value:function(){if(typeof arguments[0]=="string"){var c=arguments[0];return C.parse(c)}if(typeof arguments[0]=="number")return new C(arguments[0])}},{key:"sqrt",value:function(c){return C.valueOf(c).sqrt()}},{key:"parse",value:function(c){for(var u=0,B=c.length;EA.isWhitespace(c.charAt(u));)u++;var b=!1;if(u<B){var T=c.charAt(u);T!=="-"&&T!=="+"||(u++,T==="-"&&(b=!0))}for(var O=new C,nt=0,_t=0,Lt=0,ge=!1;!(u>=B);){var Se=c.charAt(u);if(u++,EA.isDigit(Se)){var hA=Se-"0";O.selfMultiply(C.TEN),O.selfAdd(hA),nt++}else{if(Se!=="."){if(Se==="e"||Se==="E"){var $A=c.substring(u);try{Lt=zA.parseInt($A)}catch(yn){throw yn instanceof NumberFormatException?new NumberFormatException("Invalid exponent "+$A+" in string "+c):yn}break}throw new NumberFormatException("Unexpected character '"+Se+"' at position "+u+" in string "+c)}_t=nt,ge=!0}}var Li=O;ge||(_t=nt);var Vi=nt-_t-Lt;if(Vi===0)Li=O;else if(Vi>0){var Xr=C.TEN.pow(Vi);Li=O.divide(Xr)}else if(Vi<0){var Vr=C.TEN.pow(-Vi);Li=O.multiply(Vr)}return b?Li.negate():Li}},{key:"createNaN",value:function(){return new C(mt.NaN,mt.NaN)}},{key:"copy",value:function(c){return new C(c)}},{key:"magnitude",value:function(c){var u=Math.abs(c),B=Math.log(u)/Math.log(10),b=Math.trunc(Math.floor(B));return 10*Math.pow(10,b)<=u&&(b+=1),b}},{key:"stringOfChar",value:function(c,u){for(var B=new ei,b=0;b<u;b++)B.append(c);return B.toString()}}])})();rA.PI=new rA(3.141592653589793,12246467991473532e-32),rA.TWO_PI=new rA(6.283185307179586,24492935982947064e-32),rA.PI_2=new rA(1.5707963267948966,6123233995736766e-32),rA.E=new rA(2.718281828459045,14456468917292502e-32),rA.NaN=new rA(mt.NaN,mt.NaN),rA.EPS=123259516440783e-46,rA.SPLIT=134217729,rA.MAX_PRINT_DIGITS=32,rA.TEN=rA.valueOf(10),rA.ONE=rA.valueOf(1),rA.SCI_NOT_EXPONENT_CHAR="E",rA.SCI_NOT_ZERO="0.0E0";var oA=(function(){function C(){r(this,C)}return o(C,null,[{key:"orientationIndex",value:function(c,u,B){var b=C.orientationIndexFilter(c,u,B);if(b<=1)return b;var T=rA.valueOf(u.x).selfAdd(-c.x),O=rA.valueOf(u.y).selfAdd(-c.y),nt=rA.valueOf(B.x).selfAdd(-u.x),_t=rA.valueOf(B.y).selfAdd(-u.y);return T.selfMultiply(_t).selfSubtract(O.selfMultiply(nt)).signum()}},{key:"signOfDet2x2",value:function(){if(arguments[3]instanceof rA&&arguments[2]instanceof rA&&arguments[0]instanceof rA&&arguments[1]instanceof rA){var c=arguments[1],u=arguments[2],B=arguments[3];return arguments[0].multiply(B).selfSubtract(c.multiply(u)).signum()}if(typeof arguments[3]=="number"&&typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var b=arguments[0],T=arguments[1],O=arguments[2],nt=arguments[3],_t=rA.valueOf(b),Lt=rA.valueOf(T),ge=rA.valueOf(O),Se=rA.valueOf(nt);return _t.multiply(Se).selfSubtract(Lt.multiply(ge)).signum()}}},{key:"intersection",value:function(c,u,B,b){var T=new rA(c.y).selfSubtract(u.y),O=new rA(u.x).selfSubtract(c.x),nt=new rA(c.x).selfMultiply(u.y).selfSubtract(new rA(u.x).selfMultiply(c.y)),_t=new rA(B.y).selfSubtract(b.y),Lt=new rA(b.x).selfSubtract(B.x),ge=new rA(B.x).selfMultiply(b.y).selfSubtract(new rA(b.x).selfMultiply(B.y)),Se=O.multiply(ge).selfSubtract(Lt.multiply(nt)),hA=_t.multiply(nt).selfSubtract(T.multiply(ge)),$A=T.multiply(Lt).selfSubtract(_t.multiply(O)),Li=Se.selfDivide($A).doubleValue(),Vi=hA.selfDivide($A).doubleValue();return mt.isNaN(Li)||mt.isInfinite(Li)||mt.isNaN(Vi)||mt.isInfinite(Vi)?null:new Tt(Li,Vi)}},{key:"orientationIndexFilter",value:function(c,u,B){var b=null,T=(c.x-B.x)*(u.y-B.y),O=(c.y-B.y)*(u.x-B.x),nt=T-O;if(T>0){if(O<=0)return C.signum(nt);b=T+O}else{if(!(T<0)||O>=0)return C.signum(nt);b=-T-O}var _t=C.DP_SAFE_EPSILON*b;return nt>=_t||-nt>=_t?C.signum(nt):2}},{key:"signum",value:function(c){return c>0?1:c<0?-1:0}}])})();oA.DP_SAFE_EPSILON=1e-15;var re=(function(){return o((function C(){r(this,C)}),[{key:"getM",value:function(C){if(this.hasM()){var c=this.getDimension()-this.getMeasures();return this.getOrdinate(C,c)}return mt.NaN}},{key:"setOrdinate",value:function(C,c,u){}},{key:"getZ",value:function(C){return this.hasZ()?this.getOrdinate(C,2):mt.NaN}},{key:"size",value:function(){}},{key:"getOrdinate",value:function(C,c){}},{key:"getCoordinate",value:function(){}},{key:"getCoordinateCopy",value:function(C){}},{key:"createCoordinate",value:function(){}},{key:"getDimension",value:function(){}},{key:"hasM",value:function(){return this.getMeasures()>0}},{key:"getX",value:function(C){}},{key:"hasZ",value:function(){return this.getDimension()-this.getMeasures()>2}},{key:"getMeasures",value:function(){return 0}},{key:"expandEnvelope",value:function(C){}},{key:"copy",value:function(){}},{key:"getY",value:function(C){}},{key:"toCoordinateArray",value:function(){}},{key:"interfaces_",get:function(){return[F]}}])})();re.X=0,re.Y=1,re.Z=2,re.M=3;var te=(function(){function C(){r(this,C)}return o(C,null,[{key:"index",value:function(c,u,B){return oA.orientationIndex(c,u,B)}},{key:"isCCW",value:function(){if(arguments[0]instanceof Array){var c=arguments[0],u=c.length-1;if(u<3)throw new H("Ring has fewer than 4 points, so orientation cannot be determined");for(var B=c[0],b=0,T=1;T<=u;T++){var O=c[T];O.y>B.y&&(B=O,b=T)}var nt=b;do(nt-=1)<0&&(nt=u);while(c[nt].equals2D(B)&&nt!==b);var _t=b;do _t=(_t+1)%u;while(c[_t].equals2D(B)&&_t!==b);var Lt=c[nt],ge=c[_t];if(Lt.equals2D(B)||ge.equals2D(B)||Lt.equals2D(ge))return!1;var Se=C.index(Lt,B,ge);return Se===0?Lt.x>ge.x:Se>0}if(ye(arguments[0],re)){var hA=arguments[0],$A=hA.size()-1;if($A<3)throw new H("Ring has fewer than 4 points, so orientation cannot be determined");for(var Li=hA.getCoordinate(0),Vi=0,Xr=1;Xr<=$A;Xr++){var Vr=hA.getCoordinate(Xr);Vr.y>Li.y&&(Li=Vr,Vi=Xr)}var yn=null,hs=Vi;do(hs-=1)<0&&(hs=$A),yn=hA.getCoordinate(hs);while(yn.equals2D(Li)&&hs!==Vi);var Ms=null,r0=Vi;do r0=(r0+1)%$A,Ms=hA.getCoordinate(r0);while(Ms.equals2D(Li)&&r0!==Vi);if(yn.equals2D(Li)||Ms.equals2D(Li)||yn.equals2D(Ms))return!1;var wl=C.index(yn,Li,Ms);return wl===0?yn.x>Ms.x:wl>0}}}])})();te.CLOCKWISE=-1,te.RIGHT=te.CLOCKWISE,te.COUNTERCLOCKWISE=1,te.LEFT=te.COUNTERCLOCKWISE,te.COLLINEAR=0,te.STRAIGHT=te.COLLINEAR;var Pe=(function(){return o((function C(){r(this,C),C.constructor_.apply(this,arguments)}),[{key:"getCoordinate",value:function(){return this._minCoord}},{key:"getRightmostSide",value:function(C,c){var u=this.getRightmostSideOfSegment(C,c);return u<0&&(u=this.getRightmostSideOfSegment(C,c-1)),u<0&&(this._minCoord=null,this.checkForRightmostCoordinate(C)),u}},{key:"findRightmostEdgeAtVertex",value:function(){var C=this._minDe.getEdge().getCoordinates();Dt.isTrue(this._minIndex>0&&this._minIndex<C.length,"rightmost point expected to be interior vertex of edge");var c=C[this._minIndex-1],u=C[this._minIndex+1],B=te.index(this._minCoord,u,c),b=!1;(c.y<this._minCoord.y&&u.y<this._minCoord.y&&B===te.COUNTERCLOCKWISE||c.y>this._minCoord.y&&u.y>this._minCoord.y&&B===te.CLOCKWISE)&&(b=!0),b&&(this._minIndex=this._minIndex-1)}},{key:"getRightmostSideOfSegment",value:function(C,c){var u=C.getEdge().getCoordinates();if(c<0||c+1>=u.length||u[c].y===u[c+1].y)return-1;var B=Ee.LEFT;return u[c].y<u[c+1].y&&(B=Ee.RIGHT),B}},{key:"getEdge",value:function(){return this._orientedDe}},{key:"checkForRightmostCoordinate",value:function(C){for(var c=C.getEdge().getCoordinates(),u=0;u<c.length-1;u++)(this._minCoord===null||c[u].x>this._minCoord.x)&&(this._minDe=C,this._minIndex=u,this._minCoord=c[u])}},{key:"findRightmostEdgeAtNode",value:function(){var C=this._minDe.getNode().getEdges();this._minDe=C.getRightmostEdge(),this._minDe.isForward()||(this._minDe=this._minDe.getSym(),this._minIndex=this._minDe.getEdge().getCoordinates().length-1)}},{key:"findEdge",value:function(C){for(var c=C.iterator();c.hasNext();){var u=c.next();u.isForward()&&this.checkForRightmostCoordinate(u)}Dt.isTrue(this._minIndex!==0||this._minCoord.equals(this._minDe.getCoordinate()),"inconsistency in rightmost processing"),this._minIndex===0?this.findRightmostEdgeAtNode():this.findRightmostEdgeAtVertex(),this._orientedDe=this._minDe,this.getRightmostSide(this._minDe,this._minIndex)===Ee.LEFT&&(this._orientedDe=this._minDe.getSym())}}],[{key:"constructor_",value:function(){this._minIndex=-1,this._minCoord=null,this._minDe=null,this._orientedDe=null}}])})(),iA=(function(C){function c(u,B){var b;return r(this,c),(b=i(this,c,[B?u+" [ "+B+" ]":u])).pt=B?new Tt(B):void 0,b.name=Object.keys({TopologyException:c})[0],b}return h(c,C),o(c,[{key:"getCoordinate",value:function(){return this.pt}}])})(wt),QA=(function(){return o((function C(){r(this,C),this.array=[]}),[{key:"addLast",value:function(C){this.array.push(C)}},{key:"removeFirst",value:function(){return this.array.shift()}},{key:"isEmpty",value:function(){return this.array.length===0}}])})(),Xe=(function(C){function c(u){var B;return r(this,c),(B=i(this,c)).array=[],u instanceof Ue&&B.addAll(u),B}return h(c,C),o(c,[{key:"interfaces_",get:function(){return[$i,Ue]}},{key:"ensureCapacity",value:function(){}},{key:"add",value:function(u){return arguments.length===1?this.array.push(u):this.array.splice(arguments[0],0,arguments[1]),!0}},{key:"clear",value:function(){this.array=[]}},{key:"addAll",value:function(u){var B,b=a(u);try{for(b.s();!(B=b.n()).done;){var T=B.value;this.array.push(T)}}catch(O){b.e(O)}finally{b.f()}}},{key:"set",value:function(u,B){var b=this.array[u];return this.array[u]=B,b}},{key:"iterator",value:function(){return new JA(this)}},{key:"get",value:function(u){if(u<0||u>=this.size())throw new ki;return this.array[u]}},{key:"isEmpty",value:function(){return this.array.length===0}},{key:"sort",value:function(u){u?this.array.sort((function(B,b){return u.compare(B,b)})):this.array.sort()}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}},{key:"remove",value:function(u){for(var B=0,b=this.array.length;B<b;B++)if(this.array[B]===u)return!!this.array.splice(B,1);return!1}},{key:Symbol.iterator,value:function(){return this.array.values()}}])})($i),JA=(function(){return o((function C(c){r(this,C),this.arrayList=c,this.position=0}),[{key:"next",value:function(){if(this.position===this.arrayList.size())throw new OA;return this.arrayList.get(this.position++)}},{key:"hasNext",value:function(){return this.position<this.arrayList.size()}},{key:"set",value:function(C){return this.arrayList.set(this.position-1,C)}},{key:"remove",value:function(){this.arrayList.remove(this.arrayList.get(this.position))}}])})(),SA=(function(){return o((function C(){r(this,C),C.constructor_.apply(this,arguments)}),[{key:"clearVisitedEdges",value:function(){for(var C=this._dirEdgeList.iterator();C.hasNext();)C.next().setVisited(!1)}},{key:"getRightmostCoordinate",value:function(){return this._rightMostCoord}},{key:"computeNodeDepth",value:function(C){for(var c=null,u=C.getEdges().iterator();u.hasNext();){var B=u.next();if(B.isVisited()||B.getSym().isVisited()){c=B;break}}if(c===null)throw new iA("unable to find edge to compute depths at "+C.getCoordinate());C.getEdges().computeDepths(c);for(var b=C.getEdges().iterator();b.hasNext();){var T=b.next();T.setVisited(!0),this.copySymDepths(T)}}},{key:"computeDepth",value:function(C){this.clearVisitedEdges();var c=this._finder.getEdge();c.getNode(),c.getLabel(),c.setEdgeDepths(Ee.RIGHT,C),this.copySymDepths(c),this.computeDepths(c)}},{key:"create",value:function(C){this.addReachable(C),this._finder.findEdge(this._dirEdgeList),this._rightMostCoord=this._finder.getCoordinate()}},{key:"findResultEdges",value:function(){for(var C=this._dirEdgeList.iterator();C.hasNext();){var c=C.next();c.getDepth(Ee.RIGHT)>=1&&c.getDepth(Ee.LEFT)<=0&&!c.isInteriorAreaEdge()&&c.setInResult(!0)}}},{key:"computeDepths",value:function(C){var c=new _A,u=new QA,B=C.getNode();for(u.addLast(B),c.add(B),C.setVisited(!0);!u.isEmpty();){var b=u.removeFirst();c.add(b),this.computeNodeDepth(b);for(var T=b.getEdges().iterator();T.hasNext();){var O=T.next().getSym();if(!O.isVisited()){var nt=O.getNode();c.contains(nt)||(u.addLast(nt),c.add(nt))}}}}},{key:"compareTo",value:function(C){var c=C;return this._rightMostCoord.x<c._rightMostCoord.x?-1:this._rightMostCoord.x>c._rightMostCoord.x?1:0}},{key:"getEnvelope",value:function(){if(this._env===null){for(var C=new Ne,c=this._dirEdgeList.iterator();c.hasNext();)for(var u=c.next().getEdge().getCoordinates(),B=0;B<u.length-1;B++)C.expandToInclude(u[B]);this._env=C}return this._env}},{key:"addReachable",value:function(C){var c=new pA;for(c.add(C);!c.empty();){var u=c.pop();this.add(u,c)}}},{key:"copySymDepths",value:function(C){var c=C.getSym();c.setDepth(Ee.LEFT,C.getDepth(Ee.RIGHT)),c.setDepth(Ee.RIGHT,C.getDepth(Ee.LEFT))}},{key:"add",value:function(C,c){C.setVisited(!0),this._nodes.add(C);for(var u=C.getEdges().iterator();u.hasNext();){var B=u.next();this._dirEdgeList.add(B);var b=B.getSym().getNode();b.isVisited()||c.push(b)}}},{key:"getNodes",value:function(){return this._nodes}},{key:"getDirectedEdges",value:function(){return this._dirEdgeList}},{key:"interfaces_",get:function(){return[z]}}],[{key:"constructor_",value:function(){this._finder=null,this._dirEdgeList=new Xe,this._nodes=new Xe,this._rightMostCoord=null,this._env=null,this._finder=new Pe}}])})(),ci=(function(){return o((function C(){r(this,C)}),null,[{key:"intersection",value:function(C,c,u,B){var b=C.x<c.x?C.x:c.x,T=C.y<c.y?C.y:c.y,O=C.x>c.x?C.x:c.x,nt=C.y>c.y?C.y:c.y,_t=u.x<B.x?u.x:B.x,Lt=u.y<B.y?u.y:B.y,ge=u.x>B.x?u.x:B.x,Se=u.y>B.y?u.y:B.y,hA=((b>_t?b:_t)+(O<ge?O:ge))/2,$A=((T>Lt?T:Lt)+(nt<Se?nt:Se))/2,Li=C.x-hA,Vi=C.y-$A,Xr=c.x-hA,Vr=c.y-$A,yn=u.x-hA,hs=u.y-$A,Ms=B.x-hA,r0=B.y-$A,wl=Vi-Vr,Ec=Xr-Li,sh=Li*Vr-Xr*Vi,oh=hs-r0,_g=Ms-yn,ah=yn*r0-Ms*hs,wh=wl*_g-oh*Ec,wo=(Ec*ah-_g*sh)/wh,zs=(oh*sh-wl*ah)/wh;return mt.isNaN(wo)||mt.isInfinite(wo)||mt.isNaN(zs)||mt.isInfinite(zs)?null:new Tt(wo+hA,zs+$A)}}])})(),dA=(function(){return o((function C(){r(this,C)}),null,[{key:"arraycopy",value:function(C,c,u,B,b){for(var T=0,O=c;O<c+b;O++)u[B+T]=C[O],T++}},{key:"getProperty",value:function(C){return{"line.separator":`
|
|
26825
26825
|
`}[C]}}])})(),jA=(function(){function C(){r(this,C)}return o(C,null,[{key:"log10",value:function(c){var u=Math.log(c);return mt.isInfinite(u)||mt.isNaN(u)?u:u/C.LOG_10}},{key:"min",value:function(c,u,B,b){var T=c;return u<T&&(T=u),B<T&&(T=B),b<T&&(T=b),T}},{key:"clamp",value:function(){if(typeof arguments[2]=="number"&&typeof arguments[0]=="number"&&typeof arguments[1]=="number"){var c=arguments[0],u=arguments[1],B=arguments[2];return c<u?u:c>B?B:c}if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var b=arguments[0],T=arguments[1],O=arguments[2];return b<T?T:b>O?O:b}}},{key:"wrap",value:function(c,u){return c<0?u- -c%u:c%u}},{key:"max",value:function(){if(arguments.length===3){var c=arguments[1],u=arguments[2],B=arguments[0];return c>B&&(B=c),u>B&&(B=u),B}if(arguments.length===4){var b=arguments[1],T=arguments[2],O=arguments[3],nt=arguments[0];return b>nt&&(nt=b),T>nt&&(nt=T),O>nt&&(nt=O),nt}}},{key:"average",value:function(c,u){return(c+u)/2}}])})();jA.LOG_10=Math.log(10);var BA=(function(){function C(){r(this,C)}return o(C,null,[{key:"segmentToSegment",value:function(c,u,B,b){if(c.equals(u))return C.pointToSegment(c,B,b);if(B.equals(b))return C.pointToSegment(b,c,u);var T=!1;if(Ne.intersects(c,u,B,b)){var O=(u.x-c.x)*(b.y-B.y)-(u.y-c.y)*(b.x-B.x);if(O===0)T=!0;else{var nt=(c.y-B.y)*(b.x-B.x)-(c.x-B.x)*(b.y-B.y),_t=((c.y-B.y)*(u.x-c.x)-(c.x-B.x)*(u.y-c.y))/O,Lt=nt/O;(Lt<0||Lt>1||_t<0||_t>1)&&(T=!0)}}else T=!0;return T?jA.min(C.pointToSegment(c,B,b),C.pointToSegment(u,B,b),C.pointToSegment(B,c,u),C.pointToSegment(b,c,u)):0}},{key:"pointToSegment",value:function(c,u,B){if(u.x===B.x&&u.y===B.y)return c.distance(u);var b=(B.x-u.x)*(B.x-u.x)+(B.y-u.y)*(B.y-u.y),T=((c.x-u.x)*(B.x-u.x)+(c.y-u.y)*(B.y-u.y))/b;if(T<=0)return c.distance(u);if(T>=1)return c.distance(B);var O=((u.y-c.y)*(B.x-u.x)-(u.x-c.x)*(B.y-u.y))/b;return Math.abs(O)*Math.sqrt(b)}},{key:"pointToLinePerpendicular",value:function(c,u,B){var b=(B.x-u.x)*(B.x-u.x)+(B.y-u.y)*(B.y-u.y),T=((u.y-c.y)*(B.x-u.x)-(u.x-c.x)*(B.y-u.y))/b;return Math.abs(T)*Math.sqrt(b)}},{key:"pointToSegmentString",value:function(c,u){if(u.length===0)throw new H("Line array must contain at least one vertex");for(var B=c.distance(u[0]),b=0;b<u.length-1;b++){var T=C.pointToSegment(c,u[b],u[b+1]);T<B&&(B=T)}return B}}])})(),Xi=(function(){return o((function C(){r(this,C)}),[{key:"create",value:function(){if(arguments.length===1)arguments[0]instanceof Array||ye(arguments[0],re);else if(arguments.length!==2){if(arguments.length===3){var C=arguments[0],c=arguments[1];return this.create(C,c)}}}}])})(),Gi=(function(){return o((function C(){r(this,C)}),[{key:"filter",value:function(C){}}])})(),Fi=(function(){return o((function C(){r(this,C)}),null,[{key:"ofLine",value:function(C){var c=C.size();if(c<=1)return 0;var u=0,B=new Tt;C.getCoordinate(0,B);for(var b=B.x,T=B.y,O=1;O<c;O++){C.getCoordinate(O,B);var nt=B.x,_t=B.y,Lt=nt-b,ge=_t-T;u+=Math.sqrt(Lt*Lt+ge*ge),b=nt,T=_t}return u}}])})(),Ir=o((function C(){r(this,C)})),Ii=(function(){function C(){r(this,C)}return o(C,null,[{key:"copyCoord",value:function(c,u,B,b){for(var T=Math.min(c.getDimension(),B.getDimension()),O=0;O<T;O++)B.setOrdinate(b,O,c.getOrdinate(u,O))}},{key:"isRing",value:function(c){var u=c.size();return u===0||!(u<=3)&&c.getOrdinate(0,re.X)===c.getOrdinate(u-1,re.X)&&c.getOrdinate(0,re.Y)===c.getOrdinate(u-1,re.Y)}},{key:"scroll",value:function(){if(arguments.length===2){if(ye(arguments[0],re)&&Number.isInteger(arguments[1])){var c=arguments[0],u=arguments[1];C.scroll(c,u,C.isRing(c))}else if(ye(arguments[0],re)&&arguments[1]instanceof Tt){var B=arguments[0],b=arguments[1],T=C.indexOf(b,B);if(T<=0)return null;C.scroll(B,T)}}else if(arguments.length===3){var O=arguments[0],nt=arguments[1],_t=arguments[2];if(nt<=0)return null;for(var Lt=O.copy(),ge=_t?O.size()-1:O.size(),Se=0;Se<ge;Se++)for(var hA=0;hA<O.getDimension();hA++)O.setOrdinate(Se,hA,Lt.getOrdinate((nt+Se)%ge,hA));if(_t)for(var $A=0;$A<O.getDimension();$A++)O.setOrdinate(ge,$A,O.getOrdinate(0,$A))}}},{key:"isEqual",value:function(c,u){var B=c.size();if(B!==u.size())return!1;for(var b=Math.min(c.getDimension(),u.getDimension()),T=0;T<B;T++)for(var O=0;O<b;O++){var nt=c.getOrdinate(T,O),_t=u.getOrdinate(T,O);if(c.getOrdinate(T,O)!==u.getOrdinate(T,O)&&(!mt.isNaN(nt)||!mt.isNaN(_t)))return!1}return!0}},{key:"minCoordinateIndex",value:function(){if(arguments.length===1){var c=arguments[0];return C.minCoordinateIndex(c,0,c.size()-1)}if(arguments.length===3){for(var u=arguments[0],B=arguments[2],b=-1,T=null,O=arguments[1];O<=B;O++){var nt=u.getCoordinate(O);(T===null||T.compareTo(nt)>0)&&(T=nt,b=O)}return b}}},{key:"extend",value:function(c,u,B){var b=c.create(B,u.getDimension()),T=u.size();if(C.copy(u,0,b,0,T),T>0)for(var O=T;O<B;O++)C.copy(u,T-1,b,O,1);return b}},{key:"reverse",value:function(c){for(var u=c.size()-1,B=Math.trunc(u/2),b=0;b<=B;b++)C.swap(c,b,u-b)}},{key:"swap",value:function(c,u,B){if(u===B)return null;for(var b=0;b<c.getDimension();b++){var T=c.getOrdinate(u,b);c.setOrdinate(u,b,c.getOrdinate(B,b)),c.setOrdinate(B,b,T)}}},{key:"copy",value:function(c,u,B,b,T){for(var O=0;O<T;O++)C.copyCoord(c,u+O,B,b+O)}},{key:"ensureValidRing",value:function(c,u){var B=u.size();return B===0?u:B<=3?C.createClosedRing(c,u,4):u.getOrdinate(0,re.X)===u.getOrdinate(B-1,re.X)&&u.getOrdinate(0,re.Y)===u.getOrdinate(B-1,re.Y)?u:C.createClosedRing(c,u,B+1)}},{key:"indexOf",value:function(c,u){for(var B=0;B<u.size();B++)if(c.x===u.getOrdinate(B,re.X)&&c.y===u.getOrdinate(B,re.Y))return B;return-1}},{key:"createClosedRing",value:function(c,u,B){var b=c.create(B,u.getDimension()),T=u.size();C.copy(u,0,b,0,T);for(var O=T;O<B;O++)C.copy(u,0,b,O,1);return b}},{key:"minCoordinate",value:function(c){for(var u=null,B=0;B<c.size();B++){var b=c.getCoordinate(B);(u===null||u.compareTo(b)>0)&&(u=b)}return u}}])})(),cA=(function(){function C(){r(this,C)}return o(C,null,[{key:"toDimensionSymbol",value:function(c){switch(c){case C.FALSE:return C.SYM_FALSE;case C.TRUE:return C.SYM_TRUE;case C.DONTCARE:return C.SYM_DONTCARE;case C.P:return C.SYM_P;case C.L:return C.SYM_L;case C.A:return C.SYM_A}throw new H("Unknown dimension value: "+c)}},{key:"toDimensionValue",value:function(c){switch(EA.toUpperCase(c)){case C.SYM_FALSE:return C.FALSE;case C.SYM_TRUE:return C.TRUE;case C.SYM_DONTCARE:return C.DONTCARE;case C.SYM_P:return C.P;case C.SYM_L:return C.L;case C.SYM_A:return C.A}throw new H("Unknown dimension symbol: "+c)}}])})();cA.P=0,cA.L=1,cA.A=2,cA.FALSE=-1,cA.TRUE=-2,cA.DONTCARE=-3,cA.SYM_FALSE="F",cA.SYM_TRUE="T",cA.SYM_DONTCARE="*",cA.SYM_P="0",cA.SYM_L="1",cA.SYM_A="2";var Ni=(function(){return o((function C(){r(this,C)}),[{key:"filter",value:function(C){}}])})(),FA=(function(){return o((function C(){r(this,C)}),[{key:"filter",value:function(C,c){}},{key:"isDone",value:function(){}},{key:"isGeometryChanged",value:function(){}}])})(),bi=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"computeEnvelopeInternal",value:function(){return this.isEmpty()?new Ne:this._points.expandEnvelope(new Ne)}},{key:"isRing",value:function(){return this.isClosed()&&this.isSimple()}},{key:"getCoordinates",value:function(){return this._points.toCoordinateArray()}},{key:"copyInternal",value:function(){return new c(this._points.copy(),this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];if(!this.isEquivalentClass(u))return!1;var b=u;if(this._points.size()!==b._points.size())return!1;for(var T=0;T<this._points.size();T++)if(!this.equal(this._points.getCoordinate(T),b._points.getCoordinate(T),B))return!1;return!0}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var u=0;u<Math.trunc(this._points.size()/2);u++){var B=this._points.size()-1-u;if(!this._points.getCoordinate(u).equals(this._points.getCoordinate(B))){if(this._points.getCoordinate(u).compareTo(this._points.getCoordinate(B))>0){var b=this._points.copy();Ii.reverse(b),this._points=b}return null}}}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._points.getCoordinate(0)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?cA.FALSE:0}},{key:"isClosed",value:function(){return!this.isEmpty()&&this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints()-1))}},{key:"reverseInternal",value:function(){var u=this._points.copy();return Ii.reverse(u),this.getFactory().createLineString(u)}},{key:"getEndPoint",value:function(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}},{key:"getTypeCode",value:function(){return be.TYPECODE_LINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getLength",value:function(){return Fi.ofLine(this._points)}},{key:"getNumPoints",value:function(){return this._points.size()}},{key:"compareToSameClass",value:function(){if(arguments.length===1){for(var u=arguments[0],B=0,b=0;B<this._points.size()&&b<u._points.size();){var T=this._points.getCoordinate(B).compareTo(u._points.getCoordinate(b));if(T!==0)return T;B++,b++}return B<this._points.size()?1:b<u._points.size()?-1:0}if(arguments.length===2){var O=arguments[0];return arguments[1].compare(this._points,O._points)}}},{key:"apply",value:function(){if(ye(arguments[0],Gi))for(var u=arguments[0],B=0;B<this._points.size();B++)u.filter(this._points.getCoordinate(B));else if(ye(arguments[0],FA)){var b=arguments[0];if(this._points.size()===0)return null;for(var T=0;T<this._points.size()&&(b.filter(this._points,T),!b.isDone());T++);b.isGeometryChanged()&&this.geometryChanged()}else ye(arguments[0],Ni)?arguments[0].filter(this):ye(arguments[0],Y)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){throw new _e}},{key:"isEquivalentClass",value:function(u){return u instanceof c}},{key:"getCoordinateN",value:function(u){return this._points.getCoordinate(u)}},{key:"getGeometryType",value:function(){return be.TYPENAME_LINESTRING}},{key:"getCoordinateSequence",value:function(){return this._points}},{key:"isEmpty",value:function(){return this._points.size()===0}},{key:"init",value:function(u){if(u===null&&(u=this.getFactory().getCoordinateSequenceFactory().create([])),u.size()===1)throw new H("Invalid number of points in LineString (found "+u.size()+" - must be 0 or >= 2)");this._points=u}},{key:"isCoordinate",value:function(u){for(var B=0;B<this._points.size();B++)if(this._points.getCoordinate(B).equals(u))return!0;return!1}},{key:"getStartPoint",value:function(){return this.isEmpty()?null:this.getPointN(0)}},{key:"getPointN",value:function(u){return this.getFactory().createPoint(this._points.getCoordinate(u))}},{key:"interfaces_",get:function(){return[Ir]}}],[{key:"constructor_",value:function(){if(this._points=null,arguments.length!==0){if(arguments.length===2){var u=arguments[0],B=arguments[1];be.constructor_.call(this,B),this.init(u)}}}}])})(be),tr=o((function C(){r(this,C)})),uA=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"computeEnvelopeInternal",value:function(){if(this.isEmpty())return new Ne;var u=new Ne;return u.expandToInclude(this._coordinates.getX(0),this._coordinates.getY(0)),u}},{key:"getCoordinates",value:function(){return this.isEmpty()?[]:[this.getCoordinate()]}},{key:"copyInternal",value:function(){return new c(this._coordinates.copy(),this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];return!!this.isEquivalentClass(u)&&(!(!this.isEmpty()||!u.isEmpty())||this.isEmpty()===u.isEmpty()&&this.equal(u.getCoordinate(),this.getCoordinate(),B))}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){}},{key:"getCoordinate",value:function(){return this._coordinates.size()!==0?this._coordinates.getCoordinate(0):null}},{key:"getBoundaryDimension",value:function(){return cA.FALSE}},{key:"reverseInternal",value:function(){return this.getFactory().createPoint(this._coordinates.copy())}},{key:"getTypeCode",value:function(){return be.TYPECODE_POINT}},{key:"getDimension",value:function(){return 0}},{key:"getNumPoints",value:function(){return this.isEmpty()?0:1}},{key:"getX",value:function(){if(this.getCoordinate()===null)throw new IllegalStateException("getX called on empty Point");return this.getCoordinate().x}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var u=arguments[0];return this.getCoordinate().compareTo(u.getCoordinate())}if(arguments.length===2){var B=arguments[0];return arguments[1].compare(this._coordinates,B._coordinates)}}},{key:"apply",value:function(){if(ye(arguments[0],Gi)){var u=arguments[0];if(this.isEmpty())return null;u.filter(this.getCoordinate())}else if(ye(arguments[0],FA)){var B=arguments[0];if(this.isEmpty())return null;B.filter(this._coordinates,0),B.isGeometryChanged()&&this.geometryChanged()}else ye(arguments[0],Ni)?arguments[0].filter(this):ye(arguments[0],Y)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return be.TYPENAME_POINT}},{key:"getCoordinateSequence",value:function(){return this._coordinates}},{key:"getY",value:function(){if(this.getCoordinate()===null)throw new IllegalStateException("getY called on empty Point");return this.getCoordinate().y}},{key:"isEmpty",value:function(){return this._coordinates.size()===0}},{key:"init",value:function(u){u===null&&(u=this.getFactory().getCoordinateSequenceFactory().create([])),Dt.isTrue(u.size()<=1),this._coordinates=u}},{key:"isSimple",value:function(){return!0}},{key:"interfaces_",get:function(){return[tr]}}],[{key:"constructor_",value:function(){this._coordinates=null;var u=arguments[0],B=arguments[1];be.constructor_.call(this,B),this.init(u)}}])})(be),me=(function(){function C(){r(this,C)}return o(C,null,[{key:"ofRing",value:function(){if(arguments[0]instanceof Array){var c=arguments[0];return Math.abs(C.ofRingSigned(c))}if(ye(arguments[0],re)){var u=arguments[0];return Math.abs(C.ofRingSigned(u))}}},{key:"ofRingSigned",value:function(){if(arguments[0]instanceof Array){var c=arguments[0];if(c.length<3)return 0;for(var u=0,B=c[0].x,b=1;b<c.length-1;b++){var T=c[b].x-B,O=c[b+1].y;u+=T*(c[b-1].y-O)}return u/2}if(ye(arguments[0],re)){var nt=arguments[0],_t=nt.size();if(_t<3)return 0;var Lt=new Tt,ge=new Tt,Se=new Tt;nt.getCoordinate(0,ge),nt.getCoordinate(1,Se);var hA=ge.x;Se.x-=hA;for(var $A=0,Li=1;Li<_t-1;Li++)Lt.y=ge.y,ge.x=Se.x,ge.y=Se.y,nt.getCoordinate(Li+1,Se),Se.x-=hA,$A+=ge.x*(Lt.y-Se.y);return $A/2}}}])})(),Ke=(function(){return o((function C(){r(this,C)}),null,[{key:"sort",value:function(){var C=arguments,c=arguments[0];if(arguments.length===1)c.sort((function(hA,$A){return hA.compareTo($A)}));else if(arguments.length===2)c.sort((function(hA,$A){return C[1].compare(hA,$A)}));else if(arguments.length===3){var u=c.slice(arguments[1],arguments[2]);u.sort();var B=c.slice(0,arguments[1]).concat(u,c.slice(arguments[2],c.length));c.splice(0,c.length);var b,T=a(B);try{for(T.s();!(b=T.n()).done;){var O=b.value;c.push(O)}}catch(hA){T.e(hA)}finally{T.f()}}else if(arguments.length===4){var nt=c.slice(arguments[1],arguments[2]);nt.sort((function(hA,$A){return C[3].compare(hA,$A)}));var _t=c.slice(0,arguments[1]).concat(nt,c.slice(arguments[2],c.length));c.splice(0,c.length);var Lt,ge=a(_t);try{for(ge.s();!(Lt=ge.n()).done;){var Se=Lt.value;c.push(Se)}}catch(hA){ge.e(hA)}finally{ge.f()}}}},{key:"asList",value:function(C){var c,u=new Xe,B=a(C);try{for(B.s();!(c=B.n()).done;){var b=c.value;u.add(b)}}catch(T){B.e(T)}finally{B.f()}return u}},{key:"copyOf",value:function(C,c){return C.slice(0,c)}}])})(),wA=o((function C(){r(this,C)})),ve=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"computeEnvelopeInternal",value:function(){return this._shell.getEnvelopeInternal()}},{key:"getCoordinates",value:function(){if(this.isEmpty())return[];for(var u=new Array(this.getNumPoints()).fill(null),B=-1,b=this._shell.getCoordinates(),T=0;T<b.length;T++)u[++B]=b[T];for(var O=0;O<this._holes.length;O++)for(var nt=this._holes[O].getCoordinates(),_t=0;_t<nt.length;_t++)u[++B]=nt[_t];return u}},{key:"getArea",value:function(){var u=0;u+=me.ofRing(this._shell.getCoordinateSequence());for(var B=0;B<this._holes.length;B++)u-=me.ofRing(this._holes[B].getCoordinateSequence());return u}},{key:"copyInternal",value:function(){for(var u=this._shell.copy(),B=new Array(this._holes.length).fill(null),b=0;b<this._holes.length;b++)B[b]=this._holes[b].copy();return new c(u,B,this._factory)}},{key:"isRectangle",value:function(){if(this.getNumInteriorRing()!==0||this._shell===null||this._shell.getNumPoints()!==5)return!1;for(var u=this._shell.getCoordinateSequence(),B=this.getEnvelopeInternal(),b=0;b<5;b++){var T=u.getX(b);if(T!==B.getMinX()&&T!==B.getMaxX())return!1;var O=u.getY(b);if(O!==B.getMinY()&&O!==B.getMaxY())return!1}for(var nt=u.getX(0),_t=u.getY(0),Lt=1;Lt<=4;Lt++){var ge=u.getX(Lt),Se=u.getY(Lt);if(ge!==nt==(Se!==_t))return!1;nt=ge,_t=Se}return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];if(!this.isEquivalentClass(u))return!1;var b=u,T=this._shell,O=b._shell;if(!T.equalsExact(O,B)||this._holes.length!==b._holes.length)return!1;for(var nt=0;nt<this._holes.length;nt++)if(!this._holes[nt].equalsExact(b._holes[nt],B))return!1;return!0}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){if(arguments.length===0){this._shell=this.normalized(this._shell,!0);for(var u=0;u<this._holes.length;u++)this._holes[u]=this.normalized(this._holes[u],!1);Ke.sort(this._holes)}else if(arguments.length===2){var B=arguments[0],b=arguments[1];if(B.isEmpty())return null;var T=B.getCoordinateSequence(),O=Ii.minCoordinateIndex(T,0,T.size()-2);Ii.scroll(T,O,!0),te.isCCW(T)===b&&Ii.reverse(T)}}},{key:"getCoordinate",value:function(){return this._shell.getCoordinate()}},{key:"getNumInteriorRing",value:function(){return this._holes.length}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"reverseInternal",value:function(){for(var u=this.getExteriorRing().reverse(),B=new Array(this.getNumInteriorRing()).fill(null),b=0;b<B.length;b++)B[b]=this.getInteriorRingN(b).reverse();return this.getFactory().createPolygon(u,B)}},{key:"getTypeCode",value:function(){return be.TYPECODE_POLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getLength",value:function(){var u=0;u+=this._shell.getLength();for(var B=0;B<this._holes.length;B++)u+=this._holes[B].getLength();return u}},{key:"getNumPoints",value:function(){for(var u=this._shell.getNumPoints(),B=0;B<this._holes.length;B++)u+=this._holes[B].getNumPoints();return u}},{key:"convexHull",value:function(){return this.getExteriorRing().convexHull()}},{key:"normalized",value:function(u,B){var b=u.copy();return this.normalize(b,B),b}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var u=arguments[0],B=this._shell,b=u._shell;return B.compareToSameClass(b)}if(arguments.length===2){var T=arguments[1],O=arguments[0],nt=this._shell,_t=O._shell,Lt=nt.compareToSameClass(_t,T);if(Lt!==0)return Lt;for(var ge=this.getNumInteriorRing(),Se=O.getNumInteriorRing(),hA=0;hA<ge&&hA<Se;){var $A=this.getInteriorRingN(hA),Li=O.getInteriorRingN(hA),Vi=$A.compareToSameClass(Li,T);if(Vi!==0)return Vi;hA++}return hA<ge?1:hA<Se?-1:0}}},{key:"apply",value:function(){if(ye(arguments[0],Gi)){var u=arguments[0];this._shell.apply(u);for(var B=0;B<this._holes.length;B++)this._holes[B].apply(u)}else if(ye(arguments[0],FA)){var b=arguments[0];if(this._shell.apply(b),!b.isDone())for(var T=0;T<this._holes.length&&(this._holes[T].apply(b),!b.isDone());T++);b.isGeometryChanged()&&this.geometryChanged()}else if(ye(arguments[0],Ni))arguments[0].filter(this);else if(ye(arguments[0],Y)){var O=arguments[0];O.filter(this),this._shell.apply(O);for(var nt=0;nt<this._holes.length;nt++)this._holes[nt].apply(O)}}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();var u=new Array(this._holes.length+1).fill(null);u[0]=this._shell;for(var B=0;B<this._holes.length;B++)u[B+1]=this._holes[B];return u.length<=1?this.getFactory().createLinearRing(u[0].getCoordinateSequence()):this.getFactory().createMultiLineString(u)}},{key:"getGeometryType",value:function(){return be.TYPENAME_POLYGON}},{key:"getExteriorRing",value:function(){return this._shell}},{key:"isEmpty",value:function(){return this._shell.isEmpty()}},{key:"getInteriorRingN",value:function(u){return this._holes[u]}},{key:"interfaces_",get:function(){return[wA]}}],[{key:"constructor_",value:function(){this._shell=null,this._holes=null;var u=arguments[0],B=arguments[1],b=arguments[2];if(be.constructor_.call(this,b),u===null&&(u=this.getFactory().createLinearRing()),B===null&&(B=[]),be.hasNullElements(B))throw new H("holes must not contain null elements");if(u.isEmpty()&&be.hasNonEmptyElements(B))throw new H("shell is empty but holes are not");this._shell=u,this._holes=B}}])})(be),sA=(function(C){function c(){return r(this,c),i(this,c,arguments)}return h(c,C),o(c)})(Ci),aA=(function(C){function c(u){var B;return r(this,c),(B=i(this,c)).array=[],u instanceof Ue&&B.addAll(u),B}return h(c,C),o(c,[{key:"contains",value:function(u){var B,b=a(this.array);try{for(b.s();!(B=b.n()).done;)if(B.value.compareTo(u)===0)return!0}catch(T){b.e(T)}finally{b.f()}return!1}},{key:"add",value:function(u){if(this.contains(u))return!1;for(var B=0,b=this.array.length;B<b;B++)if(this.array[B].compareTo(u)===1)return!!this.array.splice(B,0,u);return this.array.push(u),!0}},{key:"addAll",value:function(u){var B,b=a(u);try{for(b.s();!(B=b.n()).done;){var T=B.value;this.add(T)}}catch(O){b.e(O)}finally{b.f()}return!0}},{key:"remove",value:function(){throw new _e}},{key:"size",value:function(){return this.array.length}},{key:"isEmpty",value:function(){return this.array.length===0}},{key:"toArray",value:function(){return this.array.slice()}},{key:"iterator",value:function(){return new Le(this.array)}}])})(sA),Le=(function(){return o((function C(c){r(this,C),this.array=c,this.position=0}),[{key:"next",value:function(){if(this.position===this.array.length)throw new OA;return this.array[this.position++]}},{key:"hasNext",value:function(){return this.position<this.array.length}},{key:"remove",value:function(){throw new _e}}])})(),ne=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"computeEnvelopeInternal",value:function(){for(var u=new Ne,B=0;B<this._geometries.length;B++)u.expandToInclude(this._geometries[B].getEnvelopeInternal());return u}},{key:"getGeometryN",value:function(u){return this._geometries[u]}},{key:"getCoordinates",value:function(){for(var u=new Array(this.getNumPoints()).fill(null),B=-1,b=0;b<this._geometries.length;b++)for(var T=this._geometries[b].getCoordinates(),O=0;O<T.length;O++)u[++B]=T[O];return u}},{key:"getArea",value:function(){for(var u=0,B=0;B<this._geometries.length;B++)u+=this._geometries[B].getArea();return u}},{key:"copyInternal",value:function(){for(var u=new Array(this._geometries.length).fill(null),B=0;B<u.length;B++)u[B]=this._geometries[B].copy();return new c(u,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];if(!this.isEquivalentClass(u))return!1;var b=u;if(this._geometries.length!==b._geometries.length)return!1;for(var T=0;T<this._geometries.length;T++)if(!this._geometries[T].equalsExact(b._geometries[T],B))return!1;return!0}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var u=0;u<this._geometries.length;u++)this._geometries[u].normalize();Ke.sort(this._geometries)}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._geometries[0].getCoordinate()}},{key:"getBoundaryDimension",value:function(){for(var u=cA.FALSE,B=0;B<this._geometries.length;B++)u=Math.max(u,this._geometries[B].getBoundaryDimension());return u}},{key:"reverseInternal",value:function(){for(var u=this._geometries.length,B=new Xe(u),b=0;b<u;b++)B.add(this._geometries[b].reverse());return this.getFactory().buildGeometry(B)}},{key:"getTypeCode",value:function(){return be.TYPECODE_GEOMETRYCOLLECTION}},{key:"getDimension",value:function(){for(var u=cA.FALSE,B=0;B<this._geometries.length;B++)u=Math.max(u,this._geometries[B].getDimension());return u}},{key:"getLength",value:function(){for(var u=0,B=0;B<this._geometries.length;B++)u+=this._geometries[B].getLength();return u}},{key:"getNumPoints",value:function(){for(var u=0,B=0;B<this._geometries.length;B++)u+=this._geometries[B].getNumPoints();return u}},{key:"getNumGeometries",value:function(){return this._geometries.length}},{key:"compareToSameClass",value:function(){if(arguments.length===1){var u=arguments[0],B=new aA(Ke.asList(this._geometries)),b=new aA(Ke.asList(u._geometries));return this.compare(B,b)}if(arguments.length===2){for(var T=arguments[1],O=arguments[0],nt=this.getNumGeometries(),_t=O.getNumGeometries(),Lt=0;Lt<nt&&Lt<_t;){var ge=this.getGeometryN(Lt),Se=O.getGeometryN(Lt),hA=ge.compareToSameClass(Se,T);if(hA!==0)return hA;Lt++}return Lt<nt?1:Lt<_t?-1:0}}},{key:"apply",value:function(){if(ye(arguments[0],Gi))for(var u=arguments[0],B=0;B<this._geometries.length;B++)this._geometries[B].apply(u);else if(ye(arguments[0],FA)){var b=arguments[0];if(this._geometries.length===0)return null;for(var T=0;T<this._geometries.length&&(this._geometries[T].apply(b),!b.isDone());T++);b.isGeometryChanged()&&this.geometryChanged()}else if(ye(arguments[0],Ni)){var O=arguments[0];O.filter(this);for(var nt=0;nt<this._geometries.length;nt++)this._geometries[nt].apply(O)}else if(ye(arguments[0],Y)){var _t=arguments[0];_t.filter(this);for(var Lt=0;Lt<this._geometries.length;Lt++)this._geometries[Lt].apply(_t)}}},{key:"getBoundary",value:function(){return be.checkNotGeometryCollection(this),Dt.shouldNeverReachHere(),null}},{key:"getGeometryType",value:function(){return be.TYPENAME_GEOMETRYCOLLECTION}},{key:"isEmpty",value:function(){for(var u=0;u<this._geometries.length;u++)if(!this._geometries[u].isEmpty())return!1;return!0}}],[{key:"constructor_",value:function(){if(this._geometries=null,arguments.length!==0){if(arguments.length===2){var u=arguments[0],B=arguments[1];if(be.constructor_.call(this,B),u===null&&(u=[]),be.hasNullElements(u))throw new H("geometries must not contain null elements");this._geometries=u}}}}])})(be),Je=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"copyInternal",value:function(){for(var u=new Array(this._geometries.length).fill(null),B=0;B<u.length;B++)u[B]=this._geometries[B].copy();return new c(u,this._factory)}},{key:"isValid",value:function(){return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];return!!this.isEquivalentClass(u)&&E(c,"equalsExact",this,1).call(this,u,B)}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"getCoordinate",value:function(){if(arguments.length===1&&Number.isInteger(arguments[0])){var u=arguments[0];return this._geometries[u].getCoordinate()}return E(c,"getCoordinate",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return cA.FALSE}},{key:"getTypeCode",value:function(){return be.TYPECODE_MULTIPOINT}},{key:"getDimension",value:function(){return 0}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return be.TYPENAME_MULTIPOINT}},{key:"interfaces_",get:function(){return[tr]}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];ne.constructor_.call(this,u,B)}}])})(ne),Be=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"copyInternal",value:function(){return new c(this._points.copy(),this._factory)}},{key:"getBoundaryDimension",value:function(){return cA.FALSE}},{key:"isClosed",value:function(){return!!this.isEmpty()||E(c,"isClosed",this,1).call(this)}},{key:"reverseInternal",value:function(){var u=this._points.copy();return Ii.reverse(u),this.getFactory().createLinearRing(u)}},{key:"getTypeCode",value:function(){return be.TYPECODE_LINEARRING}},{key:"validateConstruction",value:function(){if(!this.isEmpty()&&!E(c,"isClosed",this,1).call(this))throw new H("Points of LinearRing do not form a closed linestring");if(this.getCoordinateSequence().size()>=1&&this.getCoordinateSequence().size()<c.MINIMUM_VALID_SIZE)throw new H("Invalid number of points in LinearRing (found "+this.getCoordinateSequence().size()+" - must be 0 or >= 4)")}},{key:"getGeometryType",value:function(){return be.TYPENAME_LINEARRING}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];bi.constructor_.call(this,u,B),this.validateConstruction()}}])})(bi);Be.MINIMUM_VALID_SIZE=4;var Oe=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"setOrdinate",value:function(u,B){switch(u){case c.X:this.x=B;break;case c.Y:this.y=B;break;default:throw new H("Invalid ordinate index: "+u)}}},{key:"getZ",value:function(){return Tt.NULL_ORDINATE}},{key:"getOrdinate",value:function(u){switch(u){case c.X:return this.x;case c.Y:return this.y}throw new H("Invalid ordinate index: "+u)}},{key:"setZ",value:function(u){throw new H("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new c(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+")"}},{key:"setCoordinate",value:function(u){this.x=u.x,this.y=u.y,this.z=u.getZ()}}],[{key:"constructor_",value:function(){if(arguments.length===0)Tt.constructor_.call(this);else if(arguments.length===1){if(arguments[0]instanceof c){var u=arguments[0];Tt.constructor_.call(this,u.x,u.y)}else if(arguments[0]instanceof Tt){var B=arguments[0];Tt.constructor_.call(this,B.x,B.y)}}else if(arguments.length===2){var b=arguments[0],T=arguments[1];Tt.constructor_.call(this,b,T,Tt.NULL_ORDINATE)}}}])})(Tt);Oe.X=0,Oe.Y=1,Oe.Z=-1,Oe.M=-1;var He=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(u,B){switch(u){case c.X:this.x=B;break;case c.Y:this.y=B;break;case c.M:this._m=B;break;default:throw new H("Invalid ordinate index: "+u)}}},{key:"setM",value:function(u){this._m=u}},{key:"getZ",value:function(){return Tt.NULL_ORDINATE}},{key:"getOrdinate",value:function(u){switch(u){case c.X:return this.x;case c.Y:return this.y;case c.M:return this._m}throw new H("Invalid ordinate index: "+u)}},{key:"setZ",value:function(u){throw new H("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new c(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(u){this.x=u.x,this.y=u.y,this.z=u.getZ(),this._m=u.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,arguments.length===0)Tt.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof c){var u=arguments[0];Tt.constructor_.call(this,u.x,u.y),this._m=u._m}else if(arguments[0]instanceof Tt){var B=arguments[0];Tt.constructor_.call(this,B.x,B.y),this._m=this.getM()}}else if(arguments.length===3){var b=arguments[0],T=arguments[1],O=arguments[2];Tt.constructor_.call(this,b,T,Tt.NULL_ORDINATE),this._m=O}}}])})(Tt);He.X=0,He.Y=1,He.Z=-1,He.M=2;var TA=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(u,B){switch(u){case Tt.X:this.x=B;break;case Tt.Y:this.y=B;break;case Tt.Z:this.z=B;break;case Tt.M:this._m=B;break;default:throw new H("Invalid ordinate index: "+u)}}},{key:"setM",value:function(u){this._m=u}},{key:"getOrdinate",value:function(u){switch(u){case Tt.X:return this.x;case Tt.Y:return this.y;case Tt.Z:return this.getZ();case Tt.M:return this.getM()}throw new H("Invalid ordinate index: "+u)}},{key:"copy",value:function(){return new c(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(u){this.x=u.x,this.y=u.y,this.z=u.getZ(),this._m=u.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,arguments.length===0)Tt.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof c){var u=arguments[0];Tt.constructor_.call(this,u),this._m=u._m}else if(arguments[0]instanceof Tt){var B=arguments[0];Tt.constructor_.call(this,B),this._m=this.getM()}}else if(arguments.length===4){var b=arguments[0],T=arguments[1],O=arguments[2],nt=arguments[3];Tt.constructor_.call(this,b,T,O),this._m=nt}}}])})(Tt),le=(function(){function C(){r(this,C)}return o(C,null,[{key:"measures",value:function(c){return c instanceof Oe?0:c instanceof He||c instanceof TA?1:0}},{key:"dimension",value:function(c){return c instanceof Oe?2:c instanceof He?3:c instanceof TA?4:3}},{key:"create",value:function(){if(arguments.length===1){var c=arguments[0];return C.create(c,0)}if(arguments.length===2){var u=arguments[0],B=arguments[1];return u===2?new Oe:u===3&&B===0?new Tt:u===3&&B===1?new He:u===4&&B===1?new TA:new Tt}}}])})(),Kt=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"getCoordinate",value:function(u){return this.get(u)}},{key:"addAll",value:function(){if(arguments.length===2&&typeof arguments[1]=="boolean"&&ye(arguments[0],Ue)){for(var u=arguments[1],B=!1,b=arguments[0].iterator();b.hasNext();)this.add(b.next(),u),B=!0;return B}return E(c,"addAll",this,1).apply(this,arguments)}},{key:"clone",value:function(){for(var u=E(c,"clone",this,1).call(this),B=0;B<this.size();B++)u.add(B,this.get(B).clone());return u}},{key:"toCoordinateArray",value:function(){if(arguments.length===0)return this.toArray(c.coordArrayType);if(arguments.length===1){if(arguments[0])return this.toArray(c.coordArrayType);for(var u=this.size(),B=new Array(u).fill(null),b=0;b<u;b++)B[b]=this.get(u-b-1);return B}}},{key:"add",value:function(){if(arguments.length===1){var u=arguments[0];return E(c,"add",this,1).call(this,u)}if(arguments.length===2){if(arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var B=arguments[0],b=arguments[1];return this.add(B,b,!0),!0}if(arguments[0]instanceof Tt&&typeof arguments[1]=="boolean"){var T=arguments[0];if(!arguments[1]&&this.size()>=1&&this.get(this.size()-1).equals2D(T))return null;E(c,"add",this,1).call(this,T)}else if(arguments[0]instanceof Object&&typeof arguments[1]=="boolean"){var O=arguments[0],nt=arguments[1];return this.add(O,nt),!0}}else if(arguments.length===3){if(typeof arguments[2]=="boolean"&&arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var _t=arguments[0],Lt=arguments[1];if(arguments[2])for(var ge=0;ge<_t.length;ge++)this.add(_t[ge],Lt);else for(var Se=_t.length-1;Se>=0;Se--)this.add(_t[Se],Lt);return!0}if(typeof arguments[2]=="boolean"&&Number.isInteger(arguments[0])&&arguments[1]instanceof Tt){var hA=arguments[0],$A=arguments[1];if(!arguments[2]){var Li=this.size();if(Li>0&&(hA>0&&this.get(hA-1).equals2D($A)||hA<Li&&this.get(hA).equals2D($A)))return null}E(c,"add",this,1).call(this,hA,$A)}}else if(arguments.length===4){var Vi=arguments[0],Xr=arguments[1],Vr=arguments[2],yn=arguments[3],hs=1;Vr>yn&&(hs=-1);for(var Ms=Vr;Ms!==yn;Ms+=hs)this.add(Vi[Ms],Xr);return!0}}},{key:"closeRing",value:function(){if(this.size()>0){var u=this.get(0).copy();this.add(u,!1)}}}],[{key:"constructor_",value:function(){if(arguments.length!==0){if(arguments.length===1){var u=arguments[0];this.ensureCapacity(u.length),this.add(u,!0)}else if(arguments.length===2){var B=arguments[0],b=arguments[1];this.ensureCapacity(B.length),this.add(B,b)}}}}])})(Xe);Kt.coordArrayType=new Array(0).fill(null);var Ce=(function(){function C(){r(this,C)}return o(C,null,[{key:"isRing",value:function(c){return!(c.length<4)&&!!c[0].equals2D(c[c.length-1])}},{key:"ptNotInList",value:function(c,u){for(var B=0;B<c.length;B++){var b=c[B];if(C.indexOf(b,u)<0)return b}return null}},{key:"scroll",value:function(c,u){var B=C.indexOf(u,c);if(B<0)return null;var b=new Array(c.length).fill(null);dA.arraycopy(c,B,b,0,c.length-B),dA.arraycopy(c,0,b,c.length-B,B),dA.arraycopy(b,0,c,0,c.length)}},{key:"equals",value:function(){if(arguments.length===2){var c=arguments[0],u=arguments[1];if(c===u)return!0;if(c===null||u===null||c.length!==u.length)return!1;for(var B=0;B<c.length;B++)if(!c[B].equals(u[B]))return!1;return!0}if(arguments.length===3){var b=arguments[0],T=arguments[1],O=arguments[2];if(b===T)return!0;if(b===null||T===null||b.length!==T.length)return!1;for(var nt=0;nt<b.length;nt++)if(O.compare(b[nt],T[nt])!==0)return!1;return!0}}},{key:"intersection",value:function(c,u){for(var B=new Kt,b=0;b<c.length;b++)u.intersects(c[b])&&B.add(c[b],!0);return B.toCoordinateArray()}},{key:"measures",value:function(c){if(c===null||c.length===0)return 0;var u,B=0,b=a(c);try{for(b.s();!(u=b.n()).done;){var T=u.value;B=Math.max(B,le.measures(T))}}catch(O){b.e(O)}finally{b.f()}return B}},{key:"hasRepeatedPoints",value:function(c){for(var u=1;u<c.length;u++)if(c[u-1].equals(c[u]))return!0;return!1}},{key:"removeRepeatedPoints",value:function(c){return C.hasRepeatedPoints(c)?new Kt(c,!1).toCoordinateArray():c}},{key:"reverse",value:function(c){for(var u=c.length-1,B=Math.trunc(u/2),b=0;b<=B;b++){var T=c[b];c[b]=c[u-b],c[u-b]=T}}},{key:"removeNull",value:function(c){for(var u=0,B=0;B<c.length;B++)c[B]!==null&&u++;var b=new Array(u).fill(null);if(u===0)return b;for(var T=0,O=0;O<c.length;O++)c[O]!==null&&(b[T++]=c[O]);return b}},{key:"copyDeep",value:function(){if(arguments.length===1){for(var c=arguments[0],u=new Array(c.length).fill(null),B=0;B<c.length;B++)u[B]=c[B].copy();return u}if(arguments.length===5)for(var b=arguments[0],T=arguments[1],O=arguments[2],nt=arguments[3],_t=arguments[4],Lt=0;Lt<_t;Lt++)O[nt+Lt]=b[T+Lt].copy()}},{key:"isEqualReversed",value:function(c,u){for(var B=0;B<c.length;B++){var b=c[B],T=u[c.length-B-1];if(b.compareTo(T)!==0)return!1}return!0}},{key:"envelope",value:function(c){for(var u=new Ne,B=0;B<c.length;B++)u.expandToInclude(c[B]);return u}},{key:"toCoordinateArray",value:function(c){return c.toArray(C.coordArrayType)}},{key:"dimension",value:function(c){if(c===null||c.length===0)return 3;var u,B=0,b=a(c);try{for(b.s();!(u=b.n()).done;){var T=u.value;B=Math.max(B,le.dimension(T))}}catch(O){b.e(O)}finally{b.f()}return B}},{key:"atLeastNCoordinatesOrNothing",value:function(c,u){return u.length>=c?u:[]}},{key:"indexOf",value:function(c,u){for(var B=0;B<u.length;B++)if(c.equals(u[B]))return B;return-1}},{key:"increasingDirection",value:function(c){for(var u=0;u<Math.trunc(c.length/2);u++){var B=c.length-1-u,b=c[u].compareTo(c[B]);if(b!==0)return b}return 1}},{key:"compare",value:function(c,u){for(var B=0;B<c.length&&B<u.length;){var b=c[B].compareTo(u[B]);if(b!==0)return b;B++}return B<u.length?-1:B<c.length?1:0}},{key:"minCoordinate",value:function(c){for(var u=null,B=0;B<c.length;B++)(u===null||u.compareTo(c[B])>0)&&(u=c[B]);return u}},{key:"extract",value:function(c,u,B){u=jA.clamp(u,0,c.length);var b=(B=jA.clamp(B,-1,c.length))-u+1;B<0&&(b=0),u>=c.length&&(b=0),B<u&&(b=0);var T=new Array(b).fill(null);if(b===0)return T;for(var O=0,nt=u;nt<=B;nt++)T[O++]=c[nt];return T}}])})(),IA=(function(){return o((function C(){r(this,C)}),[{key:"compare",value:function(C,c){var u=C,B=c;return Ce.compare(u,B)}},{key:"interfaces_",get:function(){return[St]}}])})(),MA=(function(){return o((function C(){r(this,C)}),[{key:"compare",value:function(C,c){var u=C,B=c;if(u.length<B.length)return-1;if(u.length>B.length)return 1;if(u.length===0)return 0;var b=Ce.compare(u,B);return Ce.isEqualReversed(u,B)?0:b}},{key:"OLDcompare",value:function(C,c){var u=C,B=c;if(u.length<B.length)return-1;if(u.length>B.length)return 1;if(u.length===0)return 0;for(var b=Ce.increasingDirection(u),T=Ce.increasingDirection(B),O=b>0?0:u.length-1,nt=T>0?0:u.length-1,_t=0;_t<u.length;_t++){var Lt=u[O].compareTo(B[nt]);if(Lt!==0)return Lt;O+=b,nt+=T}return 0}},{key:"interfaces_",get:function(){return[St]}}])})();Ce.ForwardComparator=IA,Ce.BidirectionalComparator=MA,Ce.coordArrayType=new Array(0).fill(null);var vA=(function(){return o((function C(c){r(this,C),this.str=c}),[{key:"append",value:function(C){this.str+=C}},{key:"setCharAt",value:function(C,c){this.str=this.str.substr(0,C)+c+this.str.substr(C+1)}},{key:"toString",value:function(){return this.str}}])})(),Bi=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"getM",value:function(c){return this.hasM()?this._coordinates[c].getM():mt.NaN}},{key:"setOrdinate",value:function(c,u,B){switch(u){case re.X:this._coordinates[c].x=B;break;case re.Y:this._coordinates[c].y=B;break;default:this._coordinates[c].setOrdinate(u,B)}}},{key:"getZ",value:function(c){return this.hasZ()?this._coordinates[c].getZ():mt.NaN}},{key:"size",value:function(){return this._coordinates.length}},{key:"getOrdinate",value:function(c,u){switch(u){case re.X:return this._coordinates[c].x;case re.Y:return this._coordinates[c].y;default:return this._coordinates[c].getOrdinate(u)}}},{key:"getCoordinate",value:function(){if(arguments.length===1){var c=arguments[0];return this._coordinates[c]}if(arguments.length===2){var u=arguments[0];arguments[1].setCoordinate(this._coordinates[u])}}},{key:"getCoordinateCopy",value:function(c){var u=this.createCoordinate();return u.setCoordinate(this._coordinates[c]),u}},{key:"createCoordinate",value:function(){return le.create(this.getDimension(),this.getMeasures())}},{key:"getDimension",value:function(){return this._dimension}},{key:"getX",value:function(c){return this._coordinates[c].x}},{key:"getMeasures",value:function(){return this._measures}},{key:"expandEnvelope",value:function(c){for(var u=0;u<this._coordinates.length;u++)c.expandToInclude(this._coordinates[u]);return c}},{key:"copy",value:function(){for(var c=new Array(this.size()).fill(null),u=0;u<this._coordinates.length;u++){var B=this.createCoordinate();B.setCoordinate(this._coordinates[u]),c[u]=B}return new C(c,this._dimension,this._measures)}},{key:"toString",value:function(){if(this._coordinates.length>0){var c=new vA(17*this._coordinates.length);c.append("("),c.append(this._coordinates[0]);for(var u=1;u<this._coordinates.length;u++)c.append(", "),c.append(this._coordinates[u]);return c.append(")"),c.toString()}return"()"}},{key:"getY",value:function(c){return this._coordinates[c].y}},{key:"toCoordinateArray",value:function(){return this._coordinates}},{key:"interfaces_",get:function(){return[re,N]}}],[{key:"constructor_",value:function(){if(this._dimension=3,this._measures=0,this._coordinates=null,arguments.length===1){if(arguments[0]instanceof Array){var c=arguments[0];C.constructor_.call(this,c,Ce.dimension(c),Ce.measures(c))}else if(Number.isInteger(arguments[0])){var u=arguments[0];this._coordinates=new Array(u).fill(null);for(var B=0;B<u;B++)this._coordinates[B]=new Tt}else if(ye(arguments[0],re)){var b=arguments[0];if(b===null)return this._coordinates=new Array(0).fill(null),null;this._dimension=b.getDimension(),this._measures=b.getMeasures(),this._coordinates=new Array(b.size()).fill(null);for(var T=0;T<this._coordinates.length;T++)this._coordinates[T]=b.getCoordinateCopy(T)}}else if(arguments.length===2){if(arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var O=arguments[0],nt=arguments[1];C.constructor_.call(this,O,nt,Ce.measures(O))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var _t=arguments[0],Lt=arguments[1];this._coordinates=new Array(_t).fill(null),this._dimension=Lt;for(var ge=0;ge<_t;ge++)this._coordinates[ge]=le.create(Lt)}}else if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var Se=arguments[0],hA=arguments[1],$A=arguments[2];this._dimension=hA,this._measures=$A,this._coordinates=Se===null?new Array(0).fill(null):Se}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var Li=arguments[0],Vi=arguments[1],Xr=arguments[2];this._coordinates=new Array(Li).fill(null),this._dimension=Vi,this._measures=Xr;for(var Vr=0;Vr<Li;Vr++)this._coordinates[Vr]=this.createCoordinate()}}}}])})(),Zi=(function(){function C(){r(this,C)}return o(C,[{key:"readResolve",value:function(){return C.instance()}},{key:"create",value:function(){if(arguments.length===1){if(arguments[0]instanceof Array)return new Bi(arguments[0]);if(ye(arguments[0],re))return new Bi(arguments[0])}else{if(arguments.length===2){var c=arguments[1];return c>3&&(c=3),c<2&&(c=2),new Bi(arguments[0],c)}if(arguments.length===3){var u=arguments[2],B=arguments[1]-u;return u>1&&(u=1),B>3&&(B=3),B<2&&(B=2),new Bi(arguments[0],B+u,u)}}}},{key:"interfaces_",get:function(){return[Xi,N]}}],[{key:"instance",value:function(){return C.instanceObject}}])})();Zi.instanceObject=new Zi;var sr=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"copyInternal",value:function(){for(var u=new Array(this._geometries.length).fill(null),B=0;B<u.length;B++)u[B]=this._geometries[B].copy();return new c(u,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];return!!this.isEquivalentClass(u)&&E(c,"equalsExact",this,1).call(this,u,B)}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"getTypeCode",value:function(){return be.TYPECODE_MULTIPOLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();for(var u=new Xe,B=0;B<this._geometries.length;B++)for(var b=this._geometries[B].getBoundary(),T=0;T<b.getNumGeometries();T++)u.add(b.getGeometryN(T));var O=new Array(u.size()).fill(null);return this.getFactory().createMultiLineString(u.toArray(O))}},{key:"getGeometryType",value:function(){return be.TYPENAME_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[wA]}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];ne.constructor_.call(this,u,B)}}])})(ne),Wr=(function(){return o((function C(){r(this,C)}),[{key:"get",value:function(){}},{key:"put",value:function(){}},{key:"size",value:function(){}},{key:"values",value:function(){}},{key:"entrySet",value:function(){}}])})(),Gr=(function(C){function c(){var u;return r(this,c),(u=i(this,c)).map=new Map,u}return h(c,C),o(c,[{key:"get",value:function(u){return this.map.get(u)||null}},{key:"put",value:function(u,B){return this.map.set(u,B),B}},{key:"values",value:function(){for(var u=new Xe,B=this.map.values(),b=B.next();!b.done;)u.add(b.value),b=B.next();return u}},{key:"entrySet",value:function(){var u=new _A;return this.map.entries().forEach((function(B){return u.add(B)})),u}},{key:"size",value:function(){return this.map.size()}}])})(Wr),Hr=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"equals",value:function(c){if(!(c instanceof C))return!1;var u=c;return this._modelType===u._modelType&&this._scale===u._scale}},{key:"compareTo",value:function(c){var u=c,B=this.getMaximumSignificantDigits(),b=u.getMaximumSignificantDigits();return zA.compare(B,b)}},{key:"getScale",value:function(){return this._scale}},{key:"isFloating",value:function(){return this._modelType===C.FLOATING||this._modelType===C.FLOATING_SINGLE}},{key:"getType",value:function(){return this._modelType}},{key:"toString",value:function(){var c="UNKNOWN";return this._modelType===C.FLOATING?c="Floating":this._modelType===C.FLOATING_SINGLE?c="Floating-Single":this._modelType===C.FIXED&&(c="Fixed (Scale="+this.getScale()+")"),c}},{key:"makePrecise",value:function(){if(typeof arguments[0]=="number"){var c=arguments[0];return mt.isNaN(c)||this._modelType===C.FLOATING_SINGLE?c:this._modelType===C.FIXED?Math.round(c*this._scale)/this._scale:c}if(arguments[0]instanceof Tt){var u=arguments[0];if(this._modelType===C.FLOATING)return null;u.x=this.makePrecise(u.x),u.y=this.makePrecise(u.y)}}},{key:"getMaximumSignificantDigits",value:function(){var c=16;return this._modelType===C.FLOATING?c=16:this._modelType===C.FLOATING_SINGLE?c=6:this._modelType===C.FIXED&&(c=1+Math.trunc(Math.ceil(Math.log(this.getScale())/Math.log(10)))),c}},{key:"setScale",value:function(c){this._scale=Math.abs(c)}},{key:"interfaces_",get:function(){return[N,z]}}],[{key:"constructor_",value:function(){if(this._modelType=null,this._scale=null,arguments.length===0)this._modelType=C.FLOATING;else if(arguments.length===1){if(arguments[0]instanceof An){var c=arguments[0];this._modelType=c,c===C.FIXED&&this.setScale(1)}else if(typeof arguments[0]=="number"){var u=arguments[0];this._modelType=C.FIXED,this.setScale(u)}else if(arguments[0]instanceof C){var B=arguments[0];this._modelType=B._modelType,this._scale=B._scale}}}},{key:"mostPrecise",value:function(c,u){return c.compareTo(u)>=0?c:u}}])})(),An=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"readResolve",value:function(){return C.nameToTypeMap.get(this._name)}},{key:"toString",value:function(){return this._name}},{key:"interfaces_",get:function(){return[N]}}],[{key:"constructor_",value:function(){this._name=null;var c=arguments[0];this._name=c,C.nameToTypeMap.put(c,this)}}])})();An.nameToTypeMap=new Gr,Hr.Type=An,Hr.FIXED=new An("FIXED"),Hr.FLOATING=new An("FLOATING"),Hr.FLOATING_SINGLE=new An("FLOATING SINGLE"),Hr.maximumPreciseValue=9007199254740992;var ds=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),o(c,[{key:"copyInternal",value:function(){for(var u=new Array(this._geometries.length).fill(null),B=0;B<u.length;B++)u[B]=this._geometries[B].copy();return new c(u,this._factory)}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof be){var u=arguments[0],B=arguments[1];return!!this.isEquivalentClass(u)&&E(c,"equalsExact",this,1).call(this,u,B)}return E(c,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?cA.FALSE:0}},{key:"isClosed",value:function(){if(this.isEmpty())return!1;for(var u=0;u<this._geometries.length;u++)if(!this._geometries[u].isClosed())return!1;return!0}},{key:"getTypeCode",value:function(){return be.TYPECODE_MULTILINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getBoundary",value:function(){throw new _e}},{key:"getGeometryType",value:function(){return be.TYPENAME_MULTILINESTRING}},{key:"interfaces_",get:function(){return[Ir]}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];ne.constructor_.call(this,u,B)}}])})(ne),ys=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return o(C,[{key:"createEmpty",value:function(c){switch(c){case-1:return this.createGeometryCollection();case 0:return this.createPoint();case 1:return this.createLineString();case 2:return this.createPolygon();default:throw new H("Invalid dimension: "+c)}}},{key:"toGeometry",value:function(c){return c.isNull()?this.createPoint():c.getMinX()===c.getMaxX()&&c.getMinY()===c.getMaxY()?this.createPoint(new Tt(c.getMinX(),c.getMinY())):c.getMinX()===c.getMaxX()||c.getMinY()===c.getMaxY()?this.createLineString([new Tt(c.getMinX(),c.getMinY()),new Tt(c.getMaxX(),c.getMaxY())]):this.createPolygon(this.createLinearRing([new Tt(c.getMinX(),c.getMinY()),new Tt(c.getMinX(),c.getMaxY()),new Tt(c.getMaxX(),c.getMaxY()),new Tt(c.getMaxX(),c.getMinY()),new Tt(c.getMinX(),c.getMinY())]),null)}},{key:"createLineString",value:function(){if(arguments.length===0)return this.createLineString(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){var c=arguments[0];return this.createLineString(c!==null?this.getCoordinateSequenceFactory().create(c):null)}if(ye(arguments[0],re))return new bi(arguments[0],this)}}},{key:"createMultiLineString",value:function(){return arguments.length===0?new ds(null,this):arguments.length===1?new ds(arguments[0],this):void 0}},{key:"buildGeometry",value:function(c){for(var u=null,B=!1,b=!1,T=c.iterator();T.hasNext();){var O=T.next(),nt=O.getTypeCode();u===null&&(u=nt),nt!==u&&(B=!0),O instanceof ne&&(b=!0)}if(u===null)return this.createGeometryCollection();if(B||b)return this.createGeometryCollection(C.toGeometryArray(c));var _t=c.iterator().next();if(c.size()>1){if(_t instanceof ve)return this.createMultiPolygon(C.toPolygonArray(c));if(_t instanceof bi)return this.createMultiLineString(C.toLineStringArray(c));if(_t instanceof uA)return this.createMultiPoint(C.toPointArray(c));Dt.shouldNeverReachHere("Unhandled geometry type: "+_t.getGeometryType())}return _t}},{key:"createMultiPointFromCoords",value:function(c){return this.createMultiPoint(c!==null?this.getCoordinateSequenceFactory().create(c):null)}},{key:"createPoint",value:function(){if(arguments.length===0)return this.createPoint(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Tt){var c=arguments[0];return this.createPoint(c!==null?this.getCoordinateSequenceFactory().create([c]):null)}if(ye(arguments[0],re))return new uA(arguments[0],this)}}},{key:"getCoordinateSequenceFactory",value:function(){return this._coordinateSequenceFactory}},{key:"createPolygon",value:function(){if(arguments.length===0)return this.createPolygon(null,null);if(arguments.length===1){if(ye(arguments[0],re)){var c=arguments[0];return this.createPolygon(this.createLinearRing(c))}if(arguments[0]instanceof Array){var u=arguments[0];return this.createPolygon(this.createLinearRing(u))}if(arguments[0]instanceof Be){var B=arguments[0];return this.createPolygon(B,null)}}else if(arguments.length===2)return new ve(arguments[0],arguments[1],this)}},{key:"getSRID",value:function(){return this._SRID}},{key:"createGeometryCollection",value:function(){return arguments.length===0?new ne(null,this):arguments.length===1?new ne(arguments[0],this):void 0}},{key:"getPrecisionModel",value:function(){return this._precisionModel}},{key:"createLinearRing",value:function(){if(arguments.length===0)return this.createLinearRing(this.getCoordinateSequenceFactory().create([]));if(arguments.length===1){if(arguments[0]instanceof Array){var c=arguments[0];return this.createLinearRing(c!==null?this.getCoordinateSequenceFactory().create(c):null)}if(ye(arguments[0],re))return new Be(arguments[0],this)}}},{key:"createMultiPolygon",value:function(){return arguments.length===0?new sr(null,this):arguments.length===1?new sr(arguments[0],this):void 0}},{key:"createMultiPoint",value:function(){if(arguments.length===0)return new Je(null,this);if(arguments.length===1){if(arguments[0]instanceof Array)return new Je(arguments[0],this);if(ye(arguments[0],re)){var c=arguments[0];if(c===null)return this.createMultiPoint(new Array(0).fill(null));for(var u=new Array(c.size()).fill(null),B=0;B<c.size();B++){var b=this.getCoordinateSequenceFactory().create(1,c.getDimension(),c.getMeasures());Ii.copy(c,B,b,0,1),u[B]=this.createPoint(b)}return this.createMultiPoint(u)}}}},{key:"interfaces_",get:function(){return[N]}}],[{key:"constructor_",value:function(){if(this._precisionModel=null,this._coordinateSequenceFactory=null,this._SRID=null,arguments.length===0)C.constructor_.call(this,new Hr,0);else if(arguments.length===1){if(ye(arguments[0],Xi)){var c=arguments[0];C.constructor_.call(this,new Hr,0,c)}else if(arguments[0]instanceof Hr){var u=arguments[0];C.constructor_.call(this,u,0,C.getDefaultCoordinateSequenceFactory())}}else if(arguments.length===2){var B=arguments[0],b=arguments[1];C.constructor_.call(this,B,b,C.getDefaultCoordinateSequenceFactory())}else if(arguments.length===3){var T=arguments[0],O=arguments[1],nt=arguments[2];this._precisionModel=T,this._coordinateSequenceFactory=nt,this._SRID=O}}},{key:"toMultiPolygonArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"toGeometryArray",value:function(c){if(c===null)return null;var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"getDefaultCoordinateSequenceFactory",value:function(){return Zi.instance()}},{key:"toMultiLineStringArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"toLineStringArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"toMultiPointArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"toLinearRingArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"toPointArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"toPolygonArray",value:function(c){var u=new Array(c.size()).fill(null);return c.toArray(u)}},{key:"createPointFromInternalCoord",value:function(c,u){return u.getPrecisionModel().makePrecise(c),u.getFactory().createPoint(c)}}])})(),Fs="XY",Ys="XYZ",ea="XYM",Wn="XYZM",Qa={POINT:"Point",LINE_STRING:"LineString",LINEAR_RING:"LinearRing",POLYGON:"Polygon",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection",CIRCLE:"Circle"},Y0="EMPTY",na=1,sa=2,Cs=3,Ka=4,so=5,yl=6;for(var il in Qa)Qa[il].toUpperCase();var C0=(function(){return o((function C(c){r(this,C),this.wkt=c,this.index_=-1}),[{key:"isAlpha_",value:function(C){return C>="a"&&C<="z"||C>="A"&&C<="Z"}},{key:"isNumeric_",value:function(C,c){return C>="0"&&C<="9"||C=="."&&!(c!==void 0&&c)}},{key:"isWhiteSpace_",value:function(C){return C==" "||C==" "||C=="\r"||C==`
|