anymap-ts 0.9.0 → 0.10.0

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.
@@ -25646,7 +25646,7 @@ ${a.replace(/gl_FragColor/g,"fragColor")}`:t.length===1?`
25646
25646
  fragColor.rgb *= fragColor.a;
25647
25647
  `}
25648
25648
  }
25649
- `}function Pve(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 OqA(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 k8(A,t,e){let i=A.getUniformLocation(t,e);if(!i)throw new Error(`Failed to get uniform location for ${e}`);return i}function OPt(A){let t=A.createTexture();if(!t)throw new Error("Failed to create texture");return t}function Hve(A){let t=A.createBuffer();if(!t)throw new Error("Failed to create buffer");return t}function SSe(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 $Pt(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 DSe(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 kSe(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 RSe(A){let t=[],e=[],i=2/A,r=1/A,n=(s,a)=>{let o=-1+s*i,l=1-a*i,g=s*r,h=a*r;t.push(o,l),e.push(g,h)};for(let s=0;s<A;s++){for(let a=0;a<=A;a++)n(a,s),n(a,s+1);s<A-1&&(n(A,s+1),n(0,s+1))}return{vertexArr:new Float32Array(t),texCoordArr:new Float32Array(e)}}function YqA(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 JqA=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=OPt(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(YqA(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 jqA(A=!1,t=!1){return A&&t?"mapbox-wgs84":A?"mapbox":t?"wgs84-globe":"maplibre-globe"}function MSe(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 qqA=A=>A instanceof Float32Array?A:new Float32Array(A),GSe=A=>A==="mapbox"||A==="mapbox-wgs84",KqA=A=>A==="maplibre-globe"||A==="wgs84-globe";function zqA(A){let t=A.includes("wgs84")?"wgs84":"mercator",e=GSe(A)?"mapbox-globe":"maplibre-globe";return{inputSpace:t,projection:e}}function WqA(A,t){let{fragmentShaderSource:e,shaderData:i,customShaderConfig:r,projectionMode:n}=t,s=r||void 0,a=s&&s.bands.length>0,o=t.variantName||MSe({projectionMode:n,shaderData:i,customShaderConfig:r}),{inputSpace:l,projection:g}=zqA(n),h=UqA({inputSpace:l,projection:g,shaderData:i}),I=a&&s?HqA({bands:s.bands,customUniforms:s.customUniforms?Object.keys(s.customUniforms):[],customFrag:s.customFrag}):e,p=Pve(A,A.VERTEX_SHADER,h),E=Pve(A,A.FRAGMENT_SHADER,I);if(!p||!E)throw new Error(`Failed to create shaders for variant: ${o}`);let f=OqA(A,p,E);if(!f)throw new Error(`Failed to create program for variant: ${o}`);let Q=new Map,y=new Map;if(a&&s){for(let z of s.bands){let N=A.getUniformLocation(f,z);N&&Q.set(z,N)}if(s.customUniforms)for(let z of Object.keys(s.customUniforms)){let N=A.getUniformLocation(f,z);N&&y.set(z,N)}}let v=KqA(n),S=GSe(n),G=z=>v?A.getUniformLocation(f,z):null,H=z=>S?A.getUniformLocation(f,z):null,Y={program:f,scaleLoc:k8(A,f,"scale"),scaleXLoc:k8(A,f,"scale_x"),scaleYLoc:k8(A,f,"scale_y"),shiftXLoc:k8(A,f,"shift_x"),shiftYLoc:k8(A,f,"shift_y"),worldXOffsetLoc:k8(A,f,"u_worldXOffset"),matrixLoc:v?null:k8(A,f,"matrix"),projMatrixLoc:G("u_projection_matrix"),fallbackMatrixLoc:G("u_projection_fallback_matrix"),tileMercatorCoordsLoc:G("u_projection_tile_mercator_coords"),clippingPlaneLoc:G("u_projection_clipping_plane"),projectionTransitionLoc:G("u_projection_transition"),opacityLoc:k8(A,f,"opacity"),texScaleLoc:k8(A,f,"u_texScale"),texOffsetLoc:k8(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:a?null:A.getUniformLocation(f,"cmap"),colormapLoc:A.getUniformLocation(f,"colormap"),texLoc:a?null:A.getUniformLocation(f,"tex"),projectionMode:n,useCustomShader:!!a,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(p),A.deleteShader(E),{shaderProgram:Y,variantName:o}}function VqA(A,t,e,i,r,n){let s=(l,g)=>{l&&g&&A.uniformMatrix4fv(l,!1,qqA(g))},a=(l,g)=>{l&&g&&A.uniform4f(l,...g)},o=(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),a(t.tileMercatorCoordsLoc,i.tileMercatorCoords),a(t.clippingPlaneLoc,i.clippingPlane),o(t.projectionTransitionLoc,i.projectionTransition);break}case"mapbox":case"mapbox-wgs84":{s(t.matrixLoc,e),s(t.globeToMercMatrixLoc,r?.globeToMercatorMatrix),o(t.globeTransitionLoc,r?.transition??1),t.tileRenderLoc&&A.uniform1i(t.tileRenderLoc,n?1:0);break}default:{s(t.matrixLoc,e);break}}}var FJ=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function tHt(A,t,e,i){let r=Math.max(0,A),n=Math.min(1,e),s=Math.max(0,t),a=Math.min(1,i),o=n-r,l=a-s;return new Float32Array([2/o,0,0,0,0,2/l,0,0,0,0,1,0,-(r+n)/o,-(s+a)/l,0,1])}function eHt(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 ZqA(A,t){return A.x0<t.x1&&A.x1>t.x0&&A.y0<t.y1&&A.y1>t.y0}function AHt(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 Ove(A,t){return Math.floor(Od(A)*Math.pow(2,t))}function Yve(A,t){let e=Math.max(-NJ,Math.min(NJ,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 NSe(A,t){let[[e,i],[r,n]]=t,s=Math.max(-NJ,i),a=Math.min(NJ,n),o=Ove(e,A),l=Ove(r,A),g=Yve(a,A),h=Yve(s,A),I=Math.pow(2,A),p=[],E=new Set;o>l&&(l+=I);for(let f=o;f<=l;f++){let Q=(f%I+I)%I;for(let y=g;y<=h;y++){let v=Math.max(0,Math.min(I-1,y)),S=`${A},${Q},${v}`;E.has(S)||(E.add(S),p.push([A,Q,v]))}}return p}function FSe(A,t,e){let[[i,r],[n,s]]=t,{xMin:a,xMax:o,yMin:l,yMax:g}=AHt(e),h=o-a,I=g-l,p=Math.pow(2,A),E=Y=>Math.floor((Y-a)/h*p),f=Y=>{let z=Math.max(Math.min(Y,g),l),N=(g-z)/I;return Math.floor(N*p)},Q=E(i),y=E(n),v=f(s),S=f(r),G=[],H=new Set;Q>y&&(y+=p);for(let Y=Q;Y<=y;Y++){let z=(Y%p+p)%p;for(let N=v;N<=S;N++){let F=Math.max(0,Math.min(p-1,N)),O=`${A},${z},${F}`;H.has(O)||(H.add(O),G.push([A,z,F]))}}return G}function vp(A){return A.join(",")}function Jve(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 XqA(A,t){return t?Math.min(Math.max(0,Math.floor(A)),t):Math.max(0,Math.floor(A))}function trt(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 Od(A){let t=A;return A>180?t=A-360:A<-180&&(t=A+360),(t+180)/360}function C_(A){let t=Math.max(-NJ,Math.min(NJ,A));return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2}function VF(A){let t=Math.PI*(1-2*A);return 180/Math.PI*Math.atan(Math.sinh(t))}function Zit(A){return A*360-180}function $qA(A,t,e,i){let r=Math.pow(2,A),{xMin:n,xMax:s,yMin:a,yMax:o}=AHt(i),l=s-n,g=o-a,h=n+t/r*l,I=n+(t+1)/r*l,p=o-e/r*g,E=o-(e+1)/r*g;return{west:h,east:I,south:E,north:p}}function LSe(A,t,e,i){let r=t-1,n=Math.floor(e/2),s=Math.floor(i/2);for(;r>=0;){let a=vp([r,n,s]),o=A.get(a);if(o&&o.data)return{tile:o,ancestorZ:r,ancestorX:n,ancestorY:s};r--,n=Math.floor(n/2),s=Math.floor(s/2)}return null}function TSe(A,t,e,i,r,n=2){let s=0,a=[];for(let o=1;o<=n;o++){let l=t+o;if(l>r)break;let g=Math.pow(2,o),h=e*g,I=i*g,p=g*g,E=[];for(let Q=0;Q<g;Q++)for(let y=0;y<g;y++){let v=h+y,S=I+Q,G=vp([l,v,S]),H=A.get(G);H&&H.data&&E.push({tile:H,childZ:l,childX:v,childY:S})}let f=E.length/p;if(f===1)return E;f>s&&(s=f,a=E)}return a.length>0?a:null}function jve(A,t){if(t==="EPSG:3857")return{x0:(A.xMin+L1)/(2*L1),y0:(L1-A.yMax)/(2*L1),x1:(A.xMax+L1)/(2*L1),y1:(L1-A.yMin)/(2*L1)};let e=A.yMin,i=A.yMax;e>i&&([e,i]=[i,e]);let r={x0:Od(A.xMin),y0:C_(i),x1:Od(A.xMax),y1:C_(e)};return t==="EPSG:4326"&&(r.latMin=e,r.latMax=i),r}function CCt(A,t,e,i){let r=(A-t)/(e-t);return Math.floor(Math.max(0,Math.min(i-1,r*i)))}function tKA(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 USe(A){return A?.type==="globe"||A?.name==="globe"}function eKA(A,t,e,i){let r=A&&typeof A=="object"&&!Array.isArray(A)&&!ArrayBuffer.isView(A)?A:null,n=r?.shaderData,s,a=r?.defaultProjectionData;a&&a.mainMatrix&&a.fallbackMatrix&&a.tileMercatorCoords&&a.clippingPlane&&typeof a.projectionTransition=="number"&&(s={mainMatrix:a.mainMatrix,fallbackMatrix:a.fallbackMatrix,tileMercatorCoords:a.tileMercatorCoords,clippingPlane:a.clippingPlane,projectionTransition:a.projectionTransition});let o=null;s?.mainMatrix&&s.mainMatrix.length?o=s.mainMatrix:Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array?o=A:r?.modelViewProjectionMatrix?o=r.modelViewProjectionMatrix:r?.projectionMatrix&&(o=r.projectionMatrix);let l=Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array;return{matrix:o,shaderData:n,projectionData:s,mapbox:!!t||l?{projection:t??{name:"mercator"},globeToMercatorMatrix:e??FJ,transition:typeof i=="number"?i:1}:void 0}}function AKA(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 a=Math.floor((r+180)/360),o=Math.floor((s+180)/360),l=[];for(let g=a;g<=o;g++)l.push(g);return l.length>0?l:[0]}function iHt(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 iKA(A,t){let{bandData:e,bandTextures:i,bandTexturesUploaded:r,bandTexturesConfigured:n,customShaderConfig:s,width:a,height:o,ensureTexture:l}=t,g=2;for(let h of s.bands){let I=e.get(h);if(!I)return!1;let p=i.get(h);if(!p)if(l){let E=l(h);E&&(p=E,i.set(h,p))}else p=A.createTexture(),p&&i.set(h,p);if(!p)return!1;A.activeTexture(A.TEXTURE0+g),A.bindTexture(A.TEXTURE_2D,p),n.has(h)||($Pt(A),n.add(h)),r.has(h)||(A.texImage2D(A.TEXTURE_2D,0,A.R32F,a,o,0,A.RED,A.FLOAT,I),r.add(h)),g++}return!0}function rKA(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 nKA(A,t){let{texture:e,data:i,width:r,height:n,channels:s,configured:a}=t;A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,e),a||$Pt(A);let{format:o,internalFormat:l}=SSe(A,s);return A.texImage2D(A.TEXTURE_2D,0,l,r,n,0,o,A.FLOAT,i),{configured:!0,uploaded:!0}}function NCt(A,t,e,i,r){let n=e.wgs84Bounds??null,s,a,o,l;n?(s=(n.lon1-n.lon0)/2,a=(n.lat1-n.lat0)/2,o=(n.lon0+n.lon1)/2,l=(n.lat0+n.lat1)/2):(s=(e.mercatorBounds.x1-e.mercatorBounds.x0)/2,a=(e.mercatorBounds.y1-e.mercatorBounds.y0)/2,o=(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,a),A.uniform1f(t.shiftXLoc,o),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 I=e.mercatorBounds.latMin!==void 0&&e.mercatorBounds.latMax!==void 0,p=I&&!n;if(t.reprojectLoc!==null&&A.uniform1i(t.reprojectLoc,p?1:0),p&&t.latBoundsLoc!==null&&I&&A.uniform2f(t.latBoundsLoc,e.mercatorBounds.latMin,e.mercatorBounds.latMax),p&&t.latIsAscendingLoc!==null&&A.uniform1i(t.latIsAscendingLoc,e.latIsAscending?1:0),rKA(A,t,e.vertexBuffer,e.pixCoordBuffer),e.useIndexedMesh&&e.indexBuffer&&A.bindBuffer(A.ELEMENT_ARRAY_BUFFER,e.indexBuffer),t.useCustomShader&&r){if(!iKA(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 qve(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 Kve(A,t,e,i,r,n,s,a,o,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=>a.ensureBandTexture(o,g),latIsAscending:l}}function sKA(A,t,e,i,r,n,s,a,o,l,g=!1,h,I,p=!0){iHt(A,t,l);let E=s.length/2;for(let f of e){let[Q,y,v]=f,S=vp(f),G=r.get(S),H=o?.[S],Y=null,z=S,N=[1,1],F=[0,0];if(G&&G.data)Y=G;else{let nt=LSe(r,Q,y,v);if(nt){Y=nt.tile,z=vp([nt.ancestorZ,nt.ancestorX,nt.ancestorY]);let tt=Q-nt.ancestorZ,W=Math.pow(2,tt),V=y%W,it=v%W;N=[1/W,1/W],F=[V/W,it/W]}else if(h!==void 0){let tt=TSe(r,Q,y,v,h);if(tt&&tt.length>0){let W;if(H)W=H;else{let[V,it,at]=Jve(f);W={x0:it-V,x1:it+V,y0:at-V,y1:at+V}}for(let V of tt){if(!V.tile.data||!V.tile.vertexBuffer||!V.tile.pixCoordBuffer||!V.tile.tileTexture)continue;let it=V.childZ-Q,at=Math.pow(2,it),pt=V.childX%at,Ct=V.childY%at,mt=W.x1-W.x0,ft=W.y1-W.y0,Qt={x0:W.x0+pt/at*mt,x1:W.x0+(pt+1)/at*mt,y0:W.y0+Ct/at*ft,y1:W.y0+(Ct+1)/at*ft};if(H?.latMin!==void 0&&H?.latMax!==void 0){let ie=H.latMax-H.latMin;Qt.latMin=H.latMin+Ct/at*ie,Qt.latMax=H.latMin+(Ct+1)/at*ie}if(H?.lonMin!==void 0&&H?.lonMax!==void 0){let ie=H.lonMax-H.lonMin;Qt.lonMin=H.lonMin+pt/at*ie,Qt.lonMax=H.lonMin+(pt+1)/at*ie}let yt=qve(A,V.tile,s,a),Mt=vp([V.childZ,V.childX,V.childY]),qt=Kve(V.tile,Qt,yt,E,n,[1,1],[0,0],r,Mt,p);NCt(A,t,qt,g?[0]:i,l)}continue}}}if(!Y||!Y.data||!Y.vertexBuffer||!Y.pixCoordBuffer||!Y.tileTexture)continue;if(g&&I?.[S]){let nt=I[S];N=nt.texScale,F=nt.texOffset}let O=qve(A,Y,s,a),K;if(H)K=H;else{let[nt,tt,W]=Jve(f);K={x0:tt-nt,x1:tt+nt,y0:W-nt,y1:W+nt}}let $=Kve(Y,K,O,E,n,N,F,r,z,p);NCt(A,t,$,g?[0]:i,l)}}var aKA=class PSe{constructor(t,e,i){this.shaderCache=new Map,this.customShaderConfig=null,this.gl=PSe.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=jqA(i,r),s=e||this.customShaderConfig,a=MSe({projectionMode:n,shaderData:t,customShaderConfig:s}),o=this.shaderCache.get(a);if(o)return o;let{shaderProgram:l}=WqA(this.gl,{fragmentShaderSource:this.fragmentShaderSource,shaderData:t,customShaderConfig:s,projectionMode:n,variantName:a});return this.shaderCache.set(a,l),l}applyCommonUniforms(t,e,i,r,n,s,a,o=!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 I=t.customUniformLocs.get(g);I&&l.uniform1f(I,h)}a&&VqA(l,t,a,n,s,o)}renderTiles(t,e,i,r,n,s,a,o,l,g=!1,h,I,p=!0){sKA(this.gl,t,e,i,r,n,s,a,o,l,g,h,I,p)}dispose(){let t=this.gl;for(let[,e]of this.shaderCache)t.deleteProgram(e.program);this.shaderCache.clear()}};function rHt(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 oKA(A,t){let e;try{e=Ud(A,"EPSG:3857")}catch(i){throw new Error(rHt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function lKA(A,t){let e;try{e=Ud(A,"EPSG:4326")}catch(i){throw new Error(rHt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function HSe(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 nHt(A,t,e,i,r,n=!0){if(!HSe(e,"sourceCRSToPixel"))return[i/2,r/2];let[s,a,o,l]=e,g=(A-s)/(o-s),h=(t-a)/(l-a),I=g*i,p=n?h*r:(1-h)*r;return[I,p]}function FCt(A,t,e,i,r,n=!0){let[s,a,o,l]=e;if(!HSe(e,"pixelToSourceCRS"))return[(s+o)/2,(a+l)/2];let g=i<=1?.5:A/i,h=r<=1?.5:t/r,I=s+g*(o-s),p=n?a+h*(l-a):l-h*(l-a);return[I,p]}function Art(A){let t;try{t=Ud("EPSG:4326",A)}catch(e){throw new Error(rHt(A,e))}return{forward:(e,i)=>t.forward([e,i]),inverse:(e,i)=>t.inverse([e,i])}}function zve(A,t,e){let{xMin:i,yMin:r,xMax:n,yMax:s}=A,a=1/0,o=-1/0,l=1/0,g=-1/0;for(let h=0;h<=e;h++){let I=h/e,p=[[i+I*(n-i),r],[i+I*(n-i),s],[i,r+I*(s-r)],[n,r+I*(s-r)]];for(let[E,f]of p){let[Q,y]=t.forward(E,f);if(!isFinite(Q)||!isFinite(y))continue;let v=(Q+L1)/(2*L1),S=(L1-y)/(2*L1);a=Math.min(a,v),o=Math.max(o,v),l=Math.min(l,S),g=Math.max(g,S)}}return isFinite(a)?{x0:a,y0:l,x1:o,y1:g}:null}function OSe(A,t,e,i,r,n,s,a,o,l,g=!0){if(a&&o){let S=l??Art(a),G=g?A+.5:A,H=g?t+.5:t,[Y,z]=FCt(G,H,o,i,r,s),[N,F]=S.inverse(Y,z);return{lat:F,lon:N}}let h=i<=1?.5:g?(A+.5)/i:A/i,I=r<=1?.5:g?(t+.5)/r:t/r,p=e.x0+h*(e.x1-e.x0),E=e.y0+I*(e.y1-e.y0),f=Zit(p),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):VF(E),lon:f}}function YSe(A,t,e,i,r,n){let[s,a,o]=A,l=Math.pow(2,s),g=(a+t/i)/l,h=(o+e/i)/l;if(r==="EPSG:4326"){let{xMin:f,xMax:Q,yMin:y,yMax:v}=n,S=f+g*(Q-f);return{lat:v-h*(v-y),lon:S}}let I=g*360-180,p=180-h*360;return{lat:360/Math.PI*Math.atan(Math.exp(p*Math.PI/180))-90,lon:I}}function sHt(A){let t=1/0,e=-1/0,i=1/0,r=-1/0;if(A.type==="Point"){let[s,a]=A.coordinates;return{west:s,east:s,south:a,north:a}}let n=s=>{for(let[a,o]of s)a<t&&(t=a),a>e&&(e=a),o<i&&(i=o),o>r&&(r=o)};return A.type==="Polygon"?A.coordinates.forEach(n):A.coordinates.forEach(s=>s.forEach(n)),{west:t,east:e,south:i,north:r}}function gKA(A,t,e,i,r,n,s,a,o){let l=sHt(A);if(s&&a){let G=o??Art(s),H=5,Y=[];for(let W=0;W<=H;W++){let V=W/H,it=l.west+V*(l.east-l.west),at=l.south+V*(l.north-l.south);Y.push([it,l.south]),Y.push([it,l.north]),Y.push([l.west,at]),Y.push([l.east,at])}let z=1/0,N=-1/0,F=1/0,O=-1/0;for(let[W,V]of Y){let[it,at]=G.forward(W,V);if(!isFinite(it)||!isFinite(at))continue;let[pt,Ct]=nHt(it,at,a,e,i,n);z=Math.min(z,pt),N=Math.max(N,pt),F=Math.min(F,Ct),O=Math.max(O,Ct)}if(!isFinite(z)||!isFinite(N)||!isFinite(F)||!isFinite(O))return null;let K=Math.max(0,Math.floor(z)),$=Math.min(e,Math.floor(N)+1),nt=Math.max(0,Math.floor(F)),tt=Math.min(i,Math.floor(O)+1);return $<=K||tt<=nt?null:{minX:K,maxX:$,minY:nt,maxY:tt}}let g=Od(l.west),h=Od(l.east),I=C_(l.north),p=C_(l.south),E=Math.max(t.x0,Math.min(g,h)),f=Math.min(t.x1,Math.max(g,h)),Q,y,v,S;if(r==="EPSG:4326"&&t.latMin!==void 0&&t.latMax!==void 0){let G=t.latMax,H=t.latMin,Y=Math.min(Math.max(l.north,H),G),z=Math.min(Math.max(l.south,H),G),N=G-H;if(N===0)return null;let F=V=>n?(V-H)/N:(G-V)/N,O=F(Y),K=F(z),$=Math.min(O,K),nt=Math.max(O,K);if(f<=E||nt<=$)return null;let tt=(E-t.x0)/(t.x1-t.x0)*e,W=(f-t.x0)/(t.x1-t.x0)*e;Q=Math.max(0,Math.floor(tt)),y=Math.min(e,Math.ceil(W)),v=Math.max(0,Math.floor($*i)),S=Math.min(i,Math.ceil(nt*i))}else{let G=Math.max(t.y0,Math.min(I,p)),H=Math.min(t.y1,Math.max(I,p));if(f<=E||H<=G)return null;let Y=(E-t.x0)/(t.x1-t.x0)*e,z=(f-t.x0)/(t.x1-t.x0)*e,N=(G-t.y0)/(t.y1-t.y0)*i,F=(H-t.y0)/(t.y1-t.y0)*i;Q=Math.max(0,Math.floor(Y)),y=Math.min(e,Math.ceil(z)),v=Math.max(0,Math.floor(N)),S=Math.min(i,Math.ceil(F))}return y<=Q||S<=v?null:{minX:Q,maxX:y,minY:v,maxY:S}}function BCt(A,t){let e=!1,[i,r]=A;for(let n=0,s=t.length-1;n<t.length;s=n++){let a=t[n][0],o=t[n][1],l=t[s][0],g=t[s][1];o>r!=g>r&&i<(l-a)*(r-o)/(g-o)+a&&(e=!e)}return e}function cKA(A,t){if(t.type==="Point")return A[0]===t.coordinates[0]&&A[1]===t.coordinates[1];if(t.type==="Polygon"){if(!BCt(A,t.coordinates[0]))return!1;for(let e=1;e<t.coordinates.length;e++)if(BCt(A,t.coordinates[e]))return!1;return!0}for(let e of t.coordinates)if(BCt(A,e[0])){let i=!1;for(let r=1;r<e.length;r++)if(BCt(A,e[r])){i=!0;break}if(!i)return!0}return!1}function JSe(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(cKA(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(I=>I);for(let I of h)for(let[p,E]of I)if(s([p,E]))return!0}let a=[[A[0],A[1]],[A[1],A[2]],[A[2],A[3]],[A[3],A[0]]],o=h=>h.slice(0,-1).map((I,p)=>[h[p],h[p+1]]),l=t.type==="Polygon"?o(t.coordinates[0]):t.type==="MultiPolygon"?t.coordinates.flatMap(h=>o(h[0])):[],g=(h,I,p,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(I,h),v=Q(E,p),S=f(y,v);if(S===0)return!1;let G=f(Q(p,h),v)/S,H=f(Q(p,h),y)/S;return G>=0&&G<=1&&H>=0&&H<=1};for(let h of a)for(let I of l)if(g(h[0],h[1],I[0],I[1]))return!0;return!1}function hKA(A,t,e,i,r,n){let s=[],a=[[0,0],[1,0],[1,1],[0,1]];for(let[o,l]of a){let g=YSe(A,t+o,e+l,i,r,n);s.push([g.lon,g.lat])}return s}function uKA(A,t,e,i,r,n,s,a,o,l){let g=[[0,0],[1,0],[1,1],[0,1]],h=[];for(let[I,p]of g){let{lon:E,lat:f}=OSe(i+I,r+p,A,t,e,n,s,a,o,l,!1);h.push([E,f])}return h}function IKA(A,t,e,i,r,n,s){let a=hKA(A,t,e,i,r,n);return JSe(a,s)}function pKA(A,t,e,i,r,n,s,a,o,l,g){let h=uKA(A,t,e,i,r,n,a,o,l,g);return JSe(h,s)}function dKA(A,t,e,i){let r=[[A.west,A.south],[A.east,A.north]];return e==="EPSG:4326"?FSe(t,r,i):NSe(t,r)}function CKA(A,t,e,i){let r=sHt(A);return dKA(r,t,e,i)}function BKA(A,t,e,i,r,n,s,a,o,l){if(a&&o){let E=l??Art(a),[f,Q]=E.forward(A,t),[y,v,S,G]=o;if(f<y||f>S||Q<v||Q>G)return null;let[H,Y]=nHt(f,Q,o,i,r,s),z=Math.floor(H),N=Math.floor(Y);return z<0||z>=i||N<0||N>=r?null:{x:z,y:N}}let g,h;if(n==="EPSG:4326"&&e.latMin!==void 0&&e.latMax!==void 0){g=(Od(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=(Od(A)-e.x0)/(e.x1-e.x0),h=(C_(t)-e.y0)/(e.y1-e.y0);if(g<0||g>1||h<0||h>1)return null;let I=Math.floor(g*i),p=Math.floor(h*r);return{x:Math.min(I,i-1),y:Math.min(p,r-1)}}function EKA(A,t,e,i,r,n,s,a,o){let l=[],g=[[]],h=[[]];for(let I=0;I<r.length;I++){let p=r[I],E=p.toLowerCase(),f=o[I]*a[I],Q=n[p];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[p],v,S;if(y===void 0){v=[],S=[];for(let Y=0;Y<a[I];Y++){let z=f+Y;z<s[I]&&(v.push(z),Q&&S.push(Q[z]))}}else if(Array.isArray(y)){v=[],S=[];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+a[I]&&(v.push(z),S.push(Y))}}else if(typeof y=="object"&&"selected"in y){let Y=y.selected,z=y.type,N=Array.isArray(Y)?Y:[Y];v=[],S=[];for(let F of N){let O;z==="index"?O=typeof F=="number"?F:0:Q?(O=Q.indexOf(F),O<0&&(O=typeof F=="number"?F:0)):O=typeof F=="number"?F:0,O>=f&&O<f+a[I]&&(v.push(O),Array.isArray(Y)&&S.push(F))}}else{let Y;Q?(Y=Q.indexOf(y),Y<0&&(Y=typeof y=="number"?y:0)):Y=typeof y=="number"?y:0,v=[Y],S=[]}let G=[],H=[];for(let Y=0;Y<v.length;Y++)for(let z=0;z<g.length;z++)G.push([...g[z],v[Y]]),S.length>0?H.push([...h[z],S[Y]]):H.push([...h[z]]);g=G.length>0?G:g.map(Y=>[...Y,0]),h.length=0,h.push(...H.length>0?H:h.map(()=>[]))}}for(let I=0;I<g.length;I++){let p=g[I],E=h[I]||[],f=p.map((S,G)=>{let H=r[G].toLowerCase();return["x","lon","longitude","y","lat","latitude"].includes(H)?S:S-o[G]*a[G]}),Q=new Array(r.length);Q[r.length-1]=1;for(let S=r.length-2;S>=0;S--)Q[S]=Q[S+1]*a[S+1];let y=0;for(let S=0;S<r.length;S++)y+=f[S]*Q[S];let v=A[y];l.push({keys:E,value:v})}return l}function aHt(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 Wve(A,t,e,i,r,n,s){let a=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 I=A[l],p=e[l],E=r[g],f;if(I===void 0)f=Array(i[g]).fill(null).map((y,v)=>v);else if(Array.isArray(I))f=I.map(y=>{let v=p?p.indexOf(y):typeof y=="number"?y:0;return v>=0?v:typeof y=="number"?y:0});else if(typeof I=="object"&&"selected"in I){let y=I.selected,v=I.type;f=(Array.isArray(y)?y:[y]).map(G=>{if(v==="index")return typeof G=="number"?G:0;if(p){let H=p.indexOf(G);return H>=0?H:typeof G=="number"?G:0}return typeof G=="number"?G:0})}else if(p){let y=p.indexOf(I);f=[y>=0?y:typeof I=="number"?I:0]}else f=[typeof I=="number"?I:0];return f.map(y=>Math.floor(y/E)).filter((y,v,S)=>S.indexOf(y)===v)}),o=[[]];return a.forEach(l=>{let g=[];l.forEach(h=>{o.forEach(I=>{g.push([...I,h])})}),o=g}),o}function jSe(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 fKA(A,t,e,i,r,n,s,a,o){let l=i.describe(),g=l.dimensions,h=l.coordinates,I=l.shape||[],p=l.chunks||[],E=nt=>Array.isArray(nt)?!0:nt&&typeof nt=="object"&&"selected"in nt?Array.isArray(nt.selected):!1,f=Object.keys(e).filter(nt=>!E(e[nt])).length,y=g.length-f>2,v=y?{}:[],S=[],G=[],H=g.map(nt=>{let tt=nt.toLowerCase();return["x","lon","longitude"].includes(tt)?"lon":["y","lat","latitude"].includes(tt)?"lat":nt}),Y=y?H:["lat","lon"],z=()=>{let nt={lat:S,lon:G};if(y){let tt=W=>{let V=W.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(V))return;let it=e[W],at;if(Array.isArray(it))at=it;else if(it&&typeof it=="object"&&"selected"in it){let pt=it.selected;at=Array.isArray(pt)?pt:[pt]}else it!==void 0&&typeof it!="object"?at=[it]:h[W]&&(at=h[W]);at&&(nt[W]=at)};g.forEach(tt)}return nt},N=i.levels[s];if(!N)throw new Error(`No level path found for level index ${s}`);let F=trt(N,s),O=CKA(t,F,r,n);if(O.length===0)return{[A]:v,dimensions:Y,coordinates:z()};let K=new Map;await Promise.all(O.map(async nt=>{let[,tt,W]=nt,V=Wve(e,g,h,I,p,tt,W),it=vp(nt),at=new Map;await Promise.all(V.map(async pt=>{try{let Ct=await i.getChunk(N,pt),mt=new Float32Array(Ct.data),ft=pt.join(",");at.set(ft,mt)}catch(Ct){console.warn(`Failed to fetch chunk ${pt} for tile ${it}:`,Ct)}})),K.set(it,at)}));for(let nt of O){let tt=vp(nt),W=K.get(tt);if(!W||W.size===0)continue;let[,V,it]=nt,at=Wve(e,g,h,I,p,V,it);for(let pt=0;pt<a;pt++)for(let Ct=0;Ct<a;Ct++){if(!IKA(nt,Ct,pt,a,r,n,t))continue;let mt=[];for(let Qt of at){let yt=Qt.join(","),Mt=W.get(yt);if(!Mt)continue;let qt=EKA(Mt,Ct,pt,e,g,h,I,p,Qt);for(let{keys:ie,value:Dt}of qt){let Pe=jSe(Dt,o);Pe!==null&&mt.push({keys:ie,value:Pe})}}if(mt.length===0)continue;let ft=YSe(nt,Ct+.5,pt+.5,a,r,n);S.push(ft.lat),G.push(ft.lon);for(let{keys:Qt,value:yt}of mt)Qt.length>0?aHt(v,Qt,yt):Array.isArray(v)&&v.push(yt)}}return{[A]:v,dimensions:Y,coordinates:z()}}async function _KA(A,t,e,i,r,n,s,a,o,l,g=1,h,I,p,E,f,Q){let y=it=>Array.isArray(it)?!0:it&&typeof it=="object"&&"selected"in it?Array.isArray(it.selected):!1,v=Object.keys(e).filter(it=>!y(e[it])).length,G=o.length-v>2,H=G?{}:[],Y=[],z=[],N=o.map(it=>{let at=it.toLowerCase();return["x","lon","longitude"].includes(at)?"lon":["y","lat","latitude"].includes(at)?"lat":it}),F=G?N:["lat","lon"],O=()=>{let it={lat:Y,lon:z};if(G){let at=pt=>{let Ct=pt.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(Ct))return;let mt=e[pt],ft;if(Array.isArray(mt))ft=mt;else if(mt&&typeof mt=="object"&&"selected"in mt){let Qt=mt.selected;ft=Array.isArray(Qt)?Qt:[Qt]}else mt!==void 0&&typeof mt!="object"?ft=[mt]:l[pt]&&(ft=l[pt]);ft&&(it[pt]=ft)};o.forEach(at)}return it};if(!i)return{[A]:H,dimensions:F,coordinates:O()};let K=0,$=r,nt=0,tt=n;if(!f){let it=sHt(t),at=Od(it.west),pt=Od(it.east),Ct=C_(it.north),mt=C_(it.south),ft=Math.max(s.x0,Math.min(at,pt)),Qt=Math.min(s.x1,Math.max(at,pt));if(a==="EPSG:4326"&&s.latMin!==void 0&&s.latMax!==void 0){let yt=s.latMax,Mt=s.latMin,qt=Math.min(Math.max(it.north,Mt),yt),ie=Math.min(Math.max(it.south,Mt),yt),Dt=yt-Mt;if(Dt===0)return{[A]:H,dimensions:F,coordinates:O()};let Pe=$A=>p?($A-Mt)/Dt:(yt-$A)/Dt,me=Pe(qt),ue=Pe(ie),Et=Math.min(me,ue),xe=Math.max(me,ue);if(Qt<=ft||xe<=Et)return{[A]:H,dimensions:F,coordinates:O()};let vA=(ft-s.x0)/(s.x1-s.x0)*r,ce=(Qt-s.x0)/(s.x1-s.x0)*r;K=Math.max(0,Math.floor(vA)),$=Math.min(r,Math.ceil(ce+1)),nt=Math.max(0,Math.floor(Et*n)),tt=Math.min(n,Math.ceil(xe*n))}else{let yt=Math.max(s.y0,Math.min(Ct,mt)),Mt=Math.min(s.y1,Math.max(Ct,mt));if(Qt<=ft||Mt<=yt)return{[A]:H,dimensions:F,coordinates:O()};let qt=(ft-s.x0)/(s.x1-s.x0)*r,ie=(Qt-s.x0)/(s.x1-s.x0)*r,Dt=(yt-s.y0)/(s.y1-s.y0)*n,Pe=(Mt-s.y0)/(s.y1-s.y0)*n;K=Math.max(0,Math.floor(qt)),$=Math.min(r,Math.ceil(ie+1)),nt=Math.max(0,Math.floor(Dt)),tt=Math.min(n,Math.ceil(Pe+1))}if($<=K||tt<=nt)return{[A]:H,dimensions:F,coordinates:O()}}let W=f?Art(f):void 0;for(let it=nt;it<tt;it++)for(let at=K;at<$;at++){if(!pKA(s,r,n,at,it,a,t,p,f,Q,W))continue;let{lat:pt,lon:Ct}=OSe(at,it,s,r,n,a,p,f,Q,W),mt=(it*r+at)*g,ft=[];for(let Qt=0;Qt<g;Qt++){let yt=i[mt+Qt],Mt=jSe(yt,E);if(Mt!==null)if(G&&I){let qt=h?.[Qt],ie=qt&&qt.length===I.length?qt:[Qt];ft.push({keys:ie,value:Mt})}else ft.push({keys:[],value:Mt})}if(ft.length!==0){Y.push(pt),z.push(Ct);for(let{keys:Qt,value:yt}of ft)Qt.length>0?aHt(H,Qt,yt):Array.isArray(H)&&H.push(yt)}}return{[A]:H,dimensions:F,coordinates:O()}}function qSe(){return{lastFetchTime:0,throttleTimeout:null,throttledPending:!1}}function KSe(A,t){if(t<=0)return 0;let i=Date.now()-A.lastFetchTime;return i<t?t-i:0}function zSe(A,t,e){A.throttleTimeout||(A.throttledPending=!0,A.throttleTimeout=setTimeout(()=>{A.throttleTimeout=null,A.throttledPending=!1,e()},t))}function WSe(A){A.lastFetchTime=Date.now()}function VSe(A){A.throttleTimeout&&(clearTimeout(A.throttleTimeout),A.throttleTimeout=null),A.throttledPending=!1}function ZSe(){return{controllers:new Map,currentVersion:0}}function XSe(A,t){for(let[e,i]of A.controllers)e<t&&(i.abort(),A.controllers.delete(e))}function kCt(A){for(let t of A.controllers.values())t.abort();A.controllers.clear()}function mKA(A){for(let t of A.controllers.values())if(!t.signal.aborted)return!0;return!1}function $Se(){return{callback:void 0,metadataLoading:!1,chunksLoading:!1}}function tDe(A,t){A.callback=t}function eDe(A){if(!A.callback)return;let t={loading:A.metadataLoading||A.chunksLoading,metadata:A.metadataLoading,chunks:A.chunksLoading,error:null};A.callback(t)}var QKA=class{constructor({store:A,selector:t,fillValue:e,dimIndices:i,coordinates:r,maxCachedTiles:n=64,bandNames:s=[],fixedDataScale:a=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=a}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 o=e.indexOf(s);if(o>=0)return o}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,a=new Array(n.length).fill(0);for(let o=0;o<n.length;o++){let l=n[o],g=this.getDimKeyForName(l);if(g==="lon")a[o]=i;else if(g==="lat")a[o]=r;else{let h=Fve(this.selector,g,l,this.dimIndices),p=this.normalizeSelection(h,l).map(y=>Math.max(0,Math.min(y,A.shape[o]-1))),E=Math.floor(p[0]/s[o]);p.some(y=>Math.floor(y/s[o])!==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[o]/s[o])-1);a[o]=Math.min(E,Q)}}return a}extractSliceFromChunk(A,t,e,i){let r=this.store.tileSize,n=this.store.tileSize,s=1,a=this.store.dimensions||[],o=e.chunks,l=[],g=-1,h=-1,I=n,p=r,E=[],f=[];for(let G=0;G<a.length;G++){let H=a[G],Y=this.getDimKeyForName(H);if(Y==="lat")g=G,I=Math.min(t[G],n),l.push(-1);else if(Y==="lon")h=G,p=Math.min(t[G],r),l.push(-1);else{let z=Fve(this.selector,Y,H,this.dimIndices),N=this.normalizeSelection(z,H),F=i[G]*o[G],O=N.map(K=>Math.max(0,Math.min(K-F,t[G]-1)));E[G]=O,l.push(O[0]),O.length>1&&f.push(G)}}let Q=G=>{let H=0,Y=1;for(let z=G.length-1;z>=0;z--)H+=G[z]*Y,Y*=t[z];return H},y=[[]];f.forEach(G=>{let H=E[G],Y=[];y.forEach(z=>{H.forEach(N=>{Y.push([...z,N])})}),y=Y}),s=y.length||1;let v=new Map,S=[];for(let G=0;G<s;G++){let H=new Float32Array(r*n);H.fill(this.fillValue),S.push(H)}for(let G=0;G<I;G++)for(let H=0;H<p;H++)g>=0&&(l[g]=G),h>=0&&(l[h]=H),y.forEach((Y,z)=>{let N=[...l],F=0;for(let $=0;$<f.length;$++)N[f[$]]=Y[F++];let O=Q(N),K=G*r+H;O<A.length&&(S[z][K]=A[O])});for(let G=0;G<s;G++){let H=this.bandNames[G]||`band_${G}`;v.set(H,S[G])}return{channels:s,bandData:v}}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}=DSe(n,this.fillValue,this.fixedDataScale);A.bandData.set(r,s),i.push(s)}A.data=kSe(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||($Pt(t),A.textureConfigured=!0);let{format:e,internalFormat:i}=SSe(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?OPt(this.gl):null,bandTextures:new Map,bandTexturesUploaded:new Set,bandTexturesConfigured:new Set,textureUploaded:!1,textureConfigured:!1,vertexBuffer:this.gl?Hve(this.gl):null,pixCoordBuffer:this.gl?Hve(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=OPt(this.gl),e.bandTextures.set(t,i)),i}getTile(A){return this.tiles.get(vp(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=vp(i),n=this.tiles.get(r);if(!n)continue;let s=this.store.levels[i[0]];if(!s)continue;let a=await this.store.getLevelArray(s),o=this.computeChunkIndices(a,i);if(n.chunkData&&n.chunkShape&&this.arraysEqual(n.chunkIndices,o)){if(e<n.selectorVersion)continue;let g=this.extractSliceFromChunk(n.chunkData,n.chunkShape,a,o);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 a=await this.store.getLevelArray(s),o=vp(A),l=this.getOrCreateTile(o);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(a,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,a,g);return this.applyNormalization(l,Q),l.selectorHash=t,l.selectorVersion=e,l.loading=!1,l}let I=await this.store.getChunk(s,g,{signal:i}),p=I.shape.map(Q=>Number(Q)),E=I.data instanceof Float32Array?new Float32Array(I.data.buffer):Float32Array.from(I.data);if(e<l.selectorVersion)return l.loading=!1,null;l.chunkData=E,l.chunkShape=p,l.chunkIndices=g;let f=this.extractSliceFromChunk(E,p,a,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 ADe(A,t,e,i,r){let n=vp([A,t,e]),s=i?.[n];if(s)return s;let a=$qA(A,t,e,r);return{x0:Od(a.west),x1:Od(a.east),y0:C_(a.north),y1:C_(a.south),latMin:a.south,latMax:a.north,lonMin:a.west,lonMax:a.east}}function iDe(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??Zit(A.x0),a=A.lonMax??Zit(A.x1),o=A.latMin??VF(A.y1),l=A.latMax??VF(A.y0),g=a-s,h=Zit(e),I=Zit(i),p=g>0?(I-h)/g:1,E=g>0?(h-s)/g:0;return{overlap:{x0:e,y0:r,x1:i,y1:n},latBounds:{min:o,max:l},texScale:[p,1],texOffset:[E,0]}}function rDe({renderer:A,mode:t,tileId:e,context:i,regions:r}){return r?yKA(A,e,i,r):xKA(A,t,e,i)}function yKA(A,t,e,i){if(i.length===0)return!0;let r=eHt(t),n={lon0:r.x0,lon1:r.x1,lat0:(VF(r.y1)+90)/180,lat1:(VF(r.y0)+90)/180},s=tHt(r.x0,r.y0,r.x1,r.y1),{colormapTexture:a,uniforms:o,customShaderConfig:l}=e,g=e.isGlobe??!0,h=i.some(E=>!!E.wgs84Bounds),I=A.getProgram(e.shaderData,l,!0,h);A.gl.useProgram(I.program),A.applyCommonUniforms(I,a,o,l,e.projectionData,{projection:{name:g?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:g?0:1},s,!0),iHt(A.gl,I,l);let p=!1;for(let E of i){let f;if(E.wgs84Bounds){let S=E.wgs84Bounds,G=S.lat0<n.lat1&&S.lat1>n.lat0,H;if(S.crossesAntimeridian){let z=S.lon0<1&&n.lon0<1&&n.lon1>S.lon0,N=n.lon0<S.lon1&&n.lon1>0;H=z||N}else H=S.lon0<n.lon1&&S.lon1>n.lon0;f=G&&H}else f=ZqA(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};NCt(A.gl,I,y,[0],l)||(p=!0)}return p}function xKA(A,t,e,i){let r=t.getTiledState?.();return r?.tileCache?t.getCRS()==="EPSG:4326"?wKA(A,t,e,i,r):SKA(A,t,e,i,r):!0}function wKA(A,t,e,i,r){let{customShaderConfig:n}=i,{visibleTiles:s,tileBounds:a}=r,o=t.getXYLimits(),l=t.getMaxLevelIndex(),g=t.getLevels();if(!o||s.length===0)return!0;let h=eHt(e),I=tHt(h.x0,h.y0,h.x1,h.y1),p=[];for(let S of s){let G=vp(S),H=a?.[G];H&&H.x0<h.x1&&H.x1>h.x0&&H.y0<h.y1&&H.y1>h.y0&&p.push(S)}if(p.length===0)return!1;let E=A.getProgram(i.shaderData,n,!0,!1);A.gl.useProgram(E.program);let f=g[l]??"",Q=trt(f,l),y=!1,v=!1;for(let S of p){let G=bKA(A,E,S,h,I,r,i,o,Q);G.rendered&&(y=!0),G.missing&&(v=!0)}return v||!y}function bKA(A,t,e,i,r,n,s,a,o){let{tileCache:l,vertexArr:g,pixCoordArr:h,tileSize:I,tileBounds:p}=n,{colormapTexture:E,uniforms:f,customShaderConfig:Q}=s,y=vp(e),v=l.get(y),S=e,G=!1;if(!v?.data){G=!0;let it=LSe(l,e[0],e[1],e[2]);if(it)v=it.tile,S=[it.ancestorZ,it.ancestorX,it.ancestorY];else{let at=TSe(l,e[0],e[1],e[2],o);if(at&&at.length>0){let pt=!1;for(let Ct of at){if(!Ct.tile.data)continue;vKA(A,t,Ct,i,r,n,s,a)&&(pt=!0)}return{rendered:pt,missing:!0}}return{rendered:!1,missing:!0}}}let[H,Y,z]=S,N=vp(S),F=ADe(H,Y,z,p,a),O=iDe(F,i);if(!O)return{rendered:!1,missing:G};let{overlap:K,latBounds:$,texScale:nt,texOffset:tt}=O,W={[N]:{x0:K.x0,y0:K.y0,x1:K.x1,y1:K.y1,latMin:$.min,latMax:$.max}},V=s.isGlobe??!0;return A.applyCommonUniforms(t,E,f,Q,s.projectionData,{projection:{name:V?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:V?0:1},r,!0),A.renderTiles(t,[S],[0],l,I,g,h,W,Q,!0,void 0,{[N]:{texScale:nt,texOffset:tt}},n.latIsAscending),{rendered:!0,missing:G}}function vKA(A,t,e,i,r,n,s,a){let{tileCache:o,vertexArr:l,pixCoordArr:g,tileSize:h,tileBounds:I}=n,{colormapTexture:p,uniforms:E,customShaderConfig:f}=s,Q=[e.childZ,e.childX,e.childY],y=vp(Q),v=ADe(e.childZ,e.childX,e.childY,I,a),S=iDe(v,i);if(!S)return!1;let{overlap:G,latBounds:H,texScale:Y,texOffset:z}=S,N={[y]:{x0:G.x0,y0:G.y0,x1:G.x1,y1:G.y1,latMin:H.min,latMax:H.max}},F=s.isGlobe??!0;return A.applyCommonUniforms(t,p,E,f,s.projectionData,{projection:{name:F?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:F?0:1},r,!0),A.renderTiles(t,[Q],[0],o,h,l,g,N,f,!0,void 0,{[y]:{texScale:Y,texOffset:z}},n.latIsAscending),!0}function SKA(A,t,e,i,r){let{tileCache:n,vertexArr:s,pixCoordArr:a,tileSize:o,tileBounds:l}=r,{colormapTexture:g,uniforms:h,customShaderConfig:I}=i,p=t.getLevels(),E=t.getMaxLevelIndex(),f=eHt(e),Q=tHt(f.x0,f.y0,f.x1,f.y1),y=[e.z,e.x,e.y],v=y.join(","),S=l?.[v],G={[v]:{x0:f.x0,y0:f.y0,x1:f.x1,y1:f.y1,latMin:S?.latMin,latMax:S?.latMax}},H=p[E]??"",Y=trt(H,E),z=A.getProgram(i.shaderData,I,!0);A.gl.useProgram(z.program);let N=i.isGlobe??!0;return A.applyCommonUniforms(z,g,h,I,i.projectionData,{projection:{name:N?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:N?0:1},Q,!0),A.renderTiles(z,[y],[0],n,o,s,a,G,I,!0,Y),!n.get(v)?.data}function Vve(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 DKA=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=Mve,this.visibleTiles=[],this.crs="EPSG:4326",this.xyLimits=null,this.tileBounds={},this.pendingChunks=new Set,this.currentLevel=null,this.selectorVersion=0,this.throttleState=qSe(),this.requestCanceller=ZSe(),this.loadingManager=$Se(),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||Mve,this.crs=A.crs,this.xyLimits=A.xyLimits;let t=zF(this.variable,this.selector);this.tileCache=new QKA({store:this.zarrStore,selector:this.selector,fillValue:A.fill_value??0,dimIndices:A.dimIndices,coordinates:A.coordinates,maxCachedTiles:dqA,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=USe(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[a,o]of Object.entries(this.tileBounds)){let l=Vve(o);l&&this.tileCache.setTileBounds(a,l)}let n=JSON.stringify(this.selector),s=[];for(let a of this.visibleTiles){let o=vp(a);if(this.pendingChunks.has(o))continue;let l=this.tileCache.upsert(o);(!l.data||l.selectorHash!==n)&&s.push(a)}if(s.length>0){let a=KSe(this.throttleState,this.throttleMs);if(a>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),zSe(this.throttleState,a,this.invalidate);return}WSe(this.throttleState);let o=this.pendingChunks.size===0;for(let g of s)this.pendingChunks.add(vp(g));o&&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(vp(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=trt(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 rDe({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){VSe(this.throttleState),kCt(this.requestCanceller),this.tileCache?.clear(),this.tileCache=null,this.pendingChunks.clear(),this.emitLoadingState()}setLoadingCallback(A){tDe(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,eDe(this.loadingManager)}async setSelector(A){this.selector=A,this.selectorVersion++;let t=zF(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?CqA:1;if(this.currentSubdivisions===t)return;let e=RSe(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=XqA(t,this.maxLevelIndex),i=A.getBounds()?.toArray();if(!i)return{tiles:[],pyramidLevel:e,mapZoom:t,bounds:null};let r=this.zarrStore.levels[e],n=trt(r,e);return this.crs==="EPSG:4326"&&this.xyLimits?{tiles:FSe(n,i,this.xyLimits),pyramidLevel:e,mapZoom:t,bounds:i}:{tiles:NSe(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}=AHt(this.xyLimits),n=e-t,s=r-i,a={};for(let o of A){let[l,g,h]=o,I=Math.pow(2,l),p=n/I,E=s/I,f=t+g*p,Q=f+p,y=r-h*E,v=y-E,S=Od(f),G=Od(Q),H=C_(y),Y=C_(v);a[vp(o)]={x0:S,y0:H,x1:G,y1:Y,latMin:v,latMax:y,lonMin:f,lonMax:Q}}return a}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=vp(A);return this.pendingChunks.delete(s),this.emitLoadingState(),null}let r=vp(A),n=Vve(this.tileBounds[r]);try{let s=await this.tileCache.fetchTile(A,t,e,i,n);return this.pendingChunks.delete(r),s?(XSe(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?Xit(t):this.selector,i=this.currentLevel??this.maxLevelIndex,r=this.zarrStore.describe();return fKA(this.variable,A,e,this.zarrStore,this.crs,this.xyLimits,i,this.tileSize,{scaleFactor:r.scaleFactor,addOffset:r.addOffset,fillValue:r.fill_value})}},kKA=1e4,RKA=1e3,MKA=270;function $it(A){return isFinite(A)?((A+180)%360+360)%360-180:A}function GKA(A){let{bounds:t,width:e,height:i,latIsAscending:r,transformer:n}=A,s=e>1?e/(e-1):1,a=i>1?i/(i-1):1;return new qit({forwardTransform:(o,l)=>FCt(o*s,l*a,t,e,i,r),inverseTransform:(o,l)=>{let[g,h]=nHt(o,l,t,e,i,r);return[g/s,h/a]},forwardReproject:(o,l)=>n.forward(o,l),inverseReproject:(o,l)=>n.inverse(o,l)},e,i)}function NKA(A,t,e,i,r=!1){return{lon0:Od(A),lat0:(e+90)/180,lon1:Od(t),lat1:(i+90)/180,crossesAntimeridian:r}}function FKA(A,t,e,i,r,n=!1){let s=A.length/2,a=new Float32Array(s*2),o=n?360-t+e||1:e-t||1,l=r-i||1;for(let g=0;g<s;g++){let h=A[g*2],I=A[g*2+1];h=$it(h),n&&h<t&&(h+=360),a[g*2]=(h-t)/o*2-1,a[g*2+1]=(I-i)/l*2-1}return a}function TPt(A,t){return Math.abs(A-t)>180}function Zve(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 LKA(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],I=e[g+1],p=e[g+2];n[h]&&n[I]&&n[p]&&l.push(h,I,p)}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 a=new Array(t.length);for(let l=0;l<t.length;l++)a[l]=t[l];let o=[];for(let l=0;l<e.length;l+=3){let g=e[l],h=e[l+1],I=e[l+2];if(!n[g]||!n[h]||!n[I])continue;let p=A[g*2],E=A[g*2+1],f=t[g*2],Q=t[g*2+1],y=A[h*2],v=A[h*2+1],S=t[h*2],G=t[h*2+1],H=A[I*2],Y=A[I*2+1],z=t[I*2],N=t[I*2+1],F=$it(p),O=$it(y),K=$it(H),$=TPt(F,O),nt=TPt(O,K),tt=TPt(K,F),W=($?1:0)+(nt?1:0)+(tt?1:0);if(W===0)o.push(g,h,I);else if(W===2){let V=$?nt?[1,2,0]:[0,1,2]:[2,0,1],[it,at,pt]=V,Ct=[g,h,I],mt=[F,O,K],ft=[E,v,Y],Qt=[f,S,z],yt=[Q,G,N],Mt=Ct[it],qt=Ct[at],ie=Ct[pt],Dt=mt[it],Pe=ft[it],me=Qt[it],ue=yt[it],Et=mt[at],xe=ft[at],vA=Qt[at],ce=yt[at],$A=mt[pt],sA=ft[pt],rA=Qt[pt],le=yt[pt],YA=Zve(Dt,Pe,Et,xe),Ci=Zve(Dt,Pe,$A,sA),Li=me+YA.t*(vA-me),eA=ue+YA.t*(ce-ue),he=me+Ci.t*(rA-me),UA=ue+Ci.t*(le-ue),MA=Dt>0,nA=MA?179.9999:-179.9999,je=MA?-179.9999:179.9999,We=s.length/2;s.push(nA,YA.lat,nA,Ci.lat),s.push(je,YA.lat,je,Ci.lat),a.push(Li,eA,he,UA),a.push(Li,eA,he,UA);let Vt=We,jt=We+1,we=We+2,Ye=We+3;o.push(Mt,Vt,jt),o.push(we,qt,ie),o.push(we,ie,Ye)}else o.push(g,h,I)}return{positions:new Float64Array(s),texCoords:new Float64Array(a),indices:new Uint32Array(o)}}function TKA(A){let{geoBounds:t,width:e,height:i,subdivisions:r,transformer:n,latIsAscending:s,maxError:a=BqA}=A,{xMin:o,xMax:l,yMin:g,yMax:h}=t,p=GKA({bounds:[o,g,l,h],width:e,height:i,latIsAscending:s,transformer:n});for(let it=0;it<RKA&&p.getMaxError()>a;it++){let at=p.uvs.length/2;p.refine();let pt=p.uvs.length/2;if(pt>=kKA||pt===at)break}let E=p.uvs,f=(r+1)**2,Q=new Float64Array(E.length+f*2);Q.set(E);let y=E.length;for(let it=0;it<=r;it++)for(let at=0;at<=r;at++)Q[y++]=at/r,Q[y++]=it/r;let S=new jit(Q).triangles,G=Q.length/2,H=new Float64Array(G*2),Y=[],z=1/0,N=-1/0;for(let it=0;it<G;it++){let at=Q[it*2],pt=Q[it*2+1],Ct=o+at*(l-o),mt=s?g+pt*(h-g):h-pt*(h-g),[ft,Qt]=n.forward(Ct,mt);H[it*2]=ft,H[it*2+1]=Qt,isFinite(ft)&&isFinite(Qt)&&(Y.push($it(ft)),z=Math.min(z,Qt),N=Math.max(N,Qt))}isFinite(z)||(z=-90),isFinite(N)||(N=90);let F=-180,O=180,K=!1;if(Y.length>0){Y.sort((at,pt)=>at-pt),F=Y[0],O=Y[Y.length-1];let it=O-F;if(it>0){let at=0,pt=0;for(let mt=0;mt<Y.length-1;mt++){let ft=Y[mt+1]-Y[mt];ft>at&&(at=ft,pt=mt+1)}Y[0]+360-Y[Y.length-1]<at&&it<MKA&&(K=!0,F=Y[pt],O=Y[pt-1])}}K&&F>=180&&(F=F-360,F<=O&&(K=!1));let $=K||O-F>=180,nt=new Float64Array(Q),tt=LKA(H,nt,S,$),W=FKA(tt.positions,F,O,z,N,K),V=NKA(F,O,z,N,K);return{positions:W,texCoords:new Float32Array(tt.texCoords),indices:tt.indices,wgs84Bounds:V}}var UKA=128,PKA=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=qSe(),this.requestCanceller=ZSe(),this.loadingManager=$Se(),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=zF(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=oKA(this.proj4def,t),this.cachedWGS84Transformer=Art(this.proj4def),this.cached4326Transformer=lKA(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=jve(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],a=A.shape;if(n<a[t]||s<a[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>UKA;){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:a,yMin:o,yMax:l}=this.xyLimits,[g,h]=this.regionSize;if(this.proj4def&&this.cachedWGS84Transformer){let K=this.cachedWGS84Transformer,$=Math.ceil(this.width/h),nt=Math.ceil(this.height/g),tt=[];for(let W=0;W<nt;W++)for(let V=0;V<$;V++){let it=this.getRegionBounds(V,W),at=(it.xMin+it.xMax)/2,pt=(it.yMin+it.yMax)/2,mt=[K.inverse(it.xMin,it.yMin),K.inverse(it.xMax,it.yMin),K.inverse(it.xMax,it.yMax),K.inverse(it.xMin,it.yMax),K.inverse(at,it.yMin),K.inverse(at,it.yMax),K.inverse(it.xMin,pt),K.inverse(it.xMax,pt)].filter(qt=>isFinite(qt[0])&&isFinite(qt[1]));if(mt.length===0)continue;let ft=Math.min(...mt.map(qt=>qt[0])),Qt=Math.max(...mt.map(qt=>qt[0])),yt=Math.min(...mt.map(qt=>qt[1])),Mt=Math.max(...mt.map(qt=>qt[1]));Qt>=e&&ft<=r&&Mt>=i&&yt<=n&&tt.push({regionX:V,regionY:W})}return tt}let I=CCt(e,s,a,this.width),p=CCt(r,s,a,this.width),E=CCt(i,o,l,this.height),f=CCt(n,o,l,this.height);this.latIsAscending===!1&&(E=this.height-1-E,f=this.height-1-f);let Q=Math.floor(Math.min(I,p)/h),y=Math.floor(Math.max(I,p)/h),v=Math.floor(Math.min(E,f)/g),S=Math.floor(Math.max(E,f)/g),G=Math.ceil(this.width/h),H=Math.ceil(this.height/g),Y=Math.max(0,Q),z=Math.min(G-1,y),N=Math.max(0,v),F=Math.min(H-1,S),O=[];for(let K=N;K<=F;K++)for(let $=Y;$<=z;$++)O.push({regionX:$,regionY:K});return O}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 a=0;a<i.length;a++)for(let o=0;o<t.length;o++)n.push([...t[o],i[a]]),s.push([...e[o],r[a]]);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,a]=n,{xMin:o,xMax:l,yMin:g,yMax:h}=this.xyLimits,I=A*a,p=Math.min(I+a,i),E=t*s,f=Math.min(E+s,r),Q=o+I/i*(l-o),y=o+p/i*(l-o),v,S;return this.latIsAscending===!1?(S=h-E/r*(h-g),v=h-f/r*(h-g)):(v=g+E/r*(h-g),S=g+f/r*(h-g)),{xMin:Q,xMax:y,yMin:v,yMax:S}}createRegionGeometry(A,t,e,i){if(!i.levelMeta&&!this.regionSize)return;let r=this.getRegionBounds(A,t,i.levelMeta??void 0),n=i.mercatorBounds??jve(r,this.crs);if(i.mercatorBounds=n,this.proj4def&&this.cached4326Transformer){let s=(r.xMin+r.xMax)/2,a=(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,a)].map(p=>p[1]).filter(p=>isFinite(p)),g=l.length>0?Math.max(...l)-Math.min(...l):0,h=Math.max(Gve,Math.min(Nve,Math.ceil(g))),I=TKA({geoBounds:r,width:i.width,height:i.height,subdivisions:h,transformer:this.cached4326Transformer,latIsAscending:this.latIsAscending});i.vertexArr=I.positions,i.pixCoordArr=I.texCoords,i.indexArr=I.indices,i.wgs84Bounds=I.wgs84Bounds,i.useIndexedMesh=!0,i.vertexCount=i.indexArr.length}else{let s;if(this.crs==="EPSG:3857"){let l=.5-r.yMin/(2*L1),g=.5-r.yMax/(2*L1);s=Math.abs(VF(g)-VF(l))}else s=Math.abs(r.yMax-r.yMin);let a=this.isGlobeProjection?Math.max(Gve,Math.min(Nve,Math.ceil(s))):EqA,o=RSe(a);if(i.vertexArr=o.vertexArr,i.useIndexedMesh=!1,i.vertexCount=o.vertexArr.length/2,this.crs==="EPSG:4326"){let l=r.yMin,g=r.yMax;i.mercatorBounds={x0:Od(r.xMin),x1:Od(r.xMax),y0:C_(g),y1:C_(l),latMin:l,latMax:g},i.latIsAscending=this.latIsAscending,i.pixCoordArr=o.texCoordArr}else i.pixCoordArr=this.latIsAscending?tKA(o.texCoordArr):o.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],a=this.classifyDimension(n);if(a==="lon")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.x:t.spatialBounds?.type==="bbox"?e[s.index]=Im(t.spatialBounds.minX,t.spatialBounds.maxX):e[s.index]=t.includeSpatialSlices?Im(0,this.width):0;else if(a==="lat")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.y:t.spatialBounds?.type==="bbox"?e[s.index]=Im(t.spatialBounds.minY,t.spatialBounds.maxY):e[s.index]=t.includeSpatialSlices?Im(0,this.height):0;else{let o=A[n]||(a==="time"?A.time:void 0);if(o!==void 0){let l=o.selected,g=o.type;if(t.trackMultiValue&&Array.isArray(l)&&l.length>1){let h=[],I=[];for(let p of l){let E=await this.resolveSelectionIndex(n,s,p,g);h.push(E),I.push(p)}i.push({dimIndex:s.index,dimName:n,values:h,labels:I}),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:o,regionY:l}of e)this.visibleRegionKeys.add(this.makeRegionKey(i,o,l));if(this.currentLevelCoversViewport()){let o=`${i}:`;for(let l of this.visibleRegionKeys)l.startsWith(o)||this.visibleRegionKeys.delete(l)}let r=[],n=[];for(let{regionX:o,regionY:l}of e){let g=this.makeRegionKey(i,o,l),h=this.regionCache.get(g);h?.loading||(h?.data?h.selectorVersion!==this.selectorVersion&&n.push({regionX:o,regionY:l}):r.push({regionX:o,regionY:l}))}let s=`${i}:${this.selectorVersion}:${e.map(o=>`${o.regionX},${o.regionY}`).join("|")}`,a=s!==this.lastViewportHash;this.lastViewportHash=s,!(r.length===0&&n.length===0&&!a)&&(r.length>0&&this.fetchRegions(r,t),n.length>0&&this.fetchRegionsThrottled(n,t))}fetchRegionsThrottled(A,t){let e=KSe(this.throttleState,this.throttleMs);if(e>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),zSe(this.throttleState,e,this.invalidate);return}WSe(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 a=this.makeRegionKey(e.index,n,s),o=this.regionCache.get(a);o||(o=this.createRegionState(e.index,n,s),this.regionCache.set(a,o)),o.loading=!0}let i=32,r=[];for(let{regionX:n,regionY:s}of A){if(this.currentLevelIndex!==e.index){kCt(this.requestCanceller),this.clearBatchLoadingFlags(A,e.index);break}let a=this.fetchRegion(n,s,t,e).then(()=>{r.splice(r.indexOf(a),1)}).catch(()=>{r.splice(r.indexOf(a),1)});r.push(a),r.length>=i&&await Promise.race(r)}r.length>0&&await Promise.allSettled(r),mKA(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,a=new AbortController;this.requestCanceller.controllers.set(n,a);let o=this.regionCache.get(r);o||(o=this.createRegionState(i.index,A,t),this.regionCache.set(r,o)),o.loading=!0;let[l,g]=i.regionSize,h=t*l,I=Math.min(h+l,i.height),p=A*g,E=Math.min(p+g,i.width),f=E-p,Q=I-h;try{let y=[...i.baseSliceArgs],v=this.dimIndices.lat.index,S=this.dimIndices.lon.index;y[v]=Im(h,I),y[S]=Im(p,E);let G=this.zarrStore.describe(),H=this.levels[i.index],Y=H?.fillValue??G.fill_value,{combinations:z}=this.buildChannelCombinations(i.baseMultiValueDims),N=z.length||1,F=f*Q,O=[],K=new Float32Array(F*N);if(K.fill(Y??0),N===1){if(a.signal.aborted||this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let mt=await r2(i.zarrArray,y,{opts:{signal:a.signal}});if(a.signal.aborted||this.isRemoved){o.loading=!1;return}if(this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let ft=new Float32Array(mt.data);O.push(ft),K.set(ft)}else for(let mt=0;mt<N;mt++){if(a.signal.aborted||this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let ft=[...y],Qt=z[mt];for(let qt=0;qt<i.baseMultiValueDims.length;qt++)ft[i.baseMultiValueDims[qt].dimIndex]=Qt[qt];let yt=await r2(i.zarrArray,ft,{opts:{signal:a.signal}});if(a.signal.aborted||this.isRemoved){o.loading=!1;return}if(this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let Mt=new Float32Array(yt.data);O.push(Mt);for(let qt=0;qt<F;qt++)K[qt*N+mt]=Mt[qt]}if(s<o.selectorVersion){o.loading=!1;return}o.selectorVersion=s,XSe(this.requestCanceller,n);let $=O,nt=f,tt=Q;if(this.proj4def&&this.cachedMercatorTransformer&&this.xyLimits&&!o.mercatorBounds){let mt={width:i.width,height:i.height,regionSize:i.regionSize},ft=this.getRegionBounds(A,t,mt);o.mercatorBounds=this.computeRegionMercatorBounds(ft)}let V=H?.scaleFactor??G.scaleFactor,it=H?.addOffset??G.addOffset;o.bandData.clear(),o.bandTexturesUploaded.clear();let at=[];for(let mt=0;mt<$.length;mt++){let ft=this.bandNames[mt]||`band_${mt}`,Qt=$[mt];if(V!==1||it!==0){let qt=new Float32Array(Qt.length);for(let ie=0;ie<Qt.length;ie++){let Dt=Qt[ie];Number.isFinite(Dt)?qt[ie]=Dt*V+it:qt[ie]=Dt}Qt=qt}let yt=Y!==null&&(V!==1||it!==0)?Y*V+it:Y,{normalized:Mt}=DSe(Qt,yt,this.fixedDataScale);o.bandData.set(ft,Mt),at.push(Mt)}o.data=kSe(at,N);let pt=!o.vertexBuffer||o.width!==nt||o.height!==tt;o.width=nt,o.height=tt,o.channels=N,o.loading=!1,o.levelMeta={width:i.width,height:i.height,regionSize:[...i.regionSize]},o.texture||(o.texture=e.createTexture());let Ct=nKA(e,{texture:o.texture,data:o.data,width:nt,height:tt,channels:N,configured:!1});o.textureUploaded=Ct.uploaded,pt&&this.createRegionGeometry(A,t,e,o),this.invalidate()}catch(y){y instanceof DOMException&&y.name==="AbortError"||console.error(`[fetchRegion] Error fetching region ${r}:`,y),o.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,kCt(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),a=2*L1;e=s/a}else if(this.crs==="EPSG:3857"){let r=this.xyLimits.xMax-this.xyLimits.xMin,n=2*L1;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,a=n.shape[s]/e;i.push({index:r,effectivePixels:a})}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],a=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=a,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;iHt(r,t,i);for(let n of this.getLoadedRegions())NCt(r,t,this.regionToRenderable(n),e,i)}renderToTile(A,t,e){return rDe({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,VSe(this.throttleState),kCt(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){tDe(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=zve(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=zve(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=zF(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),eDe(this.loadingManager)}async resolveSelectionIndex(A,t,e,i){if(i==="index"||!this.zarrStore.root)return typeof e=="number"?e:0;try{let r=await ySe(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,a=i.map(h=>h.dimName);if(t.type==="point"){let h=[];if(s===1){let I=await r2(this.zarrArray,e),p=this.extractScalarValue(I);if(p===null)return null;h.push(p)}else for(let I=0;I<s;I++){let p=[...e],E=r[I];for(let y=0;y<i.length;y++)p[i[y].dimIndex]=E[y];let f=await r2(this.zarrArray,p),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:a}}let o=t.maxX-t.minX,l=t.maxY-t.minY;if(s===1){let h=await r2(this.zarrArray,e);return{type:"bbox",values:[],data:new Float32Array(h.data),width:o,height:l,channels:1,channelLabels:n,multiValueDimNames:a}}let g=new Float32Array(o*l*s);for(let h=0;h<s;h++){let I=[...e],p=r[h];for(let f=0;f<i.length;f++)I[i[f].dimIndex]=p[f];let E=await r2(this.zarrArray,I);for(let f=0;f<o*l;f++)g[f*s+h]=E.data[f]}return{type:"bbox",values:[],data:g,width:o,height:l,channels:s,channelLabels:n,multiValueDimNames:a}}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?Xit(t):this.selector,i=this.zarrStore.describe(),r=this.levels[this.currentLevelIndex],n=r?.scaleFactor??i.scaleFactor,s=r?.addOffset??i.addOffset,a=r?.fillValue??i.fill_value;if(A.type==="Point"){let[S,G]=A.coordinates,H={lat:[G],lon:[S]},Y=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,z=BKA(S,G,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 N=await this.fetchQueryData(e,{type:"point",x:z.x,y:z.y});if(!N)return{[this.variable]:[],dimensions:["lat","lon"],coordinates:H};let{values:F,channelLabels:O,multiValueDimNames:K}=N,$=K.length>0,nt=$?{}:[];for(let at=0;at<F.length;at++){let pt=F[at];if(!(pt==null||!Number.isFinite(pt))&&!(a!==null&&pt===a))if(n!==1&&(pt*=n),s!==0&&(pt+=s),$){let Ct=O?.[at];Ct&&K.length>0&&Ct.length===K.length?nt=aHt(nt,Ct,pt):Array.isArray(nt)&&nt.push(pt)}else Array.isArray(nt)&&nt.push(pt)}let tt=i.dimensions,W=tt.map(at=>{let pt=at.toLowerCase();return["x","lon","longitude"].includes(pt)?"lon":["y","lat","latitude"].includes(pt)?"lat":at}),V=$?W:["lat","lon"],it={lat:H.lat,lon:H.lon};if($)for(let at of tt){let pt=at.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(pt))continue;let Ct=e[at];if(Ct&&"selected"in Ct){let mt=Ct.selected,ft=Array.isArray(mt)?mt:[mt];it[at]=ft}else i.coordinates[at]&&(it[at]=i.coordinates[at])}return{[this.variable]:nt,dimensions:V,coordinates:it}}let o=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,l=gKA(A,this.mercatorBounds,this.width,this.height,this.crs??"EPSG:4326",this.latIsAscending,this.proj4def,o,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:I,minY:p,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+I/this.width*f,y0:this.mercatorBounds.y0+p/this.height*Q,y1:this.mercatorBounds.y0+E/this.height*Q};if(this.mercatorBounds.latMin!==void 0&&this.mercatorBounds.latMax!==void 0){let S=this.mercatorBounds.latMax-this.mercatorBounds.latMin;this.latIsAscending?(y.latMin=this.mercatorBounds.latMin+p/this.height*S,y.latMax=this.mercatorBounds.latMin+E/this.height*S):(y.latMax=this.mercatorBounds.latMax-p/this.height*S,y.latMin=this.mercatorBounds.latMax-E/this.height*S)}let v=null;if(this.proj4def&&o){let[S,G]=FCt(h,p,o,this.width,this.height,this.latIsAscending),[H,Y]=FCt(I,E,o,this.width,this.height,this.latIsAscending);v=[Math.min(S,H),Math.min(G,Y),Math.max(S,H),Math.max(G,Y)]}return _KA(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:a},this.proj4def,v)}},nDe=class{constructor({id:A,source:t,variable:e,selector:i={},colormap:r,clim:n,opacity:s=1,minzoom:a=0,maxzoom:o=1/0,zarrVersion:l,spatialDimensions:g={},bounds:h,crs:I,latIsAscending:p=null,fillValue:E,customFrag:f,uniforms:Q,renderingMode:y="3d",onLoadingStateChange:v,throttleMs:S=100,proj4:G,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=PqA,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]");G&&!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=I,this.latIsAscending=p??null,this.selector=i,this.normalizedSelector=Xit(i),this.selectorHash=this.computeSelectorHash(this.normalizedSelector),this.renderingMode=y,this.invalidate=()=>{},this.colormap=new JqA(r),this.clim=n,this.fixedDataScale=Math.max(Math.abs(n[0]),Math.abs(n[1]),1),this.opacity=s,this.minZoom=a,this.maxZoom=o,this.customFrag=f,this.customUniforms=Q||{},this.bandNames=zF(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=v,this.throttleMs=S,this.proj4=G,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 USe(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=Xit(A),e=this.computeSelectorHash(t);e!==this.selectorHash&&(this.selectorHash=e,this.selector=A,this.normalizedSelector=t,this.bandNames=zF(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 aKA(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 DKA(this.zarrStore,this.variable,this.normalizedSelector,this.invalidate,this.throttleMs,this.fixedDataScale):this.mode=new PKA(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 bqA({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=Xit(this.selector),await this.loadInitialDimensionValues(),this.bandNames=zF(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]=xSe(e);for(let t of Object.keys(this.dimIndices))if(!fqA.has(t.toLowerCase()))try{this.dimensionValues[t]=await ySe(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 a=eKA(t,e,i,r);if(!a.matrix)return;let o=!a.mapbox&&!a.shaderData?{projection:{name:"mercator"},globeToMercatorMatrix:FJ,transition:1}:void 0,l=this.isGlobeProjection(),g=AKA(this.map,l),h=this.colormap.ensureTexture(this.gl),I={gl:this.gl,matrix:a.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:a.shaderData,projectionData:a.projectionData,mapbox:a.mapbox??o};this.mode.render(this.renderer,I),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 HCt=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")),a=[...n,...s];for(let[g,h]of a)this.executeMethod("addLayer",[],h);let o=this.model.get("_controls")||{},l=Object.keys(i);for(let[g,h]of Object.entries(o)){let I=h;I.type==="layer-control"?this.executeMethod("addLayerControl",[],{position:I.position,layers:l,...I.options}):I.type==="draw-control"?this.executeMethod("addDrawControl",[],{position:I.position,...I.options}):I.type==="control-grid"?this.executeMethod("addControlGrid",[],{position:I.position,...I.options}):this.executeMethod("addControl",[I.type],{position:I.position,...I.options})}}getMap(){return this.map}getIsMapReady(){return this.isMapReady}getModel(){return this.model}};var OCt=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")||{}}};jYt();var $Ne=Zl(ky(),1),Z9=63710088e-1,tFe={centimeters:Z9*100,centimetres:Z9*100,degrees:360/(2*Math.PI),feet:Z9*3.28084,inches:Z9*39.37,kilometers:Z9/1e3,kilometres:Z9/1e3,meters:Z9,metres:Z9,miles:Z9/1609.344,millimeters:Z9*1e3,millimetres:Z9*1e3,nauticalmiles:Z9/1852,radians:1,yards:Z9*1.0936};function VE(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 u3(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(!rNe(A[0])||!rNe(A[1]))throw new Error("coordinates must contain numbers");return VE({type:"Point",coordinates:A},t,e)}function Fm(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 VE({type:"Polygon",coordinates:A},t,e)}function O1(A,t,e={}){if(A.length<2)throw new Error("coordinates must be an array of two or more positions");return VE({type:"LineString",coordinates:A},t,e)}function tl(A,t={}){let e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=A,e}function eFe(A,t,e={}){return VE({type:"MultiLineString",coordinates:A},t,e)}function cft(A,t,e={}){return VE({type:"MultiPolygon",coordinates:A},t,e)}function bJt(A,t="kilometers"){let e=tFe[t];if(!e)throw new Error(t+" units is invalid");return A*e}function AFe(A,t="kilometers"){let e=tFe[t];if(!e)throw new Error(t+" units is invalid");return A/e}function PEt(A){return A%(2*Math.PI)*180/Math.PI}function CB(A){return A%360*Math.PI/180}function iFe(A,t="kilometers",e="kilometers"){if(!(A>=0))throw new Error("length must be a positive number");return bJt(AFe(A,t),e)}function rNe(A){return!isNaN(A)&&A!==null&&!Array.isArray(A)}function fnt(A){return A!==null&&typeof A=="object"&&!Array.isArray(A)}function I3(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 qd(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 Lm(A){return A.type==="Feature"?A.geometry:A}function HEt(A,t){return A.type==="FeatureCollection"?"FeatureCollection":A.type==="GeometryCollection"?"GeometryCollection":A.type==="Feature"&&A.geometry!==null?A.geometry.type:A.type}function rFe(A,t,e={}){if(e.final===!0)return Oni(A,t);let i=I3(A),r=I3(t),n=CB(i[0]),s=CB(r[0]),a=CB(i[1]),o=CB(r[1]),l=Math.sin(s-n)*Math.cos(o),g=Math.cos(a)*Math.sin(o)-Math.sin(a)*Math.cos(o)*Math.cos(s-n);return PEt(Math.atan2(l,g))}function Oni(A,t){let e=rFe(t,A);return e=(e+180)%360,e}function pnt(A,t,e={}){var i=I3(A),r=I3(t),n=CB(r[1]-i[1]),s=CB(r[0]-i[0]),a=CB(i[1]),o=CB(r[1]),l=Math.pow(Math.sin(n/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(o);return bJt(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),e.units)}function Yni(A,t,e={}){let i;return e.final?i=nNe(I3(t),I3(A)):i=nNe(I3(A),I3(t)),i>180?-(360-i):i}function nNe(A,t){let e=CB(A[1]),i=CB(t[1]),r=CB(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(PEt(s)+360)%360}function Fk(A,t,e){if(A!==null)for(var i,r,n,s,a,o,l,g=0,h=0,I,p=A.type,E=p==="FeatureCollection",f=p==="Feature",Q=E?A.features.length:1,y=0;y<Q;y++){l=E?A.features[y].geometry:f?A.geometry:A,I=l?l.type==="GeometryCollection":!1,a=I?l.geometries.length:1;for(var v=0;v<a;v++){var S=0,G=0;if(s=I?l.geometries[v]:l,s!==null){o=s.coordinates;var H=s.type;switch(g=e&&(H==="Polygon"||H==="MultiPolygon")?1:0,H){case null:break;case"Point":if(t(o,h,y,S,G)===!1)return!1;h++,S++;break;case"LineString":case"MultiPoint":for(i=0;i<o.length;i++){if(t(o[i],h,y,S,G)===!1)return!1;h++,H==="MultiPoint"&&S++}H==="LineString"&&S++;break;case"Polygon":case"MultiLineString":for(i=0;i<o.length;i++){for(r=0;r<o[i].length-g;r++){if(t(o[i][r],h,y,S,G)===!1)return!1;h++}H==="MultiLineString"&&S++,H==="Polygon"&&G++}H==="Polygon"&&S++;break;case"MultiPolygon":for(i=0;i<o.length;i++){for(G=0,r=0;r<o[i].length;r++){for(n=0;n<o[i][r].length-g;n++){if(t(o[i][r][n],h,y,S,G)===!1)return!1;h++}G++}S++}break;case"GeometryCollection":for(i=0;i<s.geometries.length;i++)if(Fk(s.geometries[i],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function l7(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 Jni(A,t,e){var i=e;return l7(A,function(r,n){n===0&&e===void 0?i=r:i=t(i,r,n)}),i}function jni(A){var t=[];return Fk(A,function(e){t.push(e)}),t}function Lk(A,t){var e,i,r,n,s,a,o,l,g,h,I=0,p=A.type==="FeatureCollection",E=A.type==="Feature",f=p?A.features.length:1;for(e=0;e<f;e++){for(a=p?A.features[e].geometry:E?A.geometry:A,l=p?A.features[e].properties:E?A.properties:{},g=p?A.features[e].bbox:E?A.bbox:void 0,h=p?A.features[e].id:E?A.id:void 0,o=a?a.type==="GeometryCollection":!1,s=o?a.geometries.length:1,r=0;r<s;r++){if(n=o?a.geometries[r]:a,n===null){if(t(null,I,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,I,l,g,h)===!1)return!1;break}case"GeometryCollection":{for(i=0;i<n.geometries.length;i++)if(t(n.geometries[i],I,l,g,h)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}I++}}function qni(A,t,e){var i=e;return Lk(A,function(r,n,s,a,o){i=t(i,r,n,s,a,o)}),i}function g7(A,t){Lk(A,function(e,i,r,n,s){var a=e===null?null:e.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return t(VE(e,r,{bbox:n,id:s}),i,0)===!1?!1:void 0}var o;switch(a){case"MultiPoint":o="Point";break;case"MultiLineString":o="LineString";break;case"MultiPolygon":o="Polygon";break}for(var l=0;l<e.coordinates.length;l++){var g=e.coordinates[l],h={type:o,coordinates:g};if(t(VE(h,r),i,l)===!1)return!1}})}function int(A,t){g7(A,function(e,i,r){var n=0;if(e.geometry){var s=e.geometry.type;if(!(s==="Point"||s==="MultiPoint")){var a,o=0,l=0,g=0;if(Fk(e,function(h,I,p,E,f){if(a===void 0||i>o||E>l||f>g){a=h,o=i,l=E,g=f,n=0;return}var Q=O1([a,h],e.properties);if(t(Q,i,r,f,n)===!1)return!1;n++,a=h})===!1)return!1}}})}function OEt(A){return qni(A,(t,e)=>t+Kni(e),0)}function Kni(A){let t=0,e;switch(A.type){case"Polygon":return sNe(A.coordinates);case"MultiPolygon":for(e=0;e<A.coordinates.length;e++)t+=sNe(A.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function sNe(A){let t=0;if(A&&A.length>0){t+=Math.abs(aNe(A[0]));for(let e=1;e<A.length;e++)t-=Math.abs(aNe(A[e]))}return t}var zni=Z9*Z9/2,qYt=Math.PI/180;function aNe(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],a=r[0]*qYt,o=n[1]*qYt,l=s[0]*qYt;e+=(l-a)*Math.sin(o),i++}return e*zni}function Mu(A,t={}){if(A.bbox!=null&&t.recompute!==!0)return A.bbox;let e=[1/0,1/0,-1/0,-1/0];return Fk(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 Wni(A,t,e){var i=A.length,r=wj(A[0],t),n=[],s,a,o;let l,g;for(e||(e=[]),s=1;s<i;s++){for(l=A[s-1],g=A[s],a=o=wj(g,t);;)if(r|a){if(r&a)break;r?(l=oJt(l,g,r,t),r=wj(l,t)):(g=oJt(l,g,a,t),a=wj(g,t))}else{n.push(l),a!==o?(n.push(g),s<i-1&&(e.push(n),n=[])):s===i-1&&n.push(g);break}r=o}return n.length&&e.push(n),e}function Vni(A,t){var e,i,r,n,s,a,o;for(i=1;i<=8;i*=2){for(e=[],r=A[A.length-1],n=!(wj(r,t)&i),s=0;s<A.length;s++)a=A[s],o=!(wj(a,t)&i),o!==n&&e.push(oJt(r,a,i,t)),o&&e.push(a),r=a,n=o;if(A=e,!A.length)break}return e}function oJt(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 wj(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 Zni(A,t){let e=Lm(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(a=>{Wni(a,t,s)}),s.length===1?O1(s[0],r):eFe(s,r)}case"Polygon":return Fm(oNe(n,t),r);case"MultiPolygon":return cft(n.map(s=>oNe(s,t)),r);default:throw new Error("geometry "+i+" not supported")}}function oNe(A,t){let e=[];for(let i of A){let r=Vni(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 o7=11102230246251565e-32,H1=134217729,Xni=(3+8*o7)*o7;function KYt(A,t,e,i,r){let n,s,a,o,l=t[0],g=i[0],h=0,I=0;g>l==g>-l?(n=l,l=t[++h]):(n=g,g=i[++I]);let p=0;if(h<A&&I<e)for(g>l==g>-l?(s=l+n,a=n-(s-l),l=t[++h]):(s=g+n,a=n-(s-g),g=i[++I]),n=s,a!==0&&(r[p++]=a);h<A&&I<e;)g>l==g>-l?(s=n+l,o=s-n,a=n-(s-o)+(l-o),l=t[++h]):(s=n+g,o=s-n,a=n-(s-o)+(g-o),g=i[++I]),n=s,a!==0&&(r[p++]=a);for(;h<A;)s=n+l,o=s-n,a=n-(s-o)+(l-o),l=t[++h],n=s,a!==0&&(r[p++]=a);for(;I<e;)s=n+g,o=s-n,a=n-(s-o)+(g-o),g=i[++I],n=s,a!==0&&(r[p++]=a);return(n!==0||p===0)&&(r[p++]=n),p}function $ni(A,t){let e=t[0];for(let i=1;i<A;i++)e+=t[i];return e}function _nt(A){return new Float64Array(A)}var tsi=(3+16*o7)*o7,esi=(2+12*o7)*o7,Asi=(9+64*o7)*o7*o7,_j=_nt(4),lNe=_nt(8),gNe=_nt(12),cNe=_nt(16),dB=_nt(4);function isi(A,t,e,i,r,n,s){let a,o,l,g,h,I,p,E,f,Q,y,v,S,G,H,Y,z,N,F=A-r,O=e-r,K=t-n,$=i-n;G=F*$,I=H1*F,p=I-(I-F),E=F-p,I=H1*$,f=I-(I-$),Q=$-f,H=E*Q-(G-p*f-E*f-p*Q),Y=K*O,I=H1*K,p=I-(I-K),E=K-p,I=H1*O,f=I-(I-O),Q=O-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,_j[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,_j[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,_j[2]=v-(N-h)+(y-h),_j[3]=N;let nt=$ni(4,_j),tt=esi*s;if(nt>=tt||-nt>=tt||(h=A-F,a=A-(F+h)+(h-r),h=e-O,l=e-(O+h)+(h-r),h=t-K,o=t-(K+h)+(h-n),h=i-$,g=i-($+h)+(h-n),a===0&&o===0&&l===0&&g===0)||(tt=Asi*s+Xni*Math.abs(nt),nt+=F*g+$*a-(K*l+O*o),nt>=tt||-nt>=tt))return nt;G=a*$,I=H1*a,p=I-(I-a),E=a-p,I=H1*$,f=I-(I-$),Q=$-f,H=E*Q-(G-p*f-E*f-p*Q),Y=o*O,I=H1*o,p=I-(I-o),E=o-p,I=H1*O,f=I-(I-O),Q=O-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,dB[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,dB[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,dB[2]=v-(N-h)+(y-h),dB[3]=N;let W=KYt(4,_j,4,dB,lNe);G=F*g,I=H1*F,p=I-(I-F),E=F-p,I=H1*g,f=I-(I-g),Q=g-f,H=E*Q-(G-p*f-E*f-p*Q),Y=K*l,I=H1*K,p=I-(I-K),E=K-p,I=H1*l,f=I-(I-l),Q=l-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,dB[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,dB[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,dB[2]=v-(N-h)+(y-h),dB[3]=N;let V=KYt(W,lNe,4,dB,gNe);G=a*g,I=H1*a,p=I-(I-a),E=a-p,I=H1*g,f=I-(I-g),Q=g-f,H=E*Q-(G-p*f-E*f-p*Q),Y=o*l,I=H1*o,p=I-(I-o),E=o-p,I=H1*l,f=I-(I-l),Q=l-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,dB[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,dB[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,dB[2]=v-(N-h)+(y-h),dB[3]=N;let it=KYt(V,gNe,4,dB,cNe);return cNe[it-1]}function rsi(A,t,e,i,r,n){let s=(t-n)*(e-r),a=(A-r)*(i-n),o=s-a,l=Math.abs(s+a);return Math.abs(o)>=tsi*l?o:-isi(A,t,e,i,r,n,l)}function nsi(A,t){var e,i,r=0,n,s,a,o,l,g,h,I=A[0],p=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]-I,a=g[1]-p,i;i<Q;i++){if(h=f[i+1],o=h[0]-I,l=h[1]-p,a===0&&l===0){if(o<=0&&s>=0||s<=0&&o>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(n=rsi(s,o,a,l,0,0),n===0)return 0;(n>0&&l>0&&a<=0||n<0&&l<=0&&a>0)&&r++}g=h,a=l,s=o}}return r%2!==0}function p3(A,t,e={}){if(!A)throw new Error("point is required");if(!t)throw new Error("polygon is required");let i=I3(A),r=Lm(t),n=r.type,s=t.bbox,a=r.coordinates;if(s&&ssi(i,s)===!1)return!1;n==="Polygon"&&(a=[a]);let o=!1;for(var l=0;l<a.length;++l){let g=nsi(i,a[l]);if(g===0)return!e.ignoreBoundary;g&&(o=!0)}return o}function ssi(A,t){return t[0]<=A[0]&&t[1]<=A[1]&&t[2]>=A[0]&&t[3]>=A[1]}function BB(A,t,e={}){let i=I3(A),r=qd(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")),asi(r[n],r[n+1],i,s,typeof e.epsilon>"u"?null:e.epsilon))return!0}return!1}function asi(A,t,e,i,r){let n=e[0],s=e[1],a=A[0],o=A[1],l=t[0],g=t[1],h=e[0]-a,I=e[1]-o,p=l-a,E=g-o,f=h*E-I*p;if(r!==null){if(Math.abs(f)>r)return!1}else if(f!==0)return!1;if(Math.abs(p)===Math.abs(E)&&Math.abs(p)===0)return i?!1:e[0]===A[0]&&e[1]===A[1];if(i){if(i==="start")return Math.abs(p)>=Math.abs(E)?p>0?a<n&&n<=l:l<=n&&n<a:E>0?o<s&&s<=g:g<=s&&s<o;if(i==="end")return Math.abs(p)>=Math.abs(E)?p>0?a<=n&&n<l:l<n&&n<=a:E>0?o<=s&&s<g:g<s&&s<=o;if(i==="both")return Math.abs(p)>=Math.abs(E)?p>0?a<n&&n<l:l<n&&n<a:E>0?o<s&&s<g:g<s&&s<o}else return Math.abs(p)>=Math.abs(E)?p>0?a<=n&&n<=l:l<=n&&n<=a:E>0?o<=s&&s<=g:g<=s&&s<=o;return!1}function osi(A,t,e,i,r){nFe(A,t,e||0,i||A.length-1,r||lsi)}function nFe(A,t,e,i,r){for(;i>e;){if(i-e>600){var n=i-e+1,s=t-e+1,a=Math.log(n),o=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*o*(n-o)/n)*(s-n/2<0?-1:1),g=Math.max(e,Math.floor(t-s*o/n+l)),h=Math.min(i,Math.floor(t+(n-s)*o/n+l));nFe(A,t,g,h,r)}var I=A[t],p=e,E=i;for($rt(A,e,t),r(A[i],I)>0&&$rt(A,e,i);p<E;){for($rt(A,p,E),p++,E--;r(A[p],I)<0;)p++;for(;r(A[E],I)>0;)E--}r(A[e],I)===0?$rt(A,e,E):(E++,$rt(A,E,i)),E<=t&&(e=E+1),t<=E&&(i=E-1)}}function $rt(A,t,e){var i=A[t];A[t]=A[e],A[e]=i}function lsi(A,t){return A<t?-1:A>t?1:0}var vJt=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(!mEt(t,e))return i;let r=this.toBBox,n=[];for(;e;){for(let s=0;s<e.children.length;s++){let a=e.children[s],o=e.leaf?r(a):a;mEt(t,o)&&(e.leaf?i.push(a):WYt(t,o)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!mEt(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(mEt(t,s)){if(e.leaf||WYt(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=yj([]),this}remove(t,e){if(!t)return this;let i=this.data,r=this.toBBox(t),n=[],s=[],a,o,l;for(;i||n.length;){if(i||(i=n.pop(),o=n[n.length-1],a=s.pop(),l=!0),i.leaf){let g=gsi(t,i.children,e);if(g!==-1)return i.children.splice(g,1),n.push(i),this._condense(n),this}!l&&!i.leaf&&WYt(i,r)?(n.push(i),s.push(a),a=0,o=i,i=i.children[0]):o?(a++,i=o.children[a],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,a;if(n<=s)return a=yj(t.slice(e,i+1)),mj(a,this.toBBox),a;r||(r=Math.ceil(Math.log(n)/Math.log(s)),s=Math.ceil(n/Math.pow(s,r-1))),a=yj([]),a.leaf=!1,a.height=r;let o=Math.ceil(n/s),l=o*Math.ceil(Math.sqrt(s));hNe(t,e,i,l,this.compareMinX);for(let g=e;g<=i;g+=l){let h=Math.min(g+l-1,i);hNe(t,g,h,o,this.compareMinY);for(let I=g;I<=h;I+=o){let p=Math.min(I+o-1,h);a.children.push(this._build(t,I,p,r-1))}}return mj(a,this.toBBox),a}_chooseSubtree(t,e,i,r){for(;r.push(e),!(e.leaf||r.length-1===i);){let n=1/0,s=1/0,a;for(let o=0;o<e.children.length;o++){let l=e.children[o],g=zYt(l),h=usi(t,l)-g;h<s?(s=h,n=g<n?g:n,a=l):h===s&&g<n&&(n=g,a=l)}e=a||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),nnt(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),a=yj(i.children.splice(s,i.children.length-s));a.height=i.height,a.leaf=i.leaf,mj(i,this.toBBox),mj(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=yj([t,e]),this.data.height=t.height+1,this.data.leaf=!1,mj(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let r,n=1/0,s=1/0;for(let a=e;a<=i-e;a++){let o=rnt(t,0,a,this.toBBox),l=rnt(t,a,i,this.toBBox),g=Isi(o,l),h=zYt(o)+zYt(l);g<n?(n=g,r=a,s=h<s?h:s):g===n&&h<s&&(s=h,r=a)}return r||i-e}_chooseSplitAxis(t,e,i){let r=t.leaf?this.compareMinX:csi,n=t.leaf?this.compareMinY:hsi,s=this._allDistMargin(t,e,i,r),a=this._allDistMargin(t,e,i,n);s<a&&t.children.sort(r)}_allDistMargin(t,e,i,r){t.children.sort(r);let n=this.toBBox,s=rnt(t,0,e,n),a=rnt(t,i-e,i,n),o=_Et(s)+_Et(a);for(let l=e;l<i-e;l++){let g=t.children[l];nnt(s,t.leaf?n(g):g),o+=_Et(s)}for(let l=i-e-1;l>=e;l--){let g=t.children[l];nnt(a,t.leaf?n(g):g),o+=_Et(a)}return o}_adjustParentBBoxes(t,e,i){for(let r=i;r>=0;r--)nnt(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():mj(t[e],this.toBBox)}};function gsi(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 mj(A,t){rnt(A,0,A.children.length,t,A)}function rnt(A,t,e,i,r){r||(r=yj(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];nnt(r,A.leaf?i(s):s)}return r}function nnt(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 csi(A,t){return A.minX-t.minX}function hsi(A,t){return A.minY-t.minY}function zYt(A){return(A.maxX-A.minX)*(A.maxY-A.minY)}function _Et(A){return A.maxX-A.minX+(A.maxY-A.minY)}function usi(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 Isi(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 WYt(A,t){return A.minX<=t.minX&&A.minY<=t.minY&&t.maxX<=A.maxX&&t.maxY<=A.maxY}function mEt(A,t){return t.minX<=A.maxX&&t.minY<=A.maxY&&t.maxX>=A.minX&&t.maxY>=A.minY}function yj(A){return{children:A,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function hNe(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;osi(A,s,t,e,r),n.push(t,s,s,e)}}function VYt(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=Mu(A);else if(A.type==="FeatureCollection")t=Mu(A);else throw new Error("invalid geojson");return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}}var psi=class{constructor(A=9){this.tree=new vJt(A),this.tree.toBBox=VYt}insert(A){if(A.type!=="Feature")throw new Error("invalid feature");return A.bbox=A.bbox?A.bbox:Mu(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:Mu(e),t.push(e)}):l7(A,function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:Mu(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:Mu(A),this.tree.remove(A,t),this}clear(){return this.tree.clear(),this}search(A){var t=this.tree.search(VYt(A));return tl(t)}collides(A){return this.tree.collides(VYt(A))}all(){let A=this.tree.all();return tl(A)}toJSON(){return this.tree.toJSON()}fromJSON(A){return this.tree.fromJSON(A),this}};function SJt(A){return new psi(A)}function dsi(A,t){if(t=t??{},!fnt(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 Fk(A,function(s){Csi(s,n,i)}),A}function Csi(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 sFe(A){if(!A)throw new Error("geojson is required");let t=[];return g7(A,e=>{Bsi(e,t)}),tl(t)}function Bsi(A,t){let e=[],i=A.geometry;if(i!==null){switch(i.type){case"Polygon":e=qd(i);break;case"LineString":e=[qd(i)]}e.forEach(r=>{Esi(r,A.properties).forEach(s=>{s.id=t.length,t.push(s)})})}}function Esi(A,t){let e=[];return A.reduce((i,r)=>{let n=O1([i,r],t);return n.bbox=fsi(i,r),e.push(n),r}),e}function fsi(A,t){let e=A[0],i=A[1],r=t[0],n=t[1],s=e<r?e:r,a=i<n?i:n,o=e>r?e:r,l=i>n?i:n;return[s,a,o,l]}var YEt=class{constructor(t=[],e=_si){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,a=e[s],o=s+1;if(o<this.length&&i(e[o],a)<0&&(s=o,a=e[o]),i(a,n)>=0)break;e[t]=a,t=s}e[t]=n}};function _si(A,t){return A<t?-1:A>t?1:0}function aFe(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 msi(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 JEt=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 Qsi(A,t){if(A.type==="FeatureCollection"){let e=A.features;for(let i=0;i<e.length;i++)uNe(e[i],t)}else uNe(A,t)}var QEt=0,yEt=0,xEt=0;function uNe(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],a=null;yEt=yEt+1;for(let o=0;o<i[r][n].length-1;o++){a=i[r][n][o+1];let l=new JEt(s,QEt,yEt,xEt),g=new JEt(a,QEt,yEt,xEt+1);l.otherEvent=g,g.otherEvent=l,aFe(l,g)>0?(g.isLeftEndpoint=!0,l.isLeftEndpoint=!1):(l.isLeftEndpoint=!0,g.isLeftEndpoint=!1),t.push(l),t.push(g),s=a,xEt=xEt+1}}QEt=QEt+1}var ysi=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function xsi(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,a=t.leftSweepEvent.p.y,o=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,g=(l-a)*(r-e)-(o-s)*(n-i),h=(o-s)*(i-a)-(l-a)*(e-s),I=(r-e)*(i-a)-(n-i)*(e-s);if(g===0)return!1;let p=h/g,E=I/g;if(p>=0&&p<=1&&E>=0&&E<=1){let f=e+p*(r-e),Q=i+p*(n-i);return[f,Q]}return!1}function wsi(A,t){t=t||!1;let e=[],i=new YEt([],msi);for(;A.length;){let r=A.pop();if(r.isLeftEndpoint){let n=new ysi(r);for(let s=0;s<i.data.length;s++){let a=i.data[s];if(t&&a.leftSweepEvent.featureId===r.featureId)continue;let o=xsi(n,a);o!==!1&&e.push(o)}i.push(n)}else r.isLeftEndpoint===!1&&i.pop()}return e}function bsi(A,t){let e=new YEt([],aFe);return Qsi(A,e),wsi(e,t)}var vsi=bsi;function Rj(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(VE(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(VE(t));let s=vsi(tl(n),r),a=[];if(i){let o={};s.forEach(l=>{let g=l.join(",");o[g]||(o[g]=!0,a.push(l))})}else a=s;return tl(a.map(o=>u3(o)))}var Ssi=Object.defineProperty,Dsi=Object.defineProperties,ksi=Object.getOwnPropertyDescriptors,INe=Object.getOwnPropertySymbols,Rsi=Object.prototype.hasOwnProperty,Msi=Object.prototype.propertyIsEnumerable,pNe=(A,t,e)=>t in A?Ssi(A,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):A[t]=e,Gsi=(A,t)=>{for(var e in t||(t={}))Rsi.call(t,e)&&pNe(A,e,t[e]);if(INe)for(var e of INe(t))Msi.call(t,e)&&pNe(A,e,t[e]);return A},Nsi=(A,t)=>Dsi(A,ksi(t));function bj(A,t,e={}){if(!A||!t)throw new Error("lines and inputPoint are required arguments");let i=I3(t),r=u3([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,a=-1;return g7(A,function(o,l,g){a!==g&&(a=g,s=0);let h=qd(o);for(let I=0;I<h.length-1;I++){let p=u3(h[I]),E=I3(p),f=u3(h[I+1]),Q=I3(f),y=pnt(p,f,e),v,S;Q[0]===i[0]&&Q[1]===i[1]?[v,S]=[Q,!0]:E[0]===i[0]&&E[1]===i[1]?[v,S]=[E,!1]:[v,S]=Tsi(E,Q,i);let G=pnt(t,v,e);if(G<r.properties.pointDistance){let H=pnt(p,v,e);r=u3(v,{lineStringIndex:g,segmentIndex:S?I+1:I,totalDistance:n+H,lineDistance:s+H,segmentDistance:H,pointDistance:G,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),r.properties=Nsi(Gsi({},r.properties),{multiFeatureIndex:r.properties.lineStringIndex,index:r.properties.segmentIndex,location:r.properties.totalDistance,dist:r.properties.pointDistance})}n+=y,s+=y}}),r}function EL(A,t){let[e,i,r]=A,[n,s,a]=t;return e*n+i*s+r*a}function tnt(A,t){let[e,i,r]=A,[n,s,a]=t;return[i*a-r*s,r*n-e*a,e*s-i*n]}function Fsi(A){return Math.sqrt(Math.pow(A[0],2)+Math.pow(A[1],2)+Math.pow(A[2],2))}function dNe(A){let t=Fsi(A);return[A[0]/t,A[1]/t,A[2]/t]}function ZYt(A){let t=CB(A[1]),e=CB(A[0]);return[Math.cos(t)*Math.cos(e),Math.cos(t)*Math.sin(e),Math.sin(t)]}function Lsi(A){let[t,e,i]=A,r=Math.min(Math.max(i,-1),1),n=PEt(Math.asin(r));return[PEt(Math.atan2(e,t)),n]}function Tsi(A,t,e){let i=ZYt(A),r=ZYt(t),n=ZYt(e),s=tnt(i,r);if(s[0]===0&&s[1]===0&&s[2]===0)return EL(i,r)>0?[[...t],!0]:[[...e],!1];let a=tnt(s,n);if(a[0]===0&&a[1]===0&&a[2]===0)return[[...t],!0];let o=tnt(a,s),l=dNe(o),g=[-l[0],-l[1],-l[2]],h=EL(n,l)>EL(n,g)?l:g,I=dNe(s),p=EL(tnt(i,h),I),E=EL(tnt(h,r),I);return p>=0&&E>=0?[Lsi(h),!1]:EL(i,n)>EL(r,n)?[[...A],!1]:[[...t],!0]}function DJt(A,t){if(!A)throw new Error("line is required");if(!t)throw new Error("splitter is required");let e=HEt(A),i=HEt(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=dsi(t,{precision:7});switch(A.type!=="Feature"&&(A=VE(A)),i){case"Point":return lJt(A,r);case"MultiPoint":return CNe(A,r);case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":return CNe(A,Rj(A,r,{ignoreSelfIntersections:!0}))}}function CNe(A,t){var e=[],i=SJt();return g7(t,function(r){if(e.forEach(function(a,o){a.id=o}),!e.length)e=lJt(A,r).features,i.load(tl(e));else{var n=i.search(r);if(n.features.length){var s=oFe(r,n);e=e.filter(function(a){return a.id!==s.id}),i.remove(s),l7(lJt(s,r),function(a){e.push(a),i.insert(a)})}}}),tl(e)}function lJt(A,t){var e=[],i=qd(A)[0],r=qd(A)[A.geometry.coordinates.length-1];if(XYt(i,I3(t))||XYt(r,I3(t)))return tl([A]);var n=SJt(),s=sFe(A);n.load(s);var a=n.search(t);if(!a.features.length)return tl([A]);var o=oFe(t,a),l=[i],g=Jni(s,function(h,I,p){var E=qd(I)[1],f=I3(t);return p===o.id?(h.push(f),e.push(O1(h)),XYt(f,E)?[f]:[f,E]):(h.push(E),h)},l);return g.length>1&&e.push(O1(g)),tl(e)}function oFe(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 l7(t,function(r){var n=bj(r,A),s=n.properties.dist;s<i&&(e=r,i=s)}),e}function XYt(A,t){return A[0]===t[0]&&A[1]===t[1]}function BNe(A,t){let e=Lm(A),i=Lm(t),r=e.type,n=i.type,s=e.coordinates,a=i.coordinates;switch(r){case"Point":if(n==="Point")return RJt(s,a);throw new Error("feature2 "+n+" geometry not supported");case"MultiPoint":switch(n){case"Point":return Hsi(e,i);case"MultiPoint":return Osi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"Point":return BB(i,e,{ignoreEndVertices:!0});case"LineString":return jsi(e,i);case"MultiPoint":return Ysi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Point":return p3(i,e,{ignoreBoundary:!0});case"LineString":return Ksi(e,i);case"Polygon":return kJt(e,i);case"MultiPoint":return Jsi(e,i);case"MultiPolygon":return Psi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPolygon":if(n==="Polygon")return Usi(e,i);throw new Error("feature2 "+n+" geometry not supported");default:throw new Error("feature1 "+r+" geometry not supported")}}function Usi(A,t){return A.coordinates.some(e=>kJt({type:"Polygon",coordinates:e},t))}function Psi(A,t){return t.coordinates.every(e=>kJt(A,{type:"Polygon",coordinates:e}))}function Hsi(A,t){let e,i=!1;for(e=0;e<A.coordinates.length;e++)if(RJt(A.coordinates[e],t.coordinates)){i=!0;break}return i}function Osi(A,t){for(let e of t.coordinates){let i=!1;for(let r of A.coordinates)if(RJt(e,r)){i=!0;break}if(!i)return!1}return!0}function Ysi(A,t){let e=!1;for(let i of t.coordinates)if(BB(i,A,{ignoreEndVertices:!0})&&(e=!0),!BB(i,A))return!1;return!!e}function Jsi(A,t){for(let e of t.coordinates)if(!p3(e,A,{ignoreBoundary:!0}))return!1;return!0}function jsi(A,t){let e=!1;for(let i of t.coordinates)if(BB({type:"Point",coordinates:i},A,{ignoreEndVertices:!0})&&(e=!0),!BB({type:"Point",coordinates:i},A,{ignoreEndVertices:!1}))return!1;return e}function qsi(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=O1([e[r],e[r+1]]),s=DJt(n,VE(t));s.features.length===0?i.push(n):i.push(...s.features)}return tl(i)}function Ksi(A,t){let e=Mu(A),i=Mu(t);if(!lFe(e,i))return!1;for(let s of t.coordinates)if(!p3(s,A))return!1;let r=!1,n=qsi(t,A);for(let s of n.features){let a=zsi(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!p3(a,A))return!1;!r&&p3(a,A,{ignoreBoundary:!0})&&(r=!0)}return r}function kJt(A,t){if(A.type==="Feature"&&A.geometry===null||t.type==="Feature"&&t.geometry===null)return!1;let e=Mu(A),i=Mu(t);if(!lFe(e,i))return!1;let r=Lm(t).coordinates;for(let n of r)for(let s of n)if(!p3(s,A))return!1;return!0}function lFe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function RJt(A,t){return A[0]===t[0]&&A[1]===t[1]}function zsi(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function jEt(A,t={}){let e=Lm(A);switch(!t.properties&&A.type==="Feature"&&(t.properties=A.properties),e.type){case"Polygon":return Wsi(e,t);case"MultiPolygon":return Vsi(e,t);default:throw new Error("invalid poly")}}function Wsi(A,t={}){let i=Lm(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{};return gFe(i,r)}function Vsi(A,t={}){let i=Lm(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{},n=[];return i.forEach(s=>{n.push(gFe(s,r))}),tl(n)}function gFe(A,t){return A.length>1?eFe(A,t):O1(A[0],t)}var Zsi=Object.defineProperty,Mj=(A,t)=>Zsi(A,"name",{value:t,configurable:!0}),cFe=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||!snt(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=gJt(t),r=gJt(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(!snt(t,e))return!1;let n=t,s=e;if(r&&!this.compareCoord(n[0],s[0])){let o=this.fixStartIndex(s,n);if(o)s=o;else return!1}let a=this.compareCoord(n[i],s[i]);return this.direction||a?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 snt(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?MJt(t.properties,e.properties):!0)&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return snt(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)}};Mj(cFe,"GeojsonEquality");var Xsi=cFe;function snt(A,t){return A.coordinates?A.coordinates.length===t.coordinates.length:A.length===t.length}Mj(snt,"sameLength");function gJt(A){return A.coordinates.map(t=>({type:A.type.replace("Multi",""),coordinates:t}))}Mj(gJt,"explode");function hFe(A,t,e){return new Xsi(e).compare(A,t)}Mj(hFe,"geojsonEquality");function MJt(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],a=ENe(n)&&ENe(s);if(a&&!MJt(n,s)||!a&&n!==s)return!1}return!0}Mj(MJt,"equal");var ENe=Mj(A=>A!=null&&typeof A=="object","isObject");function uFe(A,t={}){var e=typeof t=="object"?t.mutate:t;if(!A)throw new Error("geojson is required");var i=HEt(A),r=[];switch(i){case"LineString":r=$Yt(A,i);break;case"MultiLineString":case"Polygon":qd(A).forEach(function(s){r.push($Yt(s,i))});break;case"MultiPolygon":qd(A).forEach(function(s){var a=[];s.forEach(function(o){a.push($Yt(o,i))}),r.push(a)});break;case"Point":return A;case"MultiPoint":var n={};qd(A).forEach(function(s){var a=s.join("-");Object.prototype.hasOwnProperty.call(n,a)||(r.push(s),n[a]=!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):VE({type:i,coordinates:r},A.properties,{bbox:A.bbox,id:A.id})}function $Yt(A,t){let e=qd(A);if(e.length===2&&!fNe(e[0],e[1]))return e;let i=[],r=0,n=1,s=2;for(i.push(e[r]);s<e.length;)BB(e[n],O1([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(BB(i[0],O1([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(!fNe(i[0],i[i.length-1]))throw new Error("invalid polygon, first and last points not equal")}return i}function fNe(A,t){return A[0]===t[0]&&A[1]===t[1]}function $si(A,t,{ignoreSelfIntersections:e=!0}={ignoreSelfIntersections:!0}){let i=!0;return g7(A,r=>{g7(t,n=>{if(i===!1)return!1;i=tai(r.geometry,n.geometry,e)})}),i}function tai(A,t,e){switch(A.type){case"Point":switch(t.type){case"Point":return!rai(A.coordinates,t.coordinates);case"LineString":return!_Ne(t,A);case"Polygon":return!p3(A,t)}break;case"LineString":switch(t.type){case"Point":return!_Ne(A,t);case"LineString":return!eai(A,t,e);case"Polygon":return!mNe(t,A,e)}break;case"Polygon":switch(t.type){case"Point":return!p3(t,A);case"LineString":return!mNe(A,t,e);case"Polygon":return!Aai(t,A,e)}}return!1}function _Ne(A,t){for(let e=0;e<A.coordinates.length-1;e++)if(iai(A.coordinates[e],A.coordinates[e+1],t.coordinates))return!0;return!1}function eai(A,t,e){return Rj(A,t,{ignoreSelfIntersections:e}).features.length>0}function mNe(A,t,e){for(let r of t.coordinates)if(p3(r,A))return!0;return Rj(t,jEt(A),{ignoreSelfIntersections:e}).features.length>0}function Aai(A,t,e){for(let r of A.coordinates[0])if(p3(r,t))return!0;for(let r of t.coordinates[0])if(p3(r,A))return!0;return Rj(jEt(A),jEt(t),{ignoreSelfIntersections:e}).features.length>0}function iai(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 rai(A,t){return A[0]===t[0]&&A[1]===t[1]}function GJt(A,t,{ignoreSelfIntersections:e=!0}={}){let i=!1;return g7(A,r=>{g7(t,n=>{if(i===!0)return!0;i=!$si(r.geometry,n.geometry,{ignoreSelfIntersections:e})})}),i}function IFe(A){return A&&A.__esModule&&Object.prototype.hasOwnProperty.call(A,"default")?A.default:A}var tJt,QNe;function nai(){return QNe||(QNe=1,tJt=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}),tJt}var sai=nai(),ant=IFe(sai);function aai(A,t,e={}){if(e=e||{},!fnt(e))throw new Error("options is invalid");var i=e.tolerance||0,r=[],n=SJt();let s=sFe(A);n.load(s);var a;let o=[];return int(t,function(l){var g=!1;l&&(l7(n.search(l),function(h){if(g===!1){var I=qd(l).sort(),p=qd(h).sort();if(ant(I,p))g=!0,a?a=eJt(a,l)||a:a=l;else if(i===0?BB(I[0],h)&&BB(I[1],h):bj(h,I[0]).properties.dist<=i&&bj(h,I[1]).properties.dist<=i)g=!0,a?a=eJt(a,l)||a:a=l;else if(i===0?BB(p[0],l)&&BB(p[1],l):bj(l,p[0]).properties.dist<=i&&bj(l,p[1]).properties.dist<=i)if(a){let E=eJt(a,h);E?a=E:o.push(h)}else a=h}}),g===!1&&a&&(r.push(a),o.length&&(r=r.concat(o),o=[]),a=void 0))}),a&&r.push(a),tl(r)}function eJt(A,t){var e=qd(t),i=qd(A),r=i[0],n=i[i.length-1],s=A.geometry.coordinates;if(ant(e[0],r))s.unshift(e[1]);else if(ant(e[0],n))s.push(e[1]);else if(ant(e[1],r))s.unshift(e[0]);else if(ant(e[1],n))s.push(e[0]);else return;return A}function pFe(A,t){let e=Lm(A),i=Lm(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(hFe(A,t,{precision:6}))return!1;let s=0;switch(r){case"MultiPoint":for(var a=0;a<e.coordinates.length;a++)for(var o=0;o<i.coordinates.length;o++){var l=e.coordinates[a],g=i.coordinates[o];if(l[0]===g[0]&&l[1]===g[1])return!0}return!1;case"LineString":case"MultiLineString":int(A,h=>{int(t,I=>{aai(h,I).features.length&&s++})});break;case"Polygon":case"MultiPolygon":int(A,h=>{int(t,I=>{Rj(h,I).features.length&&s++})});break}return s>0}function oai(A,t){var e=Lm(A),i=Lm(t),r=e.type,n=i.type;switch(r){case"Point":switch(n){case"MultiPoint":return lai(e,i);case"LineString":return BB(e,i,{ignoreEndVertices:!0});case"Polygon":case"MultiPolygon":return p3(e,i,{ignoreBoundary:!0});default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPoint":switch(n){case"MultiPoint":return gai(e,i);case"LineString":return cai(e,i);case"Polygon":case"MultiPolygon":return hai(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"LineString":return uai(e,i);case"Polygon":case"MultiPolygon":return pai(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Polygon":case"MultiPolygon":return dai(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}default:throw new Error("feature1 "+r+" geometry not supported")}}function lai(A,t){var e,i=!1;for(e=0;e<t.coordinates.length;e++)if(CFe(t.coordinates[e],A.coordinates)){i=!0;break}return i}function gai(A,t){for(var e=0;e<A.coordinates.length;e++){for(var i=!1,r=0;r<t.coordinates.length;r++)CFe(A.coordinates[e],t.coordinates[r])&&(i=!0);if(!i)return!1}return!0}function cai(A,t){for(var e=!1,i=0;i<A.coordinates.length;i++){if(!BB(A.coordinates[i],t))return!1;e||(e=BB(A.coordinates[i],t,{ignoreEndVertices:!0}))}return e}function hai(A,t){for(var e=!0,i=!1,r=0;r<A.coordinates.length;r++){if(i=p3(A.coordinates[r],t),!i){e=!1;break}i=p3(A.coordinates[r],t,{ignoreBoundary:!0})}return e&&i}function uai(A,t){for(var e=0;e<A.coordinates.length;e++)if(!BB(A.coordinates[e],t))return!1;return!0}function Iai(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=O1([e[r],e[r+1]]),s=DJt(n,VE(t));s.features.length===0?i.push(n):i.push(...s.features)}return tl(i)}function pai(A,t){let e=Mu(t),i=Mu(A);if(!dFe(e,i))return!1;for(let s of A.coordinates)if(!p3(s,t))return!1;let r=!1,n=Iai(A,t);for(let s of n.features){let a=Cai(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!p3(a,t))return!1;!r&&p3(a,t,{ignoreBoundary:!0})&&(r=!0)}return r}function dai(A,t){var e=Mu(A),i=Mu(t);if(!dFe(i,e))return!1;for(var r=0;r<A.coordinates[0].length;r++)if(!p3(A.coordinates[0][r],t))return!1;return!0}function dFe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function CFe(A,t){return A[0]===t[0]&&A[1]===t[1]}function Cai(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function BFe(A,t={}){let e=Mu(A),i=(e[0]+e[2])/2,r=(e[1]+e[3])/2;return u3([i,r],t.properties,t)}var MEt={exports:{}},Bai=MEt.exports,yNe;function Eai(){return yNe||(yNe=1,(function(A,t){(function(e,i){A.exports=i()})(Bai,(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,I()?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(I())return Reflect.construct.apply(null,arguments);var B=[null];B.push.apply(B,c);var b=new(C.bind.apply(C,B));return u&&p(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 a(C,c,u){return c&&s(C.prototype,c),u&&s(C,u),Object.defineProperty(C,"prototype",{writable:!1}),C}function o(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(dt){throw dt},f:b}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
25649
+ `}function Pve(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 OqA(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 k8(A,t,e){let i=A.getUniformLocation(t,e);if(!i)throw new Error(`Failed to get uniform location for ${e}`);return i}function OPt(A){let t=A.createTexture();if(!t)throw new Error("Failed to create texture");return t}function Hve(A){let t=A.createBuffer();if(!t)throw new Error("Failed to create buffer");return t}function SSe(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 $Pt(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 DSe(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 kSe(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 RSe(A){let t=[],e=[],i=2/A,r=1/A,n=(s,a)=>{let o=-1+s*i,l=1-a*i,g=s*r,h=a*r;t.push(o,l),e.push(g,h)};for(let s=0;s<A;s++){for(let a=0;a<=A;a++)n(a,s),n(a,s+1);s<A-1&&(n(A,s+1),n(0,s+1))}return{vertexArr:new Float32Array(t),texCoordArr:new Float32Array(e)}}function YqA(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 JqA=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=OPt(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(YqA(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 jqA(A=!1,t=!1){return A&&t?"mapbox-wgs84":A?"mapbox":t?"wgs84-globe":"maplibre-globe"}function MSe(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 qqA=A=>A instanceof Float32Array?A:new Float32Array(A),GSe=A=>A==="mapbox"||A==="mapbox-wgs84",KqA=A=>A==="maplibre-globe"||A==="wgs84-globe";function zqA(A){let t=A.includes("wgs84")?"wgs84":"mercator",e=GSe(A)?"mapbox-globe":"maplibre-globe";return{inputSpace:t,projection:e}}function WqA(A,t){let{fragmentShaderSource:e,shaderData:i,customShaderConfig:r,projectionMode:n}=t,s=r||void 0,a=s&&s.bands.length>0,o=t.variantName||MSe({projectionMode:n,shaderData:i,customShaderConfig:r}),{inputSpace:l,projection:g}=zqA(n),h=UqA({inputSpace:l,projection:g,shaderData:i}),I=a&&s?HqA({bands:s.bands,customUniforms:s.customUniforms?Object.keys(s.customUniforms):[],customFrag:s.customFrag}):e,p=Pve(A,A.VERTEX_SHADER,h),E=Pve(A,A.FRAGMENT_SHADER,I);if(!p||!E)throw new Error(`Failed to create shaders for variant: ${o}`);let f=OqA(A,p,E);if(!f)throw new Error(`Failed to create program for variant: ${o}`);let Q=new Map,y=new Map;if(a&&s){for(let z of s.bands){let N=A.getUniformLocation(f,z);N&&Q.set(z,N)}if(s.customUniforms)for(let z of Object.keys(s.customUniforms)){let N=A.getUniformLocation(f,z);N&&y.set(z,N)}}let v=KqA(n),S=GSe(n),G=z=>v?A.getUniformLocation(f,z):null,H=z=>S?A.getUniformLocation(f,z):null,Y={program:f,scaleLoc:k8(A,f,"scale"),scaleXLoc:k8(A,f,"scale_x"),scaleYLoc:k8(A,f,"scale_y"),shiftXLoc:k8(A,f,"shift_x"),shiftYLoc:k8(A,f,"shift_y"),worldXOffsetLoc:k8(A,f,"u_worldXOffset"),matrixLoc:v?null:k8(A,f,"matrix"),projMatrixLoc:G("u_projection_matrix"),fallbackMatrixLoc:G("u_projection_fallback_matrix"),tileMercatorCoordsLoc:G("u_projection_tile_mercator_coords"),clippingPlaneLoc:G("u_projection_clipping_plane"),projectionTransitionLoc:G("u_projection_transition"),opacityLoc:k8(A,f,"opacity"),texScaleLoc:k8(A,f,"u_texScale"),texOffsetLoc:k8(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:a?null:A.getUniformLocation(f,"cmap"),colormapLoc:A.getUniformLocation(f,"colormap"),texLoc:a?null:A.getUniformLocation(f,"tex"),projectionMode:n,useCustomShader:!!a,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(p),A.deleteShader(E),{shaderProgram:Y,variantName:o}}function VqA(A,t,e,i,r,n){let s=(l,g)=>{l&&g&&A.uniformMatrix4fv(l,!1,qqA(g))},a=(l,g)=>{l&&g&&A.uniform4f(l,...g)},o=(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),a(t.tileMercatorCoordsLoc,i.tileMercatorCoords),a(t.clippingPlaneLoc,i.clippingPlane),o(t.projectionTransitionLoc,i.projectionTransition);break}case"mapbox":case"mapbox-wgs84":{s(t.matrixLoc,e),s(t.globeToMercMatrixLoc,r?.globeToMercatorMatrix),o(t.globeTransitionLoc,r?.transition??1),t.tileRenderLoc&&A.uniform1i(t.tileRenderLoc,n?1:0);break}default:{s(t.matrixLoc,e);break}}}var FJ=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function tHt(A,t,e,i){let r=Math.max(0,A),n=Math.min(1,e),s=Math.max(0,t),a=Math.min(1,i),o=n-r,l=a-s;return new Float32Array([2/o,0,0,0,0,2/l,0,0,0,0,1,0,-(r+n)/o,-(s+a)/l,0,1])}function eHt(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 ZqA(A,t){return A.x0<t.x1&&A.x1>t.x0&&A.y0<t.y1&&A.y1>t.y0}function AHt(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 Ove(A,t){return Math.floor(Od(A)*Math.pow(2,t))}function Yve(A,t){let e=Math.max(-NJ,Math.min(NJ,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 NSe(A,t){let[[e,i],[r,n]]=t,s=Math.max(-NJ,i),a=Math.min(NJ,n),o=Ove(e,A),l=Ove(r,A),g=Yve(a,A),h=Yve(s,A),I=Math.pow(2,A),p=[],E=new Set;o>l&&(l+=I);for(let f=o;f<=l;f++){let Q=(f%I+I)%I;for(let y=g;y<=h;y++){let v=Math.max(0,Math.min(I-1,y)),S=`${A},${Q},${v}`;E.has(S)||(E.add(S),p.push([A,Q,v]))}}return p}function FSe(A,t,e){let[[i,r],[n,s]]=t,{xMin:a,xMax:o,yMin:l,yMax:g}=AHt(e),h=o-a,I=g-l,p=Math.pow(2,A),E=Y=>Math.floor((Y-a)/h*p),f=Y=>{let z=Math.max(Math.min(Y,g),l),N=(g-z)/I;return Math.floor(N*p)},Q=E(i),y=E(n),v=f(s),S=f(r),G=[],H=new Set;Q>y&&(y+=p);for(let Y=Q;Y<=y;Y++){let z=(Y%p+p)%p;for(let N=v;N<=S;N++){let F=Math.max(0,Math.min(p-1,N)),O=`${A},${z},${F}`;H.has(O)||(H.add(O),G.push([A,z,F]))}}return G}function vp(A){return A.join(",")}function Jve(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 XqA(A,t){return t?Math.min(Math.max(0,Math.floor(A)),t):Math.max(0,Math.floor(A))}function trt(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 Od(A){let t=A;return A>180?t=A-360:A<-180&&(t=A+360),(t+180)/360}function C_(A){let t=Math.max(-NJ,Math.min(NJ,A));return(1-Math.log(Math.tan(t*Math.PI/180)+1/Math.cos(t*Math.PI/180))/Math.PI)/2}function VF(A){let t=Math.PI*(1-2*A);return 180/Math.PI*Math.atan(Math.sinh(t))}function Zit(A){return A*360-180}function $qA(A,t,e,i){let r=Math.pow(2,A),{xMin:n,xMax:s,yMin:a,yMax:o}=AHt(i),l=s-n,g=o-a,h=n+t/r*l,I=n+(t+1)/r*l,p=o-e/r*g,E=o-(e+1)/r*g;return{west:h,east:I,south:E,north:p}}function LSe(A,t,e,i){let r=t-1,n=Math.floor(e/2),s=Math.floor(i/2);for(;r>=0;){let a=vp([r,n,s]),o=A.get(a);if(o&&o.data)return{tile:o,ancestorZ:r,ancestorX:n,ancestorY:s};r--,n=Math.floor(n/2),s=Math.floor(s/2)}return null}function TSe(A,t,e,i,r,n=2){let s=0,a=[];for(let o=1;o<=n;o++){let l=t+o;if(l>r)break;let g=Math.pow(2,o),h=e*g,I=i*g,p=g*g,E=[];for(let Q=0;Q<g;Q++)for(let y=0;y<g;y++){let v=h+y,S=I+Q,G=vp([l,v,S]),H=A.get(G);H&&H.data&&E.push({tile:H,childZ:l,childX:v,childY:S})}let f=E.length/p;if(f===1)return E;f>s&&(s=f,a=E)}return a.length>0?a:null}function jve(A,t){if(t==="EPSG:3857")return{x0:(A.xMin+L1)/(2*L1),y0:(L1-A.yMax)/(2*L1),x1:(A.xMax+L1)/(2*L1),y1:(L1-A.yMin)/(2*L1)};let e=A.yMin,i=A.yMax;e>i&&([e,i]=[i,e]);let r={x0:Od(A.xMin),y0:C_(i),x1:Od(A.xMax),y1:C_(e)};return t==="EPSG:4326"&&(r.latMin=e,r.latMax=i),r}function CCt(A,t,e,i){let r=(A-t)/(e-t);return Math.floor(Math.max(0,Math.min(i-1,r*i)))}function tKA(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 USe(A){return A?.type==="globe"||A?.name==="globe"}function eKA(A,t,e,i){let r=A&&typeof A=="object"&&!Array.isArray(A)&&!ArrayBuffer.isView(A)?A:null,n=r?.shaderData,s,a=r?.defaultProjectionData;a&&a.mainMatrix&&a.fallbackMatrix&&a.tileMercatorCoords&&a.clippingPlane&&typeof a.projectionTransition=="number"&&(s={mainMatrix:a.mainMatrix,fallbackMatrix:a.fallbackMatrix,tileMercatorCoords:a.tileMercatorCoords,clippingPlane:a.clippingPlane,projectionTransition:a.projectionTransition});let o=null;s?.mainMatrix&&s.mainMatrix.length?o=s.mainMatrix:Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array?o=A:r?.modelViewProjectionMatrix?o=r.modelViewProjectionMatrix:r?.projectionMatrix&&(o=r.projectionMatrix);let l=Array.isArray(A)||A instanceof Float32Array||A instanceof Float64Array;return{matrix:o,shaderData:n,projectionData:s,mapbox:!!t||l?{projection:t??{name:"mercator"},globeToMercatorMatrix:e??FJ,transition:typeof i=="number"?i:1}:void 0}}function AKA(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 a=Math.floor((r+180)/360),o=Math.floor((s+180)/360),l=[];for(let g=a;g<=o;g++)l.push(g);return l.length>0?l:[0]}function iHt(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 iKA(A,t){let{bandData:e,bandTextures:i,bandTexturesUploaded:r,bandTexturesConfigured:n,customShaderConfig:s,width:a,height:o,ensureTexture:l}=t,g=2;for(let h of s.bands){let I=e.get(h);if(!I)return!1;let p=i.get(h);if(!p)if(l){let E=l(h);E&&(p=E,i.set(h,p))}else p=A.createTexture(),p&&i.set(h,p);if(!p)return!1;A.activeTexture(A.TEXTURE0+g),A.bindTexture(A.TEXTURE_2D,p),n.has(h)||($Pt(A),n.add(h)),r.has(h)||(A.texImage2D(A.TEXTURE_2D,0,A.R32F,a,o,0,A.RED,A.FLOAT,I),r.add(h)),g++}return!0}function rKA(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 nKA(A,t){let{texture:e,data:i,width:r,height:n,channels:s,configured:a}=t;A.activeTexture(A.TEXTURE0),A.bindTexture(A.TEXTURE_2D,e),a||$Pt(A);let{format:o,internalFormat:l}=SSe(A,s);return A.texImage2D(A.TEXTURE_2D,0,l,r,n,0,o,A.FLOAT,i),{configured:!0,uploaded:!0}}function NCt(A,t,e,i,r){let n=e.wgs84Bounds??null,s,a,o,l;n?(s=(n.lon1-n.lon0)/2,a=(n.lat1-n.lat0)/2,o=(n.lon0+n.lon1)/2,l=(n.lat0+n.lat1)/2):(s=(e.mercatorBounds.x1-e.mercatorBounds.x0)/2,a=(e.mercatorBounds.y1-e.mercatorBounds.y0)/2,o=(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,a),A.uniform1f(t.shiftXLoc,o),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 I=e.mercatorBounds.latMin!==void 0&&e.mercatorBounds.latMax!==void 0,p=I&&!n;if(t.reprojectLoc!==null&&A.uniform1i(t.reprojectLoc,p?1:0),p&&t.latBoundsLoc!==null&&I&&A.uniform2f(t.latBoundsLoc,e.mercatorBounds.latMin,e.mercatorBounds.latMax),p&&t.latIsAscendingLoc!==null&&A.uniform1i(t.latIsAscendingLoc,e.latIsAscending?1:0),rKA(A,t,e.vertexBuffer,e.pixCoordBuffer),e.useIndexedMesh&&e.indexBuffer&&A.bindBuffer(A.ELEMENT_ARRAY_BUFFER,e.indexBuffer),t.useCustomShader&&r){if(!iKA(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 qve(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 Kve(A,t,e,i,r,n,s,a,o,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=>a.ensureBandTexture(o,g),latIsAscending:l}}function sKA(A,t,e,i,r,n,s,a,o,l,g=!1,h,I,p=!0){iHt(A,t,l);let E=s.length/2;for(let f of e){let[Q,y,v]=f,S=vp(f),G=r.get(S),H=o?.[S],Y=null,z=S,N=[1,1],F=[0,0];if(G&&G.data)Y=G;else{let nt=LSe(r,Q,y,v);if(nt){Y=nt.tile,z=vp([nt.ancestorZ,nt.ancestorX,nt.ancestorY]);let tt=Q-nt.ancestorZ,W=Math.pow(2,tt),V=y%W,it=v%W;N=[1/W,1/W],F=[V/W,it/W]}else if(h!==void 0){let tt=TSe(r,Q,y,v,h);if(tt&&tt.length>0){let W;if(H)W=H;else{let[V,it,at]=Jve(f);W={x0:it-V,x1:it+V,y0:at-V,y1:at+V}}for(let V of tt){if(!V.tile.data||!V.tile.vertexBuffer||!V.tile.pixCoordBuffer||!V.tile.tileTexture)continue;let it=V.childZ-Q,at=Math.pow(2,it),pt=V.childX%at,Ct=V.childY%at,mt=W.x1-W.x0,ft=W.y1-W.y0,Qt={x0:W.x0+pt/at*mt,x1:W.x0+(pt+1)/at*mt,y0:W.y0+Ct/at*ft,y1:W.y0+(Ct+1)/at*ft};if(H?.latMin!==void 0&&H?.latMax!==void 0){let ie=H.latMax-H.latMin;Qt.latMin=H.latMin+Ct/at*ie,Qt.latMax=H.latMin+(Ct+1)/at*ie}if(H?.lonMin!==void 0&&H?.lonMax!==void 0){let ie=H.lonMax-H.lonMin;Qt.lonMin=H.lonMin+pt/at*ie,Qt.lonMax=H.lonMin+(pt+1)/at*ie}let yt=qve(A,V.tile,s,a),Mt=vp([V.childZ,V.childX,V.childY]),qt=Kve(V.tile,Qt,yt,E,n,[1,1],[0,0],r,Mt,p);NCt(A,t,qt,g?[0]:i,l)}continue}}}if(!Y||!Y.data||!Y.vertexBuffer||!Y.pixCoordBuffer||!Y.tileTexture)continue;if(g&&I?.[S]){let nt=I[S];N=nt.texScale,F=nt.texOffset}let O=qve(A,Y,s,a),K;if(H)K=H;else{let[nt,tt,W]=Jve(f);K={x0:tt-nt,x1:tt+nt,y0:W-nt,y1:W+nt}}let $=Kve(Y,K,O,E,n,N,F,r,z,p);NCt(A,t,$,g?[0]:i,l)}}var aKA=class PSe{constructor(t,e,i){this.shaderCache=new Map,this.customShaderConfig=null,this.gl=PSe.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=jqA(i,r),s=e||this.customShaderConfig,a=MSe({projectionMode:n,shaderData:t,customShaderConfig:s}),o=this.shaderCache.get(a);if(o)return o;let{shaderProgram:l}=WqA(this.gl,{fragmentShaderSource:this.fragmentShaderSource,shaderData:t,customShaderConfig:s,projectionMode:n,variantName:a});return this.shaderCache.set(a,l),l}applyCommonUniforms(t,e,i,r,n,s,a,o=!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 I=t.customUniformLocs.get(g);I&&l.uniform1f(I,h)}a&&VqA(l,t,a,n,s,o)}renderTiles(t,e,i,r,n,s,a,o,l,g=!1,h,I,p=!0){sKA(this.gl,t,e,i,r,n,s,a,o,l,g,h,I,p)}dispose(){let t=this.gl;for(let[,e]of this.shaderCache)t.deleteProgram(e.program);this.shaderCache.clear()}};function rHt(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 oKA(A,t){let e;try{e=Ud(A,"EPSG:3857")}catch(i){throw new Error(rHt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function lKA(A,t){let e;try{e=Ud(A,"EPSG:4326")}catch(i){throw new Error(rHt(A,i))}return{forward:(i,r)=>e.forward([i,r]),inverse:(i,r)=>e.inverse([i,r]),bounds:t}}function HSe(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 nHt(A,t,e,i,r,n=!0){if(!HSe(e,"sourceCRSToPixel"))return[i/2,r/2];let[s,a,o,l]=e,g=(A-s)/(o-s),h=(t-a)/(l-a),I=g*i,p=n?h*r:(1-h)*r;return[I,p]}function FCt(A,t,e,i,r,n=!0){let[s,a,o,l]=e;if(!HSe(e,"pixelToSourceCRS"))return[(s+o)/2,(a+l)/2];let g=i<=1?.5:A/i,h=r<=1?.5:t/r,I=s+g*(o-s),p=n?a+h*(l-a):l-h*(l-a);return[I,p]}function Art(A){let t;try{t=Ud("EPSG:4326",A)}catch(e){throw new Error(rHt(A,e))}return{forward:(e,i)=>t.forward([e,i]),inverse:(e,i)=>t.inverse([e,i])}}function zve(A,t,e){let{xMin:i,yMin:r,xMax:n,yMax:s}=A,a=1/0,o=-1/0,l=1/0,g=-1/0;for(let h=0;h<=e;h++){let I=h/e,p=[[i+I*(n-i),r],[i+I*(n-i),s],[i,r+I*(s-r)],[n,r+I*(s-r)]];for(let[E,f]of p){let[Q,y]=t.forward(E,f);if(!isFinite(Q)||!isFinite(y))continue;let v=(Q+L1)/(2*L1),S=(L1-y)/(2*L1);a=Math.min(a,v),o=Math.max(o,v),l=Math.min(l,S),g=Math.max(g,S)}}return isFinite(a)?{x0:a,y0:l,x1:o,y1:g}:null}function OSe(A,t,e,i,r,n,s,a,o,l,g=!0){if(a&&o){let S=l??Art(a),G=g?A+.5:A,H=g?t+.5:t,[Y,z]=FCt(G,H,o,i,r,s),[N,F]=S.inverse(Y,z);return{lat:F,lon:N}}let h=i<=1?.5:g?(A+.5)/i:A/i,I=r<=1?.5:g?(t+.5)/r:t/r,p=e.x0+h*(e.x1-e.x0),E=e.y0+I*(e.y1-e.y0),f=Zit(p),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):VF(E),lon:f}}function YSe(A,t,e,i,r,n){let[s,a,o]=A,l=Math.pow(2,s),g=(a+t/i)/l,h=(o+e/i)/l;if(r==="EPSG:4326"){let{xMin:f,xMax:Q,yMin:y,yMax:v}=n,S=f+g*(Q-f);return{lat:v-h*(v-y),lon:S}}let I=g*360-180,p=180-h*360;return{lat:360/Math.PI*Math.atan(Math.exp(p*Math.PI/180))-90,lon:I}}function sHt(A){let t=1/0,e=-1/0,i=1/0,r=-1/0;if(A.type==="Point"){let[s,a]=A.coordinates;return{west:s,east:s,south:a,north:a}}let n=s=>{for(let[a,o]of s)a<t&&(t=a),a>e&&(e=a),o<i&&(i=o),o>r&&(r=o)};return A.type==="Polygon"?A.coordinates.forEach(n):A.coordinates.forEach(s=>s.forEach(n)),{west:t,east:e,south:i,north:r}}function gKA(A,t,e,i,r,n,s,a,o){let l=sHt(A);if(s&&a){let G=o??Art(s),H=5,Y=[];for(let W=0;W<=H;W++){let V=W/H,it=l.west+V*(l.east-l.west),at=l.south+V*(l.north-l.south);Y.push([it,l.south]),Y.push([it,l.north]),Y.push([l.west,at]),Y.push([l.east,at])}let z=1/0,N=-1/0,F=1/0,O=-1/0;for(let[W,V]of Y){let[it,at]=G.forward(W,V);if(!isFinite(it)||!isFinite(at))continue;let[pt,Ct]=nHt(it,at,a,e,i,n);z=Math.min(z,pt),N=Math.max(N,pt),F=Math.min(F,Ct),O=Math.max(O,Ct)}if(!isFinite(z)||!isFinite(N)||!isFinite(F)||!isFinite(O))return null;let K=Math.max(0,Math.floor(z)),$=Math.min(e,Math.floor(N)+1),nt=Math.max(0,Math.floor(F)),tt=Math.min(i,Math.floor(O)+1);return $<=K||tt<=nt?null:{minX:K,maxX:$,minY:nt,maxY:tt}}let g=Od(l.west),h=Od(l.east),I=C_(l.north),p=C_(l.south),E=Math.max(t.x0,Math.min(g,h)),f=Math.min(t.x1,Math.max(g,h)),Q,y,v,S;if(r==="EPSG:4326"&&t.latMin!==void 0&&t.latMax!==void 0){let G=t.latMax,H=t.latMin,Y=Math.min(Math.max(l.north,H),G),z=Math.min(Math.max(l.south,H),G),N=G-H;if(N===0)return null;let F=V=>n?(V-H)/N:(G-V)/N,O=F(Y),K=F(z),$=Math.min(O,K),nt=Math.max(O,K);if(f<=E||nt<=$)return null;let tt=(E-t.x0)/(t.x1-t.x0)*e,W=(f-t.x0)/(t.x1-t.x0)*e;Q=Math.max(0,Math.floor(tt)),y=Math.min(e,Math.ceil(W)),v=Math.max(0,Math.floor($*i)),S=Math.min(i,Math.ceil(nt*i))}else{let G=Math.max(t.y0,Math.min(I,p)),H=Math.min(t.y1,Math.max(I,p));if(f<=E||H<=G)return null;let Y=(E-t.x0)/(t.x1-t.x0)*e,z=(f-t.x0)/(t.x1-t.x0)*e,N=(G-t.y0)/(t.y1-t.y0)*i,F=(H-t.y0)/(t.y1-t.y0)*i;Q=Math.max(0,Math.floor(Y)),y=Math.min(e,Math.ceil(z)),v=Math.max(0,Math.floor(N)),S=Math.min(i,Math.ceil(F))}return y<=Q||S<=v?null:{minX:Q,maxX:y,minY:v,maxY:S}}function BCt(A,t){let e=!1,[i,r]=A;for(let n=0,s=t.length-1;n<t.length;s=n++){let a=t[n][0],o=t[n][1],l=t[s][0],g=t[s][1];o>r!=g>r&&i<(l-a)*(r-o)/(g-o)+a&&(e=!e)}return e}function cKA(A,t){if(t.type==="Point")return A[0]===t.coordinates[0]&&A[1]===t.coordinates[1];if(t.type==="Polygon"){if(!BCt(A,t.coordinates[0]))return!1;for(let e=1;e<t.coordinates.length;e++)if(BCt(A,t.coordinates[e]))return!1;return!0}for(let e of t.coordinates)if(BCt(A,e[0])){let i=!1;for(let r=1;r<e.length;r++)if(BCt(A,e[r])){i=!0;break}if(!i)return!0}return!1}function JSe(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(cKA(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(I=>I);for(let I of h)for(let[p,E]of I)if(s([p,E]))return!0}let a=[[A[0],A[1]],[A[1],A[2]],[A[2],A[3]],[A[3],A[0]]],o=h=>h.slice(0,-1).map((I,p)=>[h[p],h[p+1]]),l=t.type==="Polygon"?o(t.coordinates[0]):t.type==="MultiPolygon"?t.coordinates.flatMap(h=>o(h[0])):[],g=(h,I,p,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(I,h),v=Q(E,p),S=f(y,v);if(S===0)return!1;let G=f(Q(p,h),v)/S,H=f(Q(p,h),y)/S;return G>=0&&G<=1&&H>=0&&H<=1};for(let h of a)for(let I of l)if(g(h[0],h[1],I[0],I[1]))return!0;return!1}function hKA(A,t,e,i,r,n){let s=[],a=[[0,0],[1,0],[1,1],[0,1]];for(let[o,l]of a){let g=YSe(A,t+o,e+l,i,r,n);s.push([g.lon,g.lat])}return s}function uKA(A,t,e,i,r,n,s,a,o,l){let g=[[0,0],[1,0],[1,1],[0,1]],h=[];for(let[I,p]of g){let{lon:E,lat:f}=OSe(i+I,r+p,A,t,e,n,s,a,o,l,!1);h.push([E,f])}return h}function IKA(A,t,e,i,r,n,s){let a=hKA(A,t,e,i,r,n);return JSe(a,s)}function pKA(A,t,e,i,r,n,s,a,o,l,g){let h=uKA(A,t,e,i,r,n,a,o,l,g);return JSe(h,s)}function dKA(A,t,e,i){let r=[[A.west,A.south],[A.east,A.north]];return e==="EPSG:4326"?FSe(t,r,i):NSe(t,r)}function CKA(A,t,e,i){let r=sHt(A);return dKA(r,t,e,i)}function BKA(A,t,e,i,r,n,s,a,o,l){if(a&&o){let E=l??Art(a),[f,Q]=E.forward(A,t),[y,v,S,G]=o;if(f<y||f>S||Q<v||Q>G)return null;let[H,Y]=nHt(f,Q,o,i,r,s),z=Math.floor(H),N=Math.floor(Y);return z<0||z>=i||N<0||N>=r?null:{x:z,y:N}}let g,h;if(n==="EPSG:4326"&&e.latMin!==void 0&&e.latMax!==void 0){g=(Od(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=(Od(A)-e.x0)/(e.x1-e.x0),h=(C_(t)-e.y0)/(e.y1-e.y0);if(g<0||g>1||h<0||h>1)return null;let I=Math.floor(g*i),p=Math.floor(h*r);return{x:Math.min(I,i-1),y:Math.min(p,r-1)}}function EKA(A,t,e,i,r,n,s,a,o){let l=[],g=[[]],h=[[]];for(let I=0;I<r.length;I++){let p=r[I],E=p.toLowerCase(),f=o[I]*a[I],Q=n[p];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[p],v,S;if(y===void 0){v=[],S=[];for(let Y=0;Y<a[I];Y++){let z=f+Y;z<s[I]&&(v.push(z),Q&&S.push(Q[z]))}}else if(Array.isArray(y)){v=[],S=[];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+a[I]&&(v.push(z),S.push(Y))}}else if(typeof y=="object"&&"selected"in y){let Y=y.selected,z=y.type,N=Array.isArray(Y)?Y:[Y];v=[],S=[];for(let F of N){let O;z==="index"?O=typeof F=="number"?F:0:Q?(O=Q.indexOf(F),O<0&&(O=typeof F=="number"?F:0)):O=typeof F=="number"?F:0,O>=f&&O<f+a[I]&&(v.push(O),Array.isArray(Y)&&S.push(F))}}else{let Y;Q?(Y=Q.indexOf(y),Y<0&&(Y=typeof y=="number"?y:0)):Y=typeof y=="number"?y:0,v=[Y],S=[]}let G=[],H=[];for(let Y=0;Y<v.length;Y++)for(let z=0;z<g.length;z++)G.push([...g[z],v[Y]]),S.length>0?H.push([...h[z],S[Y]]):H.push([...h[z]]);g=G.length>0?G:g.map(Y=>[...Y,0]),h.length=0,h.push(...H.length>0?H:h.map(()=>[]))}}for(let I=0;I<g.length;I++){let p=g[I],E=h[I]||[],f=p.map((S,G)=>{let H=r[G].toLowerCase();return["x","lon","longitude","y","lat","latitude"].includes(H)?S:S-o[G]*a[G]}),Q=new Array(r.length);Q[r.length-1]=1;for(let S=r.length-2;S>=0;S--)Q[S]=Q[S+1]*a[S+1];let y=0;for(let S=0;S<r.length;S++)y+=f[S]*Q[S];let v=A[y];l.push({keys:E,value:v})}return l}function aHt(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 Wve(A,t,e,i,r,n,s){let a=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 I=A[l],p=e[l],E=r[g],f;if(I===void 0)f=Array(i[g]).fill(null).map((y,v)=>v);else if(Array.isArray(I))f=I.map(y=>{let v=p?p.indexOf(y):typeof y=="number"?y:0;return v>=0?v:typeof y=="number"?y:0});else if(typeof I=="object"&&"selected"in I){let y=I.selected,v=I.type;f=(Array.isArray(y)?y:[y]).map(G=>{if(v==="index")return typeof G=="number"?G:0;if(p){let H=p.indexOf(G);return H>=0?H:typeof G=="number"?G:0}return typeof G=="number"?G:0})}else if(p){let y=p.indexOf(I);f=[y>=0?y:typeof I=="number"?I:0]}else f=[typeof I=="number"?I:0];return f.map(y=>Math.floor(y/E)).filter((y,v,S)=>S.indexOf(y)===v)}),o=[[]];return a.forEach(l=>{let g=[];l.forEach(h=>{o.forEach(I=>{g.push([...I,h])})}),o=g}),o}function jSe(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 fKA(A,t,e,i,r,n,s,a,o){let l=i.describe(),g=l.dimensions,h=l.coordinates,I=l.shape||[],p=l.chunks||[],E=nt=>Array.isArray(nt)?!0:nt&&typeof nt=="object"&&"selected"in nt?Array.isArray(nt.selected):!1,f=Object.keys(e).filter(nt=>!E(e[nt])).length,y=g.length-f>2,v=y?{}:[],S=[],G=[],H=g.map(nt=>{let tt=nt.toLowerCase();return["x","lon","longitude"].includes(tt)?"lon":["y","lat","latitude"].includes(tt)?"lat":nt}),Y=y?H:["lat","lon"],z=()=>{let nt={lat:S,lon:G};if(y){let tt=W=>{let V=W.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(V))return;let it=e[W],at;if(Array.isArray(it))at=it;else if(it&&typeof it=="object"&&"selected"in it){let pt=it.selected;at=Array.isArray(pt)?pt:[pt]}else it!==void 0&&typeof it!="object"?at=[it]:h[W]&&(at=h[W]);at&&(nt[W]=at)};g.forEach(tt)}return nt},N=i.levels[s];if(!N)throw new Error(`No level path found for level index ${s}`);let F=trt(N,s),O=CKA(t,F,r,n);if(O.length===0)return{[A]:v,dimensions:Y,coordinates:z()};let K=new Map;await Promise.all(O.map(async nt=>{let[,tt,W]=nt,V=Wve(e,g,h,I,p,tt,W),it=vp(nt),at=new Map;await Promise.all(V.map(async pt=>{try{let Ct=await i.getChunk(N,pt),mt=new Float32Array(Ct.data),ft=pt.join(",");at.set(ft,mt)}catch(Ct){console.warn(`Failed to fetch chunk ${pt} for tile ${it}:`,Ct)}})),K.set(it,at)}));for(let nt of O){let tt=vp(nt),W=K.get(tt);if(!W||W.size===0)continue;let[,V,it]=nt,at=Wve(e,g,h,I,p,V,it);for(let pt=0;pt<a;pt++)for(let Ct=0;Ct<a;Ct++){if(!IKA(nt,Ct,pt,a,r,n,t))continue;let mt=[];for(let Qt of at){let yt=Qt.join(","),Mt=W.get(yt);if(!Mt)continue;let qt=EKA(Mt,Ct,pt,e,g,h,I,p,Qt);for(let{keys:ie,value:Dt}of qt){let Pe=jSe(Dt,o);Pe!==null&&mt.push({keys:ie,value:Pe})}}if(mt.length===0)continue;let ft=YSe(nt,Ct+.5,pt+.5,a,r,n);S.push(ft.lat),G.push(ft.lon);for(let{keys:Qt,value:yt}of mt)Qt.length>0?aHt(v,Qt,yt):Array.isArray(v)&&v.push(yt)}}return{[A]:v,dimensions:Y,coordinates:z()}}async function _KA(A,t,e,i,r,n,s,a,o,l,g=1,h,I,p,E,f,Q){let y=it=>Array.isArray(it)?!0:it&&typeof it=="object"&&"selected"in it?Array.isArray(it.selected):!1,v=Object.keys(e).filter(it=>!y(e[it])).length,G=o.length-v>2,H=G?{}:[],Y=[],z=[],N=o.map(it=>{let at=it.toLowerCase();return["x","lon","longitude"].includes(at)?"lon":["y","lat","latitude"].includes(at)?"lat":it}),F=G?N:["lat","lon"],O=()=>{let it={lat:Y,lon:z};if(G){let at=pt=>{let Ct=pt.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(Ct))return;let mt=e[pt],ft;if(Array.isArray(mt))ft=mt;else if(mt&&typeof mt=="object"&&"selected"in mt){let Qt=mt.selected;ft=Array.isArray(Qt)?Qt:[Qt]}else mt!==void 0&&typeof mt!="object"?ft=[mt]:l[pt]&&(ft=l[pt]);ft&&(it[pt]=ft)};o.forEach(at)}return it};if(!i)return{[A]:H,dimensions:F,coordinates:O()};let K=0,$=r,nt=0,tt=n;if(!f){let it=sHt(t),at=Od(it.west),pt=Od(it.east),Ct=C_(it.north),mt=C_(it.south),ft=Math.max(s.x0,Math.min(at,pt)),Qt=Math.min(s.x1,Math.max(at,pt));if(a==="EPSG:4326"&&s.latMin!==void 0&&s.latMax!==void 0){let yt=s.latMax,Mt=s.latMin,qt=Math.min(Math.max(it.north,Mt),yt),ie=Math.min(Math.max(it.south,Mt),yt),Dt=yt-Mt;if(Dt===0)return{[A]:H,dimensions:F,coordinates:O()};let Pe=$A=>p?($A-Mt)/Dt:(yt-$A)/Dt,me=Pe(qt),ue=Pe(ie),Et=Math.min(me,ue),xe=Math.max(me,ue);if(Qt<=ft||xe<=Et)return{[A]:H,dimensions:F,coordinates:O()};let vA=(ft-s.x0)/(s.x1-s.x0)*r,ce=(Qt-s.x0)/(s.x1-s.x0)*r;K=Math.max(0,Math.floor(vA)),$=Math.min(r,Math.ceil(ce+1)),nt=Math.max(0,Math.floor(Et*n)),tt=Math.min(n,Math.ceil(xe*n))}else{let yt=Math.max(s.y0,Math.min(Ct,mt)),Mt=Math.min(s.y1,Math.max(Ct,mt));if(Qt<=ft||Mt<=yt)return{[A]:H,dimensions:F,coordinates:O()};let qt=(ft-s.x0)/(s.x1-s.x0)*r,ie=(Qt-s.x0)/(s.x1-s.x0)*r,Dt=(yt-s.y0)/(s.y1-s.y0)*n,Pe=(Mt-s.y0)/(s.y1-s.y0)*n;K=Math.max(0,Math.floor(qt)),$=Math.min(r,Math.ceil(ie+1)),nt=Math.max(0,Math.floor(Dt)),tt=Math.min(n,Math.ceil(Pe+1))}if($<=K||tt<=nt)return{[A]:H,dimensions:F,coordinates:O()}}let W=f?Art(f):void 0;for(let it=nt;it<tt;it++)for(let at=K;at<$;at++){if(!pKA(s,r,n,at,it,a,t,p,f,Q,W))continue;let{lat:pt,lon:Ct}=OSe(at,it,s,r,n,a,p,f,Q,W),mt=(it*r+at)*g,ft=[];for(let Qt=0;Qt<g;Qt++){let yt=i[mt+Qt],Mt=jSe(yt,E);if(Mt!==null)if(G&&I){let qt=h?.[Qt],ie=qt&&qt.length===I.length?qt:[Qt];ft.push({keys:ie,value:Mt})}else ft.push({keys:[],value:Mt})}if(ft.length!==0){Y.push(pt),z.push(Ct);for(let{keys:Qt,value:yt}of ft)Qt.length>0?aHt(H,Qt,yt):Array.isArray(H)&&H.push(yt)}}return{[A]:H,dimensions:F,coordinates:O()}}function qSe(){return{lastFetchTime:0,throttleTimeout:null,throttledPending:!1}}function KSe(A,t){if(t<=0)return 0;let i=Date.now()-A.lastFetchTime;return i<t?t-i:0}function zSe(A,t,e){A.throttleTimeout||(A.throttledPending=!0,A.throttleTimeout=setTimeout(()=>{A.throttleTimeout=null,A.throttledPending=!1,e()},t))}function WSe(A){A.lastFetchTime=Date.now()}function VSe(A){A.throttleTimeout&&(clearTimeout(A.throttleTimeout),A.throttleTimeout=null),A.throttledPending=!1}function ZSe(){return{controllers:new Map,currentVersion:0}}function XSe(A,t){for(let[e,i]of A.controllers)e<t&&(i.abort(),A.controllers.delete(e))}function kCt(A){for(let t of A.controllers.values())t.abort();A.controllers.clear()}function mKA(A){for(let t of A.controllers.values())if(!t.signal.aborted)return!0;return!1}function $Se(){return{callback:void 0,metadataLoading:!1,chunksLoading:!1}}function tDe(A,t){A.callback=t}function eDe(A){if(!A.callback)return;let t={loading:A.metadataLoading||A.chunksLoading,metadata:A.metadataLoading,chunks:A.chunksLoading,error:null};A.callback(t)}var QKA=class{constructor({store:A,selector:t,fillValue:e,dimIndices:i,coordinates:r,maxCachedTiles:n=64,bandNames:s=[],fixedDataScale:a=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=a}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 o=e.indexOf(s);if(o>=0)return o}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,a=new Array(n.length).fill(0);for(let o=0;o<n.length;o++){let l=n[o],g=this.getDimKeyForName(l);if(g==="lon")a[o]=i;else if(g==="lat")a[o]=r;else{let h=Fve(this.selector,g,l,this.dimIndices),p=this.normalizeSelection(h,l).map(y=>Math.max(0,Math.min(y,A.shape[o]-1))),E=Math.floor(p[0]/s[o]);p.some(y=>Math.floor(y/s[o])!==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[o]/s[o])-1);a[o]=Math.min(E,Q)}}return a}extractSliceFromChunk(A,t,e,i){let r=this.store.tileSize,n=this.store.tileSize,s=1,a=this.store.dimensions||[],o=e.chunks,l=[],g=-1,h=-1,I=n,p=r,E=[],f=[];for(let G=0;G<a.length;G++){let H=a[G],Y=this.getDimKeyForName(H);if(Y==="lat")g=G,I=Math.min(t[G],n),l.push(-1);else if(Y==="lon")h=G,p=Math.min(t[G],r),l.push(-1);else{let z=Fve(this.selector,Y,H,this.dimIndices),N=this.normalizeSelection(z,H),F=i[G]*o[G],O=N.map(K=>Math.max(0,Math.min(K-F,t[G]-1)));E[G]=O,l.push(O[0]),O.length>1&&f.push(G)}}let Q=G=>{let H=0,Y=1;for(let z=G.length-1;z>=0;z--)H+=G[z]*Y,Y*=t[z];return H},y=[[]];f.forEach(G=>{let H=E[G],Y=[];y.forEach(z=>{H.forEach(N=>{Y.push([...z,N])})}),y=Y}),s=y.length||1;let v=new Map,S=[];for(let G=0;G<s;G++){let H=new Float32Array(r*n);H.fill(this.fillValue),S.push(H)}for(let G=0;G<I;G++)for(let H=0;H<p;H++)g>=0&&(l[g]=G),h>=0&&(l[h]=H),y.forEach((Y,z)=>{let N=[...l],F=0;for(let $=0;$<f.length;$++)N[f[$]]=Y[F++];let O=Q(N),K=G*r+H;O<A.length&&(S[z][K]=A[O])});for(let G=0;G<s;G++){let H=this.bandNames[G]||`band_${G}`;v.set(H,S[G])}return{channels:s,bandData:v}}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}=DSe(n,this.fillValue,this.fixedDataScale);A.bandData.set(r,s),i.push(s)}A.data=kSe(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||($Pt(t),A.textureConfigured=!0);let{format:e,internalFormat:i}=SSe(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?OPt(this.gl):null,bandTextures:new Map,bandTexturesUploaded:new Set,bandTexturesConfigured:new Set,textureUploaded:!1,textureConfigured:!1,vertexBuffer:this.gl?Hve(this.gl):null,pixCoordBuffer:this.gl?Hve(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=OPt(this.gl),e.bandTextures.set(t,i)),i}getTile(A){return this.tiles.get(vp(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=vp(i),n=this.tiles.get(r);if(!n)continue;let s=this.store.levels[i[0]];if(!s)continue;let a=await this.store.getLevelArray(s),o=this.computeChunkIndices(a,i);if(n.chunkData&&n.chunkShape&&this.arraysEqual(n.chunkIndices,o)){if(e<n.selectorVersion)continue;let g=this.extractSliceFromChunk(n.chunkData,n.chunkShape,a,o);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 a=await this.store.getLevelArray(s),o=vp(A),l=this.getOrCreateTile(o);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(a,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,a,g);return this.applyNormalization(l,Q),l.selectorHash=t,l.selectorVersion=e,l.loading=!1,l}let I=await this.store.getChunk(s,g,{signal:i}),p=I.shape.map(Q=>Number(Q)),E=I.data instanceof Float32Array?new Float32Array(I.data.buffer):Float32Array.from(I.data);if(e<l.selectorVersion)return l.loading=!1,null;l.chunkData=E,l.chunkShape=p,l.chunkIndices=g;let f=this.extractSliceFromChunk(E,p,a,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 ADe(A,t,e,i,r){let n=vp([A,t,e]),s=i?.[n];if(s)return s;let a=$qA(A,t,e,r);return{x0:Od(a.west),x1:Od(a.east),y0:C_(a.north),y1:C_(a.south),latMin:a.south,latMax:a.north,lonMin:a.west,lonMax:a.east}}function iDe(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??Zit(A.x0),a=A.lonMax??Zit(A.x1),o=A.latMin??VF(A.y1),l=A.latMax??VF(A.y0),g=a-s,h=Zit(e),I=Zit(i),p=g>0?(I-h)/g:1,E=g>0?(h-s)/g:0;return{overlap:{x0:e,y0:r,x1:i,y1:n},latBounds:{min:o,max:l},texScale:[p,1],texOffset:[E,0]}}function rDe({renderer:A,mode:t,tileId:e,context:i,regions:r}){return r?yKA(A,e,i,r):xKA(A,t,e,i)}function yKA(A,t,e,i){if(i.length===0)return!0;let r=eHt(t),n={lon0:r.x0,lon1:r.x1,lat0:(VF(r.y1)+90)/180,lat1:(VF(r.y0)+90)/180},s=tHt(r.x0,r.y0,r.x1,r.y1),{colormapTexture:a,uniforms:o,customShaderConfig:l}=e,g=e.isGlobe??!0,h=i.some(E=>!!E.wgs84Bounds),I=A.getProgram(e.shaderData,l,!0,h);A.gl.useProgram(I.program),A.applyCommonUniforms(I,a,o,l,e.projectionData,{projection:{name:g?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:g?0:1},s,!0),iHt(A.gl,I,l);let p=!1;for(let E of i){let f;if(E.wgs84Bounds){let S=E.wgs84Bounds,G=S.lat0<n.lat1&&S.lat1>n.lat0,H;if(S.crossesAntimeridian){let z=S.lon0<1&&n.lon0<1&&n.lon1>S.lon0,N=n.lon0<S.lon1&&n.lon1>0;H=z||N}else H=S.lon0<n.lon1&&S.lon1>n.lon0;f=G&&H}else f=ZqA(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};NCt(A.gl,I,y,[0],l)||(p=!0)}return p}function xKA(A,t,e,i){let r=t.getTiledState?.();return r?.tileCache?t.getCRS()==="EPSG:4326"?wKA(A,t,e,i,r):SKA(A,t,e,i,r):!0}function wKA(A,t,e,i,r){let{customShaderConfig:n}=i,{visibleTiles:s,tileBounds:a}=r,o=t.getXYLimits(),l=t.getMaxLevelIndex(),g=t.getLevels();if(!o||s.length===0)return!0;let h=eHt(e),I=tHt(h.x0,h.y0,h.x1,h.y1),p=[];for(let S of s){let G=vp(S),H=a?.[G];H&&H.x0<h.x1&&H.x1>h.x0&&H.y0<h.y1&&H.y1>h.y0&&p.push(S)}if(p.length===0)return!1;let E=A.getProgram(i.shaderData,n,!0,!1);A.gl.useProgram(E.program);let f=g[l]??"",Q=trt(f,l),y=!1,v=!1;for(let S of p){let G=bKA(A,E,S,h,I,r,i,o,Q);G.rendered&&(y=!0),G.missing&&(v=!0)}return v||!y}function bKA(A,t,e,i,r,n,s,a,o){let{tileCache:l,vertexArr:g,pixCoordArr:h,tileSize:I,tileBounds:p}=n,{colormapTexture:E,uniforms:f,customShaderConfig:Q}=s,y=vp(e),v=l.get(y),S=e,G=!1;if(!v?.data){G=!0;let it=LSe(l,e[0],e[1],e[2]);if(it)v=it.tile,S=[it.ancestorZ,it.ancestorX,it.ancestorY];else{let at=TSe(l,e[0],e[1],e[2],o);if(at&&at.length>0){let pt=!1;for(let Ct of at){if(!Ct.tile.data)continue;vKA(A,t,Ct,i,r,n,s,a)&&(pt=!0)}return{rendered:pt,missing:!0}}return{rendered:!1,missing:!0}}}let[H,Y,z]=S,N=vp(S),F=ADe(H,Y,z,p,a),O=iDe(F,i);if(!O)return{rendered:!1,missing:G};let{overlap:K,latBounds:$,texScale:nt,texOffset:tt}=O,W={[N]:{x0:K.x0,y0:K.y0,x1:K.x1,y1:K.y1,latMin:$.min,latMax:$.max}},V=s.isGlobe??!0;return A.applyCommonUniforms(t,E,f,Q,s.projectionData,{projection:{name:V?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:V?0:1},r,!0),A.renderTiles(t,[S],[0],l,I,g,h,W,Q,!0,void 0,{[N]:{texScale:nt,texOffset:tt}},n.latIsAscending),{rendered:!0,missing:G}}function vKA(A,t,e,i,r,n,s,a){let{tileCache:o,vertexArr:l,pixCoordArr:g,tileSize:h,tileBounds:I}=n,{colormapTexture:p,uniforms:E,customShaderConfig:f}=s,Q=[e.childZ,e.childX,e.childY],y=vp(Q),v=ADe(e.childZ,e.childX,e.childY,I,a),S=iDe(v,i);if(!S)return!1;let{overlap:G,latBounds:H,texScale:Y,texOffset:z}=S,N={[y]:{x0:G.x0,y0:G.y0,x1:G.x1,y1:G.y1,latMin:H.min,latMax:H.max}},F=s.isGlobe??!0;return A.applyCommonUniforms(t,p,E,f,s.projectionData,{projection:{name:F?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:F?0:1},r,!0),A.renderTiles(t,[Q],[0],o,h,l,g,N,f,!0,void 0,{[y]:{texScale:Y,texOffset:z}},n.latIsAscending),!0}function SKA(A,t,e,i,r){let{tileCache:n,vertexArr:s,pixCoordArr:a,tileSize:o,tileBounds:l}=r,{colormapTexture:g,uniforms:h,customShaderConfig:I}=i,p=t.getLevels(),E=t.getMaxLevelIndex(),f=eHt(e),Q=tHt(f.x0,f.y0,f.x1,f.y1),y=[e.z,e.x,e.y],v=y.join(","),S=l?.[v],G={[v]:{x0:f.x0,y0:f.y0,x1:f.x1,y1:f.y1,latMin:S?.latMin,latMax:S?.latMax}},H=p[E]??"",Y=trt(H,E),z=A.getProgram(i.shaderData,I,!0);A.gl.useProgram(z.program);let N=i.isGlobe??!0;return A.applyCommonUniforms(z,g,h,I,i.projectionData,{projection:{name:N?"globe":"mercator"},globeToMercatorMatrix:FJ,transition:N?0:1},Q,!0),A.renderTiles(z,[y],[0],n,o,s,a,G,I,!0,Y),!n.get(v)?.data}function Vve(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 DKA=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=Mve,this.visibleTiles=[],this.crs="EPSG:4326",this.xyLimits=null,this.tileBounds={},this.pendingChunks=new Set,this.currentLevel=null,this.selectorVersion=0,this.throttleState=qSe(),this.requestCanceller=ZSe(),this.loadingManager=$Se(),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||Mve,this.crs=A.crs,this.xyLimits=A.xyLimits;let t=zF(this.variable,this.selector);this.tileCache=new QKA({store:this.zarrStore,selector:this.selector,fillValue:A.fill_value??0,dimIndices:A.dimIndices,coordinates:A.coordinates,maxCachedTiles:dqA,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=USe(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[a,o]of Object.entries(this.tileBounds)){let l=Vve(o);l&&this.tileCache.setTileBounds(a,l)}let n=JSON.stringify(this.selector),s=[];for(let a of this.visibleTiles){let o=vp(a);if(this.pendingChunks.has(o))continue;let l=this.tileCache.upsert(o);(!l.data||l.selectorHash!==n)&&s.push(a)}if(s.length>0){let a=KSe(this.throttleState,this.throttleMs);if(a>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),zSe(this.throttleState,a,this.invalidate);return}WSe(this.throttleState);let o=this.pendingChunks.size===0;for(let g of s)this.pendingChunks.add(vp(g));o&&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(vp(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=trt(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 rDe({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){VSe(this.throttleState),kCt(this.requestCanceller),this.tileCache?.clear(),this.tileCache=null,this.pendingChunks.clear(),this.emitLoadingState()}setLoadingCallback(A){tDe(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,eDe(this.loadingManager)}async setSelector(A){this.selector=A,this.selectorVersion++;let t=zF(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?CqA:1;if(this.currentSubdivisions===t)return;let e=RSe(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=XqA(t,this.maxLevelIndex),i=A.getBounds()?.toArray();if(!i)return{tiles:[],pyramidLevel:e,mapZoom:t,bounds:null};let r=this.zarrStore.levels[e],n=trt(r,e);return this.crs==="EPSG:4326"&&this.xyLimits?{tiles:FSe(n,i,this.xyLimits),pyramidLevel:e,mapZoom:t,bounds:i}:{tiles:NSe(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}=AHt(this.xyLimits),n=e-t,s=r-i,a={};for(let o of A){let[l,g,h]=o,I=Math.pow(2,l),p=n/I,E=s/I,f=t+g*p,Q=f+p,y=r-h*E,v=y-E,S=Od(f),G=Od(Q),H=C_(y),Y=C_(v);a[vp(o)]={x0:S,y0:H,x1:G,y1:Y,latMin:v,latMax:y,lonMin:f,lonMax:Q}}return a}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=vp(A);return this.pendingChunks.delete(s),this.emitLoadingState(),null}let r=vp(A),n=Vve(this.tileBounds[r]);try{let s=await this.tileCache.fetchTile(A,t,e,i,n);return this.pendingChunks.delete(r),s?(XSe(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?Xit(t):this.selector,i=this.currentLevel??this.maxLevelIndex,r=this.zarrStore.describe();return fKA(this.variable,A,e,this.zarrStore,this.crs,this.xyLimits,i,this.tileSize,{scaleFactor:r.scaleFactor,addOffset:r.addOffset,fillValue:r.fill_value})}},kKA=1e4,RKA=1e3,MKA=270;function $it(A){return isFinite(A)?((A+180)%360+360)%360-180:A}function GKA(A){let{bounds:t,width:e,height:i,latIsAscending:r,transformer:n}=A,s=e>1?e/(e-1):1,a=i>1?i/(i-1):1;return new qit({forwardTransform:(o,l)=>FCt(o*s,l*a,t,e,i,r),inverseTransform:(o,l)=>{let[g,h]=nHt(o,l,t,e,i,r);return[g/s,h/a]},forwardReproject:(o,l)=>n.forward(o,l),inverseReproject:(o,l)=>n.inverse(o,l)},e,i)}function NKA(A,t,e,i,r=!1){return{lon0:Od(A),lat0:(e+90)/180,lon1:Od(t),lat1:(i+90)/180,crossesAntimeridian:r}}function FKA(A,t,e,i,r,n=!1){let s=A.length/2,a=new Float32Array(s*2),o=n?360-t+e||1:e-t||1,l=r-i||1;for(let g=0;g<s;g++){let h=A[g*2],I=A[g*2+1];h=$it(h),n&&h<t&&(h+=360),a[g*2]=(h-t)/o*2-1,a[g*2+1]=(I-i)/l*2-1}return a}function TPt(A,t){return Math.abs(A-t)>180}function Zve(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 LKA(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],I=e[g+1],p=e[g+2];n[h]&&n[I]&&n[p]&&l.push(h,I,p)}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 a=new Array(t.length);for(let l=0;l<t.length;l++)a[l]=t[l];let o=[];for(let l=0;l<e.length;l+=3){let g=e[l],h=e[l+1],I=e[l+2];if(!n[g]||!n[h]||!n[I])continue;let p=A[g*2],E=A[g*2+1],f=t[g*2],Q=t[g*2+1],y=A[h*2],v=A[h*2+1],S=t[h*2],G=t[h*2+1],H=A[I*2],Y=A[I*2+1],z=t[I*2],N=t[I*2+1],F=$it(p),O=$it(y),K=$it(H),$=TPt(F,O),nt=TPt(O,K),tt=TPt(K,F),W=($?1:0)+(nt?1:0)+(tt?1:0);if(W===0)o.push(g,h,I);else if(W===2){let V=$?nt?[1,2,0]:[0,1,2]:[2,0,1],[it,at,pt]=V,Ct=[g,h,I],mt=[F,O,K],ft=[E,v,Y],Qt=[f,S,z],yt=[Q,G,N],Mt=Ct[it],qt=Ct[at],ie=Ct[pt],Dt=mt[it],Pe=ft[it],me=Qt[it],ue=yt[it],Et=mt[at],xe=ft[at],vA=Qt[at],ce=yt[at],$A=mt[pt],sA=ft[pt],rA=Qt[pt],le=yt[pt],YA=Zve(Dt,Pe,Et,xe),Ci=Zve(Dt,Pe,$A,sA),Li=me+YA.t*(vA-me),eA=ue+YA.t*(ce-ue),he=me+Ci.t*(rA-me),UA=ue+Ci.t*(le-ue),MA=Dt>0,nA=MA?179.9999:-179.9999,je=MA?-179.9999:179.9999,We=s.length/2;s.push(nA,YA.lat,nA,Ci.lat),s.push(je,YA.lat,je,Ci.lat),a.push(Li,eA,he,UA),a.push(Li,eA,he,UA);let Vt=We,jt=We+1,we=We+2,Ye=We+3;o.push(Mt,Vt,jt),o.push(we,qt,ie),o.push(we,ie,Ye)}else o.push(g,h,I)}return{positions:new Float64Array(s),texCoords:new Float64Array(a),indices:new Uint32Array(o)}}function TKA(A){let{geoBounds:t,width:e,height:i,subdivisions:r,transformer:n,latIsAscending:s,maxError:a=BqA}=A,{xMin:o,xMax:l,yMin:g,yMax:h}=t,p=GKA({bounds:[o,g,l,h],width:e,height:i,latIsAscending:s,transformer:n});for(let it=0;it<RKA&&p.getMaxError()>a;it++){let at=p.uvs.length/2;p.refine();let pt=p.uvs.length/2;if(pt>=kKA||pt===at)break}let E=p.uvs,f=(r+1)**2,Q=new Float64Array(E.length+f*2);Q.set(E);let y=E.length;for(let it=0;it<=r;it++)for(let at=0;at<=r;at++)Q[y++]=at/r,Q[y++]=it/r;let S=new jit(Q).triangles,G=Q.length/2,H=new Float64Array(G*2),Y=[],z=1/0,N=-1/0;for(let it=0;it<G;it++){let at=Q[it*2],pt=Q[it*2+1],Ct=o+at*(l-o),mt=s?g+pt*(h-g):h-pt*(h-g),[ft,Qt]=n.forward(Ct,mt);H[it*2]=ft,H[it*2+1]=Qt,isFinite(ft)&&isFinite(Qt)&&(Y.push($it(ft)),z=Math.min(z,Qt),N=Math.max(N,Qt))}isFinite(z)||(z=-90),isFinite(N)||(N=90);let F=-180,O=180,K=!1;if(Y.length>0){Y.sort((at,pt)=>at-pt),F=Y[0],O=Y[Y.length-1];let it=O-F;if(it>0){let at=0,pt=0;for(let mt=0;mt<Y.length-1;mt++){let ft=Y[mt+1]-Y[mt];ft>at&&(at=ft,pt=mt+1)}Y[0]+360-Y[Y.length-1]<at&&it<MKA&&(K=!0,F=Y[pt],O=Y[pt-1])}}K&&F>=180&&(F=F-360,F<=O&&(K=!1));let $=K||O-F>=180,nt=new Float64Array(Q),tt=LKA(H,nt,S,$),W=FKA(tt.positions,F,O,z,N,K),V=NKA(F,O,z,N,K);return{positions:W,texCoords:new Float32Array(tt.texCoords),indices:tt.indices,wgs84Bounds:V}}var UKA=128,PKA=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=qSe(),this.requestCanceller=ZSe(),this.loadingManager=$Se(),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=zF(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=oKA(this.proj4def,t),this.cachedWGS84Transformer=Art(this.proj4def),this.cached4326Transformer=lKA(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=jve(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],a=A.shape;if(n<a[t]||s<a[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>UKA;){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:a,yMin:o,yMax:l}=this.xyLimits,[g,h]=this.regionSize;if(this.proj4def&&this.cachedWGS84Transformer){let K=this.cachedWGS84Transformer,$=Math.ceil(this.width/h),nt=Math.ceil(this.height/g),tt=[];for(let W=0;W<nt;W++)for(let V=0;V<$;V++){let it=this.getRegionBounds(V,W),at=(it.xMin+it.xMax)/2,pt=(it.yMin+it.yMax)/2,mt=[K.inverse(it.xMin,it.yMin),K.inverse(it.xMax,it.yMin),K.inverse(it.xMax,it.yMax),K.inverse(it.xMin,it.yMax),K.inverse(at,it.yMin),K.inverse(at,it.yMax),K.inverse(it.xMin,pt),K.inverse(it.xMax,pt)].filter(qt=>isFinite(qt[0])&&isFinite(qt[1]));if(mt.length===0)continue;let ft=Math.min(...mt.map(qt=>qt[0])),Qt=Math.max(...mt.map(qt=>qt[0])),yt=Math.min(...mt.map(qt=>qt[1])),Mt=Math.max(...mt.map(qt=>qt[1]));Qt>=e&&ft<=r&&Mt>=i&&yt<=n&&tt.push({regionX:V,regionY:W})}return tt}let I=CCt(e,s,a,this.width),p=CCt(r,s,a,this.width),E=CCt(i,o,l,this.height),f=CCt(n,o,l,this.height);this.latIsAscending===!1&&(E=this.height-1-E,f=this.height-1-f);let Q=Math.floor(Math.min(I,p)/h),y=Math.floor(Math.max(I,p)/h),v=Math.floor(Math.min(E,f)/g),S=Math.floor(Math.max(E,f)/g),G=Math.ceil(this.width/h),H=Math.ceil(this.height/g),Y=Math.max(0,Q),z=Math.min(G-1,y),N=Math.max(0,v),F=Math.min(H-1,S),O=[];for(let K=N;K<=F;K++)for(let $=Y;$<=z;$++)O.push({regionX:$,regionY:K});return O}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 a=0;a<i.length;a++)for(let o=0;o<t.length;o++)n.push([...t[o],i[a]]),s.push([...e[o],r[a]]);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,a]=n,{xMin:o,xMax:l,yMin:g,yMax:h}=this.xyLimits,I=A*a,p=Math.min(I+a,i),E=t*s,f=Math.min(E+s,r),Q=o+I/i*(l-o),y=o+p/i*(l-o),v,S;return this.latIsAscending===!1?(S=h-E/r*(h-g),v=h-f/r*(h-g)):(v=g+E/r*(h-g),S=g+f/r*(h-g)),{xMin:Q,xMax:y,yMin:v,yMax:S}}createRegionGeometry(A,t,e,i){if(!i.levelMeta&&!this.regionSize)return;let r=this.getRegionBounds(A,t,i.levelMeta??void 0),n=i.mercatorBounds??jve(r,this.crs);if(i.mercatorBounds=n,this.proj4def&&this.cached4326Transformer){let s=(r.xMin+r.xMax)/2,a=(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,a)].map(p=>p[1]).filter(p=>isFinite(p)),g=l.length>0?Math.max(...l)-Math.min(...l):0,h=Math.max(Gve,Math.min(Nve,Math.ceil(g))),I=TKA({geoBounds:r,width:i.width,height:i.height,subdivisions:h,transformer:this.cached4326Transformer,latIsAscending:this.latIsAscending});i.vertexArr=I.positions,i.pixCoordArr=I.texCoords,i.indexArr=I.indices,i.wgs84Bounds=I.wgs84Bounds,i.useIndexedMesh=!0,i.vertexCount=i.indexArr.length}else{let s;if(this.crs==="EPSG:3857"){let l=.5-r.yMin/(2*L1),g=.5-r.yMax/(2*L1);s=Math.abs(VF(g)-VF(l))}else s=Math.abs(r.yMax-r.yMin);let a=this.isGlobeProjection?Math.max(Gve,Math.min(Nve,Math.ceil(s))):EqA,o=RSe(a);if(i.vertexArr=o.vertexArr,i.useIndexedMesh=!1,i.vertexCount=o.vertexArr.length/2,this.crs==="EPSG:4326"){let l=r.yMin,g=r.yMax;i.mercatorBounds={x0:Od(r.xMin),x1:Od(r.xMax),y0:C_(g),y1:C_(l),latMin:l,latMax:g},i.latIsAscending=this.latIsAscending,i.pixCoordArr=o.texCoordArr}else i.pixCoordArr=this.latIsAscending?tKA(o.texCoordArr):o.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],a=this.classifyDimension(n);if(a==="lon")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.x:t.spatialBounds?.type==="bbox"?e[s.index]=Im(t.spatialBounds.minX,t.spatialBounds.maxX):e[s.index]=t.includeSpatialSlices?Im(0,this.width):0;else if(a==="lat")t.spatialBounds?.type==="point"?e[s.index]=t.spatialBounds.y:t.spatialBounds?.type==="bbox"?e[s.index]=Im(t.spatialBounds.minY,t.spatialBounds.maxY):e[s.index]=t.includeSpatialSlices?Im(0,this.height):0;else{let o=A[n]||(a==="time"?A.time:void 0);if(o!==void 0){let l=o.selected,g=o.type;if(t.trackMultiValue&&Array.isArray(l)&&l.length>1){let h=[],I=[];for(let p of l){let E=await this.resolveSelectionIndex(n,s,p,g);h.push(E),I.push(p)}i.push({dimIndex:s.index,dimName:n,values:h,labels:I}),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:o,regionY:l}of e)this.visibleRegionKeys.add(this.makeRegionKey(i,o,l));if(this.currentLevelCoversViewport()){let o=`${i}:`;for(let l of this.visibleRegionKeys)l.startsWith(o)||this.visibleRegionKeys.delete(l)}let r=[],n=[];for(let{regionX:o,regionY:l}of e){let g=this.makeRegionKey(i,o,l),h=this.regionCache.get(g);h?.loading||(h?.data?h.selectorVersion!==this.selectorVersion&&n.push({regionX:o,regionY:l}):r.push({regionX:o,regionY:l}))}let s=`${i}:${this.selectorVersion}:${e.map(o=>`${o.regionX},${o.regionY}`).join("|")}`,a=s!==this.lastViewportHash;this.lastViewportHash=s,!(r.length===0&&n.length===0&&!a)&&(r.length>0&&this.fetchRegions(r,t),n.length>0&&this.fetchRegionsThrottled(n,t))}fetchRegionsThrottled(A,t){let e=KSe(this.throttleState,this.throttleMs);if(e>0){this.throttleState.throttledPending||(this.throttleState.throttledPending=!0,this.emitLoadingState()),zSe(this.throttleState,e,this.invalidate);return}WSe(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 a=this.makeRegionKey(e.index,n,s),o=this.regionCache.get(a);o||(o=this.createRegionState(e.index,n,s),this.regionCache.set(a,o)),o.loading=!0}let i=32,r=[];for(let{regionX:n,regionY:s}of A){if(this.currentLevelIndex!==e.index){kCt(this.requestCanceller),this.clearBatchLoadingFlags(A,e.index);break}let a=this.fetchRegion(n,s,t,e).then(()=>{r.splice(r.indexOf(a),1)}).catch(()=>{r.splice(r.indexOf(a),1)});r.push(a),r.length>=i&&await Promise.race(r)}r.length>0&&await Promise.allSettled(r),mKA(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,a=new AbortController;this.requestCanceller.controllers.set(n,a);let o=this.regionCache.get(r);o||(o=this.createRegionState(i.index,A,t),this.regionCache.set(r,o)),o.loading=!0;let[l,g]=i.regionSize,h=t*l,I=Math.min(h+l,i.height),p=A*g,E=Math.min(p+g,i.width),f=E-p,Q=I-h;try{let y=[...i.baseSliceArgs],v=this.dimIndices.lat.index,S=this.dimIndices.lon.index;y[v]=Im(h,I),y[S]=Im(p,E);let G=this.zarrStore.describe(),H=this.levels[i.index],Y=H?.fillValue??G.fill_value,{combinations:z}=this.buildChannelCombinations(i.baseMultiValueDims),N=z.length||1,F=f*Q,O=[],K=new Float32Array(F*N);if(K.fill(Y??0),N===1){if(a.signal.aborted||this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let mt=await r2(i.zarrArray,y,{opts:{signal:a.signal}});if(a.signal.aborted||this.isRemoved){o.loading=!1;return}if(this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let ft=new Float32Array(mt.data);O.push(ft),K.set(ft)}else for(let mt=0;mt<N;mt++){if(a.signal.aborted||this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let ft=[...y],Qt=z[mt];for(let qt=0;qt<i.baseMultiValueDims.length;qt++)ft[i.baseMultiValueDims[qt].dimIndex]=Qt[qt];let yt=await r2(i.zarrArray,ft,{opts:{signal:a.signal}});if(a.signal.aborted||this.isRemoved){o.loading=!1;return}if(this.currentLevelIndex!==i.index){o.loading=!1,this.requestCanceller.controllers.delete(n);return}let Mt=new Float32Array(yt.data);O.push(Mt);for(let qt=0;qt<F;qt++)K[qt*N+mt]=Mt[qt]}if(s<o.selectorVersion){o.loading=!1;return}o.selectorVersion=s,XSe(this.requestCanceller,n);let $=O,nt=f,tt=Q;if(this.proj4def&&this.cachedMercatorTransformer&&this.xyLimits&&!o.mercatorBounds){let mt={width:i.width,height:i.height,regionSize:i.regionSize},ft=this.getRegionBounds(A,t,mt);o.mercatorBounds=this.computeRegionMercatorBounds(ft)}let V=H?.scaleFactor??G.scaleFactor,it=H?.addOffset??G.addOffset;o.bandData.clear(),o.bandTexturesUploaded.clear();let at=[];for(let mt=0;mt<$.length;mt++){let ft=this.bandNames[mt]||`band_${mt}`,Qt=$[mt];if(V!==1||it!==0){let qt=new Float32Array(Qt.length);for(let ie=0;ie<Qt.length;ie++){let Dt=Qt[ie];Number.isFinite(Dt)?qt[ie]=Dt*V+it:qt[ie]=Dt}Qt=qt}let yt=Y!==null&&(V!==1||it!==0)?Y*V+it:Y,{normalized:Mt}=DSe(Qt,yt,this.fixedDataScale);o.bandData.set(ft,Mt),at.push(Mt)}o.data=kSe(at,N);let pt=!o.vertexBuffer||o.width!==nt||o.height!==tt;o.width=nt,o.height=tt,o.channels=N,o.loading=!1,o.levelMeta={width:i.width,height:i.height,regionSize:[...i.regionSize]},o.texture||(o.texture=e.createTexture());let Ct=nKA(e,{texture:o.texture,data:o.data,width:nt,height:tt,channels:N,configured:!1});o.textureUploaded=Ct.uploaded,pt&&this.createRegionGeometry(A,t,e,o),this.invalidate()}catch(y){y instanceof DOMException&&y.name==="AbortError"||console.error(`[fetchRegion] Error fetching region ${r}:`,y),o.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,kCt(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),a=2*L1;e=s/a}else if(this.crs==="EPSG:3857"){let r=this.xyLimits.xMax-this.xyLimits.xMin,n=2*L1;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,a=n.shape[s]/e;i.push({index:r,effectivePixels:a})}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],a=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=a,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;iHt(r,t,i);for(let n of this.getLoadedRegions())NCt(r,t,this.regionToRenderable(n),e,i)}renderToTile(A,t,e){return rDe({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,VSe(this.throttleState),kCt(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){tDe(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=zve(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=zve(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=zF(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),eDe(this.loadingManager)}async resolveSelectionIndex(A,t,e,i){if(i==="index"||!this.zarrStore.root)return typeof e=="number"?e:0;try{let r=await ySe(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,a=i.map(h=>h.dimName);if(t.type==="point"){let h=[];if(s===1){let I=await r2(this.zarrArray,e),p=this.extractScalarValue(I);if(p===null)return null;h.push(p)}else for(let I=0;I<s;I++){let p=[...e],E=r[I];for(let y=0;y<i.length;y++)p[i[y].dimIndex]=E[y];let f=await r2(this.zarrArray,p),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:a}}let o=t.maxX-t.minX,l=t.maxY-t.minY;if(s===1){let h=await r2(this.zarrArray,e);return{type:"bbox",values:[],data:new Float32Array(h.data),width:o,height:l,channels:1,channelLabels:n,multiValueDimNames:a}}let g=new Float32Array(o*l*s);for(let h=0;h<s;h++){let I=[...e],p=r[h];for(let f=0;f<i.length;f++)I[i[f].dimIndex]=p[f];let E=await r2(this.zarrArray,I);for(let f=0;f<o*l;f++)g[f*s+h]=E.data[f]}return{type:"bbox",values:[],data:g,width:o,height:l,channels:s,channelLabels:n,multiValueDimNames:a}}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?Xit(t):this.selector,i=this.zarrStore.describe(),r=this.levels[this.currentLevelIndex],n=r?.scaleFactor??i.scaleFactor,s=r?.addOffset??i.addOffset,a=r?.fillValue??i.fill_value;if(A.type==="Point"){let[S,G]=A.coordinates,H={lat:[G],lon:[S]},Y=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,z=BKA(S,G,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 N=await this.fetchQueryData(e,{type:"point",x:z.x,y:z.y});if(!N)return{[this.variable]:[],dimensions:["lat","lon"],coordinates:H};let{values:F,channelLabels:O,multiValueDimNames:K}=N,$=K.length>0,nt=$?{}:[];for(let at=0;at<F.length;at++){let pt=F[at];if(!(pt==null||!Number.isFinite(pt))&&!(a!==null&&pt===a))if(n!==1&&(pt*=n),s!==0&&(pt+=s),$){let Ct=O?.[at];Ct&&K.length>0&&Ct.length===K.length?nt=aHt(nt,Ct,pt):Array.isArray(nt)&&nt.push(pt)}else Array.isArray(nt)&&nt.push(pt)}let tt=i.dimensions,W=tt.map(at=>{let pt=at.toLowerCase();return["x","lon","longitude"].includes(pt)?"lon":["y","lat","latitude"].includes(pt)?"lat":at}),V=$?W:["lat","lon"],it={lat:H.lat,lon:H.lon};if($)for(let at of tt){let pt=at.toLowerCase();if(["x","lon","longitude","y","lat","latitude"].includes(pt))continue;let Ct=e[at];if(Ct&&"selected"in Ct){let mt=Ct.selected,ft=Array.isArray(mt)?mt:[mt];it[at]=ft}else i.coordinates[at]&&(it[at]=i.coordinates[at])}return{[this.variable]:nt,dimensions:V,coordinates:it}}let o=this.xyLimits?[this.xyLimits.xMin,this.xyLimits.yMin,this.xyLimits.xMax,this.xyLimits.yMax]:null,l=gKA(A,this.mercatorBounds,this.width,this.height,this.crs??"EPSG:4326",this.latIsAscending,this.proj4def,o,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:I,minY:p,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+I/this.width*f,y0:this.mercatorBounds.y0+p/this.height*Q,y1:this.mercatorBounds.y0+E/this.height*Q};if(this.mercatorBounds.latMin!==void 0&&this.mercatorBounds.latMax!==void 0){let S=this.mercatorBounds.latMax-this.mercatorBounds.latMin;this.latIsAscending?(y.latMin=this.mercatorBounds.latMin+p/this.height*S,y.latMax=this.mercatorBounds.latMin+E/this.height*S):(y.latMax=this.mercatorBounds.latMax-p/this.height*S,y.latMin=this.mercatorBounds.latMax-E/this.height*S)}let v=null;if(this.proj4def&&o){let[S,G]=FCt(h,p,o,this.width,this.height,this.latIsAscending),[H,Y]=FCt(I,E,o,this.width,this.height,this.latIsAscending);v=[Math.min(S,H),Math.min(G,Y),Math.max(S,H),Math.max(G,Y)]}return _KA(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:a},this.proj4def,v)}},nDe=class{constructor({id:A,source:t,variable:e,selector:i={},colormap:r,clim:n,opacity:s=1,minzoom:a=0,maxzoom:o=1/0,zarrVersion:l,spatialDimensions:g={},bounds:h,crs:I,latIsAscending:p=null,fillValue:E,customFrag:f,uniforms:Q,renderingMode:y="3d",onLoadingStateChange:v,throttleMs:S=100,proj4:G,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=PqA,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]");G&&!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=I,this.latIsAscending=p??null,this.selector=i,this.normalizedSelector=Xit(i),this.selectorHash=this.computeSelectorHash(this.normalizedSelector),this.renderingMode=y,this.invalidate=()=>{},this.colormap=new JqA(r),this.clim=n,this.fixedDataScale=Math.max(Math.abs(n[0]),Math.abs(n[1]),1),this.opacity=s,this.minZoom=a,this.maxZoom=o,this.customFrag=f,this.customUniforms=Q||{},this.bandNames=zF(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=v,this.throttleMs=S,this.proj4=G,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 USe(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=Xit(A),e=this.computeSelectorHash(t);e!==this.selectorHash&&(this.selectorHash=e,this.selector=A,this.normalizedSelector=t,this.bandNames=zF(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 aKA(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 DKA(this.zarrStore,this.variable,this.normalizedSelector,this.invalidate,this.throttleMs,this.fixedDataScale):this.mode=new PKA(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 bqA({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=Xit(this.selector),await this.loadInitialDimensionValues(),this.bandNames=zF(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]=xSe(e);for(let t of Object.keys(this.dimIndices))if(!fqA.has(t.toLowerCase()))try{this.dimensionValues[t]=await ySe(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 a=eKA(t,e,i,r);if(!a.matrix)return;let o=!a.mapbox&&!a.shaderData?{projection:{name:"mercator"},globeToMercatorMatrix:FJ,transition:1}:void 0,l=this.isGlobeProjection(),g=AKA(this.map,l),h=this.colormap.ensureTexture(this.gl),I={gl:this.gl,matrix:a.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:a.shaderData,projectionData:a.projectionData,mapbox:a.mapbox??o};this.mode.render(this.renderer,I),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 HCt=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[o,l]of Object.entries(t))this.executeMethod("addSource",[o],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(([,o])=>e.has(o.type)),n=r.filter(([o,l])=>o.startsWith("basemap-")||l.type==="raster"),s=r.filter(([o,l])=>!(o.startsWith("basemap-")||l.type==="raster")),a=[...n,...s];for(let[o,l]of a)this.executeMethod("addLayer",[],l)}getMap(){return this.map}getIsMapReady(){return this.isMapReady}getModel(){return this.model}};var OCt=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")||{}}};jYt();var $Ne=Zl(ky(),1),Z9=63710088e-1,tFe={centimeters:Z9*100,centimetres:Z9*100,degrees:360/(2*Math.PI),feet:Z9*3.28084,inches:Z9*39.37,kilometers:Z9/1e3,kilometres:Z9/1e3,meters:Z9,metres:Z9,miles:Z9/1609.344,millimeters:Z9*1e3,millimetres:Z9*1e3,nauticalmiles:Z9/1852,radians:1,yards:Z9*1.0936};function VE(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 u3(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(!rNe(A[0])||!rNe(A[1]))throw new Error("coordinates must contain numbers");return VE({type:"Point",coordinates:A},t,e)}function Fm(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 VE({type:"Polygon",coordinates:A},t,e)}function O1(A,t,e={}){if(A.length<2)throw new Error("coordinates must be an array of two or more positions");return VE({type:"LineString",coordinates:A},t,e)}function tl(A,t={}){let e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=A,e}function eFe(A,t,e={}){return VE({type:"MultiLineString",coordinates:A},t,e)}function cft(A,t,e={}){return VE({type:"MultiPolygon",coordinates:A},t,e)}function bJt(A,t="kilometers"){let e=tFe[t];if(!e)throw new Error(t+" units is invalid");return A*e}function AFe(A,t="kilometers"){let e=tFe[t];if(!e)throw new Error(t+" units is invalid");return A/e}function PEt(A){return A%(2*Math.PI)*180/Math.PI}function CB(A){return A%360*Math.PI/180}function iFe(A,t="kilometers",e="kilometers"){if(!(A>=0))throw new Error("length must be a positive number");return bJt(AFe(A,t),e)}function rNe(A){return!isNaN(A)&&A!==null&&!Array.isArray(A)}function fnt(A){return A!==null&&typeof A=="object"&&!Array.isArray(A)}function I3(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 qd(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 Lm(A){return A.type==="Feature"?A.geometry:A}function HEt(A,t){return A.type==="FeatureCollection"?"FeatureCollection":A.type==="GeometryCollection"?"GeometryCollection":A.type==="Feature"&&A.geometry!==null?A.geometry.type:A.type}function rFe(A,t,e={}){if(e.final===!0)return Oni(A,t);let i=I3(A),r=I3(t),n=CB(i[0]),s=CB(r[0]),a=CB(i[1]),o=CB(r[1]),l=Math.sin(s-n)*Math.cos(o),g=Math.cos(a)*Math.sin(o)-Math.sin(a)*Math.cos(o)*Math.cos(s-n);return PEt(Math.atan2(l,g))}function Oni(A,t){let e=rFe(t,A);return e=(e+180)%360,e}function pnt(A,t,e={}){var i=I3(A),r=I3(t),n=CB(r[1]-i[1]),s=CB(r[0]-i[0]),a=CB(i[1]),o=CB(r[1]),l=Math.pow(Math.sin(n/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(o);return bJt(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)),e.units)}function Yni(A,t,e={}){let i;return e.final?i=nNe(I3(t),I3(A)):i=nNe(I3(A),I3(t)),i>180?-(360-i):i}function nNe(A,t){let e=CB(A[1]),i=CB(t[1]),r=CB(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(PEt(s)+360)%360}function Fk(A,t,e){if(A!==null)for(var i,r,n,s,a,o,l,g=0,h=0,I,p=A.type,E=p==="FeatureCollection",f=p==="Feature",Q=E?A.features.length:1,y=0;y<Q;y++){l=E?A.features[y].geometry:f?A.geometry:A,I=l?l.type==="GeometryCollection":!1,a=I?l.geometries.length:1;for(var v=0;v<a;v++){var S=0,G=0;if(s=I?l.geometries[v]:l,s!==null){o=s.coordinates;var H=s.type;switch(g=e&&(H==="Polygon"||H==="MultiPolygon")?1:0,H){case null:break;case"Point":if(t(o,h,y,S,G)===!1)return!1;h++,S++;break;case"LineString":case"MultiPoint":for(i=0;i<o.length;i++){if(t(o[i],h,y,S,G)===!1)return!1;h++,H==="MultiPoint"&&S++}H==="LineString"&&S++;break;case"Polygon":case"MultiLineString":for(i=0;i<o.length;i++){for(r=0;r<o[i].length-g;r++){if(t(o[i][r],h,y,S,G)===!1)return!1;h++}H==="MultiLineString"&&S++,H==="Polygon"&&G++}H==="Polygon"&&S++;break;case"MultiPolygon":for(i=0;i<o.length;i++){for(G=0,r=0;r<o[i].length;r++){for(n=0;n<o[i][r].length-g;n++){if(t(o[i][r][n],h,y,S,G)===!1)return!1;h++}G++}S++}break;case"GeometryCollection":for(i=0;i<s.geometries.length;i++)if(Fk(s.geometries[i],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function l7(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 Jni(A,t,e){var i=e;return l7(A,function(r,n){n===0&&e===void 0?i=r:i=t(i,r,n)}),i}function jni(A){var t=[];return Fk(A,function(e){t.push(e)}),t}function Lk(A,t){var e,i,r,n,s,a,o,l,g,h,I=0,p=A.type==="FeatureCollection",E=A.type==="Feature",f=p?A.features.length:1;for(e=0;e<f;e++){for(a=p?A.features[e].geometry:E?A.geometry:A,l=p?A.features[e].properties:E?A.properties:{},g=p?A.features[e].bbox:E?A.bbox:void 0,h=p?A.features[e].id:E?A.id:void 0,o=a?a.type==="GeometryCollection":!1,s=o?a.geometries.length:1,r=0;r<s;r++){if(n=o?a.geometries[r]:a,n===null){if(t(null,I,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,I,l,g,h)===!1)return!1;break}case"GeometryCollection":{for(i=0;i<n.geometries.length;i++)if(t(n.geometries[i],I,l,g,h)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}I++}}function qni(A,t,e){var i=e;return Lk(A,function(r,n,s,a,o){i=t(i,r,n,s,a,o)}),i}function g7(A,t){Lk(A,function(e,i,r,n,s){var a=e===null?null:e.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return t(VE(e,r,{bbox:n,id:s}),i,0)===!1?!1:void 0}var o;switch(a){case"MultiPoint":o="Point";break;case"MultiLineString":o="LineString";break;case"MultiPolygon":o="Polygon";break}for(var l=0;l<e.coordinates.length;l++){var g=e.coordinates[l],h={type:o,coordinates:g};if(t(VE(h,r),i,l)===!1)return!1}})}function int(A,t){g7(A,function(e,i,r){var n=0;if(e.geometry){var s=e.geometry.type;if(!(s==="Point"||s==="MultiPoint")){var a,o=0,l=0,g=0;if(Fk(e,function(h,I,p,E,f){if(a===void 0||i>o||E>l||f>g){a=h,o=i,l=E,g=f,n=0;return}var Q=O1([a,h],e.properties);if(t(Q,i,r,f,n)===!1)return!1;n++,a=h})===!1)return!1}}})}function OEt(A){return qni(A,(t,e)=>t+Kni(e),0)}function Kni(A){let t=0,e;switch(A.type){case"Polygon":return sNe(A.coordinates);case"MultiPolygon":for(e=0;e<A.coordinates.length;e++)t+=sNe(A.coordinates[e]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function sNe(A){let t=0;if(A&&A.length>0){t+=Math.abs(aNe(A[0]));for(let e=1;e<A.length;e++)t-=Math.abs(aNe(A[e]))}return t}var zni=Z9*Z9/2,qYt=Math.PI/180;function aNe(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],a=r[0]*qYt,o=n[1]*qYt,l=s[0]*qYt;e+=(l-a)*Math.sin(o),i++}return e*zni}function Mu(A,t={}){if(A.bbox!=null&&t.recompute!==!0)return A.bbox;let e=[1/0,1/0,-1/0,-1/0];return Fk(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 Wni(A,t,e){var i=A.length,r=wj(A[0],t),n=[],s,a,o;let l,g;for(e||(e=[]),s=1;s<i;s++){for(l=A[s-1],g=A[s],a=o=wj(g,t);;)if(r|a){if(r&a)break;r?(l=oJt(l,g,r,t),r=wj(l,t)):(g=oJt(l,g,a,t),a=wj(g,t))}else{n.push(l),a!==o?(n.push(g),s<i-1&&(e.push(n),n=[])):s===i-1&&n.push(g);break}r=o}return n.length&&e.push(n),e}function Vni(A,t){var e,i,r,n,s,a,o;for(i=1;i<=8;i*=2){for(e=[],r=A[A.length-1],n=!(wj(r,t)&i),s=0;s<A.length;s++)a=A[s],o=!(wj(a,t)&i),o!==n&&e.push(oJt(r,a,i,t)),o&&e.push(a),r=a,n=o;if(A=e,!A.length)break}return e}function oJt(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 wj(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 Zni(A,t){let e=Lm(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(a=>{Wni(a,t,s)}),s.length===1?O1(s[0],r):eFe(s,r)}case"Polygon":return Fm(oNe(n,t),r);case"MultiPolygon":return cft(n.map(s=>oNe(s,t)),r);default:throw new Error("geometry "+i+" not supported")}}function oNe(A,t){let e=[];for(let i of A){let r=Vni(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 o7=11102230246251565e-32,H1=134217729,Xni=(3+8*o7)*o7;function KYt(A,t,e,i,r){let n,s,a,o,l=t[0],g=i[0],h=0,I=0;g>l==g>-l?(n=l,l=t[++h]):(n=g,g=i[++I]);let p=0;if(h<A&&I<e)for(g>l==g>-l?(s=l+n,a=n-(s-l),l=t[++h]):(s=g+n,a=n-(s-g),g=i[++I]),n=s,a!==0&&(r[p++]=a);h<A&&I<e;)g>l==g>-l?(s=n+l,o=s-n,a=n-(s-o)+(l-o),l=t[++h]):(s=n+g,o=s-n,a=n-(s-o)+(g-o),g=i[++I]),n=s,a!==0&&(r[p++]=a);for(;h<A;)s=n+l,o=s-n,a=n-(s-o)+(l-o),l=t[++h],n=s,a!==0&&(r[p++]=a);for(;I<e;)s=n+g,o=s-n,a=n-(s-o)+(g-o),g=i[++I],n=s,a!==0&&(r[p++]=a);return(n!==0||p===0)&&(r[p++]=n),p}function $ni(A,t){let e=t[0];for(let i=1;i<A;i++)e+=t[i];return e}function _nt(A){return new Float64Array(A)}var tsi=(3+16*o7)*o7,esi=(2+12*o7)*o7,Asi=(9+64*o7)*o7*o7,_j=_nt(4),lNe=_nt(8),gNe=_nt(12),cNe=_nt(16),dB=_nt(4);function isi(A,t,e,i,r,n,s){let a,o,l,g,h,I,p,E,f,Q,y,v,S,G,H,Y,z,N,F=A-r,O=e-r,K=t-n,$=i-n;G=F*$,I=H1*F,p=I-(I-F),E=F-p,I=H1*$,f=I-(I-$),Q=$-f,H=E*Q-(G-p*f-E*f-p*Q),Y=K*O,I=H1*K,p=I-(I-K),E=K-p,I=H1*O,f=I-(I-O),Q=O-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,_j[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,_j[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,_j[2]=v-(N-h)+(y-h),_j[3]=N;let nt=$ni(4,_j),tt=esi*s;if(nt>=tt||-nt>=tt||(h=A-F,a=A-(F+h)+(h-r),h=e-O,l=e-(O+h)+(h-r),h=t-K,o=t-(K+h)+(h-n),h=i-$,g=i-($+h)+(h-n),a===0&&o===0&&l===0&&g===0)||(tt=Asi*s+Xni*Math.abs(nt),nt+=F*g+$*a-(K*l+O*o),nt>=tt||-nt>=tt))return nt;G=a*$,I=H1*a,p=I-(I-a),E=a-p,I=H1*$,f=I-(I-$),Q=$-f,H=E*Q-(G-p*f-E*f-p*Q),Y=o*O,I=H1*o,p=I-(I-o),E=o-p,I=H1*O,f=I-(I-O),Q=O-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,dB[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,dB[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,dB[2]=v-(N-h)+(y-h),dB[3]=N;let W=KYt(4,_j,4,dB,lNe);G=F*g,I=H1*F,p=I-(I-F),E=F-p,I=H1*g,f=I-(I-g),Q=g-f,H=E*Q-(G-p*f-E*f-p*Q),Y=K*l,I=H1*K,p=I-(I-K),E=K-p,I=H1*l,f=I-(I-l),Q=l-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,dB[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,dB[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,dB[2]=v-(N-h)+(y-h),dB[3]=N;let V=KYt(W,lNe,4,dB,gNe);G=a*g,I=H1*a,p=I-(I-a),E=a-p,I=H1*g,f=I-(I-g),Q=g-f,H=E*Q-(G-p*f-E*f-p*Q),Y=o*l,I=H1*o,p=I-(I-o),E=o-p,I=H1*l,f=I-(I-l),Q=l-f,z=E*Q-(Y-p*f-E*f-p*Q),y=H-z,h=H-y,dB[0]=H-(y+h)+(h-z),v=G+y,h=v-G,S=G-(v-h)+(y-h),y=S-Y,h=S-y,dB[1]=S-(y+h)+(h-Y),N=v+y,h=N-v,dB[2]=v-(N-h)+(y-h),dB[3]=N;let it=KYt(V,gNe,4,dB,cNe);return cNe[it-1]}function rsi(A,t,e,i,r,n){let s=(t-n)*(e-r),a=(A-r)*(i-n),o=s-a,l=Math.abs(s+a);return Math.abs(o)>=tsi*l?o:-isi(A,t,e,i,r,n,l)}function nsi(A,t){var e,i,r=0,n,s,a,o,l,g,h,I=A[0],p=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]-I,a=g[1]-p,i;i<Q;i++){if(h=f[i+1],o=h[0]-I,l=h[1]-p,a===0&&l===0){if(o<=0&&s>=0||s<=0&&o>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(n=rsi(s,o,a,l,0,0),n===0)return 0;(n>0&&l>0&&a<=0||n<0&&l<=0&&a>0)&&r++}g=h,a=l,s=o}}return r%2!==0}function p3(A,t,e={}){if(!A)throw new Error("point is required");if(!t)throw new Error("polygon is required");let i=I3(A),r=Lm(t),n=r.type,s=t.bbox,a=r.coordinates;if(s&&ssi(i,s)===!1)return!1;n==="Polygon"&&(a=[a]);let o=!1;for(var l=0;l<a.length;++l){let g=nsi(i,a[l]);if(g===0)return!e.ignoreBoundary;g&&(o=!0)}return o}function ssi(A,t){return t[0]<=A[0]&&t[1]<=A[1]&&t[2]>=A[0]&&t[3]>=A[1]}function BB(A,t,e={}){let i=I3(A),r=qd(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")),asi(r[n],r[n+1],i,s,typeof e.epsilon>"u"?null:e.epsilon))return!0}return!1}function asi(A,t,e,i,r){let n=e[0],s=e[1],a=A[0],o=A[1],l=t[0],g=t[1],h=e[0]-a,I=e[1]-o,p=l-a,E=g-o,f=h*E-I*p;if(r!==null){if(Math.abs(f)>r)return!1}else if(f!==0)return!1;if(Math.abs(p)===Math.abs(E)&&Math.abs(p)===0)return i?!1:e[0]===A[0]&&e[1]===A[1];if(i){if(i==="start")return Math.abs(p)>=Math.abs(E)?p>0?a<n&&n<=l:l<=n&&n<a:E>0?o<s&&s<=g:g<=s&&s<o;if(i==="end")return Math.abs(p)>=Math.abs(E)?p>0?a<=n&&n<l:l<n&&n<=a:E>0?o<=s&&s<g:g<s&&s<=o;if(i==="both")return Math.abs(p)>=Math.abs(E)?p>0?a<n&&n<l:l<n&&n<a:E>0?o<s&&s<g:g<s&&s<o}else return Math.abs(p)>=Math.abs(E)?p>0?a<=n&&n<=l:l<=n&&n<=a:E>0?o<=s&&s<=g:g<=s&&s<=o;return!1}function osi(A,t,e,i,r){nFe(A,t,e||0,i||A.length-1,r||lsi)}function nFe(A,t,e,i,r){for(;i>e;){if(i-e>600){var n=i-e+1,s=t-e+1,a=Math.log(n),o=.5*Math.exp(2*a/3),l=.5*Math.sqrt(a*o*(n-o)/n)*(s-n/2<0?-1:1),g=Math.max(e,Math.floor(t-s*o/n+l)),h=Math.min(i,Math.floor(t+(n-s)*o/n+l));nFe(A,t,g,h,r)}var I=A[t],p=e,E=i;for($rt(A,e,t),r(A[i],I)>0&&$rt(A,e,i);p<E;){for($rt(A,p,E),p++,E--;r(A[p],I)<0;)p++;for(;r(A[E],I)>0;)E--}r(A[e],I)===0?$rt(A,e,E):(E++,$rt(A,E,i)),E<=t&&(e=E+1),t<=E&&(i=E-1)}}function $rt(A,t,e){var i=A[t];A[t]=A[e],A[e]=i}function lsi(A,t){return A<t?-1:A>t?1:0}var vJt=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(!mEt(t,e))return i;let r=this.toBBox,n=[];for(;e;){for(let s=0;s<e.children.length;s++){let a=e.children[s],o=e.leaf?r(a):a;mEt(t,o)&&(e.leaf?i.push(a):WYt(t,o)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!mEt(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(mEt(t,s)){if(e.leaf||WYt(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=yj([]),this}remove(t,e){if(!t)return this;let i=this.data,r=this.toBBox(t),n=[],s=[],a,o,l;for(;i||n.length;){if(i||(i=n.pop(),o=n[n.length-1],a=s.pop(),l=!0),i.leaf){let g=gsi(t,i.children,e);if(g!==-1)return i.children.splice(g,1),n.push(i),this._condense(n),this}!l&&!i.leaf&&WYt(i,r)?(n.push(i),s.push(a),a=0,o=i,i=i.children[0]):o?(a++,i=o.children[a],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,a;if(n<=s)return a=yj(t.slice(e,i+1)),mj(a,this.toBBox),a;r||(r=Math.ceil(Math.log(n)/Math.log(s)),s=Math.ceil(n/Math.pow(s,r-1))),a=yj([]),a.leaf=!1,a.height=r;let o=Math.ceil(n/s),l=o*Math.ceil(Math.sqrt(s));hNe(t,e,i,l,this.compareMinX);for(let g=e;g<=i;g+=l){let h=Math.min(g+l-1,i);hNe(t,g,h,o,this.compareMinY);for(let I=g;I<=h;I+=o){let p=Math.min(I+o-1,h);a.children.push(this._build(t,I,p,r-1))}}return mj(a,this.toBBox),a}_chooseSubtree(t,e,i,r){for(;r.push(e),!(e.leaf||r.length-1===i);){let n=1/0,s=1/0,a;for(let o=0;o<e.children.length;o++){let l=e.children[o],g=zYt(l),h=usi(t,l)-g;h<s?(s=h,n=g<n?g:n,a=l):h===s&&g<n&&(n=g,a=l)}e=a||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),nnt(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),a=yj(i.children.splice(s,i.children.length-s));a.height=i.height,a.leaf=i.leaf,mj(i,this.toBBox),mj(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=yj([t,e]),this.data.height=t.height+1,this.data.leaf=!1,mj(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let r,n=1/0,s=1/0;for(let a=e;a<=i-e;a++){let o=rnt(t,0,a,this.toBBox),l=rnt(t,a,i,this.toBBox),g=Isi(o,l),h=zYt(o)+zYt(l);g<n?(n=g,r=a,s=h<s?h:s):g===n&&h<s&&(s=h,r=a)}return r||i-e}_chooseSplitAxis(t,e,i){let r=t.leaf?this.compareMinX:csi,n=t.leaf?this.compareMinY:hsi,s=this._allDistMargin(t,e,i,r),a=this._allDistMargin(t,e,i,n);s<a&&t.children.sort(r)}_allDistMargin(t,e,i,r){t.children.sort(r);let n=this.toBBox,s=rnt(t,0,e,n),a=rnt(t,i-e,i,n),o=_Et(s)+_Et(a);for(let l=e;l<i-e;l++){let g=t.children[l];nnt(s,t.leaf?n(g):g),o+=_Et(s)}for(let l=i-e-1;l>=e;l--){let g=t.children[l];nnt(a,t.leaf?n(g):g),o+=_Et(a)}return o}_adjustParentBBoxes(t,e,i){for(let r=i;r>=0;r--)nnt(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():mj(t[e],this.toBBox)}};function gsi(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 mj(A,t){rnt(A,0,A.children.length,t,A)}function rnt(A,t,e,i,r){r||(r=yj(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];nnt(r,A.leaf?i(s):s)}return r}function nnt(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 csi(A,t){return A.minX-t.minX}function hsi(A,t){return A.minY-t.minY}function zYt(A){return(A.maxX-A.minX)*(A.maxY-A.minY)}function _Et(A){return A.maxX-A.minX+(A.maxY-A.minY)}function usi(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 Isi(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 WYt(A,t){return A.minX<=t.minX&&A.minY<=t.minY&&t.maxX<=A.maxX&&t.maxY<=A.maxY}function mEt(A,t){return t.minX<=A.maxX&&t.minY<=A.maxY&&t.maxX>=A.minX&&t.maxY>=A.minY}function yj(A){return{children:A,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function hNe(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;osi(A,s,t,e,r),n.push(t,s,s,e)}}function VYt(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=Mu(A);else if(A.type==="FeatureCollection")t=Mu(A);else throw new Error("invalid geojson");return{minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]}}var psi=class{constructor(A=9){this.tree=new vJt(A),this.tree.toBBox=VYt}insert(A){if(A.type!=="Feature")throw new Error("invalid feature");return A.bbox=A.bbox?A.bbox:Mu(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:Mu(e),t.push(e)}):l7(A,function(e){if(e.type!=="Feature")throw new Error("invalid features");e.bbox=e.bbox?e.bbox:Mu(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:Mu(A),this.tree.remove(A,t),this}clear(){return this.tree.clear(),this}search(A){var t=this.tree.search(VYt(A));return tl(t)}collides(A){return this.tree.collides(VYt(A))}all(){let A=this.tree.all();return tl(A)}toJSON(){return this.tree.toJSON()}fromJSON(A){return this.tree.fromJSON(A),this}};function SJt(A){return new psi(A)}function dsi(A,t){if(t=t??{},!fnt(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 Fk(A,function(s){Csi(s,n,i)}),A}function Csi(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 sFe(A){if(!A)throw new Error("geojson is required");let t=[];return g7(A,e=>{Bsi(e,t)}),tl(t)}function Bsi(A,t){let e=[],i=A.geometry;if(i!==null){switch(i.type){case"Polygon":e=qd(i);break;case"LineString":e=[qd(i)]}e.forEach(r=>{Esi(r,A.properties).forEach(s=>{s.id=t.length,t.push(s)})})}}function Esi(A,t){let e=[];return A.reduce((i,r)=>{let n=O1([i,r],t);return n.bbox=fsi(i,r),e.push(n),r}),e}function fsi(A,t){let e=A[0],i=A[1],r=t[0],n=t[1],s=e<r?e:r,a=i<n?i:n,o=e>r?e:r,l=i>n?i:n;return[s,a,o,l]}var YEt=class{constructor(t=[],e=_si){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,a=e[s],o=s+1;if(o<this.length&&i(e[o],a)<0&&(s=o,a=e[o]),i(a,n)>=0)break;e[t]=a,t=s}e[t]=n}};function _si(A,t){return A<t?-1:A>t?1:0}function aFe(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 msi(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 JEt=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 Qsi(A,t){if(A.type==="FeatureCollection"){let e=A.features;for(let i=0;i<e.length;i++)uNe(e[i],t)}else uNe(A,t)}var QEt=0,yEt=0,xEt=0;function uNe(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],a=null;yEt=yEt+1;for(let o=0;o<i[r][n].length-1;o++){a=i[r][n][o+1];let l=new JEt(s,QEt,yEt,xEt),g=new JEt(a,QEt,yEt,xEt+1);l.otherEvent=g,g.otherEvent=l,aFe(l,g)>0?(g.isLeftEndpoint=!0,l.isLeftEndpoint=!1):(l.isLeftEndpoint=!0,g.isLeftEndpoint=!1),t.push(l),t.push(g),s=a,xEt=xEt+1}}QEt=QEt+1}var ysi=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function xsi(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,a=t.leftSweepEvent.p.y,o=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,g=(l-a)*(r-e)-(o-s)*(n-i),h=(o-s)*(i-a)-(l-a)*(e-s),I=(r-e)*(i-a)-(n-i)*(e-s);if(g===0)return!1;let p=h/g,E=I/g;if(p>=0&&p<=1&&E>=0&&E<=1){let f=e+p*(r-e),Q=i+p*(n-i);return[f,Q]}return!1}function wsi(A,t){t=t||!1;let e=[],i=new YEt([],msi);for(;A.length;){let r=A.pop();if(r.isLeftEndpoint){let n=new ysi(r);for(let s=0;s<i.data.length;s++){let a=i.data[s];if(t&&a.leftSweepEvent.featureId===r.featureId)continue;let o=xsi(n,a);o!==!1&&e.push(o)}i.push(n)}else r.isLeftEndpoint===!1&&i.pop()}return e}function bsi(A,t){let e=new YEt([],aFe);return Qsi(A,e),wsi(e,t)}var vsi=bsi;function Rj(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(VE(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(VE(t));let s=vsi(tl(n),r),a=[];if(i){let o={};s.forEach(l=>{let g=l.join(",");o[g]||(o[g]=!0,a.push(l))})}else a=s;return tl(a.map(o=>u3(o)))}var Ssi=Object.defineProperty,Dsi=Object.defineProperties,ksi=Object.getOwnPropertyDescriptors,INe=Object.getOwnPropertySymbols,Rsi=Object.prototype.hasOwnProperty,Msi=Object.prototype.propertyIsEnumerable,pNe=(A,t,e)=>t in A?Ssi(A,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):A[t]=e,Gsi=(A,t)=>{for(var e in t||(t={}))Rsi.call(t,e)&&pNe(A,e,t[e]);if(INe)for(var e of INe(t))Msi.call(t,e)&&pNe(A,e,t[e]);return A},Nsi=(A,t)=>Dsi(A,ksi(t));function bj(A,t,e={}){if(!A||!t)throw new Error("lines and inputPoint are required arguments");let i=I3(t),r=u3([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,a=-1;return g7(A,function(o,l,g){a!==g&&(a=g,s=0);let h=qd(o);for(let I=0;I<h.length-1;I++){let p=u3(h[I]),E=I3(p),f=u3(h[I+1]),Q=I3(f),y=pnt(p,f,e),v,S;Q[0]===i[0]&&Q[1]===i[1]?[v,S]=[Q,!0]:E[0]===i[0]&&E[1]===i[1]?[v,S]=[E,!1]:[v,S]=Tsi(E,Q,i);let G=pnt(t,v,e);if(G<r.properties.pointDistance){let H=pnt(p,v,e);r=u3(v,{lineStringIndex:g,segmentIndex:S?I+1:I,totalDistance:n+H,lineDistance:s+H,segmentDistance:H,pointDistance:G,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),r.properties=Nsi(Gsi({},r.properties),{multiFeatureIndex:r.properties.lineStringIndex,index:r.properties.segmentIndex,location:r.properties.totalDistance,dist:r.properties.pointDistance})}n+=y,s+=y}}),r}function EL(A,t){let[e,i,r]=A,[n,s,a]=t;return e*n+i*s+r*a}function tnt(A,t){let[e,i,r]=A,[n,s,a]=t;return[i*a-r*s,r*n-e*a,e*s-i*n]}function Fsi(A){return Math.sqrt(Math.pow(A[0],2)+Math.pow(A[1],2)+Math.pow(A[2],2))}function dNe(A){let t=Fsi(A);return[A[0]/t,A[1]/t,A[2]/t]}function ZYt(A){let t=CB(A[1]),e=CB(A[0]);return[Math.cos(t)*Math.cos(e),Math.cos(t)*Math.sin(e),Math.sin(t)]}function Lsi(A){let[t,e,i]=A,r=Math.min(Math.max(i,-1),1),n=PEt(Math.asin(r));return[PEt(Math.atan2(e,t)),n]}function Tsi(A,t,e){let i=ZYt(A),r=ZYt(t),n=ZYt(e),s=tnt(i,r);if(s[0]===0&&s[1]===0&&s[2]===0)return EL(i,r)>0?[[...t],!0]:[[...e],!1];let a=tnt(s,n);if(a[0]===0&&a[1]===0&&a[2]===0)return[[...t],!0];let o=tnt(a,s),l=dNe(o),g=[-l[0],-l[1],-l[2]],h=EL(n,l)>EL(n,g)?l:g,I=dNe(s),p=EL(tnt(i,h),I),E=EL(tnt(h,r),I);return p>=0&&E>=0?[Lsi(h),!1]:EL(i,n)>EL(r,n)?[[...A],!1]:[[...t],!0]}function DJt(A,t){if(!A)throw new Error("line is required");if(!t)throw new Error("splitter is required");let e=HEt(A),i=HEt(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=dsi(t,{precision:7});switch(A.type!=="Feature"&&(A=VE(A)),i){case"Point":return lJt(A,r);case"MultiPoint":return CNe(A,r);case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":return CNe(A,Rj(A,r,{ignoreSelfIntersections:!0}))}}function CNe(A,t){var e=[],i=SJt();return g7(t,function(r){if(e.forEach(function(a,o){a.id=o}),!e.length)e=lJt(A,r).features,i.load(tl(e));else{var n=i.search(r);if(n.features.length){var s=oFe(r,n);e=e.filter(function(a){return a.id!==s.id}),i.remove(s),l7(lJt(s,r),function(a){e.push(a),i.insert(a)})}}}),tl(e)}function lJt(A,t){var e=[],i=qd(A)[0],r=qd(A)[A.geometry.coordinates.length-1];if(XYt(i,I3(t))||XYt(r,I3(t)))return tl([A]);var n=SJt(),s=sFe(A);n.load(s);var a=n.search(t);if(!a.features.length)return tl([A]);var o=oFe(t,a),l=[i],g=Jni(s,function(h,I,p){var E=qd(I)[1],f=I3(t);return p===o.id?(h.push(f),e.push(O1(h)),XYt(f,E)?[f]:[f,E]):(h.push(E),h)},l);return g.length>1&&e.push(O1(g)),tl(e)}function oFe(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 l7(t,function(r){var n=bj(r,A),s=n.properties.dist;s<i&&(e=r,i=s)}),e}function XYt(A,t){return A[0]===t[0]&&A[1]===t[1]}function BNe(A,t){let e=Lm(A),i=Lm(t),r=e.type,n=i.type,s=e.coordinates,a=i.coordinates;switch(r){case"Point":if(n==="Point")return RJt(s,a);throw new Error("feature2 "+n+" geometry not supported");case"MultiPoint":switch(n){case"Point":return Hsi(e,i);case"MultiPoint":return Osi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"Point":return BB(i,e,{ignoreEndVertices:!0});case"LineString":return jsi(e,i);case"MultiPoint":return Ysi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Point":return p3(i,e,{ignoreBoundary:!0});case"LineString":return Ksi(e,i);case"Polygon":return kJt(e,i);case"MultiPoint":return Jsi(e,i);case"MultiPolygon":return Psi(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPolygon":if(n==="Polygon")return Usi(e,i);throw new Error("feature2 "+n+" geometry not supported");default:throw new Error("feature1 "+r+" geometry not supported")}}function Usi(A,t){return A.coordinates.some(e=>kJt({type:"Polygon",coordinates:e},t))}function Psi(A,t){return t.coordinates.every(e=>kJt(A,{type:"Polygon",coordinates:e}))}function Hsi(A,t){let e,i=!1;for(e=0;e<A.coordinates.length;e++)if(RJt(A.coordinates[e],t.coordinates)){i=!0;break}return i}function Osi(A,t){for(let e of t.coordinates){let i=!1;for(let r of A.coordinates)if(RJt(e,r)){i=!0;break}if(!i)return!1}return!0}function Ysi(A,t){let e=!1;for(let i of t.coordinates)if(BB(i,A,{ignoreEndVertices:!0})&&(e=!0),!BB(i,A))return!1;return!!e}function Jsi(A,t){for(let e of t.coordinates)if(!p3(e,A,{ignoreBoundary:!0}))return!1;return!0}function jsi(A,t){let e=!1;for(let i of t.coordinates)if(BB({type:"Point",coordinates:i},A,{ignoreEndVertices:!0})&&(e=!0),!BB({type:"Point",coordinates:i},A,{ignoreEndVertices:!1}))return!1;return e}function qsi(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=O1([e[r],e[r+1]]),s=DJt(n,VE(t));s.features.length===0?i.push(n):i.push(...s.features)}return tl(i)}function Ksi(A,t){let e=Mu(A),i=Mu(t);if(!lFe(e,i))return!1;for(let s of t.coordinates)if(!p3(s,A))return!1;let r=!1,n=qsi(t,A);for(let s of n.features){let a=zsi(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!p3(a,A))return!1;!r&&p3(a,A,{ignoreBoundary:!0})&&(r=!0)}return r}function kJt(A,t){if(A.type==="Feature"&&A.geometry===null||t.type==="Feature"&&t.geometry===null)return!1;let e=Mu(A),i=Mu(t);if(!lFe(e,i))return!1;let r=Lm(t).coordinates;for(let n of r)for(let s of n)if(!p3(s,A))return!1;return!0}function lFe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function RJt(A,t){return A[0]===t[0]&&A[1]===t[1]}function zsi(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function jEt(A,t={}){let e=Lm(A);switch(!t.properties&&A.type==="Feature"&&(t.properties=A.properties),e.type){case"Polygon":return Wsi(e,t);case"MultiPolygon":return Vsi(e,t);default:throw new Error("invalid poly")}}function Wsi(A,t={}){let i=Lm(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{};return gFe(i,r)}function Vsi(A,t={}){let i=Lm(A).coordinates,r=t.properties?t.properties:A.type==="Feature"?A.properties:{},n=[];return i.forEach(s=>{n.push(gFe(s,r))}),tl(n)}function gFe(A,t){return A.length>1?eFe(A,t):O1(A[0],t)}var Zsi=Object.defineProperty,Mj=(A,t)=>Zsi(A,"name",{value:t,configurable:!0}),cFe=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||!snt(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=gJt(t),r=gJt(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(!snt(t,e))return!1;let n=t,s=e;if(r&&!this.compareCoord(n[0],s[0])){let o=this.fixStartIndex(s,n);if(o)s=o;else return!1}let a=this.compareCoord(n[i],s[i]);return this.direction||a?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 snt(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?MJt(t.properties,e.properties):!0)&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return snt(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)}};Mj(cFe,"GeojsonEquality");var Xsi=cFe;function snt(A,t){return A.coordinates?A.coordinates.length===t.coordinates.length:A.length===t.length}Mj(snt,"sameLength");function gJt(A){return A.coordinates.map(t=>({type:A.type.replace("Multi",""),coordinates:t}))}Mj(gJt,"explode");function hFe(A,t,e){return new Xsi(e).compare(A,t)}Mj(hFe,"geojsonEquality");function MJt(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],a=ENe(n)&&ENe(s);if(a&&!MJt(n,s)||!a&&n!==s)return!1}return!0}Mj(MJt,"equal");var ENe=Mj(A=>A!=null&&typeof A=="object","isObject");function uFe(A,t={}){var e=typeof t=="object"?t.mutate:t;if(!A)throw new Error("geojson is required");var i=HEt(A),r=[];switch(i){case"LineString":r=$Yt(A,i);break;case"MultiLineString":case"Polygon":qd(A).forEach(function(s){r.push($Yt(s,i))});break;case"MultiPolygon":qd(A).forEach(function(s){var a=[];s.forEach(function(o){a.push($Yt(o,i))}),r.push(a)});break;case"Point":return A;case"MultiPoint":var n={};qd(A).forEach(function(s){var a=s.join("-");Object.prototype.hasOwnProperty.call(n,a)||(r.push(s),n[a]=!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):VE({type:i,coordinates:r},A.properties,{bbox:A.bbox,id:A.id})}function $Yt(A,t){let e=qd(A);if(e.length===2&&!fNe(e[0],e[1]))return e;let i=[],r=0,n=1,s=2;for(i.push(e[r]);s<e.length;)BB(e[n],O1([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(BB(i[0],O1([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(!fNe(i[0],i[i.length-1]))throw new Error("invalid polygon, first and last points not equal")}return i}function fNe(A,t){return A[0]===t[0]&&A[1]===t[1]}function $si(A,t,{ignoreSelfIntersections:e=!0}={ignoreSelfIntersections:!0}){let i=!0;return g7(A,r=>{g7(t,n=>{if(i===!1)return!1;i=tai(r.geometry,n.geometry,e)})}),i}function tai(A,t,e){switch(A.type){case"Point":switch(t.type){case"Point":return!rai(A.coordinates,t.coordinates);case"LineString":return!_Ne(t,A);case"Polygon":return!p3(A,t)}break;case"LineString":switch(t.type){case"Point":return!_Ne(A,t);case"LineString":return!eai(A,t,e);case"Polygon":return!mNe(t,A,e)}break;case"Polygon":switch(t.type){case"Point":return!p3(t,A);case"LineString":return!mNe(A,t,e);case"Polygon":return!Aai(t,A,e)}}return!1}function _Ne(A,t){for(let e=0;e<A.coordinates.length-1;e++)if(iai(A.coordinates[e],A.coordinates[e+1],t.coordinates))return!0;return!1}function eai(A,t,e){return Rj(A,t,{ignoreSelfIntersections:e}).features.length>0}function mNe(A,t,e){for(let r of t.coordinates)if(p3(r,A))return!0;return Rj(t,jEt(A),{ignoreSelfIntersections:e}).features.length>0}function Aai(A,t,e){for(let r of A.coordinates[0])if(p3(r,t))return!0;for(let r of t.coordinates[0])if(p3(r,A))return!0;return Rj(jEt(A),jEt(t),{ignoreSelfIntersections:e}).features.length>0}function iai(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 rai(A,t){return A[0]===t[0]&&A[1]===t[1]}function GJt(A,t,{ignoreSelfIntersections:e=!0}={}){let i=!1;return g7(A,r=>{g7(t,n=>{if(i===!0)return!0;i=!$si(r.geometry,n.geometry,{ignoreSelfIntersections:e})})}),i}function IFe(A){return A&&A.__esModule&&Object.prototype.hasOwnProperty.call(A,"default")?A.default:A}var tJt,QNe;function nai(){return QNe||(QNe=1,tJt=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}),tJt}var sai=nai(),ant=IFe(sai);function aai(A,t,e={}){if(e=e||{},!fnt(e))throw new Error("options is invalid");var i=e.tolerance||0,r=[],n=SJt();let s=sFe(A);n.load(s);var a;let o=[];return int(t,function(l){var g=!1;l&&(l7(n.search(l),function(h){if(g===!1){var I=qd(l).sort(),p=qd(h).sort();if(ant(I,p))g=!0,a?a=eJt(a,l)||a:a=l;else if(i===0?BB(I[0],h)&&BB(I[1],h):bj(h,I[0]).properties.dist<=i&&bj(h,I[1]).properties.dist<=i)g=!0,a?a=eJt(a,l)||a:a=l;else if(i===0?BB(p[0],l)&&BB(p[1],l):bj(l,p[0]).properties.dist<=i&&bj(l,p[1]).properties.dist<=i)if(a){let E=eJt(a,h);E?a=E:o.push(h)}else a=h}}),g===!1&&a&&(r.push(a),o.length&&(r=r.concat(o),o=[]),a=void 0))}),a&&r.push(a),tl(r)}function eJt(A,t){var e=qd(t),i=qd(A),r=i[0],n=i[i.length-1],s=A.geometry.coordinates;if(ant(e[0],r))s.unshift(e[1]);else if(ant(e[0],n))s.push(e[1]);else if(ant(e[1],r))s.unshift(e[0]);else if(ant(e[1],n))s.push(e[0]);else return;return A}function pFe(A,t){let e=Lm(A),i=Lm(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(hFe(A,t,{precision:6}))return!1;let s=0;switch(r){case"MultiPoint":for(var a=0;a<e.coordinates.length;a++)for(var o=0;o<i.coordinates.length;o++){var l=e.coordinates[a],g=i.coordinates[o];if(l[0]===g[0]&&l[1]===g[1])return!0}return!1;case"LineString":case"MultiLineString":int(A,h=>{int(t,I=>{aai(h,I).features.length&&s++})});break;case"Polygon":case"MultiPolygon":int(A,h=>{int(t,I=>{Rj(h,I).features.length&&s++})});break}return s>0}function oai(A,t){var e=Lm(A),i=Lm(t),r=e.type,n=i.type;switch(r){case"Point":switch(n){case"MultiPoint":return lai(e,i);case"LineString":return BB(e,i,{ignoreEndVertices:!0});case"Polygon":case"MultiPolygon":return p3(e,i,{ignoreBoundary:!0});default:throw new Error("feature2 "+n+" geometry not supported")}case"MultiPoint":switch(n){case"MultiPoint":return gai(e,i);case"LineString":return cai(e,i);case"Polygon":case"MultiPolygon":return hai(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"LineString":switch(n){case"LineString":return uai(e,i);case"Polygon":case"MultiPolygon":return pai(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}case"Polygon":switch(n){case"Polygon":case"MultiPolygon":return dai(e,i);default:throw new Error("feature2 "+n+" geometry not supported")}default:throw new Error("feature1 "+r+" geometry not supported")}}function lai(A,t){var e,i=!1;for(e=0;e<t.coordinates.length;e++)if(CFe(t.coordinates[e],A.coordinates)){i=!0;break}return i}function gai(A,t){for(var e=0;e<A.coordinates.length;e++){for(var i=!1,r=0;r<t.coordinates.length;r++)CFe(A.coordinates[e],t.coordinates[r])&&(i=!0);if(!i)return!1}return!0}function cai(A,t){for(var e=!1,i=0;i<A.coordinates.length;i++){if(!BB(A.coordinates[i],t))return!1;e||(e=BB(A.coordinates[i],t,{ignoreEndVertices:!0}))}return e}function hai(A,t){for(var e=!0,i=!1,r=0;r<A.coordinates.length;r++){if(i=p3(A.coordinates[r],t),!i){e=!1;break}i=p3(A.coordinates[r],t,{ignoreBoundary:!0})}return e&&i}function uai(A,t){for(var e=0;e<A.coordinates.length;e++)if(!BB(A.coordinates[e],t))return!1;return!0}function Iai(A,t){let e=A.coordinates,i=[];for(let r=0;r<e.length-1;r++){let n=O1([e[r],e[r+1]]),s=DJt(n,VE(t));s.features.length===0?i.push(n):i.push(...s.features)}return tl(i)}function pai(A,t){let e=Mu(t),i=Mu(A);if(!dFe(e,i))return!1;for(let s of A.coordinates)if(!p3(s,t))return!1;let r=!1,n=Iai(A,t);for(let s of n.features){let a=Cai(s.geometry.coordinates[0],s.geometry.coordinates[1]);if(!p3(a,t))return!1;!r&&p3(a,t,{ignoreBoundary:!0})&&(r=!0)}return r}function dai(A,t){var e=Mu(A),i=Mu(t);if(!dFe(i,e))return!1;for(var r=0;r<A.coordinates[0].length;r++)if(!p3(A.coordinates[0][r],t))return!1;return!0}function dFe(A,t){return!(A[0]>t[0]||A[2]<t[2]||A[1]>t[1]||A[3]<t[3])}function CFe(A,t){return A[0]===t[0]&&A[1]===t[1]}function Cai(A,t){return[(A[0]+t[0])/2,(A[1]+t[1])/2]}function BFe(A,t={}){let e=Mu(A),i=(e[0]+e[2])/2,r=(e[1]+e[3])/2;return u3([i,r],t.properties,t)}var MEt={exports:{}},Bai=MEt.exports,yNe;function Eai(){return yNe||(yNe=1,(function(A,t){(function(e,i){A.exports=i()})(Bai,(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,I()?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(I())return Reflect.construct.apply(null,arguments);var B=[null];B.push.apply(B,c);var b=new(C.bind.apply(C,B));return u&&p(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 a(C,c,u){return c&&s(C.prototype,c),u&&s(C,u),Object.defineProperty(C,"prototype",{writable:!1}),C}function o(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(dt){throw dt},f:b}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
25650
25650
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var T,P=!0,et=!1;return{s:function(){u=u.call(C)},n:function(){var dt=u.next();return P=dt.done,dt},e:function(dt){et=!0,T=dt},f:function(){try{P||u.return==null||u.return()}finally{if(et)throw T}}}}function l(){return l=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(C,c,u){var B=(function(T,P){for(;!{}.hasOwnProperty.call(T,P)&&(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&&p(C,c)}function I(){try{var C=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch{}return(I=function(){return!!C})()}function p(C,c){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(u,B){return u.__proto__=B,u},p(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.
25651
25651
  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 v(C){var c=typeof Map=="function"?new Map:void 0;return v=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}}),p(B,u)},v(C)}var S=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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],P=arguments[2],et=arguments[3];this.setQuadrantSegments(b),this.setEndCapStyle(T),this.setJoinStyle(P),this.setMitreLimit(et)}}}},{key:"bufferDistanceError",value:function(c){var u=Math.PI/2/c;return 1-Math.cos(u/2)}}])})();S.CAP_ROUND=1,S.CAP_FLAT=2,S.CAP_SQUARE=3,S.JOIN_ROUND=1,S.JOIN_MITRE=2,S.JOIN_BEVEL=3,S.DEFAULT_QUADRANT_SEGMENTS=8,S.DEFAULT_MITRE_LIMIT=5,S.DEFAULT_SIMPLIFY_FACTOR=.01;var G=(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),a(c,[{key:"toString",value:function(){return this.message}}])})(v(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),a(c)})(G),Y=(function(){return a((function C(){r(this,C)}),[{key:"filter",value:function(C){}}])})();function z(){}function N(){}function F(){}var O,K,$,nt,tt,W,V,it,at=(function(){return a((function C(){r(this,C)}),null,[{key:"equalsWithTolerance",value:function(C,c,u){return Math.abs(C-c)<=u}}])})(),pt=(function(){return a((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 Ct(){}function mt(){}Ct.NaN=NaN,Ct.isNaN=function(C){return Number.isNaN(C)},Ct.isInfinite=function(C){return!Number.isFinite(C)},Ct.MAX_VALUE=Number.MAX_VALUE,Ct.POSITIVE_INFINITY=Number.POSITIVE_INFINITY,Ct.NEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,typeof Float64Array=="function"&&typeof Int32Array=="function"?(W=2146435072,V=new Float64Array(1),it=new Int32Array(V.buffer),Ct.doubleToLongBits=function(C){V[0]=C;var c=0|it[0],u=0|it[1];return(u&W)===W&&1048575&u&&c!==0&&(c=0,u=2146959360),new pt(u,c)},Ct.longBitsToDouble=function(C){return it[0]=C.low,it[1]=C.high,V[0]}):(O=1023,K=Math.log2,$=Math.floor,nt=Math.pow,tt=(function(){for(var C=53;C>0;C--){var c=nt(2,C)-1;if($(K(c))+1===C)return c}return 0})(),Ct.doubleToLongBits=function(C){var c,u,B,b,T,P,et,dt,kt;if(C<0||1/C===Number.NEGATIVE_INFINITY?(P=1<<31,C=-C):P=0,C===0)return new pt(dt=P,kt=0);if(C===1/0)return new pt(dt=2146435072|P,kt=0);if(C!=C)return new pt(dt=2146959360,kt=0);if(b=0,kt=0,(c=$(C))>1)if(c<=tt)(b=$(K(c)))<=20?(kt=0,dt=c<<20-b&1048575):(kt=c%(u=nt(2,B=b-20))<<32-B,dt=c/u&1048575);else for(B=c,kt=0;(B=$(u=B/2))!==0;)b++,kt>>>=1,kt|=(1&dt)<<31,dt>>>=1,u!==B&&(dt|=524288);if(et=b+O,T=c===0,c=C-c,b<52&&c!==0)for(B=0;;){if((u=2*c)>=1?(c=u-1,T?(et--,T=!1):(B<<=1,B|=1,b++)):(c=u,T?--et==0&&(b++,T=!1):(B<<=1,b++)),b===20)dt|=B,B=0;else if(b===52){kt|=B;break}if(u===1){b<20?dt|=B<<20-b:b<52&&(kt|=B<<52-b);break}}return dt|=et<<20,new pt(dt|=P,kt)},Ct.longBitsToDouble=function(C){var c,u,B,b,T=C.high,P=C.low,et=T&1<<31?-1:1;for(B=((2146435072&T)>>20)-O,b=0,u=1<<19,c=1;c<=20;c++)T&u&&(b+=nt(2,-c)),u>>>=1;for(u=1<<31,c=21;c<=52;c++)P&u&&(b+=nt(2,-c)),u>>>=1;if(B===-1023){if(b===0)return 0*et;B=-1022}else{if(B===1024)return b===0?et/0:NaN;b+=1}return et*b*nt(2,B)});var ft=(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),a(c)})(G),Qt=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(c,null,[{key:"constructor_",value:function(){if(arguments.length===0)ft.constructor_.call(this);else if(arguments.length===1){var u=arguments[0];ft.constructor_.call(this,u)}}}])})(ft),yt=(function(){function C(){r(this,C)}return a(C,null,[{key:"shouldNeverReachHere",value:function(){if(arguments.length===0)C.shouldNeverReachHere(null);else if(arguments.length===1){var c=arguments[0];throw new Qt("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 Qt:new Qt(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 Qt("Expected "+B+" but encountered "+b+(T!==null?": "+T:""))}}}])})(),Mt=new ArrayBuffer(8),qt=new Float64Array(Mt),ie=new Int32Array(Mt),Dt=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(C,[{key:"getM",value:function(){return Ct.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!!at.equalsWithTolerance(this.x,u.x,B)&&!!at.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()||Ct.isNaN(this.getZ())&&Ct.isNaN(c.getZ()))}},{key:"equals",value:function(c){return c instanceof C&&this.equals2D(c)}},{key:"equalInZ",value:function(c,u){return at.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 yt.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,N,F]}}],[{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],P=arguments[2];this.x=b,this.y=T,this.z=P}}},{key:"hashCode",value:function(c){return qt[0]=c,ie[0]^ie[1]}}])})(),Pe=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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[mt]}}],[{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:Ct.isNaN(c)?Ct.isNaN(u)?0:-1:Ct.isNaN(u)?1:0}}])})();Dt.DimensionalComparator=Pe,Dt.NULL_ORDINATE=Ct.NaN,Dt.X=0,Dt.Y=1,Dt.Z=2,Dt.M=3;var me=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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 Dt){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 Dt){var u=arguments[0];return this.intersects(u.x,u.y)}}else if(arguments.length===2){if(arguments[0]instanceof Dt&&arguments[1]instanceof Dt){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],P=arguments[1];return!this.isNull()&&!(T>this._maxx||T<this._minx||P>this._maxy||P<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 Dt){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 Dt){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 Dt((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 Dt){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],P=arguments[1],et=arguments[2],dt=arguments[3];T<P?(this._minx=T,this._maxx=P):(this._minx=P,this._maxx=T),et<dt?(this._miny=et,this._maxy=dt):(this._miny=dt,this._maxy=et)}}},{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+Dt.hashCode(this._minx))+Dt.hashCode(this._maxx))+Dt.hashCode(this._miny))+Dt.hashCode(this._maxy)}},{key:"interfaces_",get:function(){return[z,F]}}],[{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 Dt){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],P=arguments[1],et=arguments[2],dt=arguments[3];this.init(T,P,et,dt)}}},{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],P=arguments[2],et=arguments[3],dt=Math.min(P.x,et.x),kt=Math.max(P.x,et.x),ee=Math.min(b.x,T.x),de=Math.max(b.x,T.x);return!(ee>kt)&&!(de<dt)&&(dt=Math.min(P.y,et.y),kt=Math.max(P.y,et.y),ee=Math.min(b.y,T.y),de=Math.max(b.y,T.y),!(ee>kt)&&!(de<dt))}}}])})(),ue=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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 me(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(),P=b.next(),et=T.compareTo(P);if(et!==0)return et}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[N,z,F]}},{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}}])})();ue.constructor_=function(C){C&&(this._envelope=null,this._userData=null,this._factory=C,this._SRID=C.getSRID())},ue.TYPECODE_POINT=0,ue.TYPECODE_MULTIPOINT=1,ue.TYPECODE_LINESTRING=2,ue.TYPECODE_LINEARRING=3,ue.TYPECODE_MULTILINESTRING=4,ue.TYPECODE_POLYGON=5,ue.TYPECODE_MULTIPOLYGON=6,ue.TYPECODE_GEOMETRYCOLLECTION=7,ue.TYPENAME_POINT="Point",ue.TYPENAME_MULTIPOINT="MultiPoint",ue.TYPENAME_LINESTRING="LineString",ue.TYPENAME_LINEARRING="LinearRing",ue.TYPENAME_MULTILINESTRING="MultiLineString",ue.TYPENAME_POLYGON="Polygon",ue.TYPENAME_MULTIPOLYGON="MultiPolygon",ue.TYPENAME_GEOMETRYCOLLECTION="GeometryCollection",ue.geometryChangedFilter={get interfaces_(){return[Y]},filter:function(C){C.geometryChangedAction()}};var Et=(function(){function C(){r(this,C)}return a(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)}}])})();Et.INTERIOR=0,Et.BOUNDARY=1,Et.EXTERIOR=2,Et.NONE=-1;var xe=(function(){return a((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(){}}])})(),vA=(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),a(c)})(G),ce=(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),a(c)})(G),$A=(function(C){function c(){return r(this,c),i(this,c,arguments)}return h(c,C),a(c,[{key:"contains",value:function(){}}])})(xe),sA=(function(C){function c(u){var B;return r(this,c),(B=i(this,c)).map=new Map,u instanceof xe&&B.addAll(u),B}return h(c,C),a(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=o(u);try{for(b.s();!(B=b.n()).done;){var T=B.value;this.add(T)}}catch(P){b.e(P)}finally{b.f()}return!0}},{key:"remove",value:function(){throw new ce}},{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 rA(this.map)}},{key:Symbol.iterator,value:function(){return this.map}}])})($A),rA=(function(){return a((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 vA;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 ce}}])})(),le=(function(){function C(){r(this,C)}return a(C,null,[{key:"opposite",value:function(c){return c===C.LEFT?C.RIGHT:c===C.RIGHT?C.LEFT:c}}])})();le.ON=0,le.LEFT=1,le.RIGHT=2;var YA=(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),a(c)})(G),Ci=(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),a(c)})(G),Li=(function(C){function c(){return r(this,c),i(this,c,arguments)}return h(c,C),a(c,[{key:"get",value:function(){}},{key:"set",value:function(){}},{key:"isEmpty",value:function(){}}])})(xe),eA=(function(C){function c(){var u;return r(this,c),(u=i(this,c)).array=[],u}return h(c,C),a(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 Ci;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 YA;return this.array.pop()}},{key:"peek",value:function(){if(this.array.length===0)throw new YA;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()}}])})(Li);function he(C,c){return C.interfaces_&&C.interfaces_.indexOf(c)>-1}var UA=(function(){return a((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}}])})(),MA=(function(){function C(c){r(this,C),this.value=c}return a(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)}}])})(),nA=(function(){return a((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()}}])})(),je=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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 P=b+1,et=new UA,dt=C.MAX_PRINT_DIGITS-1,kt=0;kt<=dt;kt++){c&&kt===P&&et.append(".");var ee=Math.trunc(B._hi);if(ee<0)break;var de=!1,$e=0;ee>9?(de=!0,$e="9"):$e="0"+ee,et.append($e),B=B.subtract(C.valueOf(ee)).multiply(C.TEN),de&&B.selfAdd(C.TEN);var LA=!0,Bi=C.magnitude(B._hi);if(Bi<0&&Math.abs(Bi)>=dt-kt&&(LA=!1),!LA)break}return u[0]=b,et.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,P,et=arguments[0],dt=arguments[1],kt=null,ee=null,de=null,$e=null;return T=this._hi/et,$e=(kt=(de=C.SPLIT*T)-(kt=de-T))*(ee=($e=C.SPLIT*et)-(ee=$e-et))-(P=T*et)+kt*(b=et-ee)+(B=T-kt)*ee+B*b,$e=T+(de=(this._hi-P-$e+this._lo-T*dt)/et),this._hi=$e,this._lo=T-$e+de,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],P=null,et=null,dt=null,kt=null;return c=(B=this._hi/T._hi)-(P=(dt=C.SPLIT*B)-(P=dt-B)),kt=P*(et=(kt=C.SPLIT*T._hi)-(et=kt-T._hi))-(b=B*T._hi)+P*(u=T._hi-et)+c*et+c*u,new C(kt=B+(dt=(this._hi-b-kt+this._lo-B*T._lo)/T._hi),B-kt+dt)}if(typeof arguments[0]=="number"){var ee=arguments[0];return Ct.isNaN(ee)?C.createNaN():C.copy(this).selfDivide(ee,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,P,et=arguments[0],dt=null;return dt=(b=this._hi+et)-(T=b-this._hi),B=(P=(dt=et-T+(this._hi-dt))+this._lo)+(b-(u=b+P)),this._hi=u+B,this._lo=B+(u-this._hi),this}}else if(arguments.length===2){var kt,ee,de,$e,LA=arguments[0],Bi=arguments[1],Di=null,Dr=null,br=null;de=this._hi+LA,ee=this._lo+Bi,Dr=de-(br=de-this._hi),Di=ee-($e=ee-this._lo);var Xr=(kt=de+(br=(Dr=LA-br+(this._hi-Dr))+ee))+(br=(Di=Bi-$e+(this._lo-Di))+(br+(de-kt))),Hn=br+(kt-Xr);return this._hi=Xr,this._lo=Hn,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],P=arguments[1],et=null,dt=null,kt=null,ee=null;et=(kt=C.SPLIT*this._hi)-this._hi,ee=C.SPLIT*T,et=kt-et,B=this._hi-et,dt=ee-T;var de=(kt=this._hi*T)+(ee=et*(dt=ee-dt)-kt+et*(b=T-dt)+B*dt+B*b+(this._hi*P+this._lo*T)),$e=ee+(et=kt-de);return this._hi=de,this._lo=$e,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 Ct.isNaN(u)?C.createNaN():C.copy(this).selfMultiply(u,0)}}},{key:"isNaN",value:function(){return Ct.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 P=b-B.length;T=B+C.stringOfChar("0",P)+".0"}return this.isNegative()?"-"+T:T}},{key:"reciprocal",value:function(){var c,u,B,b,T=null,P=null,et=null,dt=null;c=(B=1/this._hi)-(T=(et=C.SPLIT*B)-(T=et-B)),P=(dt=C.SPLIT*this._hi)-this._hi;var kt=B+(et=(1-(b=B*this._hi)-(dt=T*(P=dt-P)-b+T*(u=this._hi-P)+c*P+c*u)-B*this._lo)/this._hi);return new C(kt,B-kt+et)}},{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 P=B.charAt(0)+"."+T;return this.isNegative()?"-"+P+b:P+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[F,z,N]}}],[{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],P=arguments[2],et=arguments[3];return arguments[0].multiply(et).selfSubtract(T.multiply(P))}}},{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;nA.isWhitespace(c.charAt(u));)u++;var b=!1;if(u<B){var T=c.charAt(u);T!=="-"&&T!=="+"||(u++,T==="-"&&(b=!0))}for(var P=new C,et=0,dt=0,kt=0,ee=!1;!(u>=B);){var de=c.charAt(u);if(u++,nA.isDigit(de)){var $e=de-"0";P.selfMultiply(C.TEN),P.selfAdd($e),et++}else{if(de!=="."){if(de==="e"||de==="E"){var LA=c.substring(u);try{kt=MA.parseInt(LA)}catch(Xr){throw Xr instanceof NumberFormatException?new NumberFormatException("Invalid exponent "+LA+" in string "+c):Xr}break}throw new NumberFormatException("Unexpected character '"+de+"' at position "+u+" in string "+c)}dt=et,ee=!0}}var Bi=P;ee||(dt=et);var Di=et-dt-kt;if(Di===0)Bi=P;else if(Di>0){var Dr=C.TEN.pow(Di);Bi=P.divide(Dr)}else if(Di<0){var br=C.TEN.pow(-Di);Bi=P.multiply(br)}return b?Bi.negate():Bi}},{key:"createNaN",value:function(){return new C(Ct.NaN,Ct.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 UA,b=0;b<u;b++)B.append(c);return B.toString()}}])})();je.PI=new je(3.141592653589793,12246467991473532e-32),je.TWO_PI=new je(6.283185307179586,24492935982947064e-32),je.PI_2=new je(1.5707963267948966,6123233995736766e-32),je.E=new je(2.718281828459045,14456468917292502e-32),je.NaN=new je(Ct.NaN,Ct.NaN),je.EPS=123259516440783e-46,je.SPLIT=134217729,je.MAX_PRINT_DIGITS=32,je.TEN=je.valueOf(10),je.ONE=je.valueOf(1),je.SCI_NOT_EXPONENT_CHAR="E",je.SCI_NOT_ZERO="0.0E0";var We=(function(){function C(){r(this,C)}return a(C,null,[{key:"orientationIndex",value:function(c,u,B){var b=C.orientationIndexFilter(c,u,B);if(b<=1)return b;var T=je.valueOf(u.x).selfAdd(-c.x),P=je.valueOf(u.y).selfAdd(-c.y),et=je.valueOf(B.x).selfAdd(-u.x),dt=je.valueOf(B.y).selfAdd(-u.y);return T.selfMultiply(dt).selfSubtract(P.selfMultiply(et)).signum()}},{key:"signOfDet2x2",value:function(){if(arguments[3]instanceof je&&arguments[2]instanceof je&&arguments[0]instanceof je&&arguments[1]instanceof je){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],P=arguments[2],et=arguments[3],dt=je.valueOf(b),kt=je.valueOf(T),ee=je.valueOf(P),de=je.valueOf(et);return dt.multiply(de).selfSubtract(kt.multiply(ee)).signum()}}},{key:"intersection",value:function(c,u,B,b){var T=new je(c.y).selfSubtract(u.y),P=new je(u.x).selfSubtract(c.x),et=new je(c.x).selfMultiply(u.y).selfSubtract(new je(u.x).selfMultiply(c.y)),dt=new je(B.y).selfSubtract(b.y),kt=new je(b.x).selfSubtract(B.x),ee=new je(B.x).selfMultiply(b.y).selfSubtract(new je(b.x).selfMultiply(B.y)),de=P.multiply(ee).selfSubtract(kt.multiply(et)),$e=dt.multiply(et).selfSubtract(T.multiply(ee)),LA=T.multiply(kt).selfSubtract(dt.multiply(P)),Bi=de.selfDivide(LA).doubleValue(),Di=$e.selfDivide(LA).doubleValue();return Ct.isNaN(Bi)||Ct.isInfinite(Bi)||Ct.isNaN(Di)||Ct.isInfinite(Di)?null:new Dt(Bi,Di)}},{key:"orientationIndexFilter",value:function(c,u,B){var b=null,T=(c.x-B.x)*(u.y-B.y),P=(c.y-B.y)*(u.x-B.x),et=T-P;if(T>0){if(P<=0)return C.signum(et);b=T+P}else{if(!(T<0)||P>=0)return C.signum(et);b=-T-P}var dt=C.DP_SAFE_EPSILON*b;return et>=dt||-et>=dt?C.signum(et):2}},{key:"signum",value:function(c){return c>0?1:c<0?-1:0}}])})();We.DP_SAFE_EPSILON=1e-15;var Vt=(function(){return a((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 Ct.NaN}},{key:"setOrdinate",value:function(C,c,u){}},{key:"getZ",value:function(C){return this.hasZ()?this.getOrdinate(C,2):Ct.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[N]}}])})();Vt.X=0,Vt.Y=1,Vt.Z=2,Vt.M=3;var jt=(function(){function C(){r(this,C)}return a(C,null,[{key:"index",value:function(c,u,B){return We.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 P=c[T];P.y>B.y&&(B=P,b=T)}var et=b;do(et-=1)<0&&(et=u);while(c[et].equals2D(B)&&et!==b);var dt=b;do dt=(dt+1)%u;while(c[dt].equals2D(B)&&dt!==b);var kt=c[et],ee=c[dt];if(kt.equals2D(B)||ee.equals2D(B)||kt.equals2D(ee))return!1;var de=C.index(kt,B,ee);return de===0?kt.x>ee.x:de>0}if(he(arguments[0],Vt)){var $e=arguments[0],LA=$e.size()-1;if(LA<3)throw new H("Ring has fewer than 4 points, so orientation cannot be determined");for(var Bi=$e.getCoordinate(0),Di=0,Dr=1;Dr<=LA;Dr++){var br=$e.getCoordinate(Dr);br.y>Bi.y&&(Bi=br,Di=Dr)}var Xr=null,Hn=Di;do(Hn-=1)<0&&(Hn=LA),Xr=$e.getCoordinate(Hn);while(Xr.equals2D(Bi)&&Hn!==Di);var gs=null,Go=Di;do Go=(Go+1)%LA,gs=$e.getCoordinate(Go);while(gs.equals2D(Bi)&&Go!==Di);if(Xr.equals2D(Bi)||gs.equals2D(Bi)||Xr.equals2D(gs))return!1;var X0=C.index(Xr,Bi,gs);return X0===0?Xr.x>gs.x:X0>0}}}])})();jt.CLOCKWISE=-1,jt.RIGHT=jt.CLOCKWISE,jt.COUNTERCLOCKWISE=1,jt.LEFT=jt.COUNTERCLOCKWISE,jt.COLLINEAR=0,jt.STRAIGHT=jt.COLLINEAR;var we=(function(){return a((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();yt.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=jt.index(this._minCoord,u,c),b=!1;(c.y<this._minCoord.y&&u.y<this._minCoord.y&&B===jt.COUNTERCLOCKWISE||c.y>this._minCoord.y&&u.y>this._minCoord.y&&B===jt.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=le.LEFT;return u[c].y<u[c+1].y&&(B=le.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)}yt.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)===le.LEFT&&(this._orientedDe=this._minDe.getSym())}}],[{key:"constructor_",value:function(){this._minIndex=-1,this._minCoord=null,this._minDe=null,this._orientedDe=null}}])})(),Ye=(function(C){function c(u,B){var b;return r(this,c),(b=i(this,c,[B?u+" [ "+B+" ]":u])).pt=B?new Dt(B):void 0,b.name=Object.keys({TopologyException:c})[0],b}return h(c,C),a(c,[{key:"getCoordinate",value:function(){return this.pt}}])})(ft),oA=(function(){return a((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}}])})(),Ue=(function(C){function c(u){var B;return r(this,c),(B=i(this,c)).array=[],u instanceof xe&&B.addAll(u),B}return h(c,C),a(c,[{key:"interfaces_",get:function(){return[Li,xe]}},{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=o(u);try{for(b.s();!(B=b.n()).done;){var T=B.value;this.array.push(T)}}catch(P){b.e(P)}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 DA(this)}},{key:"get",value:function(u){if(u<0||u>=this.size())throw new Ci;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()}}])})(Li),DA=(function(){return a((function C(c){r(this,C),this.arrayList=c,this.position=0}),[{key:"next",value:function(){if(this.position===this.arrayList.size())throw new vA;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))}}])})(),IA=(function(){return a((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 Ye("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(le.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(le.RIGHT)>=1&&c.getDepth(le.LEFT)<=0&&!c.isInteriorAreaEdge()&&c.setInResult(!0)}}},{key:"computeDepths",value:function(C){var c=new sA,u=new oA,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 P=T.next().getSym();if(!P.isVisited()){var et=P.getNode();c.contains(et)||(u.addLast(et),c.add(et))}}}}},{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 me,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 eA;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(le.LEFT,C.getDepth(le.RIGHT)),c.setDepth(le.RIGHT,C.getDepth(le.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 Ue,this._nodes=new Ue,this._rightMostCoord=null,this._env=null,this._finder=new we}}])})(),JA=(function(){return a((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,P=C.x>c.x?C.x:c.x,et=C.y>c.y?C.y:c.y,dt=u.x<B.x?u.x:B.x,kt=u.y<B.y?u.y:B.y,ee=u.x>B.x?u.x:B.x,de=u.y>B.y?u.y:B.y,$e=((b>dt?b:dt)+(P<ee?P:ee))/2,LA=((T>kt?T:kt)+(et<de?et:de))/2,Bi=C.x-$e,Di=C.y-LA,Dr=c.x-$e,br=c.y-LA,Xr=u.x-$e,Hn=u.y-LA,gs=B.x-$e,Go=B.y-LA,X0=Di-br,ac=Dr-Bi,ch=Bi*br-Dr*Di,Hc=Hn-Go,og=gs-Xr,bh=Xr*Go-gs*Hn,hh=X0*og-Hc*ac,na=(ac*bh-og*ch)/hh,xs=(Hc*ch-X0*bh)/hh;return Ct.isNaN(na)||Ct.isInfinite(na)||Ct.isNaN(xs)||Ct.isInfinite(xs)?null:new Dt(na+$e,xs+LA)}}])})(),tA=(function(){return a((function C(){r(this,C)}),null,[{key:"arraycopy",value:function(C,c,u,B,b){for(var T=0,P=c;P<c+b;P++)u[B+T]=C[P],T++}},{key:"getProperty",value:function(C){return{"line.separator":`
25652
25652
  `}[C]}}])})(),kA=(function(){function C(){r(this,C)}return a(C,null,[{key:"log10",value:function(c){var u=Math.log(c);return Ct.isInfinite(u)||Ct.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],P=arguments[2];return b<T?T:b>P?P: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],P=arguments[3],et=arguments[0];return b>et&&(et=b),T>et&&(et=T),P>et&&(et=P),et}}},{key:"average",value:function(c,u){return(c+u)/2}}])})();kA.LOG_10=Math.log(10);var iA=(function(){function C(){r(this,C)}return a(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(me.intersects(c,u,B,b)){var P=(u.x-c.x)*(b.y-B.y)-(u.y-c.y)*(b.x-B.x);if(P===0)T=!0;else{var et=(c.y-B.y)*(b.x-B.x)-(c.x-B.x)*(b.y-B.y),dt=((c.y-B.y)*(u.x-c.x)-(c.x-B.x)*(u.y-c.y))/P,kt=et/P;(kt<0||kt>1||dt<0||dt>1)&&(T=!0)}}else T=!0;return T?kA.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 P=((u.y-c.y)*(B.x-u.x)-(u.x-c.x)*(B.y-u.y))/b;return Math.abs(P)*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}}])})(),Ri=(function(){return a((function C(){r(this,C)}),[{key:"create",value:function(){if(arguments.length===1)arguments[0]instanceof Array||he(arguments[0],Vt);else if(arguments.length!==2){if(arguments.length===3){var C=arguments[0],c=arguments[1];return this.create(C,c)}}}}])})(),hi=(function(){return a((function C(){r(this,C)}),[{key:"filter",value:function(C){}}])})(),pi=(function(){return a((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 Dt;C.getCoordinate(0,B);for(var b=B.x,T=B.y,P=1;P<c;P++){C.getCoordinate(P,B);var et=B.x,dt=B.y,kt=et-b,ee=dt-T;u+=Math.sqrt(kt*kt+ee*ee),b=et,T=dt}return u}}])})(),qi=a((function C(){r(this,C)})),WA=(function(){function C(){r(this,C)}return a(C,null,[{key:"copyCoord",value:function(c,u,B,b){for(var T=Math.min(c.getDimension(),B.getDimension()),P=0;P<T;P++)B.setOrdinate(b,P,c.getOrdinate(u,P))}},{key:"isRing",value:function(c){var u=c.size();return u===0||!(u<=3)&&c.getOrdinate(0,Vt.X)===c.getOrdinate(u-1,Vt.X)&&c.getOrdinate(0,Vt.Y)===c.getOrdinate(u-1,Vt.Y)}},{key:"scroll",value:function(){if(arguments.length===2){if(he(arguments[0],Vt)&&Number.isInteger(arguments[1])){var c=arguments[0],u=arguments[1];C.scroll(c,u,C.isRing(c))}else if(he(arguments[0],Vt)&&arguments[1]instanceof Dt){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 P=arguments[0],et=arguments[1],dt=arguments[2];if(et<=0)return null;for(var kt=P.copy(),ee=dt?P.size()-1:P.size(),de=0;de<ee;de++)for(var $e=0;$e<P.getDimension();$e++)P.setOrdinate(de,$e,kt.getOrdinate((et+de)%ee,$e));if(dt)for(var LA=0;LA<P.getDimension();LA++)P.setOrdinate(ee,LA,P.getOrdinate(0,LA))}}},{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 P=0;P<b;P++){var et=c.getOrdinate(T,P),dt=u.getOrdinate(T,P);if(c.getOrdinate(T,P)!==u.getOrdinate(T,P)&&(!Ct.isNaN(et)||!Ct.isNaN(dt)))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,P=arguments[1];P<=B;P++){var et=u.getCoordinate(P);(T===null||T.compareTo(et)>0)&&(T=et,b=P)}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 P=T;P<B;P++)C.copy(u,T-1,b,P,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 P=0;P<T;P++)C.copyCoord(c,u+P,B,b+P)}},{key:"ensureValidRing",value:function(c,u){var B=u.size();return B===0?u:B<=3?C.createClosedRing(c,u,4):u.getOrdinate(0,Vt.X)===u.getOrdinate(B-1,Vt.X)&&u.getOrdinate(0,Vt.Y)===u.getOrdinate(B-1,Vt.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,Vt.X)&&c.y===u.getOrdinate(B,Vt.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 P=T;P<B;P++)C.copy(u,0,b,P,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}}])})(),Ve=(function(){function C(){r(this,C)}return a(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(nA.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)}}])})();Ve.P=0,Ve.L=1,Ve.A=2,Ve.FALSE=-1,Ve.TRUE=-2,Ve.DONTCARE=-3,Ve.SYM_FALSE="F",Ve.SYM_TRUE="T",Ve.SYM_DONTCARE="*",Ve.SYM_P="0",Ve.SYM_L="1",Ve.SYM_A="2";var Cr=(function(){return a((function C(){r(this,C)}),[{key:"filter",value:function(C){}}])})(),mA=(function(){return a((function C(){r(this,C)}),[{key:"filter",value:function(C,c){}},{key:"isDone",value:function(){}},{key:"isGeometryChanged",value:function(){}}])})(),si=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(c,[{key:"computeEnvelopeInternal",value:function(){return this.isEmpty()?new me:this._points.expandEnvelope(new me)}},{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 ue){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();WA.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()?Ve.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 WA.reverse(u),this.getFactory().createLineString(u)}},{key:"getEndPoint",value:function(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}},{key:"getTypeCode",value:function(){return ue.TYPECODE_LINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getLength",value:function(){return pi.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 P=arguments[0];return arguments[1].compare(this._points,P._points)}}},{key:"apply",value:function(){if(he(arguments[0],hi))for(var u=arguments[0],B=0;B<this._points.size();B++)u.filter(this._points.getCoordinate(B));else if(he(arguments[0],mA)){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 he(arguments[0],Cr)?arguments[0].filter(this):he(arguments[0],Y)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){throw new ce}},{key:"isEquivalentClass",value:function(u){return u instanceof c}},{key:"getCoordinateN",value:function(u){return this._points.getCoordinate(u)}},{key:"getGeometryType",value:function(){return ue.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[qi]}}],[{key:"constructor_",value:function(){if(this._points=null,arguments.length!==0){if(arguments.length===2){var u=arguments[0],B=arguments[1];ue.constructor_.call(this,B),this.init(u)}}}}])})(ue),Mi=a((function C(){r(this,C)})),Ze=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(c,[{key:"computeEnvelopeInternal",value:function(){if(this.isEmpty())return new me;var u=new me;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 ue){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 Ve.FALSE}},{key:"reverseInternal",value:function(){return this.getFactory().createPoint(this._coordinates.copy())}},{key:"getTypeCode",value:function(){return ue.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(he(arguments[0],hi)){var u=arguments[0];if(this.isEmpty())return null;u.filter(this.getCoordinate())}else if(he(arguments[0],mA)){var B=arguments[0];if(this.isEmpty())return null;B.filter(this._coordinates,0),B.isGeometryChanged()&&this.geometryChanged()}else he(arguments[0],Cr)?arguments[0].filter(this):he(arguments[0],Y)&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return ue.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([])),yt.isTrue(u.size()<=1),this._coordinates=u}},{key:"isSimple",value:function(){return!0}},{key:"interfaces_",get:function(){return[Mi]}}],[{key:"constructor_",value:function(){this._coordinates=null;var u=arguments[0],B=arguments[1];ue.constructor_.call(this,B),this.init(u)}}])})(ue),ge=(function(){function C(){r(this,C)}return a(C,null,[{key:"ofRing",value:function(){if(arguments[0]instanceof Array){var c=arguments[0];return Math.abs(C.ofRingSigned(c))}if(he(arguments[0],Vt)){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,P=c[b+1].y;u+=T*(c[b-1].y-P)}return u/2}if(he(arguments[0],Vt)){var et=arguments[0],dt=et.size();if(dt<3)return 0;var kt=new Dt,ee=new Dt,de=new Dt;et.getCoordinate(0,ee),et.getCoordinate(1,de);var $e=ee.x;de.x-=$e;for(var LA=0,Bi=1;Bi<dt-1;Bi++)kt.y=ee.y,ee.x=de.x,ee.y=de.y,et.getCoordinate(Bi+1,de),de.x-=$e,LA+=ee.x*(kt.y-de.y);return LA/2}}}])})(),Me=(function(){return a((function C(){r(this,C)}),null,[{key:"sort",value:function(){var C=arguments,c=arguments[0];if(arguments.length===1)c.sort((function($e,LA){return $e.compareTo(LA)}));else if(arguments.length===2)c.sort((function($e,LA){return C[1].compare($e,LA)}));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=o(B);try{for(T.s();!(b=T.n()).done;){var P=b.value;c.push(P)}}catch($e){T.e($e)}finally{T.f()}}else if(arguments.length===4){var et=c.slice(arguments[1],arguments[2]);et.sort((function($e,LA){return C[3].compare($e,LA)}));var dt=c.slice(0,arguments[1]).concat(et,c.slice(arguments[2],c.length));c.splice(0,c.length);var kt,ee=o(dt);try{for(ee.s();!(kt=ee.n()).done;){var de=kt.value;c.push(de)}}catch($e){ee.e($e)}finally{ee.f()}}}},{key:"asList",value:function(C){var c,u=new Ue,B=o(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)}}])})(),cA=a((function C(){r(this,C)})),Ee=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(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 P=0;P<this._holes.length;P++)for(var et=this._holes[P].getCoordinates(),dt=0;dt<et.length;dt++)u[++B]=et[dt];return u}},{key:"getArea",value:function(){var u=0;u+=ge.ofRing(this._shell.getCoordinateSequence());for(var B=0;B<this._holes.length;B++)u-=ge.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 P=u.getY(b);if(P!==B.getMinY()&&P!==B.getMaxY())return!1}for(var et=u.getX(0),dt=u.getY(0),kt=1;kt<=4;kt++){var ee=u.getX(kt),de=u.getY(kt);if(ee!==et==(de!==dt))return!1;et=ee,dt=de}return!0}},{key:"equalsExact",value:function(){if(arguments.length===2&&typeof arguments[1]=="number"&&arguments[0]instanceof ue){var u=arguments[0],B=arguments[1];if(!this.isEquivalentClass(u))return!1;var b=u,T=this._shell,P=b._shell;if(!T.equalsExact(P,B)||this._holes.length!==b._holes.length)return!1;for(var et=0;et<this._holes.length;et++)if(!this._holes[et].equalsExact(b._holes[et],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);Me.sort(this._holes)}else if(arguments.length===2){var B=arguments[0],b=arguments[1];if(B.isEmpty())return null;var T=B.getCoordinateSequence(),P=WA.minCoordinateIndex(T,0,T.size()-2);WA.scroll(T,P,!0),jt.isCCW(T)===b&&WA.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 ue.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],P=arguments[0],et=this._shell,dt=P._shell,kt=et.compareToSameClass(dt,T);if(kt!==0)return kt;for(var ee=this.getNumInteriorRing(),de=P.getNumInteriorRing(),$e=0;$e<ee&&$e<de;){var LA=this.getInteriorRingN($e),Bi=P.getInteriorRingN($e),Di=LA.compareToSameClass(Bi,T);if(Di!==0)return Di;$e++}return $e<ee?1:$e<de?-1:0}}},{key:"apply",value:function(){if(he(arguments[0],hi)){var u=arguments[0];this._shell.apply(u);for(var B=0;B<this._holes.length;B++)this._holes[B].apply(u)}else if(he(arguments[0],mA)){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(he(arguments[0],Cr))arguments[0].filter(this);else if(he(arguments[0],Y)){var P=arguments[0];P.filter(this),this._shell.apply(P);for(var et=0;et<this._holes.length;et++)this._holes[et].apply(P)}}},{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 ue.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[cA]}}],[{key:"constructor_",value:function(){this._shell=null,this._holes=null;var u=arguments[0],B=arguments[1],b=arguments[2];if(ue.constructor_.call(this,b),u===null&&(u=this.getFactory().createLinearRing()),B===null&&(B=[]),ue.hasNullElements(B))throw new H("holes must not contain null elements");if(u.isEmpty()&&ue.hasNonEmptyElements(B))throw new H("shell is empty but holes are not");this._shell=u,this._holes=B}}])})(ue),qe=(function(C){function c(){return r(this,c),i(this,c,arguments)}return h(c,C),a(c)})($A),Ke=(function(C){function c(u){var B;return r(this,c),(B=i(this,c)).array=[],u instanceof xe&&B.addAll(u),B}return h(c,C),a(c,[{key:"contains",value:function(u){var B,b=o(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=o(u);try{for(b.s();!(B=b.n()).done;){var T=B.value;this.add(T)}}catch(P){b.e(P)}finally{b.f()}return!0}},{key:"remove",value:function(){throw new ce}},{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 Qe(this.array)}}])})(qe),Qe=(function(){return a((function C(c){r(this,C),this.array=c,this.position=0}),[{key:"next",value:function(){if(this.position===this.array.length)throw new vA;return this.array[this.position++]}},{key:"hasNext",value:function(){return this.position<this.array.length}},{key:"remove",value:function(){throw new ce}}])})(),Zt=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(c,[{key:"computeEnvelopeInternal",value:function(){for(var u=new me,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(),P=0;P<T.length;P++)u[++B]=T[P];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 ue){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();Me.sort(this._geometries)}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._geometries[0].getCoordinate()}},{key:"getBoundaryDimension",value:function(){for(var u=Ve.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 Ue(u),b=0;b<u;b++)B.add(this._geometries[b].reverse());return this.getFactory().buildGeometry(B)}},{key:"getTypeCode",value:function(){return ue.TYPECODE_GEOMETRYCOLLECTION}},{key:"getDimension",value:function(){for(var u=Ve.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 Ke(Me.asList(this._geometries)),b=new Ke(Me.asList(u._geometries));return this.compare(B,b)}if(arguments.length===2){for(var T=arguments[1],P=arguments[0],et=this.getNumGeometries(),dt=P.getNumGeometries(),kt=0;kt<et&&kt<dt;){var ee=this.getGeometryN(kt),de=P.getGeometryN(kt),$e=ee.compareToSameClass(de,T);if($e!==0)return $e;kt++}return kt<et?1:kt<dt?-1:0}}},{key:"apply",value:function(){if(he(arguments[0],hi))for(var u=arguments[0],B=0;B<this._geometries.length;B++)this._geometries[B].apply(u);else if(he(arguments[0],mA)){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(he(arguments[0],Cr)){var P=arguments[0];P.filter(this);for(var et=0;et<this._geometries.length;et++)this._geometries[et].apply(P)}else if(he(arguments[0],Y)){var dt=arguments[0];dt.filter(this);for(var kt=0;kt<this._geometries.length;kt++)this._geometries[kt].apply(dt)}}},{key:"getBoundary",value:function(){return ue.checkNotGeometryCollection(this),yt.shouldNeverReachHere(),null}},{key:"getGeometryType",value:function(){return ue.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(ue.constructor_.call(this,B),u===null&&(u=[]),ue.hasNullElements(u))throw new H("geometries must not contain null elements");this._geometries=u}}}}])})(ue),De=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(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 ue){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 Ve.FALSE}},{key:"getTypeCode",value:function(){return ue.TYPECODE_MULTIPOINT}},{key:"getDimension",value:function(){return 0}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return ue.TYPENAME_MULTIPOINT}},{key:"interfaces_",get:function(){return[Mi]}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];Zt.constructor_.call(this,u,B)}}])})(Zt),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),a(c,[{key:"copyInternal",value:function(){return new c(this._points.copy(),this._factory)}},{key:"getBoundaryDimension",value:function(){return Ve.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 WA.reverse(u),this.getFactory().createLinearRing(u)}},{key:"getTypeCode",value:function(){return ue.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 ue.TYPENAME_LINEARRING}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];si.constructor_.call(this,u,B),this.validateConstruction()}}])})(si);oe.MINIMUM_VALID_SIZE=4;var 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),a(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 Dt.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)Dt.constructor_.call(this);else if(arguments.length===1){if(arguments[0]instanceof c){var u=arguments[0];Dt.constructor_.call(this,u.x,u.y)}else if(arguments[0]instanceof Dt){var B=arguments[0];Dt.constructor_.call(this,B.x,B.y)}}else if(arguments.length===2){var b=arguments[0],T=arguments[1];Dt.constructor_.call(this,b,T,Dt.NULL_ORDINATE)}}}])})(Dt);ve.X=0,ve.Y=1,ve.Z=-1,ve.M=-1;var 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),a(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 Dt.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)Dt.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof c){var u=arguments[0];Dt.constructor_.call(this,u.x,u.y),this._m=u._m}else if(arguments[0]instanceof Dt){var B=arguments[0];Dt.constructor_.call(this,B.x,B.y),this._m=this.getM()}}else if(arguments.length===3){var b=arguments[0],T=arguments[1],P=arguments[2];Dt.constructor_.call(this,b,T,Dt.NULL_ORDINATE),this._m=P}}}])})(Dt);be.X=0,be.Y=1,be.Z=-1,be.M=2;var yA=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(c,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(u,B){switch(u){case Dt.X:this.x=B;break;case Dt.Y:this.y=B;break;case Dt.Z:this.z=B;break;case Dt.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 Dt.X:return this.x;case Dt.Y:return this.y;case Dt.Z:return this.getZ();case Dt.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)Dt.constructor_.call(this),this._m=0;else if(arguments.length===1){if(arguments[0]instanceof c){var u=arguments[0];Dt.constructor_.call(this,u),this._m=u._m}else if(arguments[0]instanceof Dt){var B=arguments[0];Dt.constructor_.call(this,B),this._m=this.getM()}}else if(arguments.length===4){var b=arguments[0],T=arguments[1],P=arguments[2],et=arguments[3];Dt.constructor_.call(this,b,T,P),this._m=et}}}])})(Dt),te=(function(){function C(){r(this,C)}return a(C,null,[{key:"measures",value:function(c){return c instanceof ve?0:c instanceof be||c instanceof yA?1:0}},{key:"dimension",value:function(c){return c instanceof ve?2:c instanceof be?3:c instanceof yA?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 ve:u===3&&B===0?new Dt:u===3&&B===1?new be:u===4&&B===1?new yA:new Dt}}}])})(),Ut=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(c,[{key:"getCoordinate",value:function(u){return this.get(u)}},{key:"addAll",value:function(){if(arguments.length===2&&typeof arguments[1]=="boolean"&&he(arguments[0],xe)){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 Dt&&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 P=arguments[0],et=arguments[1];return this.add(P,et),!0}}else if(arguments.length===3){if(typeof arguments[2]=="boolean"&&arguments[0]instanceof Array&&typeof arguments[1]=="boolean"){var dt=arguments[0],kt=arguments[1];if(arguments[2])for(var ee=0;ee<dt.length;ee++)this.add(dt[ee],kt);else for(var de=dt.length-1;de>=0;de--)this.add(dt[de],kt);return!0}if(typeof arguments[2]=="boolean"&&Number.isInteger(arguments[0])&&arguments[1]instanceof Dt){var $e=arguments[0],LA=arguments[1];if(!arguments[2]){var Bi=this.size();if(Bi>0&&($e>0&&this.get($e-1).equals2D(LA)||$e<Bi&&this.get($e).equals2D(LA)))return null}E(c,"add",this,1).call(this,$e,LA)}}else if(arguments.length===4){var Di=arguments[0],Dr=arguments[1],br=arguments[2],Xr=arguments[3],Hn=1;br>Xr&&(Hn=-1);for(var gs=br;gs!==Xr;gs+=Hn)this.add(Di[gs],Dr);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)}}}}])})(Ue);Ut.coordArrayType=new Array(0).fill(null);var ae=(function(){function C(){r(this,C)}return a(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);tA.arraycopy(c,B,b,0,c.length-B),tA.arraycopy(c,0,b,c.length-B,B),tA.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],P=arguments[2];if(b===T)return!0;if(b===null||T===null||b.length!==T.length)return!1;for(var et=0;et<b.length;et++)if(P.compare(b[et],T[et])!==0)return!1;return!0}}},{key:"intersection",value:function(c,u){for(var B=new Ut,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=o(c);try{for(b.s();!(u=b.n()).done;){var T=u.value;B=Math.max(B,te.measures(T))}}catch(P){b.e(P)}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 Ut(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,P=0;P<c.length;P++)c[P]!==null&&(b[T++]=c[P]);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],P=arguments[2],et=arguments[3],dt=arguments[4],kt=0;kt<dt;kt++)P[et+kt]=b[T+kt].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 me,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=o(c);try{for(b.s();!(u=b.n()).done;){var T=u.value;B=Math.max(B,te.dimension(T))}}catch(P){b.e(P)}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=kA.clamp(u,0,c.length);var b=(B=kA.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 P=0,et=u;et<=B;et++)T[P++]=c[et];return T}}])})(),Xe=(function(){return a((function C(){r(this,C)}),[{key:"compare",value:function(C,c){var u=C,B=c;return ae.compare(u,B)}},{key:"interfaces_",get:function(){return[mt]}}])})(),fA=(function(){return a((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=ae.compare(u,B);return ae.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=ae.increasingDirection(u),T=ae.increasingDirection(B),P=b>0?0:u.length-1,et=T>0?0:u.length-1,dt=0;dt<u.length;dt++){var kt=u[P].compareTo(B[et]);if(kt!==0)return kt;P+=b,et+=T}return 0}},{key:"interfaces_",get:function(){return[mt]}}])})();ae.ForwardComparator=Xe,ae.BidirectionalComparator=fA,ae.coordArrayType=new Array(0).fill(null);var pA=(function(){return a((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}}])})(),XA=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(C,[{key:"getM",value:function(c){return this.hasM()?this._coordinates[c].getM():Ct.NaN}},{key:"setOrdinate",value:function(c,u,B){switch(u){case Vt.X:this._coordinates[c].x=B;break;case Vt.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():Ct.NaN}},{key:"size",value:function(){return this._coordinates.length}},{key:"getOrdinate",value:function(c,u){switch(u){case Vt.X:return this._coordinates[c].x;case Vt.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 te.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 pA(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[Vt,F]}}],[{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,ae.dimension(c),ae.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 Dt}else if(he(arguments[0],Vt)){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 P=arguments[0],et=arguments[1];C.constructor_.call(this,P,et,ae.measures(P))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var dt=arguments[0],kt=arguments[1];this._coordinates=new Array(dt).fill(null),this._dimension=kt;for(var ee=0;ee<dt;ee++)this._coordinates[ee]=te.create(kt)}}else if(arguments.length===3){if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var de=arguments[0],$e=arguments[1],LA=arguments[2];this._dimension=$e,this._measures=LA,this._coordinates=de===null?new Array(0).fill(null):de}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var Bi=arguments[0],Di=arguments[1],Dr=arguments[2];this._coordinates=new Array(Bi).fill(null),this._dimension=Di,this._measures=Dr;for(var br=0;br<Bi;br++)this._coordinates[br]=this.createCoordinate()}}}}])})(),ki=(function(){function C(){r(this,C)}return a(C,[{key:"readResolve",value:function(){return C.instance()}},{key:"create",value:function(){if(arguments.length===1){if(arguments[0]instanceof Array)return new XA(arguments[0]);if(he(arguments[0],Vt))return new XA(arguments[0])}else{if(arguments.length===2){var c=arguments[1];return c>3&&(c=3),c<2&&(c=2),new XA(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 XA(arguments[0],B+u,u)}}}},{key:"interfaces_",get:function(){return[Ri,F]}}],[{key:"instance",value:function(){return C.instanceObject}}])})();ki.instanceObject=new ki;var Hi=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(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 ue){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 ue.TYPECODE_MULTIPOLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();for(var u=new Ue,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 P=new Array(u.size()).fill(null);return this.getFactory().createMultiLineString(u.toArray(P))}},{key:"getGeometryType",value:function(){return ue.TYPENAME_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[cA]}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];Zt.constructor_.call(this,u,B)}}])})(Zt),wr=(function(){return a((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(){}}])})(),Ir=(function(C){function c(){var u;return r(this,c),(u=i(this,c)).map=new Map,u}return h(c,C),a(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 Ue,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 sA;return this.map.entries().forEach((function(B){return u.add(B)})),u}},{key:"size",value:function(){return this.map.size()}}])})(wr),Er=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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 MA.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 Ct.isNaN(c)||this._modelType===C.FLOATING_SINGLE?c:this._modelType===C.FIXED?Math.round(c*this._scale)/this._scale:c}if(arguments[0]instanceof Dt){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[F,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 Rr){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}}])})(),Rr=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(C,[{key:"readResolve",value:function(){return C.nameToTypeMap.get(this._name)}},{key:"toString",value:function(){return this._name}},{key:"interfaces_",get:function(){return[F]}}],[{key:"constructor_",value:function(){this._name=null;var c=arguments[0];this._name=c,C.nameToTypeMap.put(c,this)}}])})();Rr.nameToTypeMap=new Ir,Er.Type=Rr,Er.FIXED=new Rr("FIXED"),Er.FLOATING=new Rr("FLOATING"),Er.FLOATING_SINGLE=new Rr("FLOATING SINGLE"),Er.maximumPreciseValue=9007199254740992;var jn=(function(C){function c(){var u;return r(this,c),u=i(this,c),c.constructor_.apply(u,arguments),u}return h(c,C),a(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 ue){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()?Ve.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 ue.TYPECODE_MULTILINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getBoundary",value:function(){throw new ce}},{key:"getGeometryType",value:function(){return ue.TYPENAME_MULTILINESTRING}},{key:"interfaces_",get:function(){return[qi]}}],[{key:"constructor_",value:function(){var u=arguments[0],B=arguments[1];Zt.constructor_.call(this,u,B)}}])})(Zt),Vn=(function(){function C(){r(this,C),C.constructor_.apply(this,arguments)}return a(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 Dt(c.getMinX(),c.getMinY())):c.getMinX()===c.getMaxX()||c.getMinY()===c.getMaxY()?this.createLineString([new Dt(c.getMinX(),c.getMinY()),new Dt(c.getMaxX(),c.getMaxY())]):this.createPolygon(this.createLinearRing([new Dt(c.getMinX(),c.getMinY()),new Dt(c.getMinX(),c.getMaxY()),new Dt(c.getMaxX(),c.getMaxY()),new Dt(c.getMaxX(),c.getMinY()),new Dt(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(he(arguments[0],Vt))return new si(arguments[0],this)}}},{key:"createMultiLineString",value:function(){return arguments.length===0?new jn(null,this):arguments.length===1?new jn(arguments[0],this):void 0}},{key:"buildGeometry",value:function(c){for(var u=null,B=!1,b=!1,T=c.iterator();T.hasNext();){var P=T.next(),et=P.getTypeCode();u===null&&(u=et),et!==u&&(B=!0),P instanceof Zt&&(b=!0)}if(u===null)return this.createGeometryCollection();if(B||b)return this.createGeometryCollection(C.toGeometryArray(c));var dt=c.iterator().next();if(c.size()>1){if(dt instanceof Ee)return this.createMultiPolygon(C.toPolygonArray(c));if(dt instanceof si)return this.createMultiLineString(C.toLineStringArray(c));if(dt instanceof Ze)return this.createMultiPoint(C.toPointArray(c));yt.shouldNeverReachHere("Unhandled geometry type: "+dt.getGeometryType())}return dt}},{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 Dt){var c=arguments[0];return this.createPoint(c!==null?this.getCoordinateSequenceFactory().create([c]):null)}if(he(arguments[0],Vt))return new Ze(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(he(arguments[0],Vt)){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 oe){var B=arguments[0];return this.createPolygon(B,null)}}else if(arguments.length===2)return new Ee(arguments[0],arguments[1],this)}},{key:"getSRID",value:function(){return this._SRID}},{key:"createGeometryCollection",value:function(){return arguments.length===0?new Zt(null,this):arguments.length===1?new Zt(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(he(arguments[0],Vt))return new oe(arguments[0],this)}}},{key:"createMultiPolygon",value:function(){return arguments.length===0?new Hi(null,this):arguments.length===1?new Hi(arguments[0],this):void 0}},{key:"createMultiPoint",value:function(){if(arguments.length===0)return new De(null,this);if(arguments.length===1){if(arguments[0]instanceof Array)return new De(arguments[0],this);if(he(arguments[0],Vt)){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());WA.copy(c,B,b,0,1),u[B]=this.createPoint(b)}return this.createMultiPoint(u)}}}},{key:"interfaces_",get:function(){return[F]}}],[{key:"constructor_",value:function(){if(this._precisionModel=null,this._coordinateSequenceFactory=null,this._SRID=null,arguments.length===0)C.constructor_.call(this,new Er,0);else if(arguments.length===1){if(he(arguments[0],Ri)){var c=arguments[0];C.constructor_.call(this,new Er,0,c)}else if(arguments[0]instanceof Er){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],P=arguments[1],et=arguments[2];this._precisionModel=T,this._coordinateSequenceFactory=et,this._SRID=P}}},{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 ki.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)}}])})(),rs="XY",Es="XYZ",fa="XYM",Bn="XYZM",La={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"},$o="EMPTY",Qa=1,ya=2,qn=3,so=4,Ds=5,T0=6;for(var u0 in La)La[u0].toUpperCase();var ko=(function(){return a((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==`