osmgl 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/osmgl.cjs +4 -4
- package/dist/osmgl.cjs.map +1 -1
- package/dist/osmgl.d.cts +6 -0
- package/dist/osmgl.d.ts +6 -0
- package/dist/osmgl.global.js +1 -1
- package/dist/osmgl.js +4 -4
- package/dist/osmgl.js.map +1 -1
- package/package.json +1 -1
package/dist/osmgl.global.js
CHANGED
|
@@ -2322,6 +2322,6 @@ void main() {
|
|
|
2322
2322
|
if (color.a <= 0.001) discard;
|
|
2323
2323
|
fragColor = color;
|
|
2324
2324
|
}
|
|
2325
|
-
`;var gr=n=>n.kind==="symbol",as=n=>n.kind==="placement";function Qe(n,e,t,o){for(let r of n)for(let i=0;i+5<r.length;i+=6){let a=r[i],l=r[i+1],s=r[i+2],c=r[i+3],h=r[i+4],u=r[i+5];if(Zu(e,t,a,l,s,c,h,u)||o>0&&(Vn(e,t,a,l,s,c)<=o||Vn(e,t,s,c,h,u)<=o||Vn(e,t,h,u,a,l)<=o))return true}return false}function Zu(n,e,t,o,r,i,a,l){let s=(n-r)*(o-i)-(t-r)*(e-i),c=(n-a)*(i-l)-(r-a)*(e-l),h=(n-t)*(l-o)-(a-t)*(e-o),u=s<0||c<0||h<0,f=s>0||c>0||h>0;return !(u&&f)}function Vn(n,e,t,o,r,i){let a=r-t,l=i-o,s=a*a+l*l,c=s>0?Math.max(0,Math.min(1,((n-t)*a+(e-o)*l)/s)):0;return Math.hypot(n-(t+a*c),e-(o+l*c))}function Wn(n,e){let t=new DataView(n.vertices),o=new Uint32Array(n.indices),r=e.bounds(),i=(r.maxX-r.minX)/n.extent,a=new Float64Array(o.length*2);for(let l=0;l<o.length;l++){let s=o[l]*tt;a[l*2]=r.minX+t.getInt16(s,true)*i,a[l*2+1]=r.minY+t.getInt16(s+2,true)*i;}return a}function Nn(n,e,t){let o=new DataView(n.vertices),r=t.bounds(),i=(r.maxX-r.minX)/e,a=r.minX,l=r.minY,s=new Float64Array(n.indices.length*2);for(let c=0;c<n.indices.length;c++){let h=n.indices[c]*Ie;s[c*2]=a+o.getInt16(h,true)*i,s[c*2+1]=l+o.getInt16(h+2,true)*i;}return s}var Qu={stride:8,attribs:[{name:"a_pos",size:2,type:5126,offset:0}]},qu=40,$u=10.5,ls=2.5,eh=16,th=4,oh=7,mo=class{constructor(){this.vbo=null;this.ibo=null;this.vao=null;this.capacity=0;this.perArrow=0;this.indicesPerArrow=0;this.highlightFootprint=null;this.count=0;}render(e,t,o,r,i,a,l,s=false){this.count=0;let c=t.zoom,h=r.layers.filter(B=>B.type==="symbol"&&B.layout?.placement==="map"&&r.layerVisibleAt(B,c));if(!h.length)return;let u=t.center,f=ne(u.lng),d=ie(u.lat),p=t.worldSize>0?t.pixelsPerMeter/t.worldSize:0;if(!(p>0))return;let b=[];for(let B of h){let x=o.get(B.source??Y);if(!x)continue;let w=r.bucketKeyFor(B);if(w===null)continue;let _=B.layout?.showFor==="highlight";if(_&&!this.highlightFootprint)continue;let C=p*1.5,E=B.layout?.arrowUnits==="meters"?p:1/t.worldSize,D=V(B.layout?.arrowLength,c,qu)*E,F=V(B.layout?.arrowWidth,c,$u)*E,H=V(B.layout?.arrowOutline,c,ls)*E,S=V(B.layout?.arrowGap,c,eh)*E,L=V(B.layout?.arrowDotRadius,c,th)*E,M=V(B.layout?.arrowDotGap,c,oh)*E,T=Un(D,F,L,S-M),P=H>0?Un(D,F,L,S-M,H).outline:null,k={layer:B,verts:[],shape:T};for(let O of x.visibleTiles){let G=x.getTile(O)?.data?.buckets?.[w];if(!G||!gr(G))continue;let R=new Int16Array(G.anchors),W=G.rotations?new Int16Array(G.rotations):null,j=O.bounds(),Z=(j.maxX-j.minX)/G.extent,ee=j.minX,ge=j.minY;for(let te=0;te<R.length/2;te++){let X=ee+R[te*2]*Z,re=ge+R[te*2+1]*Z;if(_&&!Qe(this.highlightFootprint,X,re,C))continue;let le=(W?W[te]:0)*Math.PI/180,q=Math.sin(le),U=-Math.cos(le),J=X-f-q*S,fe=re-d-U*S;P&&Jn(k,P,J,fe,q,U),Jn(k,T.outline,J,fe,q,U),this.count++;}}k.verts.length&&b.push(k);}if(!b.length)return;let m=b[0].shape,g=m.outline.length/2,y=[],A=[];for(let B of b){let x=y.length/2/g;for(let w of B.verts)y.push(w);A.push({layer:B.layer,first:x,count:B.verts.length/2/g});}if(this.ensureBuffers(e,y.length/2/g,m,a),!(!this.vao||!this.vbo)){this.vbo.update(new Uint8Array(new Float32Array(y).buffer)),i.use(),l?.(i),s&&i.setMat4("u_shadow_matrix",t.shadowObjectMatrix(f,d,0)),i.setMat4("u_matrix",t.objectMatrix(f,d,0)),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.vao.bind();for(let B of A){let x=B.layer.paint,w=V(x.opacity,c,1),_=He(x.color,c,[.18,.45,.76,1]),C=He(x.haloColor,c,[1,1,1,1]),v=V(B.layer.layout?.arrowOutline,c,ls)>0;rh(e,i,B,C,_,w,v,this.indicesPerArrow);}e.bindVAO(null),e.setDepthTest(true);}}ensureBuffers(e,t,o,r){let i=o.outline.length/2;if(this.vao&&t<=this.capacity&&i===this.perArrow)return;this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.capacity=Math.max(256,Math.ceil(t*1.5)),this.perArrow=i,this.indicesPerArrow=o.indices.length,this.vbo=new ve(e,new Uint8Array(this.capacity*i*8),Qu,true);let a=new Uint32Array(this.capacity*o.indices.length);for(let l=0;l<this.capacity;l++){let s=l*i;for(let c=0;c<o.indices.length;c++)a[l*o.indices.length+c]=s+o.indices[c];}this.ibo=new ye(e,a),this.vao=new pe(e,[{buffer:this.vbo,locations:r}],this.ibo);}destroy(){this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.vao=null,this.vbo=null,this.ibo=null,this.capacity=0;}};function rh(n,e,t,o,r,i,a,l){let s=a?2:1;if(a){e.setVec4v("u_color",Me([o[0],o[1],o[2],o[3]*i]));for(let c=0;c<t.count;c+=s)ss(n,t.first+c,l);}e.setVec4v("u_color",Me([r[0],r[1],r[2],r[3]*i]));for(let c=a?1:0;c<t.count;c+=s)ss(n,t.first+c,l);}function ss(n,e,t){n.gl.drawElements(n.gl.TRIANGLES,t,n.gl.UNSIGNED_INT,e*t*4);}var cs=4,Kn=12;function Un(n,e,t,o,r=0){let i=n*.38,a=e*1.35,l=i*.3,s=e*.32,c=e/2,h=-n+s,u=[],f=(g,y)=>u.push(g,y);f(0,0),f(-i,a),f(-i+l,c),f(h,s);for(let g=1;g<cs;g++){let y=g/cs*Math.PI;f(h-Math.sin(y)*s,Math.cos(y)*s);}f(h,-s),f(-i+l,-c),f(-i,-a);let d=r>0?nh(u,r):u,p=Pe(u,void 0,2);if(t<=0)return {outline:d,indices:p};let b=d.length/2,m=t+r;for(let g=0;g<Kn;g++){let y=g/Kn*Math.PI*2;d.push(o+Math.cos(y)*m,Math.sin(y)*m);}for(let g=1;g<Kn-1;g++)p.push(b,b+g,b+g+1);return {outline:d,indices:p}}function nh(n,e){let t=n.length/2,o=0;for(let a=0;a<t;a++){let l=(a+1)%t;o+=n[a*2]*n[l*2+1]-n[l*2]*n[a*2+1];}let r=o<0?-1:1,i=[];for(let a=0;a<t;a++){let l=n[(a+t-1)%t*2],s=n[(a+t-1)%t*2+1],c=n[a*2],h=n[a*2+1],u=n[(a+1)%t*2],f=n[(a+1)%t*2+1],d=Math.hypot(c-l,h-s)||1,p=Math.hypot(u-c,f-h)||1,b=r*(h-s)/d,m=-r*(c-l)/d,g=r*(f-h)/p,y=-r*(u-c)/p,A=b+g,B=m+y,x=Math.hypot(A,B);if(x<1e-9){i.push(c,h);continue}A/=x,B/=x;let w=Math.min(1/Math.max(A*b+B*m,.35),3);i.push(c+A*e*w,h+B*e*w);}return i}function Jn(n,e,t,o,r,i){let a=-i,l=r;for(let s=0;s<e.length;s+=2){let c=e[s],h=e[s+1];n.verts.push(t+r*c+a*h,o+i*c+l*h);}}function ih(n,e,t,o,r,i=0,a=0){let l=t*Math.PI/180,s={verts:[]};return Jn(s,Un(o,r,i,a).outline,n,e,Math.sin(l),-Math.cos(l)),s.verts}var ah=5;function fs(n,e){let t=1/(1<<e),o=(1<<e)-1;return [(n.x&o)*t,(n.y&o)*t,t]}var yr=class{constructor(){this.anisotropy=0;this.anisotropyPname=0;this.anisotropyChecked=false;}render(e,t,o,r,i,a,l,s=false){if(!a.size)return;let c=i.layers.filter(h=>h.type==="raster"&&!!h.overlay===s&&i.layerVisibleAt(h,l));if(c.length){r.use(),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),r.setInt("u_image",0);for(let h of c){let u=a.get(h.source);if(!u)continue;let f=V(h.paint?.opacity,l,1);if(!(f<=.001)){r.setFloat("u_opacity",f),o.bind();for(let d of u.visibleTiles){let p=this.patchFor(e,u,d);p&&(e.bindTexture(0,p.texture),r.setVec3("u_uv_transform",p.uv[0],p.uv[1],p.uv[2]),r.setMat4("u_matrix",t.tileMatrix(d,1)),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0));}}}e.bindVAO(null);}}patchFor(e,t,o){let r=t.getTile(o),i=r&&r.state==="loaded"?this.textureFor(e,r):null;if(i)return {texture:i,uv:[0,0,1]};for(let a=1;a<=ah&&a<=o.z;a++){let l=o.scaledTo(o.z-a),s=t.getTile(l);if(!s||s.state!=="loaded")continue;let c=this.textureFor(e,s);if(c)return {texture:c,uv:fs(o,a)}}return null}textureFor(e,t){let o=t.texture;if(o)return o.handle;if(!t.image)return null;let r=e.gl,i=r.createTexture();if(!i)return null;e.bindTexture(0,i),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t.image),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),this.applyAnisotropy(r);let a={handle:i,destroy:()=>r.deleteTexture(i)};return t.texture=a,t.image.close(),t.image=null,i}applyAnisotropy(e){if(!this.anisotropyChecked){this.anisotropyChecked=true;let t=e.getExtension("EXT_texture_filter_anisotropic");t&&(this.anisotropyPname=t.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropy=Math.min(4,e.getParameter(t.MAX_TEXTURE_MAX_ANISOTROPY_EXT)));}this.anisotropy>0&&e.texParameterf(e.TEXTURE_2D,this.anisotropyPname,this.anisotropy);}};var lh="indoor-",bo=class{constructor(){this.parts=null;this.stamp="";this.cache=new z;this.box=null;this.hidden=new oe;this.collected=new oe;}get active(){return this.parts!==null}footprint(){return this.parts}get hiddenCount(){return this.hidden.size}sync(e,t,o){let r=[],i;for(let f of t.layers){if(!f.id.startsWith(lh)||f.type!=="fill"||!t.layerVisibleAt(f,o))continue;let d=t.bucketKeyFor(f);d&&(r.push(d),i??(i=e.get(f.source??Y)));}if(!r.length||!i){this.parts&&this.destroy();return}let a=r.join(",")+"|"+i.visibleTiles.map(f=>f.dataKey+(i.getTile(f)?.data?"+":"-")).join(",");if(a===this.stamp)return;this.stamp=a,this.free();let l=[],s=1/0,c=1/0,h=-1/0,u=-1/0;for(let f of i.visibleTiles){let d=i.getTile(f)?.data?.buckets;if(d)for(let p of r){let b=d[p];if(!b||b.kind!=="fill")continue;let m=Wn(b,f);l.push(m);for(let g=0;g<m.length;g+=2)m[g]<s&&(s=m[g]),m[g]>h&&(h=m[g]),m[g+1]<c&&(c=m[g+1]),m[g+1]>u&&(u=m[g+1]);}}this.parts=l.length?l:null,this.box=l.length?[s,c,h,u]:null,this.hidden.clear(),this.collected.clear();}collectHidden(e,t){let o=this.parts;if(!o||!e.featureIds)return;let r=new Uint32Array(e.indices),i=new Float64Array(e.featureIds),a=new DataView(e.vertices),l=t.bounds(),s=(l.maxX-l.minX)/e.extent,c=this.box,h=new z;for(let u=0;u*3<r.length;u++){let f=i[u];if(this.hidden.has(f))continue;let d=h.get(f);d||h.set(f,d=[1/0,1/0,-1/0,-1/0]);for(let p=0;p<3;p++){let b=r[u*3+p]*Ie,m=a.getInt16(b,true),g=a.getInt16(b+2,true);m<d[0]&&(d[0]=m),g<d[1]&&(d[1]=g),m>d[2]&&(d[2]=m),g>d[3]&&(d[3]=g);}}for(let[u,f]of h){let d=l.minX+(f[0]+f[2])/2*s,p=l.minY+(f[1]+f[3])/2*s;c&&(d<c[0]||d>c[2]||p<c[1]||p>c[3])||Qe(o,d,p,0)&&this.hidden.add(u);}}destroy(){this.parts=null,this.hidden.clear(),this.collected.clear(),this.box=null,this.stamp="",this.free();}free(){this.cache.forEach(e=>{e?.vao.destroy(),e?.ibo.destroy();}),this.cache.clear();}prepare(e,t){if(!this.parts)return;let o=this.hidden.size;for(let r of e.visibleTiles){if(this.collected.has(r.dataKey))continue;let i=e.getTile(r)?.data?.buckets?.[t];!i||i.kind!=="fill-extrusion"||(this.collected.add(r.dataKey),this.collectHidden(i,r));}this.hidden.size!==o&&this.free();}indicesFor(e,t,o,r,i,a){if(!this.parts)return null;let l=this.cache.get(r.dataKey);if(l!==void 0)return l;let s=t.data?.buckets?.[o];if(!s)return null;let c=null;if(s.kind==="fill-extrusion"&&s.featureIds&&this.hidden.size){let h=new Uint32Array(s.indices),u=new Float64Array(s.featureIds),f=[];for(let d=0;d*3<h.length;d++)this.hidden.has(u[d])||f.push(h[d*3],h[d*3+1],h[d*3+2]);if(f.length<h.length){let d=new ye(e,new Uint32Array(f));c={vao:new pe(e,[{buffer:i,locations:a}],d),ibo:d,count:f.length};}}return this.cache.set(r.dataKey,c),c}};var us=35,sh=70,ch=.35,fh=.5,uh=1.1;function kt(n,e){let t=e.sky;if(!t.enabled||t.fogIntensity<=0)return {near:0,far:1/0,intensity:0,cutoff:1/0};let o=n.cameraToCenterDistance,r=_e((n.pitch-us)/(sh-us),0,1),i=t.fogRange[0]*(1-ch*r)*o,a=t.fogRange[1]*(1-fh*r)*o,l=Math.min(1,t.fogIntensity+(1-t.fogIntensity)*Math.min(1,r*2)),s=l>=.995?a*uh:1/0;return {near:i,far:a,intensity:l,cutoff:s}}function Xn(n,e,t,o){let r=o.x/Math.max(n.width,1)*2-1,i=1-o.y/Math.max(n.height,1)*2,a=null,l=new Float64Array(16),s=[0,0,0,0],c=[0,0,0,0];for(let h of e.visibleTiles){let u=e.getTile(h),f=u&&hs(u,t);if(!f||!Ne(l,n.tileMatrix64(h,f.extent))||(de(s,l,[r,i,-1,1]),de(c,l,[r,i,1,1]),s[3]===0||c[3]===0))continue;let d=s[0]/s[3],p=s[1]/s[3],b=s[2]/s[3],m=c[0]/c[3]-d,g=c[1]/c[3]-p,y=c[2]/c[3]-b,A=dh(f,d,p,b,m,g,y);A&&(!a||A.t<a.distance)&&(a={featureId:A.featureId,tile:h,layerId:t,distance:A.t});}return a}function jn(n,e,t,o){let r=o.x/Math.max(n.width,1)*2-1,i=1-o.y/Math.max(n.height,1)*2,a=null,l=new Float64Array(16),s=[0,0,0,0],c=[0,0,0,0];for(let h of e.visibleTiles){let u=e.getTile(h);if(u)for(let f of t){let d=u.data?.buckets?.[f];if(!d||d.kind!=="fill"||!d.featureIds||!Ne(l,n.tileMatrix64(h,d.extent))||(de(s,l,[r,i,-1,1]),de(c,l,[r,i,1,1]),s[3]===0||c[3]===0))continue;let p=s[0]/s[3],b=s[1]/s[3],m=s[2]/s[3],g=c[2]/c[3]-m;if(Math.abs(g)<1e-9)continue;let y=-m/g;if(y<0||y>1)continue;let A=p+(c[0]/c[3]-p)*y,B=b+(c[1]/c[3]-b)*y,x=hh(d,A,B);x!==null&&(!a||y<a.distance)&&(a={featureId:x,tile:h,layerId:f,distance:y});}}return a}function hh(n,e,t){let o=new DataView(n.vertices),r=new Uint32Array(n.indices),i=new Float64Array(n.featureIds),a=s=>o.getInt16(s*tt,true),l=s=>o.getInt16(s*tt+2,true);for(let s=0;s*3<r.length;s++){let c=r[s*3],h=r[s*3+1],u=r[s*3+2],f=a(c),d=l(c),p=a(h),b=l(h),m=a(u),g=l(u),y=(e-p)*(d-b)-(f-p)*(t-b),A=(e-m)*(b-g)-(p-m)*(t-g),B=(e-f)*(g-d)-(m-f)*(t-d),x=y<0||A<0||B<0,w=y>0||A>0||B>0;if(!(x&&w))return i[s]}return null}function hs(n,e){let t=n.data?.buckets?.[e];return !t||t.kind!=="fill-extrusion"||!t.featureIds?null:t}function dh(n,e,t,o,r,i,a){let l=new DataView(n.vertices),s=new Uint32Array(n.indices),c=new Float64Array(n.featureIds),h=b=>l.getInt16(b*Ie,true)/Et,u=b=>l.getInt16(b*Ie+2,true)/Et,f=b=>l.getUint16(b*Ie+4,true)/Mt,d=1/0,p=-1;for(let b=0;b+2<s.length;b+=3){let m=s[b],g=s[b+1],y=s[b+2],A=h(m),B=u(m),x=f(m),w=h(g)-A,_=u(g)-B,C=f(g)-x,v=h(y)-A,E=u(y)-B,D=f(y)-x,F=i*D-a*E,H=a*v-r*D,S=r*E-i*v,L=w*F+_*H+C*S;if(L>-1e-9&&L<1e-9)continue;let M=1/L,T=e-A,P=t-B,k=o-x,O=(T*F+P*H+k*S)*M;if(O<0||O>1)continue;let N=P*C-k*_,G=k*w-T*C,R=T*_-P*w,W=(r*N+i*G+a*R)*M;if(W<0||O+W>1)continue;let j=(v*N+E*G+D*R)*M;j<0||j>1||j>=d||(d=j,p=c[b/3]??0);}return p>=0?{featureId:p,t:d}:null}function Ar(n,e,t){let o=hs(n,e);if(!o)return null;let r=new Uint32Array(o.indices),i=new Float64Array(o.featureIds),a=[];for(let l=0;l+2<r.length;l+=3)i[l/3]===t&&a.push(r[l],r[l+1],r[l+2]);return a.length?{vertices:o.vertices,indices:new Uint32Array(a)}:null}var Pt=24,Yn=8,ph=2,mh=12,Br=8,Cr=8;function go(n){let e=0;for(let d of n)e+=d.length/2;if(e<2)return null;let t=(Br+2)*2,o=e*t+n.length*(Cr+2)*2+8,r=e*(Br+2)*6+n.length*Cr*6+24,i=new ArrayBuffer(o*Pt),a=new DataView(i),l=new Uint32Array(r),s=0,c=0,h=(d,p,b,m,g,y)=>{let A=s*Pt;return a.setFloat32(A,d,true),a.setFloat32(A+4,p,true),a.setFloat32(A+8,b,true),a.setFloat32(A+12,m,true),a.setFloat32(A+16,g,true),a.setFloat32(A+20,y,true),s++},u=(d,p,b,m)=>{l[c++]=d,l[c++]=p,l[c++]=m,l[c++]=d,l[c++]=m,l[c++]=b;},f=(d,p,b,m,g,y,A)=>{let B=h(d,p,0,0,0,A),x=h(d,p,b,m,1,A);for(let w=1;w<=Cr;w++){let _=Math.PI*w/Cr,C=b*Math.cos(_)+g*Math.sin(_),v=m*Math.cos(_)+y*Math.sin(_),E=h(d,p,C,v,1,A);l[c++]=B,l[c++]=x,l[c++]=E,x=E;}};for(let d of n){let p=bh(d),b=p.length/2;if(b<2)continue;let m=new Float64Array(b-1),g=new Float64Array(b-1);for(let w=0;w<b-1;w++){let _=p[w*2+2]-p[w*2],C=p[w*2+3]-p[w*2+1],v=Math.hypot(_,C)||1;m[w]=_/v,g[w]=C/v;}let y=0,A=-1,B=-1;for(let w=0;w<b;w++){let _=p[w*2],C=p[w*2+1];w>0&&(y+=Math.hypot(_-p[w*2-2],C-p[w*2-1]));let v=w>0?w-1:0,E=w<b-1?w:b-2,D=-g[v],F=m[v],H=-g[E],S=m[E],L=D+H,M=F+S,T=Math.hypot(L,M);T>1e-9?(L/=T,M/=T):(L=D,M=F);let P=L*H+M*S,k=P>1e-6?1/P:1/0,O=Math.acos(Math.min(1,Math.max(-1,m[v]*m[E]+g[v]*g[E])));if(!(O>mh*Math.PI/180)&&k<=ph){let G=h(_,C,L*k,M*k,1,y),R=h(_,C,-L*k,-M*k,-1,y);A>=0&&u(A,B,G,R),A=G,B=R;}else {let G=Math.max(1,Math.min(Br,Math.ceil(O/(Math.PI/Br)))),W=m[v]*g[E]-g[v]*m[E]>=0?1:-1,j=h(_,C,D,F,1,y),Z=h(_,C,-D,-F,-1,y);A>=0&&u(A,B,j,Z);for(let ee=1;ee<=G;ee++){let ge=W*O*(ee/G),te=Math.cos(ge),X=Math.sin(ge),re=D*te-F*X,le=D*X+F*te,q=h(_,C,re,le,1,y),U=h(_,C,-re,-le,-1,y);u(j,Z,q,U),j=q,Z=U;}A=j,B=Z;}}let x=b-2;f(p[0],p[1],-g[0],m[0],-m[0],-g[0],0),f(p[(b-1)*2],p[(b-1)*2+1],-g[x],m[x],m[x],g[x],y);}return c?{vertices:i.slice(0,s*Pt),indices:l.slice(0,c),vertexCount:s}:null}function Zn(n){if(!n.length||n[0].length<6)return null;let e=[],t=[];for(let i=0;i<n[0].length;i++)e.push(n[0][i]);for(let i=1;i<n.length;i++)if(!(n[i].length<6)){t.push(e.length/2);for(let a=0;a<n[i].length;a++)e.push(n[i][a]);}let o=Pe(e,t.length?t:void 0,2);if(!o.length)return null;let r=new Uint32Array(o.length);for(let i=0;i<o.length;i+=3)r[i]=o[i],r[i+1]=o[i+2],r[i+2]=o[i+1];return {vertices:new Float32Array(e).buffer,indices:r,vertexCount:e.length/2}}function bh(n){let e=[];for(let t=0;t<n.length;t+=2){let o=n[t],r=n[t+1],i=e.length;i>=2&&e[i-2]===o&&e[i-1]===r||e.push(o,r);}return e}var yo=5126,gh={stride:Yn,attribs:[{name:"a_pos",size:2,type:yo,offset:0}]},qn={stride:Pt,attribs:[{name:"a_pos",size:2,type:yo,offset:0},{name:"a_extrude",size:2,type:yo,offset:8},{name:"a_side",size:1,type:yo,offset:16},{name:"a_dist",size:1,type:yo,offset:20}]},Qn=class{constructor(e,t){this.revision=e;this.parts=t;}destroy(){for(let e of this.parts)e.vao.destroy(),e.vbo.destroy(),e.ibo.destroy();}},yh=(n,e)=>[n[0],n[1],n[2],n[3]*e],Ao=class{constructor(){this.objects=[];this.markers=[];this.gpu=new z;this.markerHost=null;}setMarkerHost(e){this.markerHost=e;for(let t of this.markers)t.attach(e);}add(e){this.objects.includes(e)||this.objects.push(e);}remove(e){let t=this.objects.indexOf(e);t<0||(this.objects.splice(t,1),this.gpu.get(e.id)?.destroy(),this.gpu.delete(e.id));}addMarker(e){this.markers.includes(e)||(this.markers.push(e),this.markerHost&&e.attach(this.markerHost));}removeMarker(e){let t=this.markers.indexOf(e);t<0||(this.markers.splice(t,1),e.detach());}get all(){return this.objects}get allMarkers(){return this.markers}get isEmpty(){return this.objects.length===0}updateMarkers(e){for(let t of this.markers)t.update(e);}render(e,t,o,r,i,a,l,s=false,c=false){if(!this.objects.length||c&&!this.objects.some(p=>p.ghostOpacity>0))return;this.objects.length>1&&this.objects.sort((p,b)=>p.zIndex-b.zIndex);let h=e.gl.drawingBufferWidth,u=t.width>0?h/t.width:1,f=t.worldSize*u,d=null;for(let p of this.objects){if(!p.visible)continue;let b=p.ghostOpacity;if(c&&b<=0)continue;let m=this.gpuFor(e,p,r,a);if(!m)continue;let g=s?t.shadowObjectMatrix(p.originX,p.originY,p.altitude):null,y=t.objectMatrix(p.originX,p.originY,p.altitude);for(let{part:A,vao:B,ibo:x}of m.parts){if(c&&(A.kind!=="line"||A.arrow))continue;let w=c?yh(A.color,b):A.color;if(A.kind==="fill")d!==o&&(o.use(),l?.(o),d=o),o.setVec4v("u_color",Me(w)),g&&o.setMat4("u_shadow_matrix",g),o.setMat4("u_matrix",y);else {d!==i&&(i.use(),l?.(i),d=i);let _=A.width/2*u,C=f>1e-9?1/f:1;if(i.setVec4v("u_color",Me(w)),i.setFloat("u_half_width",_),i.setFloat("u_offset",(A.offset??0)*u),i.setFloat("u_aa",1),i.setFloat("u_units_per_px",C),i.setFloat("u_units_to_px",f),i.setInt("u_pattern",c?0:A.dashArray?1:A.arrow?2:0),A.dashArray){let[v,E]=A.dashArray;i.setVec2("u_dash",v*u,(v+E)*u);}if(A.arrow){i.setVec4v("u_arrow_color",Me(A.arrowColor??[1,1,1,1]));let v=(A.arrowSize??5)*u;i.setVec3("u_arrow",(A.arrowPeriod??46)*u,Math.max(v*.4,1),Math.min(v,_*.72));}g&&i.setMat4("u_shadow_matrix",g),i.setMat4("u_matrix",y);}B.bind(),e.gl.drawElements(e.gl.TRIANGLES,x.count,x.type,0);}}e.bindVAO(null);}hitTest(e,t,o=4){let r=e.worldSize,i=(a,l,s)=>e.worldPxToPoint(ne(a)*r,ie(l)*r,s);for(let a=this.objects.length-1;a>=0;a--){let l=this.objects[a];if(l.visible&&l.hitTest(t,i,o))return l}return null}boundsOf(e){let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let a of e.rings())for(let l of a){let s=$(l);s.lng<t&&(t=s.lng),s.lng>r&&(r=s.lng),s.lat<o&&(o=s.lat),s.lat>i&&(i=s.lat);}return isFinite(t)?{west:t,south:o,east:r,north:i}:null}gpuFor(e,t,o,r){let i=this.gpu.get(t.id);if(i&&i.revision===t.revision)return i;i?.destroy();let a=[];for(let s of t.build()){let c=s.kind==="fill"?gh:qn,h=s.kind==="fill"?o:r,u=new ve(e,new Uint8Array(s.mesh.vertices),c),f=new ye(e,s.mesh.indices),d=new pe(e,[{buffer:u,locations:h}],f);a.push({part:s,vao:d,vbo:u,ibo:f});}let l=new Qn(t.revision,a);return this.gpu.set(t.id,l),a.length?l:null}destroy(){for(let e of this.gpu.values())e.destroy();this.gpu.clear();for(let e of this.markers)e.detach();this.markers=[],this.objects=[];}};var vr=32,vh=1179937895,xh=1313821514,wh=5130562,_h={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Eh={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16};async function $n(n){let{json:e,bin:t}=ys(n),o=await Fh(e,t);return Bs(e,t,o)}function Mh(n){let{json:e,bin:t}=ys(n);for(let o of e.bufferViews??[])if(o.extensions?.EXT_meshopt_compression)throw new Error("[osmgl] GLB \u0441\u0436\u0430\u0442 meshopt \u2014 \u043D\u0443\u0436\u0435\u043D parseGlbAsync");return Bs(e,t,null)}function ys(n){let e=new DataView(n);if(e.getUint32(0,true)!==vh)throw new Error("[osmgl] \u044D\u0442\u043E \u043D\u0435 GLB: \u043D\u0435\u0432\u0435\u0440\u043D\u0430\u044F \u0441\u0438\u0433\u043D\u0430\u0442\u0443\u0440\u0430");if(e.getUint32(4,true)!==2)throw new Error("[osmgl] \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F \u0442\u043E\u043B\u044C\u043A\u043E glTF 2.0");let t=null,o=null,r=12;for(;r+8<=n.byteLength;){let i=e.getUint32(r,true),a=e.getUint32(r+4,true),l=r+8;a===xh?t=JSON.parse(new TextDecoder().decode(new Uint8Array(n,l,i))):a===wh&&(o=new Uint8Array(n,l,i)),r=l+i+(4-i%4)%4;}if(!t)throw new Error("[osmgl] \u0432 GLB \u043D\u0435\u0442 JSON-\u043A\u0443\u0441\u043A\u0430");return {json:t,bin:o??new Uint8Array(0)}}async function Fh(n,e){let t=n.bufferViews??[],o=[];for(let a=0;a<t.length;a++)t[a].extensions?.EXT_meshopt_compression&&o.push(a);if(!o.length)return null;let{MeshoptDecoder:r}=await Promise.resolve().then(()=>(gs(),bs));await r.ready;let i=new Map;for(let a of o){let l=t[a].extensions.EXT_meshopt_compression,s=l.byteOffset??0,c=e.subarray(s,s+l.byteLength),h=new Uint8Array(l.count*l.byteStride);r.decodeGltfBuffer(h,l.count,l.byteStride,c,l.mode,l.filter??"NONE"),i.set(a,h);}return i}function As(n){let e=K();if(n.matrix){for(let C=0;C<16;C++)e[C]=n.matrix[C];return e}je(e);let[t,o,r]=n.translation??[0,0,0],[i,a,l,s]=n.rotation??[0,0,0,1],[c,h,u]=n.scale??[1,1,1],f=i+i,d=a+a,p=l+l,b=i*f,m=i*d,g=i*p,y=a*d,A=a*p,B=l*p,x=s*f,w=s*d,_=s*p;return e[0]=(1-(y+B))*c,e[1]=(m+_)*c,e[2]=(g-w)*c,e[4]=(m-_)*h,e[5]=(1-(b+B))*h,e[6]=(A+x)*h,e[8]=(g+w)*u,e[9]=(A-x)*u,e[10]=(1-(b+y))*u,e[12]=t,e[13]=o,e[14]=r,e}var Dh={5120:127,5121:255,5122:32767,5123:65535};function Sh(n){let e=n[0],t=n[1],o=n[2],r=n[4],i=n[5],a=n[6],l=n[8],s=n[9],c=n[10],h=e*(i*c-a*s)-r*(t*c-o*s)+l*(t*a-o*i);if(Math.abs(h)<1e-20)return [1,0,0,0,1,0,0,0,1];let u=1/h;return [(i*c-a*s)*u,(a*l-r*c)*u,(r*s-i*l)*u,(o*s-t*c)*u,(e*c-o*l)*u,(t*l-e*s)*u,(t*a-o*i)*u,(o*r-e*a)*u,(e*i-t*r)*u]}function Bs(n,e,t){let o=C=>{let v=t?.get(C);if(v)return v;let E=n.bufferViews?.[C];if(!E)return null;let D=E.byteOffset??0;return e.subarray(D,D+E.byteLength)},r=[],i=[],a=[],l=[],s=[],c=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0],u=C=>{if(C===void 0)return null;let v=n.accessors?.[C];if(!v)return null;let E=Eh[v.type]??1,D=new Float64Array(v.count*E),F=v.bufferView!==void 0?n.bufferViews?.[v.bufferView]:void 0;if(!F||v.bufferView===void 0)return {data:D,components:E};let H=o(v.bufferView);if(!H)return {data:D,components:E};let S=_h[v.componentType]??4,L=F.extensions?.EXT_meshopt_compression,M=L?L.byteStride:F.byteStride,T=M&&M>0?M:S*E,P=v.byteOffset??0,k=new DataView(H.buffer,H.byteOffset,H.byteLength),O=v.normalized?Dh[v.componentType]??1:1;for(let N=0;N<v.count;N++)for(let G=0;G<E;G++){let R=P+N*T+G*S,W;switch(v.componentType){case 5120:W=k.getInt8(R);break;case 5121:W=k.getUint8(R);break;case 5122:W=k.getInt16(R,true);break;case 5123:W=k.getUint16(R,true);break;case 5125:W=k.getUint32(R,true);break;default:W=k.getFloat32(R,true);}D[N*E+G]=O===1?W:Math.max(W/O,-1);}return {data:D,components:E}},f=(C,v,E=-1)=>{if(C.mode!==void 0&&C.mode!==4)return;let D=u(C.attributes.POSITION);if(!D)return;let F=u(C.attributes.NORMAL),H=u(C.attributes.TEXCOORD_0),S=u(C.indices),L=r.length/3,M=D.data.length/3,T=Sh(v),k=(C.material!==void 0?n.materials?.[C.material]:void 0)?.pbrMetallicRoughness?.baseColorTexture?.extensions?.KHR_texture_transform,O=k?{ox:k.offset?.[0]??0,oy:k.offset?.[1]??0,sx:k.scale?.[0]??1,sy:k.scale?.[1]??1,rot:k.rotation??0}:null;for(let X=0;X<M;X++){let re=D.data[X*3],le=D.data[X*3+1],q=D.data[X*3+2],U=v[0]*re+v[4]*le+v[8]*q+v[12],J=v[1]*re+v[5]*le+v[9]*q+v[13],fe=v[2]*re+v[6]*le+v[10]*q+v[14];if(r.push(U,J,fe),U<c[0]&&(c[0]=U),J<c[1]&&(c[1]=J),fe<c[2]&&(c[2]=fe),U>h[0]&&(h[0]=U),J>h[1]&&(h[1]=J),fe>h[2]&&(h[2]=fe),F){let ae=F.data[X*3],xe=F.data[X*3+1],Te=F.data[X*3+2],we=T[0]*ae+T[3]*xe+T[6]*Te,Ro=T[1]*ae+T[4]*xe+T[7]*Te,Go=T[2]*ae+T[5]*xe+T[8]*Te,Oo=Math.hypot(we,Ro,Go);Oo>1e-12?(we/=Oo,Ro/=Oo,Go/=Oo):(we=0,Ro=1,Go=0),i.push(we,Ro,Go);}else i.push(0,1,0);let se=H?H.data[X*2]:0,ue=H?H.data[X*2+1]:0;if(O){if(O.rot!==0){let ae=Math.cos(O.rot),xe=Math.sin(O.rot),Te=ae*se+xe*ue,we=-xe*se+ae*ue;se=Te,ue=we;}se=se*O.sx+O.ox,ue=ue*O.sy+O.oy;}a.push(se,ue);}let N=l.length;if(S)for(let X=0;X<S.data.length;X++)l.push(L+S.data[X]);else for(let X=0;X<M;X++)l.push(L+X);let G=C.material!==void 0?n.materials?.[C.material]:void 0,R=G?.pbrMetallicRoughness,W=R?.metallicFactor!==void 0||R?.roughnessFactor!==void 0,j=R?.baseColorFactor??[1,1,1,1],Z=R?.baseColorTexture?.index,ee=Z!==void 0?n.textures?.[Z]?.source:void 0,ge=G?.emissiveFactor??[0,0,0],te=G?.extensions?.KHR_materials_emissive_strength?.emissiveStrength??1;s.push({indexOffset:N,indexCount:l.length-N,baseColor:[j[0],j[1],j[2],j[3]??1],metallic:W?R?.metallicFactor??1:0,roughness:W?R?.roughnessFactor??1:1,emissive:[ge[0]*te,ge[1]*te,ge[2]*te],texture:ee??-1,doubleSided:G?.doubleSided===true,blend:G?.alphaMode==="BLEND",alphaCutoff:G?.alphaMode==="MASK"?G.alphaCutoff??.5:.02,node:E});},d=n.skins?.length?null:Ih(n,u),p=d?d.nodes:null,b=(C,v,E,D)=>{let F=n.nodes?.[C];if(!F)return;let H=As(F),S=K();Ee(S,v,H);let L=K(),M=D,T=p?.get(C);if(T?(T.parentNode=D,T.parent=E.slice(),je(L),M=C):Ee(L,E,H),F.mesh!==void 0)for(let k of n.meshes?.[F.mesh]?.primitives??[])f(k,L,M);let P=F.extensions?.KHR_lights_punctual?.light;if(P!==void 0){let k=n.extensions?.KHR_lights_punctual?.lights?.[P],O=k?.type;if(k&&(O==="point"||O==="spot"||O==="directional")){let N=-S[8],G=-S[9],R=-S[10],W=Math.hypot(N,G,R)||1,j=k.spot?.innerConeAngle??0,Z=k.spot?.outerConeAngle??Math.PI/4;m.push({type:O,color:[k.color?.[0]??1,k.color?.[1]??1,k.color?.[2]??1],intensity:k.intensity??1,range:k.range??0,position:[S[12],S[13],S[14]],direction:[N/W,G/W,R/W],cosInner:Math.cos(j),cosOuter:Math.cos(Z)});}}for(let k of F.children??[])b(k,S,L,M);},m=[],g=K();je(g);let y=K();je(y);let A=n.scenes?.[n.scene??0]?.nodes??n.nodes?.map((C,v)=>v)??[];for(let C of A)b(C,g,y,-1);let B=[];for(let C of n.images??[]){if(C.bufferView===void 0){B.push(new Uint8Array(0));continue}let v=o(C.bufferView);B.push(v?v.slice():new Uint8Array(0));}let x=r.length/3,w=new ArrayBuffer(x*vr),_=new Float32Array(w);for(let C=0;C<x;C++){let v=C*8;_[v]=r[C*3],_[v+1]=r[C*3+1],_[v+2]=r[C*3+2],_[v+3]=i[C*3],_[v+4]=i[C*3+1],_[v+5]=i[C*3+2],_[v+6]=a[C*2],_[v+7]=a[C*2+1];}return isFinite(c[0])||(c[0]=c[1]=c[2]=0,h[0]=h[1]=h[2]=0),{vertices:w,indices:new Uint32Array(l),primitives:s,images:B,min:c,max:h,animation:d,lights:m}}function Ih(n,e){let t=n.animations?.[0];if(!t||!t.channels.length)return null;let o=new Map,r=0;for(let i of t.channels){let a=i.target.node,l=i.target.path;if(a===void 0||l!=="translation"&&l!=="rotation"&&l!=="scale")continue;let s=t.samplers[i.sampler];if(!s)continue;let c=e(s.input),h=e(s.output);if(!c||!h||!c.data.length)continue;let u=l==="rotation"?4:3,f=s.interpolation==="CUBICSPLINE",d=c.data.length,p=new Float32Array(d*u);for(let m=0;m<d;m++){let g=f?(m*3+1)*u:m*u;for(let y=0;y<u;y++)p[m*u+y]=h.data[g+y];}let b=o.get(a)??{parentNode:-1,parent:je(K()),base:Lh(n.nodes?.[a]),channels:[]};b.channels.push({path:l,times:Float32Array.from(c.data),values:p,step:s.interpolation==="STEP"}),o.set(a,b),r=Math.max(r,c.data[d-1]);}return o.size?{duration:r||1,nodes:o}:null}function Lh(n){let e=n?.translation,t=n?.rotation,o=n?.scale;return {t:[e?.[0]??0,e?.[1]??0,e?.[2]??0],r:[t?.[0]??0,t?.[1]??0,t?.[2]??0,t?.[3]??1],s:[o?.[0]??1,o?.[1]??1,o?.[2]??1]}}function ei(n,e,t,o){let r=n.nodes.get(e);if(!r)return je(o);let i=K();Th(r,t,i);let a=K();if(Ee(a,r.parent,i),r.parentNode<0)return Cs(o,a);let l=K();return ei(n,r.parentNode,t,l),Ee(o,l,a)}var Cs=(n,e)=>{for(let t=0;t<16;t++)n[t]=e[t];return n};function Th(n,e,t){let o=[...n.base.t],r=[...n.base.r],i=[...n.base.s];for(let a of n.channels){let l=a.times.length,s=a.path==="rotation"?4:3,c=0;for(;c<l-1&&a.times[c+1]<e;)c++;let h=Math.min(c+1,l-1),u=a.times[h]-a.times[c],f=a.step||u<=0?0:Math.min(Math.max((e-a.times[c])/u,0),1),d=c*s,p=h*s;if(a.path==="rotation"){let b=0;for(let y=0;y<4;y++)b+=a.values[d+y]*a.values[p+y];let m=b<0?-1:1,g=0;for(let y=0;y<4;y++)r[y]=a.values[d+y]*(1-f)+a.values[p+y]*m*f,g+=r[y]*r[y];g=Math.sqrt(g)||1;for(let y=0;y<4;y++)r[y]/=g;}else {let b=a.path==="translation"?o:i;for(let m=0;m<3;m++)b[m]=a.values[d+m]*(1-f)+a.values[p+m]*f;}}return Cs(t,As({translation:o,rotation:r,scale:i}))}var Le=5126,Hh=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),vs={stride:vr,attribs:[{name:"a_pos",size:3,type:Le,offset:0},{name:"a_normal",size:3,type:Le,offset:12},{name:"a_tex",size:2,type:Le,offset:24}]},oi=class{constructor(e,t,o,r){this.vao=e;this.vbo=t;this.ibo=o;this.textures=r;this.users=0;this.instVao=null;}destroy(e){this.vao.destroy(),this.instVao?.destroy(),this.vbo.destroy(),this.ibo.destroy();for(let t of this.textures)t&&e.deleteTexture(t);}},ti=256,xr=41,xs={stride:xr*4,attribs:[{name:"a_i_m0",size:4,type:Le,offset:0,divisor:1},{name:"a_i_m1",size:4,type:Le,offset:16,divisor:1},{name:"a_i_m2",size:4,type:Le,offset:32,divisor:1},{name:"a_i_m3",size:4,type:Le,offset:48,divisor:1},{name:"a_i_s0",size:4,type:Le,offset:64,divisor:1},{name:"a_i_s1",size:4,type:Le,offset:80,divisor:1},{name:"a_i_s2",size:4,type:Le,offset:96,divisor:1},{name:"a_i_s3",size:4,type:Le,offset:112,divisor:1},{name:"a_i_n0",size:3,type:Le,offset:128,divisor:1},{name:"a_i_n1",size:3,type:Le,offset:140,divisor:1},{name:"a_i_n2",size:3,type:Le,offset:152,divisor:1}]},Bo=2,Rt=16,at=class{constructor(){this.models=[];this.gpu=new z;this.counted=new Set;this.instBuffer=null;this.instScratch=new Float32Array(ti*xr);this.drawnInstanced=new Set;this.onLoaded=null;this.growDurationSec=.45;this.fadeDurationSec=.6;this.transitioning=false;this.depthTimeSec=0;this.lightPacks=new WeakMap;this.shadow32=new Float32Array(16);this.shadowNode32=new Float32Array(16);this.shadowNodeColor32=new Float32Array(16);}add(e){this.models.includes(e)||(this.models.push(e),e.isLoaded||e.load(()=>this.onLoaded?.()));}remove(e,t){let o=this.models.indexOf(e);if(o<0)return;this.models.splice(o,1);let r=this.gpu.get(e.url);r&&(this.counted.delete(e)&&r.users--,!(r.users>0)&&(t&&r.destroy(t),this.gpu.delete(e.url)));}get all(){return this.models}get hasTransitions(){return this.transitioning}get hasAnimated(){return this.models.some(e=>e.isAnimated)}get isEmpty(){return this.models.length===0}get readyCount(){return this.models.filter(e=>e.visible&&e.isLoaded).length}render(e,t,o,r,i,a,l=0,s){if(this.models.length){this.drawnInstanced.clear(),s&&this.renderInstanced(e,t,s.shader,s.locations,i,a),o.use(),i(o),o.setInt("u_base_texture",Bo);for(let c of this.models){if(this.drawnInstanced.has(c)||!this.inView(t,c))continue;let h=c.visible&&c.fade>0?this.gpuFor(e,c,r):null;if(!h||!c.mesh)continue;let u=c.fade<1;o.setFloat("u_opacity",c.fade);let f=c.matrixFor(t);o.setMat4("u_matrix",f),o.setMat3("u_normal_matrix",c.normalMatrix());let d=a?this.shadowMatrix(t,c):null;this.uploadLights(o,c.mesh);let p=c.cameraInModelSpace(t);o.setVec3("u_camera_model",p[0],p[1],p[2]),o.setFloat("u_reflect",1),h.vao.bind();for(let b of [false,true])if(!(u&&!b))for(let m of c.mesh.primitives){if(!u&&m.blend!==b)continue;o.setMat4("u_matrix",m.node>=0?c.matrixForNode(t,m.node,l):f),d&&o.setMat4("u_shadow_matrix",m.node>=0?this.shadowMatrixForNodeAt(t,c,m.node,l):d);let g=m.texture>=0?h.textures[m.texture]:null;o.setFloat("u_has_texture",g?1:0),o.setFloat("u_alpha_cutoff",m.alphaCutoff),g&&e.bindTexture(Bo,g),o.setVec4v("u_base_color",m.baseColor),o.setVec3("u_emissive",m.emissive[0],m.emissive[1],m.emissive[2]),o.setFloat("u_metallic",m.metallic),o.setFloat("u_roughness",m.roughness),e.setCull(m.doubleSided?"none":"back"),e.setBlend(b?"premultiplied":"none"),e.setDepthMask(!b),e.gl.drawElements(e.gl.TRIANGLES,m.indexCount,e.gl.UNSIGNED_INT,m.indexOffset*4);}}e.bindVAO(null),e.setCull("back"),e.setBlend("premultiplied"),e.setDepthMask(true);}}renderInstanced(e,t,o,r,i,a){let l=new z;for(let c of this.models){if(!c.visible||c.fade<1||!c.mesh||!c.isLoaded||!this.inView(t,c)||c.mesh.primitives.some(u=>u.blend||u.node>=0))continue;let h=l.get(c.url);h?h.push(c):l.set(c.url,[c]);}let s=false;o.setFloat("u_reflect",0);for(let[,c]of l){if(c.length<2)continue;let h=this.gpuFor(e,c[0],r);if(!h||!c[0].mesh)continue;this.instBuffer||(this.instBuffer=new ve(e,this.instScratch,xs,true)),h.instVao||(h.instVao=new pe(e,[{buffer:h.vbo,locations:r},{buffer:this.instBuffer,locations:r}],h.ibo)),s||(o.use(),i(o),o.setInt("u_base_texture",Bo),o.setFloat("u_opacity",1),s=true);let u=c[0].mesh;for(let f=0;f<c.length;f+=ti){let d=Math.min(ti,c.length-f);for(let p=0;p<d;p++){let b=c[f+p],m=p*xr;this.instScratch.set(b.matrixFor(t),m);let g=a?this.shadowMatrix(t,b):Hh;this.instScratch.set(g,m+16),this.instScratch.set(b.normalMatrix(),m+32),this.drawnInstanced.add(b);}this.instBuffer.update(this.instScratch.subarray(0,d*xr)),e.bindVAO(h.instVao.vao);for(let p of u.primitives){let b=p.texture>=0?h.textures[p.texture]:null;o.setFloat("u_has_texture",b?1:0),o.setFloat("u_alpha_cutoff",p.alphaCutoff),b&&e.bindTexture(Bo,b),o.setVec4v("u_base_color",p.baseColor),o.setVec3("u_emissive",p.emissive[0],p.emissive[1],p.emissive[2]),o.setFloat("u_metallic",p.metallic),o.setFloat("u_roughness",p.roughness),e.setCull(p.doubleSided?"none":"back"),e.setBlend("none"),e.setDepthMask(true),e.gl.drawElementsInstanced(e.gl.TRIANGLES,p.indexCount,e.gl.UNSIGNED_INT,p.indexOffset*4,d);}}}s&&e.bindVAO(null);}uploadLights(e,t){let o=this.lightPacks.get(t);if(!o){let r=t.lights.filter(h=>h.type!=="directional"),i=r.length<=Rt?r:[...r].sort((h,u)=>u.intensity-h.intensity).slice(0,Rt),a=new Float32Array(Rt*4),l=new Float32Array(Rt*4),s=new Float32Array(Rt*4),c=new Float32Array(Rt*4);i.forEach((h,u)=>{let f=u*4;a[f]=h.position[0],a[f+1]=h.position[1],a[f+2]=h.position[2],a[f+3]=h.range,l[f]=h.color[0]*h.intensity,l[f+1]=h.color[1]*h.intensity,l[f+2]=h.color[2]*h.intensity,l[f+3]=h.type==="spot"?1:0,s[f]=h.direction[0],s[f+1]=h.direction[1],s[f+2]=h.direction[2],c[f]=h.cosInner,c[f+1]=h.cosOuter;}),o={count:i.length,pos:a,color:l,dir:s,cone:c},this.lightPacks.set(t,o);}e.setInt("u_light_count",o.count),o.count!==0&&(e.setVec4Array("u_light_pos",o.pos),e.setVec4Array("u_light_color",o.color),e.setVec4Array("u_light_dir",o.dir),e.setVec4Array("u_light_cone",o.cone));}inView(e,t){if(!t.mesh)return false;let r=t.origin(),i=t.boundingRadiusM();return e.isSphereVisible(r.x,r.y,t.altitude+i*.5,i)}advanceTransitions(){this.transitioning=false;for(let e of this.models)e.advanceGrow(this.growDurationSec)&&(this.transitioning=true),e.advanceFade(this.fadeDurationSec)&&(this.transitioning=true);}renderDepth(e,t,o,r){if(this.models.length){o.use();for(let i of this.models){let a=i.visible&&i.fade>.5?this.gpuFor(e,i,r):null;if(!a||!i.mesh)continue;let l=this.shadowMatrix(t,i);o.setMat4("u_matrix",l),a.vao.bind();for(let s of i.mesh.primitives)s.blend||(o.setMat4("u_matrix",s.node>=0?this.shadowMatrixForNode(t,i,s.node):l),e.gl.drawElements(e.gl.TRIANGLES,s.indexCount,e.gl.UNSIGNED_INT,s.indexOffset*4));}e.bindVAO(null);}}shadowMatrix(e,t){let o=t.origin();return t.matrixInSpace(e.shadowObjectMatrix(o.x,o.y,t.altitude),this.shadow32)}shadowMatrixForNode(e,t,o){return this.shadowMatrixForNodeInto(e,t,o,this.depthTimeSec,this.shadowNode32)}shadowMatrixForNodeAt(e,t,o,r){return this.shadowMatrixForNodeInto(e,t,o,r,this.shadowNodeColor32)}shadowMatrixForNodeInto(e,t,o,r,i){let a=t.origin();return t.matrixInSpaceForNode(e.shadowObjectMatrix(a.x,a.y,t.altitude),o,r,i)}gpuFor(e,t,o){let r=this.gpu.get(t.url);if(r)return this.counted.has(t)||(this.counted.add(t),r.users++),r;if(!t.mesh)return null;let i=e.gl,a=new ve(e,new Uint8Array(t.mesh.vertices),vs),l=new ye(e,t.mesh.indices),s=new pe(e,[{buffer:a,locations:o}],l),c=t.bitmaps.map(u=>{if(!u)return null;let f=i.createTexture();return f?(e.bindTexture(Bo,f),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,u),i.generateMipmap(i.TEXTURE_2D),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR_MIPMAP_LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.REPEAT),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.REPEAT),f):null}),h=new oi(s,a,l,c);return h.users=1,this.counted.add(t),this.gpu.set(t.url,h),h}static get layout(){return vs}static get instanceLayout(){return xs}destroy(e){for(let t of this.gpu.values())t.destroy(e);this.gpu.clear(),this.models=[];}};var ri=4,ws=new oe;function kh(n){ws.has(n)||(ws.add(n),console.warn(`[osmgl] ${n}`));}var Ph=.5,Rh=.01,Gh=300,ni=127,ii=128,Co=5120,_r=5121,vo=5122,_s=5123,xo=5126,Oh={stride:8,attribs:[{name:"a_pos",size:2,type:xo,offset:0}]},ai={stride:tt,attribs:[{name:"a_pos",size:2,type:vo,offset:0}]},Es={stride:nt,attribs:[{name:"a_p0",size:2,type:vo,offset:0},{name:"a_p1",size:2,type:vo,offset:4},{name:"a_corner",size:2,type:Co,offset:8},{name:"a_ground",size:2,type:Co,offset:10},{name:"a_dist",size:1,type:xo,offset:12},{name:"a_width",size:1,type:xo,offset:16}]},wr={stride:Ie,attribs:[{name:"a_pos",size:2,type:vo,offset:0},{name:"a_height",size:1,type:_s,offset:4},{name:"a_tint",size:1,type:_r,normalized:true,offset:6},{name:"a_ao",size:1,type:_r,normalized:true,offset:7},{name:"a_normal",size:3,type:Co,normalized:true,offset:8},{name:"a_kind",size:1,type:_r,offset:11},{name:"a_wall",size:3,type:_s,offset:12}]},zh={flat:0,water:1,foliage:2,sand:3,asphalt:4},Vh=[1,9,14,26,3],Ms={stride:It,attribs:[{name:"a_pos",size:2,type:xo,offset:0},{name:"a_level",size:1,type:vo,offset:8},{name:"a_normal",size:3,type:Co,normalized:true,offset:10},{name:"a_kind",size:1,type:_r,offset:13},{name:"a_bleed",size:2,type:Co,offset:14}]},li=class{constructor(e,t,o,r,i,a,l=r){this.vao=e;this.buffer=t;this.ibo=o;this.indexCount=r;this.indexType=i;this.extent=a;this.capIndexOffset=l;this.firstDrawTime=0;}destroy(){this.vao.destroy(),this.buffer.destroy(),this.ibo.destroy();}},Fs={enabled:false,resolution:1024,strength:.75,color:"#5a6b86",bias:.25},wo=class{constructor(){this.fill=null;this.surface=null;this.surfaceLocs=new z;this.line=null;this.building=null;this.depth=null;this.groundShadow=null;this.sky=null;this.raster=null;this.rasterLayer=new yr;this.globeBody=null;this.globeClip=null;this.globeMesh=null;this.quad=null;this.fillLocs=new z;this.lineLocs=new z;this.objectLine=null;this.objectLineLocs=new z;this.buildingLocs=new z;this.shadows={...Fs};this.shadowTarget=null;this.shadowPlaceholder=null;this.fog=null;this.shadowActive=false;this.materialTime=0;this.materialAnimating=false;this.stencilIds=new z;this.patternScale=1;this.cameraMeters=[0,0,0];this.dpr=1;this.detailScale=1;this.reliefScale=1;this.allowShadows=true;this.highlight=null;this.highlightGpu=new z;this.highlightKey="";this.groundArrows=new mo;this.highlightTris=new z;this.fillHighlightGpu=new z;this.fillHighlightKey="";this.footprintKey="";this.highlightFill=null;this.indoorMask=new bo;this.hiddenBuildings=new Set;this.hiddenVenues=new Set;this.hiddenVenueLayer=null;this.hiddenCut=new z;this.hiddenStamp="";this.shadowDepthPerMeter=1;this.shadowTexelMeters=0;this.growDurationMs=350;this.symbols=null;this.objects=null;this.models=new at;this.model=null;this.modelInstanced=null;this.modelDepth=null;this.modelLocs=new z;this.modelInstLocs=new z;}get indoorOpen(){return this.indoorMask.active}syncHiddenStamp(){let e=o=>[...o].sort((r,i)=>r-i).join(","),t=e(this.hiddenBuildings)+"#"+e(this.hiddenVenues);if(t!==this.hiddenStamp){this.hiddenStamp=t;for(let o of this.hiddenCut.values())o?.vao.destroy(),o?.ibo.destroy();this.hiddenCut.clear();}}hiddenFor(e,t){return t?this.hiddenBuildings:e===this.hiddenVenueLayer?this.hiddenVenues:null}cutHidden(e,t,o,r,i,a){if(!a||!a.size)return null;let l=r+"|"+o,s=this.hiddenCut.get(l);if(s!==void 0&&(s===null||s.vbo===i))return s;s&&(s.vao.destroy(),s.ibo.destroy());let c=t.data?.buckets?.[o];if(!c||c.kind!=="fill-extrusion"||!c.featureIds)return null;let h=new Uint32Array(c.indices),u=new Float64Array(c.featureIds),f=[];for(let p=0;p*3<h.length;p++)a.has(u[p])||f.push(h[p*3],h[p*3+1],h[p*3+2]);let d=null;if(f.length<h.length){let p=new ye(e,new Uint32Array(f));d={vao:new pe(e,[{buffer:i,locations:this.buildingLocs}],p),ibo:p,count:f.length,vbo:i};}return this.hiddenCut.set(l,d),d}init(e){this.symbols?.init(e),this.fill=new Ae(e,"fill",jl,Yl),this.surface=new Ae(e,"surface",os,rs),this.line=new Ae(e,"line",Zl,Ql),this.objectLine=new Ae(e,"objectLine",ql,$l),this.building=new Ae(e,"buildings",es,ts),this.depth=new Ae(e,"depth",Rl,On),this.groundShadow=new Ae(e,"groundShadow",Jl,Xl),this.sky=new Ae(e,"sky",Wl,Nl),this.raster=new Ae(e,"raster",Kl,Ul),this.globeBody=new Ae(e,"globeBody",Tl,Hl),this.globeClip=new Ae(e,"globeClip",kl,Pl),this.globeMesh=Wh(e,this.globeBody),this.model=new Ae(e,"model",Ol,zn),this.modelInstanced=new Ae(e,"model-instanced",zl,zn),this.modelDepth=new Ae(e,"modelDepth",Vl,On);for(let i of at.layout.attribs)this.modelLocs.set(i.name,this.model.attribLocation(i.name));for(let i of [...at.layout.attribs,...at.instanceLayout.attribs])this.modelInstLocs.set(i.name,this.modelInstanced.attribLocation(i.name));this.shadowPlaceholder=Il(e);let t=new z([["a_pos",this.groundShadow.attribLocation("a_pos")]]),o=new ve(e,new Float32Array([0,0,1,0,1,1,0,1]),Oh),r=new ye(e,new Uint16Array([0,1,2,0,2,3]));this.quad={vao:new pe(e,[{buffer:o,locations:t}],r),vbo:o,ibo:r};for(let i of ai.attribs)this.fillLocs.set(i.name,this.fill.attribLocation(i.name));for(let i of Ms.attribs)this.surfaceLocs.set(i.name,this.surface.attribLocation(i.name));for(let i of Es.attribs)this.lineLocs.set(i.name,this.line.attribLocation(i.name));for(let i of qn.attribs)this.objectLineLocs.set(i.name,this.objectLine.attribLocation(i.name));for(let i of wr.attribs)this.buildingLocs.set(i.name,this.building.attribLocation(i.name));}render(e,t,o,r,i,a=new z){if(!this.fill||!this.line||!this.building)return false;let l=t.zoom,s=false;this.materialTime=i/1e3,this.materialAnimating=false,this.fog=kt(t,r),this.patternScale=No/Math.max(Oe(t.center.lat),1),this.dpr=t.width>0?e.gl.drawingBufferWidth/t.width:1;let c=Math.max(t.pixelsPerMeter,1e-9),h=t.cameraPositionPx;this.cameraMeters=[h[0]/c,h[1]/c,h[2]/c];let u=m=>o.get(m.source??Y);this.syncHighlightFootprint(o,r),this.indoorMask.sync(o,r,l),this.syncHiddenStamp(),this.models.advanceTransitions(),this.renderShadowMap(e,t,o,r,i),this.drawSky(e,t,r),this.drawGlobeBody(e,t,r),this.raster&&this.quad&&this.rasterLayer.render(e,t,this.quad.vao,this.raster,r,a,l),this.drawTileStencil(e,t,o),e.setDepthTest(t.globeActive),e.setDepthFunc("lequal"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");let f=m=>m.type==="line"&&V(m.paint.elevation,l,0)!==0,d=new Set;for(let m of r.layers){if(m.type==="raster"||m.type==="fill-extrusion"||m.type==="symbol"||m.overlay||f(m)||!r.layerVisibleAt(m,l))continue;let g=u(m);if(g){if(m.type==="line"&&m.network){if(d.has(m.network))continue;d.add(m.network),this.drawNetwork(e,t,r,u,m.network,l,y=>!y.overlay&&!f(y)&&r.layerVisibleAt(y,l));continue}if(m.type==="surface"){if(!this.flattened(g,r,m))continue;this.drawFill(e,t,g,r,m,l);continue}m.type==="fill"?this.drawFill(e,t,g,r,m,l):this.drawLine(e,t,g,r,m,l);}}this.drawFillHighlight(e,t,o,r),this.groundArrows&&(this.groundArrows.highlightFootprint=this.highlightFootprint(),this.groundArrows.render(e,t,o,r,this.fill,this.fillLocs,m=>{this.applyFogUniforms(m,t,r),m.setVec4("u_globe",0,0,0,0),m.setInt("u_material",0),m.setFloat("u_elevation",0),m.setVec2("u_world_origin",0,0);},this.shadowActive)),this.drawGroundShadow(e,t,o,r),this.drawEarthDepth(e,t,o,r),e.setDepthTest(true),e.setDepthMask(true),e.setDepthFunc("lequal"),e.setCull("back");for(let m of r.layers){if(m.type!=="surface"||m.overlay||!r.layerVisibleAt(m,l))continue;let g=u(m);g&&(this.flattened(g,r,m)||this.drawSurface(e,t,g,r,m,l));}e.setStencilTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),e.setDepthTest(false);let p=new Set;for(let m of r.layers){if(m.type==="raster"||!f(m)||m.overlay||!r.layerVisibleAt(m,l))continue;let g=u(m);if(g){if(m.type==="line"&&m.network){if(p.has(m.network))continue;p.add(m.network),this.drawNetwork(e,t,r,u,m.network,l,y=>!y.overlay&&f(y)&&r.layerVisibleAt(y,l));continue}this.drawLine(e,t,g,r,m,l);}}this.drawOverlay(e,t,r,u,l,"roads"),e.setDepthTest(true),e.setDepthMask(true),e.setCull("back");for(let m of r.layers){if(m.type!=="fill-extrusion"||!r.layerVisibleAt(m,l))continue;let g=u(m);g&&(this.drawBuildings(e,t,g,r,m,l,i)&&(s=true),this.drawHighlight(e,t,g,r,m,l));}this.model&&!this.models.isEmpty&&(this.models.render(e,t,this.model,this.modelLocs,m=>{this.applyShadowUniforms(m),this.applyFogUniforms(m,t,r),this.applyLight(m,r);},this.shadowActive,i/1e3,this.modelInstanced?{shader:this.modelInstanced,locations:this.modelInstLocs}:void 0),(this.models.hasAnimated||this.models.hasTransitions)&&(s=true)),this.drawOverlay(e,t,r,u,l,"volume"),this.objects&&!this.objects.isEmpty&&(e.setDepthTest(true),e.setDepthFunc("lequal"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.objects.render(e,t,this.fill,this.fillLocs,this.objectLine,this.objectLineLocs,m=>{this.applyFogUniforms(m,t,r),m.setVec4("u_globe",0,0,0,0),m.setInt("u_material",0),m.setFloat("u_elevation",0),m.setVec2("u_world_origin",0,0);},this.shadowActive),e.setDepthTest(false)),this.raster&&this.quad&&this.rasterLayer.render(e,t,this.quad.vao,this.raster,r,a,l,true);let b=r.layers.filter(m=>m.type==="line"&&V(m.paint.ghostOpacity,l,0)>.001&&r.layerVisibleAt(m,l));if(b.length){e.setDepthTest(true),e.setDepthFunc("greater"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");for(let m of b){let g=u(m);g&&this.drawLine(e,t,g,r,m,l,V(m.paint.ghostOpacity,l,0));}e.setDepthFunc("lequal"),e.setDepthTest(false);}return this.objects&&!this.objects.isEmpty&&(e.setDepthTest(true),e.setDepthFunc("greater"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.objects.render(e,t,this.fill,this.fillLocs,this.objectLine,this.objectLineLocs,m=>{this.applyFogUniforms(m,t,r),m.setVec4("u_globe",0,0,0,0),m.setInt("u_material",0),m.setFloat("u_elevation",0),m.setVec2("u_world_origin",0,0);},this.shadowActive,true),e.setDepthFunc("lequal"),e.setDepthTest(false)),this.symbols&&(this.symbols.highlightFootprint=this.highlightFootprint()),this.symbols?.render(e,t,o,r),e.bindVAO(null),s||this.materialAnimating}renderShadowMap(e,t,o,r,i){if(this.shadowPlaceholder&&e.bindTexture(ri,this.shadowPlaceholder),this.shadowActive=false,!this.shadows.enabled||!this.allowShadows||!this.depth)return;let a=r.layers.filter(u=>u.type==="fill-extrusion"&&!u.overlay&&r.layerVisibleAt(u,t.zoom));if(!a.length&&this.models.isEmpty)return;this.shadowTarget?this.shadowTarget.resize(this.shadows.resolution):this.shadowTarget=new ho(e,this.shadows.resolution);let l=r.light;if(t.updateShadow(Gt(l.keyAzimuth,l.keyAltitude),Gh),!t.shadowReady)return;let s=this.shadowTarget;s.bind(),e.setDepthFunc("lequal"),e.setBlend("none"),e.setCull("none");let c=e.gl;c.enable(c.POLYGON_OFFSET_FILL),c.polygonOffset(2,4);let h=this.depth;h.use();for(let u of a){let f=o.get(u.source??Y);if(!f)continue;let d=r.bucketKeyFor(u);if(d===null)continue;let p=V(u.paint.heightScale,t.zoom,1);(u.source??Y)===Y&&this.indoorMask.prepare(f,d);for(let b of f.visibleTiles){if(!this.drawsTile(t,r,u,b))continue;let m=f.getTile(b),g=m&&this.bucketFor(e,m,d,wr,this.buildingLocs,"fill-extrusion");if(!g)continue;h.setFloat("u_height_scale",this.growScale(g,i,!f.warm)*p),h.setMat4("u_matrix",t.shadowTileMatrix(b,g.extent));let y=(u.source??Y)===Y,A=this.cutHidden(e,m,d,b.dataKey,g.buffer,this.hiddenFor(d,y)),B=y?A??this.indoorMask.indicesFor(e,m,d,b,g.buffer,this.buildingLocs):A;B?(B.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,B.count,e.gl.UNSIGNED_INT,0)):(g.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,g.indexCount,g.indexType,0));}}this.modelDepth&&(this.models.depthTimeSec=i/1e3,e.gl.polygonOffset(6,96),this.models.renderDepth(e,t,this.modelDepth,this.modelLocs),e.gl.polygonOffset(2,4)),c.disable(c.POLYGON_OFFSET_FILL),e.bindFramebuffer(null),e.viewport(0,0,e.gl.drawingBufferWidth,e.gl.drawingBufferHeight),s.bindTexture(ri),this.shadowDepthPerMeter=t.shadowDepthPerMeter(),this.shadowTexelMeters=Math.abs(t.shadowTexelWorldSize(s.size))/(t.pixelsPerMeter||1),this.shadowActive=true;}drawGlobeBody(e,t,o){if(!t.globeActive||!this.globeBody||!this.globeMesh)return;let r=this.globeBody;r.use(),this.applyGlobeUniforms(r,t,o),r.setMat4("u_matrix",t.localMatrix());let i=o.background;r.setVec3("u_body_color",i[0],i[1],i[2]),Ve(r,"u_atmo_color",o.sky.horizonColor),r.setFloat("u_atmo_strength",o.sky.enabled?1-t.globeFlatMix:0),e.setBlend("none"),e.setDepthTest(true),e.setDepthMask(true),e.setDepthFunc("less"),e.setCull("none"),this.globeMesh.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,this.globeMesh.count,e.gl.UNSIGNED_SHORT,0),e.bindVAO(null),this.drawGlobeClip(e,t),e.setBlend("premultiplied"),e.setDepthTest(false),e.setDepthMask(false);}drawGlobeClip(e,t){if(!this.globeClip||!this.quad)return;let o=e.gl,r=[0,0,-t.globeRadiusPx,1],i=[0,0,0,0];if(de(i,t.localProjMatrix,r),i[3]<=1e-6)return;let a=this.globeClip;a.use(),a.setFloat("u_center_depth",i[2]/i[3]),o.colorMask(false,false,false,false),e.setDepthTest(true),e.setDepthMask(true),e.setDepthFunc("always"),this.quad.vao.bind(),o.drawElements(o.TRIANGLES,6,o.UNSIGNED_SHORT,0),o.colorMask(true,true,true,true),e.bindVAO(null);}applyAtmosphere(e,t,o){let r=t.cameraRay();e.setVec3("u_cam_ray",r.axisElev,r.focal*this.dpr,t.height*this.dpr/2),e.setFloat("u_haze_exp",1/Math.max(o.sky.horizonBlend,.01));}skyBand(e,t){let o=e.horizonScreenY(),r=e.height*this.dpr/Math.max(Ge(e.fov),.001);return [(e.height-o)*this.dpr,Math.max(o,1)*this.dpr,Math.max(t.sky.horizonBlend*r,1)]}drawSky(e,t,o){if(!this.sky||!this.quad||!o.sky.enabled)return;let r=this.sky;r.use(),Ve(r,"u_sky_color",o.sky.skyColor),Ve(r,"u_horizon_color",o.sky.horizonColor),Nh(r,o.sky);let[i,a]=this.skyBand(t,o),l=Math.min(a*.5,t.height*this.dpr*.1);r.setVec3("u_sky_params",i,a,l),this.applyAtmosphere(r,t,o);let s=t.cameraRay();r.setVec3("u_cam_right",s.right[0],s.right[1],s.right[2]),r.setVec3("u_cam_up",s.up[0],s.up[1],s.up[2]),r.setVec3("u_cam_fwd",s.fwd[0],s.fwd[1],s.fwd[2]),r.setVec2("u_cam_center",t.width*this.dpr/2,t.height*this.dpr/2);let c=Gt(o.light.keyAzimuth,o.light.keyAltitude);r.setVec3("u_sun_dir",-c[0],-c[1],-c[2]),Ve(r,"u_sun_color",o.light.keyColor),r.setFloat("u_sun_glow",o.light.keyIntensity);let h=t.globeActive?1-t.globeFlatMix:0;if(r.setVec2("u_space",h,o.sky.starIntensity),h>.001){Ve(r,"u_space_color",o.sky.spaceColor),Ve(r,"u_atmo_color",o.sky.atmosphereColor);let u=t.globeDisc();r.setVec4("u_globe_disc",u.dir[0],u.dir[1],u.dir[2],u.angle);let[f,d,p,b]=t.localRayCorners();r.setVec3("u_ray_tl",f[0],f[1],f[2]),r.setVec3("u_ray_tr",d[0],d[1],d[2]),r.setVec3("u_ray_bl",p[0],p[1],p[2]),r.setVec3("u_ray_br",b[0],b[1],b[2]);}e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.quad.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0),e.bindVAO(null);}applyGlobeUniforms(e,t,o){if(!t.globeActive){e.setVec4("u_globe",0,0,0,0);return}let r=t.globeBasis,i=t.worldSize;e.setVec4("u_globe",1,t.globeFlatMix,t.globeRadiusPx,i),e.setVec2("u_globe_center",t.centerPointPx.x/i,t.centerPointPx.y/i);let a=t.globeCamera();e.setVec4("u_globe_cam",a.dir[0],a.dir[1],a.dir[2],a.horizonCos);let l=Gt(o.light.keyAzimuth,o.light.keyAltitude);e.setVec3("u_globe_sun",-l[0],-l[1],-l[2]),e.setVec2("u_globe_light",.16,.14),e.setMat3("u_globe_basis",[r.east[0],r.south[0],r.up[0],r.east[1],r.south[1],r.up[1],r.east[2],r.south[2],r.up[2]]);}applyTileMatrix(e,t,o,r){if(t.globeActive){let i=o.bounds();e.setVec3("u_tile_merc",i.minX,i.minY,(i.maxX-i.minX)/r),e.setMat4("u_matrix",t.localMatrix());return}e.setMat4("u_matrix",t.tileMatrix(o,r));}applyFogUniforms(e,t,o){let r=this.fog??kt(t,o);if(r.intensity<=0){e.setVec3("u_fog_range",0,1,0),e.setVec2("u_fog_vertical",0,0),this.applyAtmosphere(e,t,o);return}Ve(e,"u_fog_color",o.sky.horizonColor),e.setVec3("u_fog_range",r.near,r.far,r.intensity);let[i,a]=o.sky.fogVerticalRange;e.setVec2("u_fog_vertical",i,a),this.applyAtmosphere(e,t,o);}drawsTile(e,t,o,r){let i=this.fog;if(!i)return true;let a=e.distanceToTile(r);return a>i.cutoff?false:t.layerVisibleAt(o,e.detailZoom(a))}earthDepthLevel(e,t){let o=0;for(let i of e.layers)i.type==="surface"?o=Math.min(o,(i.elevation-(i.bevelDrop??0))*this.reliefScale):i.type==="line"&&(o=Math.min(o,V(i.paint.elevation,t.zoom,0)*this.reliefScale));let r=Math.max(Ph/Math.max(t.pixelsPerMeter,1e-9),Rh);return o-r}clipToTile(e,t){let o=this.stencilIds.get(t.dataKey);e.setStencilTest(o!==void 0),o!==void 0&&e.gl.stencilFunc(e.gl.EQUAL,o,ni);}drawTileStencil(e,t,o){if(this.stencilIds.clear(),t.globeActive){e.gl.stencilMask(255),e.clear(null,false,true),e.setStencilTest(false);return}let r=o.get(Y);if(!r||!this.fill||!this.quad)return;let i=r.visibleTiles;if(!i.length||i.length>ni)return;let a=e.gl;a.stencilMask(255),e.clear(null,false,true),e.setStencilTest(true),a.stencilOp(a.KEEP,a.KEEP,a.REPLACE),e.setColorMask(false),e.setDepthTest(false),e.setDepthMask(false),e.setCull("none");let l=this.fill;l.use(),l.setVec4("u_globe",0,0,0,0),l.setInt("u_material",0),l.setVec2("u_world_origin",0,0),l.setVec4("u_color",0,0,0,1),l.setFloat("u_elevation",0),this.quad.vao.bind();let s=0;for(let c of i)s++,this.stencilIds.set(c.dataKey,s),a.stencilFunc(a.ALWAYS,s,ni),l.setMat4("u_matrix",t.tileMatrix(c,1)),a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0);e.bindVAO(null),e.setColorMask(true),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),e.setStencilTest(false);}drawEarthDepth(e,t,o,r){if(!this.fill||!this.quad||t.globeActive)return;let i=o.get(Y);if(!i)return;let a=this.fill;a.use(),this.applyFogUniforms(a,t,r),a.setVec4("u_globe",0,0,0,0),a.setInt("u_material",0),a.setVec2("u_world_origin",0,0),a.setVec4("u_color",0,0,0,1),a.setFloat("u_elevation",0);let l=this.earthDepthLevel(r,t);e.gl.colorMask(false,false,false,false),e.setDepthTest(true),e.setDepthFunc("lequal"),e.setDepthMask(true),e.setCull("none"),e.gl.enable(e.gl.POLYGON_OFFSET_FILL),e.gl.polygonOffset(1,8),this.quad.vao.bind();let s=new Float32Array(16);for(let c of i.visibleTiles){let h=t.tileMatrix(c,1);s.set(h);for(let u=0;u<4;u++)s[12+u]+=l*h[8+u];a.setMat4("u_matrix",s),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0);}e.bindVAO(null),e.gl.disable(e.gl.POLYGON_OFFSET_FILL),e.gl.colorMask(true,true,true,true);}drawGroundShadow(e,t,o,r){if(!this.shadowActive||!this.groundShadow||!this.quad)return;let i=o.get(Y);if(!i)return;let a=this.groundShadow;a.use(),this.applyShadowUniforms(a),this.applyFogUniforms(a,t,r);let l=r.light,[,,s]=Gt(l.keyAzimuth,l.keyAltitude),c=Math.max(-s,0),h=he(l.ambientColor),u=he(l.keyColor),f=[0,0,0];for(let d=0;d<3;d++){let p=h[d]*l.ambientIntensity,b=u[d]*l.keyIntensity*c;f[d]=p>0?p/(p+b):1;}a.setVec3("u_shadow_ground",f[0],f[1],f[2]),a.setFloat("u_ground_ndotl",c),e.setBlend("multiply"),e.setDepthTest(false),e.setDepthMask(false),e.setCull("none"),this.quad.vao.bind();for(let d of i.visibleTiles)a.setMat4("u_shadow_matrix",t.shadowTileMatrix(d,1)),a.setMat4("u_matrix",t.tileMatrix(d,1)),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0);e.setBlend("premultiplied");}applyShadowUniforms(e){if(e.setInt("u_shadow_map",ri),!this.shadowActive){e.setVec4("u_shadow_params",0,0,0,0);return}let t=this.shadowTarget?.size??1,r=Math.max(this.shadows.bias,1.5*this.shadowTexelMeters)*(this.shadowDepthPerMeter||1);e.setVec4("u_shadow_params",this.shadows.strength,1/t,r,1),e.setFloat("u_shadow_normal_offset",1.5*2/t);let i=he(this.shadows.color);e.setVec3("u_shadow_color",i[0],i[1],i[2]);}get shadowsActive(){return this.shadowActive}drawOverlay(e,t,o,r,i,a){let l=()=>{e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");};l();for(let s of o.layers){if(s.type==="raster"||s.type==="symbol"||s.type==="fill-extrusion"||!s.overlay||(s.overlay===true?"volume":s.overlay)!==a||!o.layerVisibleAt(s,i))continue;let c=r(s);if(c){if(s.type==="surface"){this.flattened(c,o,s)?this.drawFill(e,t,c,o,s,i):this.drawSurface(e,t,c,o,s,i),l();continue}s.type==="fill"?this.drawFill(e,t,c,o,s,i):this.drawLine(e,t,c,o,s,i);}}}applyTileScale(e,t,o){let r=zr(t.z)/this.patternScale;e.setFloat("u_meters_per_unit",r/o);let[i,a]=Wi(t.z,t.x,t.y);e.setVec2("u_world_origin",i/this.patternScale,a/this.patternScale);let l=this.cameraMeters;e.setVec3("u_camera_local",l[0]-t.x*r,l[1]-t.y*r,l[2]);}applyMaterial(e,t,o){let r=t.paint&&"material"in t.paint?t.paint.material:void 0,i=this.detailScale<=0?0:zh[r??"flat"]??0;if(e.setInt("u_material",i),i===0)return;let a=t.paint,l=V(a.materialStrength,o,1)*this.detailScale,s=V(a.materialScale,o,Vh[i]),c=V(a.materialSpeed,o,i===1?1:0);e.setVec4("u_material_params",l,s,c,this.materialTime),c>0&&l>.004&&(this.materialAnimating=true);}drawFill(e,t,o,r,i,a){let l=this.fill,s=r.colorAt(i,a),c=V(i.paint?.opacity,a,1);if(c<=.001)return;l.use(),this.applyFogUniforms(l,t,r),this.applyGlobeUniforms(l,t,r),this.applyLight(l,r),this.applyMaterial(l,i,a),l.setVec4v("u_color",Me([s[0],s[1],s[2],s[3]*c]));let h=r.bucketKeyFor(i);if(h!==null){for(let u of o.visibleTiles){if(!this.drawsTile(t,r,i,u))continue;let f=o.getTile(u),d=f&&this.bucketFor(e,f,h,ai,this.fillLocs,"fill");d&&(this.clipToTile(e,u),this.shadowActive&&l.setMat4("u_shadow_matrix",t.shadowTileMatrix(u,d.extent)),this.applyTileScale(l,u,d.extent),this.applyTileMatrix(l,t,u,d.extent),d.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,d.indexCount,d.indexType,0));}e.setStencilTest(false);}}drawLine(e,t,o,r,i,a,l=0,s){let c=this.line,h=r.colorAt(i,a),u=V(i.paint.opacity,a,1)*(l||1),f=V(i.paint.width,a,1);if(u<=.001||f<=.01)return;let d=e.gl.drawingBufferWidth,p=e.gl.drawingBufferHeight,b=t.width>0?d/t.width:1,m=f/2*b;c.use(),this.applyFogUniforms(c,t,r),this.applyGlobeUniforms(c,t,r),this.applyLight(c,r),this.applyMaterial(c,i,a),c.setVec4v("u_color",Me([h[0],h[1],h[2],h[3]*u])),c.setFloat("u_center_w",t.cameraToCenterDistance);let g=V(i.paint.offset,a,0)*b,y=Math.max(V(i.paint.blur,a,0),0)*b;c.setFloat("u_elevation",V(i.paint.elevation,a,0)*this.reliefScale),c.setFloat("u_relief",this.reliefScale),c.setVec2("u_viewport",d,p);let A=i.paint.dashArray,B=i.paint.arrow===true,x=i.paint.arrowStyle,w=B&&(x==="head"||x==="headOnly"),_=B&&x==="dash";if(c.setInt("u_pattern",_?5:A?1:x==="headOnly"&&B?4:w?3:B?2:0),A){let[v,E]=A;c.setVec2("u_dash",v*b,(v+E)*b);}if(B){let v=He(i.paint.arrowColor,a,[1,1,1,1]);c.setVec4v("u_arrow_color",Me(v));let E=V(i.paint.arrowPeriod,a,46)*b,D=V(i.paint.arrowSize,a,5)*b;if(_){let F=V(i.paint.arrowGap,a,24)*b,H=Math.max(E-F,1),S=Math.min(D,H),L=V(i.paint.arrowShaft,a,2)*b,M=V(i.paint.arrowHead,a,4)*b,T=V(i.paint.arrowOutline,a,0)*b;c.setVec4("u_arrow",L,S,M,H),c.setVec2("u_dash",T,E);}else w?c.setVec4("u_arrow",E,D,m,0):c.setVec4("u_arrow",E,Math.max(D*.4,1),Math.min(D,m*.72),0);}let C=r.bucketKeyFor(i);if(C!==null)for(let v of o.visibleTiles){if(!this.drawsTile(t,r,i,v))continue;let E=o.getTile(v);if(!E)continue;let D=i.network?s!==void 0?[Je(i.id,s)]:(E.data?.levels??[]).map(F=>Je(i.id,F)):[C];for(let F of D){let H=this.bucketFor(e,E,F,Es,this.lineLocs,"line");if(!H)continue;let S=v.bounds(),L=(S.maxX-S.minX)*t.worldSize/H.extent*b;c.setFloat("u_tile_to_px",L);let M=L>1e-6?1/L:1;c.setFloat("u_half_width",m*M),c.setFloat("u_blur",y*M),c.setFloat("u_meters_to_units",t.pixelsPerMeter*M),c.setFloat("u_width_from_data",i.paint.widthFromData===true?1:0),c.setFloat("u_width_extra",V(i.paint.widthExtra,a,0)*M),c.setFloat("u_offset",g*M),c.setFloat("u_tile_per_px",M),this.applyTileScale(c,v,H.extent),this.shadowActive&&c.setMat4("u_shadow_matrix",t.shadowTileMatrix(v,H.extent)),this.applyTileMatrix(c,t,v,H.extent),H.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,H.indexCount,H.indexType,0);}}}drawNetwork(e,t,o,r,i,a,l){let s=o.layers.filter(h=>h.type==="line"&&h.network===i&&l(h));if(!s.length)return;let c=new Set;for(let h of s){let u=r(h);if(u)for(let f of u.visibleTiles){let d=u.getTile(f);for(let p of d?.data?.levels??[])c.add(p);}}if(c.size)for(let h of [...c].sort((u,f)=>u-f))for(let u of s){let f=r(u);f&&this.drawLine(e,t,f,o,u,a,0,h);}}drawHighlight(e,t,o,r,i,a){let l=this.highlight;if(!l||!this.building||l.layerId!==i.id)return;let s=`${i.id}/${l.featureId}`;this.highlightKey!==s&&(this.disposeHighlight(),this.highlightKey=s);let c=he(l.color)??[.31,.79,.5,1],h=this.building;h.use(),this.applyShadowUniforms(h),this.applyFogUniforms(h,t,r),this.applyLight(h,r),h.setVec4v("u_wall_color",[c[0],c[1],c[2],1]),h.setVec4v("u_roof_color",[c[0],c[1],c[2],1]),h.setFloat("u_opacity",l.opacity),h.setFloat("u_ao_strength",V(i.paint.aoStrength,a,.4)),h.setFloat("u_tint_variation",0),h.setFloat("u_facade_detail",0),h.setFloat("u_window_glow",0),h.setFloat("u_roof_variation",0),h.setFloat("u_height_scale",V(i.paint.heightScale,a,1)),e.setDepthFunc("lequal"),e.setDepthMask(false),e.setBlend("alpha");for(let u of o.visibleTiles){let f=o.getTile(u);if(!f)continue;let d=f.data?.buckets?.[i.id];if(!d)continue;let p=u.dataKey,b=this.highlightGpu.get(p);if(b===void 0){let m=Ar(f,i.id,l.featureId);if(m){let g=new ve(e,new Uint8Array(m.vertices),wr),y=new ye(e,m.indices);b={vao:new pe(e,[{buffer:g,locations:this.buildingLocs}],y),vbo:g,ibo:y,count:m.indices.length};}else b=null;this.highlightGpu.set(p,b);}b&&(this.applyTileScale(h,u,d.extent),this.shadowActive&&h.setMat4("u_shadow_matrix",t.shadowTileMatrix(u,d.extent)),h.setMat4("u_matrix",t.tileMatrix(u,d.extent)),b.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,b.count,e.gl.UNSIGNED_INT,0));}e.setBlend("none"),e.setDepthMask(true);}refreshHighlight(){this.disposeHighlight();}disposeHighlight(){for(let e of this.highlightGpu.values())e&&(e.vao.destroy(),e.vbo.destroy(),e.ibo.destroy());this.highlightGpu.clear(),this.highlightTris.clear(),this.highlightKey="";}syncHighlightFootprint(e,t){let o=this.highlight;if(!o){this.highlightTris.size&&this.highlightTris.clear();return}let r=`${o.layerId}/${o.featureId}`;this.footprintKey!==r&&(this.highlightTris.clear(),this.footprintKey=r);let i=t.layers.find(s=>s.id===o.layerId),a=e.get(i?.source??Y);if(!a)return;let l=new oe;for(let s of a.visibleTiles){if(l.add(s.dataKey),this.highlightTris.has(s.dataKey))continue;let c=a.getTile(s),h=c?.data?.buckets?.[o.layerId];if(!c||!h)continue;let u=Ar(c,o.layerId,o.featureId);u&&this.highlightTris.set(s.dataKey,Nn(u,h.extent,s));}for(let s of [...this.highlightTris.keys()])l.has(s)||this.highlightTris.delete(s);}drawFillHighlight(e,t,o,r){let i=this.highlightFill,a=this.fill;if(!i||!a)return;let l=r.layers.find(f=>f.id===i.layerId),s=l?o.get(l.source??Y):void 0;if(!l||!s)return;let c=i.bucketKey,h=he(i.color)??[.31,.79,.5,1];a.use(),this.applyFogUniforms(a,t,r),a.setVec4("u_globe",0,0,0,0),a.setInt("u_material",0),a.setFloat("u_elevation",0),a.setVec2("u_world_origin",0,0),a.setVec4v("u_color",Me([h[0],h[1],h[2],i.opacity])),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");let u=e.gl;e.setStencilTest(true),u.stencilFunc(u.NOTEQUAL,ii,ii),u.stencilOp(u.KEEP,u.KEEP,u.REPLACE),u.stencilMask(ii);for(let f of s.visibleTiles){let d=s.getTile(f),p=d?.data?.buckets?.[c];if(!d||!p||p.kind!=="fill"||!p.featureIds)continue;let b=this.fillHighlightFor(e,p,f,i.featureId,c);b&&(a.setMat4("u_matrix",t.tileMatrix(f,p.extent)),b.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,b.count,e.gl.UNSIGNED_INT,0));}e.setStencilTest(false),u.stencilOp(u.KEEP,u.KEEP,u.KEEP),u.stencilMask(255),e.bindVAO(null);}fillHighlightFor(e,t,o,r,i){let a=`${i}/${r}/${o.dataKey}`;this.fillHighlightKey!==`${i}/${r}`&&(this.fillHighlightGpu.forEach(f=>{f?.vao.destroy(),f?.ibo.destroy(),f?.vbo.destroy();}),this.fillHighlightGpu.clear(),this.fillHighlightKey=`${i}/${r}`);let l=this.fillHighlightGpu.get(a);if(l!==void 0)return l;let s=new Uint32Array(t.indices),c=new Float64Array(t.featureIds),h=[];for(let f=0;f*3<s.length;f++)c[f]===r&&h.push(s[f*3],s[f*3+1],s[f*3+2]);let u=null;if(h.length){let f=new ve(e,new Uint8Array(t.vertices),ai),d=new ye(e,new Uint32Array(h));u={vao:new pe(e,[{buffer:f,locations:this.fillLocs}],d),vbo:f,ibo:d,count:h.length};}return this.fillHighlightGpu.set(a,u),u}highlightFootprint(){return this.highlight&&this.highlightTris.size?[...this.highlightTris.values()]:this.indoorMask.footprint()}drawSurface(e,t,o,r,i,a){let l=this.surface,s=r.colorAt(i,a,[.7,.8,.7,1]),c=V(i.paint.opacity,a,1);if(c<=.001)return;l.use(),this.applyShadowUniforms(l),this.applyFogUniforms(l,t,r),this.applyGlobeUniforms(l,t,r),this.applyLight(l,r),this.applyMaterial(l,i,a),l.setVec4v("u_color",s),l.setFloat("u_opacity",c),l.setFloat("u_side_shade",V(i.paint.sideShade,a,.12));let h=i.elevation<(i.base??0),u=i.paint.sideColor?He(i.paint.sideColor,a,s):s;l.setVec3("u_side_color",u[0],u[1],u[2]),l.setFloat("u_side_light",V(i.paint.sideLight,a,h?1:0)),l.setFloat("u_relief",this.reliefScale);let f=r.bucketKeyFor(i);if(f===null)return;let d=c>=1&&!i.overlay;e.setDepthMask(d),e.setBlend(d?"none":"premultiplied"),e.setCull("none");let p=[];for(let g of o.visibleTiles){if(!this.drawsTile(t,r,i,g))continue;let y=o.getTile(g),A=y&&this.bucketFor(e,y,f,Ms,this.surfaceLocs,"surface");A&&p.push({id:g,bucket:A});}let b=(g,y)=>{this.clipToTile(e,g),this.applyTileScale(l,g,y.extent),this.shadowActive&&l.setMat4("u_shadow_matrix",t.shadowTileMatrix(g,y.extent)),this.applyTileMatrix(l,t,g,y.extent),y.vao.bind();},m=p.filter(({bucket:g})=>g.capIndexOffset<g.indexCount);if(m.length){e.setColorMask(false),e.setDepthMask(true);for(let{id:g,bucket:y}of m){b(g,y);let A=y.indexType===e.gl.UNSIGNED_INT?4:2;e.gl.drawElements(e.gl.TRIANGLES,y.indexCount-y.capIndexOffset,y.indexType,y.capIndexOffset*A);}e.setColorMask(true),e.setDepthMask(d);}for(let{id:g,bucket:y}of p)b(g,y),e.gl.drawElements(e.gl.TRIANGLES,y.capIndexOffset,y.indexType,0);e.setCull("back"),e.setDepthMask(true),e.setBlend("none");}drawBuildings(e,t,o,r,i,a,l){let s=this.building,c=r.colorAt(i,a,[.86,.84,.8,1]),h=i.paint.roofColor?r.colorAt({...i,paint:{...i.paint,color:i.paint.roofColor}},a,c):c,u=V(i.paint.opacity,a,1);if(u<=.001)return false;s.use(),this.applyShadowUniforms(s),this.applyFogUniforms(s,t,r),s.setVec4v("u_wall_color",c),s.setVec4v("u_roof_color",h),s.setFloat("u_opacity",u),s.setFloat("u_ao_strength",V(i.paint.aoStrength,a,.4)),s.setFloat("u_tint_variation",V(i.paint.tintVariation,a,.07));let f=(B,x)=>i.paint[B]?r.colorAt({...i,paint:{...i.paint,color:i.paint[B]}},a,x):x,d=f("windowColor",[.62,.71,.8,1]),p=f("windowFrameColor",[c[0]*1.1,c[1]*1.1,c[2]*1.1,1]);s.setVec3("u_window_color",d[0],d[1],d[2]),s.setVec3("u_window_frame",p[0],p[1],p[2]),s.setFloat("u_facade_detail",V(i.paint.facadeDetail,a,1)*this.detailScale),s.setFloat("u_window_glow",V(i.paint.windowGlow,a,0)),s.setFloat("u_floor_height",V(i.paint.floorHeight,a,3.2)),s.setFloat("u_window_variation",V(i.paint.windowVariation,a,1)),s.setFloat("u_seam_strength",V(i.paint.seamStrength,a,1)),s.setFloat("u_window_recess",V(i.paint.windowRecess,a,.18)),s.setFloat("u_window_recess_shade",V(i.paint.windowRecessShade,a,.16)),s.setFloat("u_plinth_height",V(i.paint.plinthHeight,a,4)),s.setFloat("u_plinth_shade",V(i.paint.plinthShade,a,.14)),s.setFloat("u_roof_variation",V(i.paint.roofVariation,a,.3)),this.applyLight(s,r);let b=u>=1;e.setDepthMask(b),e.setBlend(b?"none":"premultiplied");let m=V(i.paint.heightScale,a,1),g=false,y=r.bucketKeyFor(i);if(y===null)return g;let A=(i.source??Y)===Y;A&&this.indoorMask.prepare(o,y);for(let B of o.visibleTiles){if(!this.drawsTile(t,r,i,B))continue;let x=o.getTile(B),w=x&&this.bucketFor(e,x,y,wr,this.buildingLocs,"fill-extrusion");if(!w)continue;let _=this.growScale(w,l,!o.warm);_<1&&(g=true),s.setFloat("u_height_scale",_*m),this.applyTileScale(s,B,w.extent),this.shadowActive&&s.setMat4("u_shadow_matrix",t.shadowTileMatrix(B,w.extent)),s.setMat4("u_matrix",t.tileMatrix(B,w.extent));let v=this.cutHidden(e,x,y,B.dataKey,w.buffer,this.hiddenFor(y,A))??(x&&A?this.indoorMask.indicesFor(e,x,y,B,w.buffer,this.buildingLocs):null);v?(v.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,v.count,e.gl.UNSIGNED_INT,0)):(w.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,w.indexCount,w.indexType,0));}return g}growScale(e,t,o=true){if(e.firstDrawTime===0&&(e.firstDrawTime=t),!o||this.growDurationMs<=0)return 1;let r=(t-e.firstDrawTime)/this.growDurationMs;return r<1?Kh(Math.max(r,0)):1}applyLight(e,t){let o=t.light;Ve(e,"u_ambient_color",o.ambientColor),e.setFloat("u_ambient_intensity",o.ambientIntensity);let[r,i,a]=Gt(o.keyAzimuth,o.keyAltitude);e.setVec3("u_key_dir",r,i,a),Ve(e,"u_key_color",o.keyColor),e.setFloat("u_key_intensity",o.keyIntensity);let[l,s,c]=Gt(o.fillAzimuth,o.fillAltitude);e.setVec3("u_fill_dir",l,s,c),Ve(e,"u_fill_color",o.fillColor),e.setFloat("u_fill_intensity",o.fillIntensity);}flattened(e,t,o){let r=t.bucketKeyFor(o);if(r===null)return false;for(let i of e.visibleTiles){let a=e.getTile(i)?.data?.buckets?.[r];if(a)return a.kind==="fill"}return false}bucketFor(e,t,o,r,i,a){let l=t.buckets.get(o);if(l)return l;let s=t.data?.buckets?.[o];if(!s||s.kind==="symbol"||s.kind==="placement")return null;if(s.kind!==a)return kh(`\u0441\u043B\u043E\u0439 ${o}: \u0432 \u0442\u0430\u0439\u043B\u0435 \u043C\u0435\u0448 \xAB${s.kind}\xBB, \u0430 \u0440\u0438\u0441\u0443\u044E\u0442 \u043A\u0430\u043A \xAB${a}\xBB \u2014 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D`),null;let c=new ve(e,new Uint8Array(s.vertices),r),h=new ye(e,new Uint32Array(s.indices)),u=new pe(e,[{buffer:c,locations:i}],h),f=new li(u,c,h,h.count,h.type,s.extent,s.capIndexOffset??h.count);return t.buckets.set(o,f),f}destroy(e){this.disposeHighlight(),this.fill?.destroy(),this.surface?.destroy(),this.line?.destroy(),this.objectLine?.destroy(),this.building?.destroy(),this.symbols?.destroy(e),this.models.destroy(e.gl),this.shadowTarget?.destroy(),this.shadowTarget=null,this.shadowPlaceholder&&e.gl.deleteTexture(this.shadowPlaceholder),this.shadowPlaceholder=null,this.quad&&(this.quad.vao.destroy(),this.quad.vbo.destroy(),this.quad.ibo.destroy(),this.quad=null),this.globeMesh&&(this.globeMesh.vao.destroy(),this.globeMesh.vbo.destroy(),this.globeMesh.ibo.destroy(),this.globeMesh=null),this.fill=this.line=this.building=null,this.objectLine=null;}},Er=new z;function Wh(n,e){let r=new Float32Array(66306),i=0;for(let f=0;f<=128;f++){let d=(f/128-.5)*Math.PI;for(let p=0;p<=256;p++)r[i++]=p/256*2*Math.PI-Math.PI,r[i++]=d;}let a=new Uint16Array(256*128*6),l=0;for(let f=0;f<128;f++)for(let d=0;d<256;d++){let p=f*257+d,b=p+256+1;a[l++]=p,a[l++]=p+1,a[l++]=b,a[l++]=p+1,a[l++]=b+1,a[l++]=b;}let s={stride:8,attribs:[{name:"a_lnglat",size:2,type:xo,offset:0}]},c=new z([["a_lnglat",e.attribLocation("a_lnglat")]]),h=new ve(n,r,s),u=new ye(n,a);return {vao:new pe(n,[{buffer:h,locations:c}],u),vbo:h,ibo:u,count:a.length}}function Nh(n,e){if(e.highColor){Ve(n,"u_high_color",e.highColor);return}let t=Er.get(e.skyColor);t||(t=he(e.skyColor),Er.set(e.skyColor,t)),n.setVec3("u_high_color",t[0]*.6,t[1]*.74,Math.min(1,t[2]*.99+.02));}function Ve(n,e,t){let o=Er.get(t);o||(o=he(t),Er.set(t,o)),n.setVec3(e,o[0],o[1],o[2]);}function Gt(n,e){let t=n*Math.PI/180,o=e*Math.PI/180,r=Math.cos(o);return [-Math.sin(t)*r,Math.cos(t)*r,-Math.sin(o)]}function Kh(n){let o=n-1;return 1+2.20158*o*o*o+1.20158*o*o}var Mr=1,_o=class{constructor(e=1024){this.entries=new z;this.shelfY=0;this.shelfX=0;this.shelfHeight=0;this.texture=null;this.dirty=true;this.full=false;this.size=e,this.data=new Uint8Array(e*e);}get(e){return this.entries.get(e)}add(e,t,o,r){let i=this.entries.get(e);if(i)return i;if(this.full||o>this.size)return null;if(this.shelfX+o+Mr>this.size&&(this.shelfY+=this.shelfHeight+Mr,this.shelfX=0,this.shelfHeight=0),this.shelfY+r+Mr>this.size)return this.full||console.warn("[osmgl] \u0430\u0442\u043B\u0430\u0441 SDF \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D, \u043D\u043E\u0432\u044B\u0435 \u0441\u0438\u043C\u0432\u043E\u043B\u044B \u043D\u0435 \u0434\u043E\u0431\u0430\u0432\u043B\u044F\u044E\u0442\u0441\u044F"),this.full=true,null;let a={x:this.shelfX,y:this.shelfY,width:o,height:r};for(let l=0;l<r;l++){let s=l*o,c=(a.y+l)*this.size+a.x;this.data.set(t.subarray(s,s+o),c);}return this.shelfX+=o+Mr,r>this.shelfHeight&&(this.shelfHeight=r),this.entries.set(e,a),this.dirty=true,a}bind(e,t){let o=e.gl;this.texture?e.bindTexture(t,this.texture):(this.texture=o.createTexture(),e.bindTexture(t,this.texture),o.texStorage2D(o.TEXTURE_2D,1,o.R8,this.size,this.size),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.dirty=true),this.dirty&&(o.pixelStorei(o.UNPACK_ALIGNMENT,1),o.texSubImage2D(o.TEXTURE_2D,0,0,0,this.size,this.size,o.RED,o.UNSIGNED_BYTE,this.data),this.dirty=false);}destroy(e){this.texture&&e.gl.deleteTexture(this.texture),this.texture=null,this.entries.clear(),this.data=new Uint8Array(0);}};var si=.75,Mo=8,Ce=3,qe=24,Ot=256,Ds=255,Eo=class{constructor(e,t="Noto Sans Regular"){this.urlTemplate=e;this.fontstack=t;this.glyphs=new z;this.loaded=new oe;this.inflight=new z;}get(e){return this.glyphs.get(e)}hasRange(e){return this.loaded.has(Math.floor(e/Ot))}needsLoad(e){for(let t of e){let o=t.codePointAt(0);if(o===void 0)continue;let r=Math.floor(o/Ot);if(r<=Ds&&!this.loaded.has(r))return true}return false}async ensure(e){let t=new oe;for(let o of e){let r=o.codePointAt(0);if(r===void 0)continue;let i=Math.floor(r/Ot);i>Ds||this.loaded.has(i)||t.add(i);}return t.size?(await Promise.all([...t].map(o=>this.loadRange(o))),true):false}loadRange(e){let t=this.inflight.get(e);if(t)return t;let o=this.urlTemplate.replace("{fontstack}",encodeURIComponent(this.fontstack)).replace("{range}",`${e*Ot}-${e*Ot+Ot-1}`),r=fetch(o,{credentials:"same-origin"}).then(i=>{if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.arrayBuffer()}).then(i=>{for(let a of Ss(i))this.glyphs.set(a.id,a);this.loaded.add(e);}).catch(i=>{this.loaded.add(e),console.warn(`[osmgl] \u0433\u043B\u0438\u0444\u044B ${o} \u043D\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043B\u0438\u0441\u044C:`,i instanceof Error?i.message:i);}).finally(()=>{this.inflight.delete(e);});return this.inflight.set(e,r),r}};function Ss(n){let e=new dt(n instanceof Uint8Array?n:new Uint8Array(n)),t=[];return e.readFields((o,r,i)=>{if(o!==1||!i)return;let a=i.readVarint()+i.pos;i.readFields((l,s,c)=>{if(l!==3||!c)return;let h=c.readVarint()+c.pos,u={id:0,bitmap:null,width:0,height:0,left:0,top:0,advance:0};c.readFields((f,d,p)=>{p&&(f===1?u.id=p.readVarint():f===2?u.bitmap=p.readBytes():f===3?u.width=p.readVarint():f===4?u.height=p.readVarint():f===5?u.left=p.readSVarint():f===6?u.top=p.readSVarint():f===7&&(u.advance=p.readVarint()));},null,h),t.push(u);},null,a);},null),t}var Uh=.25,zt=1e20;function ci(n,e,t){let o=e+Ce*2,r=t+Ce*2,i=o*r,a=new Float64Array(i),l=new Float64Array(i);a.fill(zt),l.fill(0);for(let c=0;c<t;c++)for(let h=0;h<e;h++){let u=n[c*e+h]/255,f=(c+Ce)*o+(h+Ce);if(u>=1)a[f]=0,l[f]=zt;else if(u>0){let d=.5-u;a[f]=d>0?d*d:0,l[f]=d<0?d*d:0;}else a[f]=zt,l[f]=0;}Is(a,o,r),Is(l,o,r);let s=new Uint8Array(i);for(let c=0;c<i;c++){let h=Math.sqrt(a[c])-Math.sqrt(l[c]);s[c]=Jh(Math.round(255-255*(h/Mo+Uh)));}return {data:s,width:o,height:r}}function Is(n,e,t){let o=Math.max(e,t),r=new Float64Array(o),i=new Float64Array(o),a=new Int32Array(o),l=new Float64Array(o+1);for(let s=0;s<e;s++){for(let c=0;c<t;c++)r[c]=n[c*e+s];Ls(r,i,a,l,t);for(let c=0;c<t;c++)n[c*e+s]=i[c];}for(let s=0;s<t;s++){for(let c=0;c<e;c++)r[c]=n[s*e+c];Ls(r,i,a,l,e);for(let c=0;c<e;c++)n[s*e+c]=i[c];}}function Ls(n,e,t,o,r){t[0]=0,o[0]=-zt,o[1]=zt;for(let i=1,a=0;i<r;i++){let l=0;do{let s=t[a];l=(n[i]-n[s]+i*i-s*s)/(i-s)/2;}while(l<=o[a]&&--a>-1);a++,t[a]=i,o[a]=l,o[a+1]=zt;}for(let i=0,a=0;i<r;i++){for(;o[a+1]<i;)a++;let l=t[a];e[i]=(i-l)*(i-l)+n[l];}}var Jh=n=>n<0?0:n>255?255:n;var Ts=48,Fo=class{constructor(e={}){this.defs=e;this.sdfs=new z;this.pending=new oe;this.failed=new oe;}setIcons(e){this.defs=e,this.sdfs.clear(),this.failed.clear();}has(e){return this.sdfs.has(e)}get(e){return this.sdfs.get(e)}isDefined(e){return this.defs[e]!==void 0}async ensure(e){if(this.sdfs.has(e)||this.pending.has(e)||this.failed.has(e))return false;let t=this.defs[e];if(t===void 0)return this.failed.add(e),false;this.pending.add(e);try{let o=typeof t=="string"?t:t.svg,r=/viewBox="0 0 ([\d.]+) ([\d.]+)"/.exec(o),i=r?Number(r[1])/Number(r[2]):1,a=Math.max(8,Math.round(Ts*(i>1?i:1))),l=Math.max(8,Math.round(Ts/(i<1?i:1))),s=await Xh(o,a,l);return this.sdfs.set(e,ci(s,a,l)),!0}catch(o){return this.failed.add(e),console.warn(`[osmgl] \u0438\u043A\u043E\u043D\u043A\u0430 \xAB${e}\xBB \u043D\u0435 \u0440\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043E\u0432\u0430\u043B\u0430\u0441\u044C:`,o instanceof Error?o.message:o),false}finally{this.pending.delete(e);}}};async function Xh(n,e,t){let o=n.includes("width=")?n:n.replace("<svg",`<svg width="${e}" height="${t}"`),r=new Blob([o],{type:"image/svg+xml;charset=utf-8"}),i=URL.createObjectURL(r);try{let a=new Image;a.width=e,a.height=t,await new Promise((u,f)=>{a.onload=()=>u(),a.onerror=()=>f(new Error("\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0434\u0435\u043A\u043E\u0434\u0438\u0440\u043E\u0432\u0430\u0442\u044C SVG")),a.src=i;});let l=document.createElement("canvas");l.width=e,l.height=t;let s=l.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("\u043D\u0435\u0442 2D-\u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430");s.clearRect(0,0,e,t),s.drawImage(a,0,0,e,t);let c=s.getImageData(0,0,e,t).data,h=new Uint8ClampedArray(e*t);for(let u=0;u<h.length;u++)h[u]=c[u*4+3];return h}finally{URL.revokeObjectURL(i);}}var At={dot:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="5"/></svg>',entrance:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2.5 19.5 10l-2.1 2.1-3.9-3.9V21h-3V8.2l-3.9 3.9L4.5 10 12 2.5z"/></svg>',door:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 2h11a3 3 0 0 1 3 3v17H5V2zm9 9.2a1.2 1.2 0 1 0 0 2.4 1.2 1.2 0 0 0 0-2.4z"/></svg>',elevator:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 3h14v18H5V3zm7 2.2L9.2 9h5.6L12 5.2zM9.2 15h5.6L12 18.8 9.2 15z"/></svg>',"frame-circle":'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="11"/></svg>',cafe:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h12v6a6 6 0 0 1-12 0V6zm12 1h2.5a2.5 2.5 0 0 1 0 5H16V7zM3 20h14v2H3z"/></svg>',restaurant:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 2h2v8a2 2 0 0 1-4 0V2h2zM5 2v6h2V2zm7 0h2v20h-2V13a4 4 0 0 1 0-8V2zM6 12h2v10H6z"/></svg>',shop:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 8h16l-1.5 12h-13L4 8zm4-3a4 4 0 0 1 8 0v2h-2V5a2 2 0 0 0-4 0v2H8V5z"/></svg>',grocery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 4h3l3 11h9l2-8H8m1 15a2 2 0 1 0 4 0 2 2 0 0 0-4 0zm8 0a2 2 0 1 0 4 0 2 2 0 0 0-4 0z"/></svg>',fuel:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 3h9v18H4V3zm2 2v5h5V5H6zm10 2 3 3v8a2 2 0 0 1-4 0V9h1V7z"/></svg>',parking:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 3h6a5 5 0 0 1 0 10H9v8H6V3zm3 3v4h3a2 2 0 0 0 0-4H9z"/></svg>',hospital:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 3h4v7h7v4h-7v7h-4v-7H3v-4h7V3z"/></svg>',pharmacy:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11 4h2v5h5v2h-5v5h-2v-5H6V9h5V4zM5 18h14v3H5z"/></svg>',school:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 3 2 8l10 5 10-5-10-5zM5 12v5c0 2 3 4 7 4s7-2 7-4v-5l-7 3.5L5 12z"/></svg>',bank:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2 2 8h20L12 2zM4 10h3v8H4v-8zm6.5 0h3v8h-3v-8zM17 10h3v8h-3v-8zM2 20h20v2H2z"/></svg>',bus:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 5a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v10a2 2 0 0 1-2 2v2h-3v-2H9v2H6v-2a2 2 0 0 1-2-2V5zm2 2v5h12V7H6zm1 8a1.5 1.5 0 1 0 3 0 1.5 1.5 0 0 0-3 0zm7 0a1.5 1.5 0 1 0 3 0 1.5 1.5 0 0 0-3 0z"/></svg>',railway:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 3h12v11a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3V3zm2 3v4h8V6H8zm-2 15 3-3h6l3 3H6z"/></svg>',park:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a6 6 0 0 1 5.2 9 4.5 4.5 0 0 1-2.4 8.3H13V22h-2v-2.7H9.2A4.5 4.5 0 0 1 6.8 11 6 6 0 0 1 12 2z"/></svg>',hotel:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 6h3v7h10a4 4 0 0 1 4 4v3h-3v-3H5v3H2V6zm5 2a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z"/></svg>',place_of_worship:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c3 3 5 5 5 8v12h-4v-5a1 1 0 0 0-2 0v5H7V10c0-3 2-5 5-8z"/></svg>',police:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l8 3v7c0 5-3.5 8.5-8 10-4.5-1.5-8-5-8-10V5l8-3z"/></svg>',stadium:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 4c5.5 0 10 1.8 10 4v4c0 2.2-4.5 4-10 4S2 14.2 2 12V8c0-2.2 4.5-4 10-4zm0 2C7.6 6 4 7.1 4 8s3.6 2 8 2 8-1.1 8-2-3.6-2-8-2z"/></svg>',fast_food:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 9a9 9 0 0 1 18 0H3zm-1 3h20v2H2v-2zm2 4h16a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3z"/></svg>',bakery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 9c0-2 1.5-3 3-3h10c1.5 0 3 1 3 3l-1 9H5L4 9zm4-1v9h2V8H8zm4 0v9h2V8h-2z"/></svg>',ice_cream:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a5 5 0 0 1 5 5H7a5 5 0 0 1 5-5zM7 9h10l-5 13L7 9z"/></svg>',bar:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 4h18l-8 9v6h4v2H7v-2h4v-6L3 4zm3.5 2 2 2h7l2-2h-11z"/></svg>',butcher:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 3h6l2 5-3 3-5-3V3zm8 7 6 6-2 2-6-6 2-2zM3 17h8v4H3v-4z"/></svg>',alcohol_shop:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 2h4v4l3 5v11H7V11l3-5V2zm-1 11h6v7H9v-7z"/></svg>',clothing_store:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 3h6l5 3-2 4-2-1v12H8V9L6 10 4 6l5-3zm1 1.5L12 6l2-1.5h-4z"/></svg>',hairdresser:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 3l9 9-2 2-2-2-2 2 2 2-1 1a3 3 0 1 1-2-2l1-1-1-1a3 3 0 1 1 2-2L5 3zm14 0l-6 6 2 2 5-6V3zM6 17a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm0-11a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"/></svg>',laundry:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 2h14v20H5V2zm2 2v2h10V4H7zm5 4a6 6 0 1 0 0 12 6 6 0 0 0 0-12zm0 3a3 3 0 1 1 0 6 3 3 0 0 1 0-6z"/></svg>',music:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 4l11-2v13a3.5 3.5 0 1 1-2-3.2V6L11 7.4v10.1A3.5 3.5 0 1 1 9 14.3V4z"/></svg>',car:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 11l2-5a2 2 0 0 1 2-1h6a2 2 0 0 1 2 1l2 5v7h-3v-2H8v2H5v-7zm2.5-1h9l-1.2-3H8.7L7.5 10zM7 13a1.3 1.3 0 1 0 0 2.6A1.3 1.3 0 0 0 7 13zm10 0a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6z"/></svg>',bicycle:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 12a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm12 0a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM6 15a2 2 0 1 1 0 4 2 2 0 0 1 0-4zm12 0a2 2 0 1 1 0 4 2 2 0 0 1 0-4zM9 4h4l4 8-2 1-3-6H9V4z"/></svg>',atm:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 5h20v14H2V5zm2 2v3h16V7H4zm0 5v5h16v-5H4zm2 2h5v2H6v-2z"/></svg>',post:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 5h20v14H2V5zm2.5 2 7.5 6 7.5-6h-15z"/></svg>',telephone:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 2c1 0 2 3 2 4s-2 2-2 3 4 6 5 6 2-2 3-2 4 1 4 2-1 4-3 4C9 19 5 15 3 5c0-2 3-3 4-3z"/></svg>',office:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 2h11v20H4V2zm2 3v3h3V5H6zm5 0v3h3V5h-3zM6 10v3h3v-3H6zm5 0v3h3v-3h-3zM6 15v3h3v-3H6zm5 0v7h3v-7h-3zM17 8h4v14h-4V8z"/></svg>',town_hall:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l9 5v2H3V7l9-5zM5 11h3v7H5v-7zm5.5 0h3v7h-3v-7zM16 11h3v7h-3v-7zM3 20h18v2H3v-2z"/></svg>',doctors:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 2v6a5 5 0 0 0 4 4.9V16a3 3 0 1 0 6 0v-1.2a2.5 2.5 0 1 0-2 0V16a1 1 0 1 1-2 0v-3.1A5 5 0 0 0 17 8V2h-3v6a2 2 0 0 1-4 0V2H7z"/></svg>',dentist:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c3 0 4-1 6 0 2 1 2 4 1 8l-1 5c-1 4-3 4-3.5 1L14 12c-.4-2-1.6-2-2 0l-.5 4c-.5 3-2.5 3-3.5-1l-1-5C6 6 6 3 8 2c2-1 3 0 4 0z"/></svg>',veterinary:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 11c3 0 6 3 6 6a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3c0-3 3-6 6-6zM6 5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zm12 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zM10 2a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zm4 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z"/></svg>',library:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 3h5c1.5 0 2.5.5 3 1.2.5-.7 1.5-1.2 3-1.2h5v16h-5c-1.5 0-2.5.6-3 1.5-.5-.9-1.5-1.5-3-1.5H4V3zm2 2v12h3c1 0 2 .2 2.5.5V5.8C11 5.3 10 5 9 5H6z"/></svg>',college:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 3 2 8l10 5 10-5-10-5zM5 12v5c0 2 3 4 7 4s7-2 7-4v-5l-7 3.5L5 12zm15-2v7h2v-7h-2z"/></svg>',museum:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l10 5v2H2V7l10-5zM5 11h2.5v7H5v-7zm5 0h2.5v7H10v-7zm5 0h2.5v7H15v-7zM3 20h18v2H3v-2z"/></svg>',art_gallery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a10 10 0 0 0 0 20c1.7 0 2-1 1.4-2-.7-1.2 0-2.5 1.6-2.5H18a4 4 0 0 0 4-4c0-6-4.5-11.5-10-11.5zM7 9a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 7 9zm3-4a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 10 5zm5 0a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 15 5zm3 4a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 18 9z"/></svg>',theatre:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 5h8v9a4 4 0 0 1-8 0V5zm2.5 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm3 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2zM13 5h8v9a4 4 0 0 1-8 0V5zm2.5 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm3 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',cinema:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 4h20v16H2V4zm3 2v2h2V6H5zm0 5v2h2v-2H5zm0 5v2h2v-2H5zm12-10v2h2V6h-2zm0 5v2h2v-2h-2zm0 5v2h2v-2h-2zM9 6v12h6V6H9z"/></svg>',monument:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 2h4l1 13H9l1-13zM7 17h10v2H7v-2zm-2 3h14v2H5v-2z"/></svg>',castle:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 6h3V3h2v3h3V3h2v3h3V3h2v3h3v16H2V6zm7 8h6v8H9v-8z"/></svg>',attraction:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l2.9 6.3 6.9.8-5.1 4.7 1.4 6.8L12 17.2 5.9 20.6l1.4-6.8L2.2 9.1l6.9-.8L12 2z"/></svg>',zoo:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 12c3.3 0 6 2.7 6 5.5S15.3 21 12 21s-6-.7-6-3.5S8.7 12 12 12zM5 6a2.7 2.7 0 1 1 0 5.4A2.7 2.7 0 0 1 5 6zm14 0a2.7 2.7 0 1 1 0 5.4A2.7 2.7 0 0 1 19 6zM9.5 2a2.7 2.7 0 1 1 0 5.4 2.7 2.7 0 0 1 0-5.4zm5 0a2.7 2.7 0 1 1 0 5.4 2.7 2.7 0 0 1 0-5.4z"/></svg>',theme_park:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11 2h2v6h-2V2zM4 20a8 8 0 0 1 16 0v2H4v-2zm3.5-2h9A6 6 0 0 0 12 14a6 6 0 0 0-4.5 4zM3 9l3-2 3 2-3 2-3-2zm12 0l3-2 3 2-3 2-3-2z"/></svg>',information:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm-1.5 4h3v3h-3V6zm0 5h3v8h-3v-8z"/></svg>',garden:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c2 2 3 4 3 6a3 3 0 0 1-6 0c0-2 1-4 3-6zM4 9c2.5 0 5 1.5 6 4H8c-2.5 0-4-1.5-4-4zm16 0c0 2.5-1.5 4-4 4h-2c1-2.5 3.5-4 6-4zm-9 5h2v8h-2v-8z"/></svg>',pitch:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 5h20v14H2V5zm2 2v10h7V7H4zm9 0v10h7V7h-7zm-1 3a2 2 0 1 1 0 4 2 2 0 0 1 0-4z"/></svg>',playground:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 4h2v16H3V4zm16 0h2v16h-2V4zM5 6h14v2H5V6zm2 3 3 11H8L5 9h2zm10 0-3 11h2l3-11h-2z"/></svg>',swimming_pool:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 3a3 3 0 0 1 6 0v3h4a3 3 0 0 1 3 3h-3a1 1 0 0 0-1 1v3H12V6a1 1 0 0 0-2 0v8H6V3zm-4 14c2 0 2 2 5 2s3-2 5-2 3 2 5 2 3-2 5-2v3c-2 0-2 2-5 2s-3-2-5-2-3 2-5 2-3-2-5-2v-3z"/></svg>',sports_centre:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 8h3v8H4V8zM2 10h2v4H2v-4zm15-2h3v8h-3V8zm3 2h2v4h-2v-4zM8 11h8v2H8v-2z"/></svg>',bicycle_parking:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 2h5a4 4 0 0 1 0 8H7v5H4V2zm3 3v2h2a1 1 0 0 0 0-2H7zm-2 13a4 4 0 1 1 8 0 4 4 0 0 1-8 0zm10 0a4 4 0 1 1 8 0 4 4 0 0 1-8 0z"/></svg>',aerialway:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 4l20-2v2L13 5v2h1l4 3v6a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-6l4-3h1V5.3L2 6V4zm7 8v3h6v-3H9z"/></svg>',ferry_terminal:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11 2h2v3h4v4h-4v5l7 2-2 6c-2 0-2-1-4-1s-2 1-4 1-2-1-4-1-2 1-4 1l-2-6 7-2V9H3V5h4V2h4zM9 7v2h6V7H9z"/></svg>',traffic_signals:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-3v3h4v2H7v-2h4v-3H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2zm4 1.6a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2zm0 4.3a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2zm0 4.3a1.4 1.4 0 1 0 0 2.8 1.4 1.4 0 0 0 0-2.8z"/></svg>',road_closed:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 10.1h16v3.8H4z"/></svg>',gate:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 4h3v16H2V4zm17 0h3v16h-3V4zM6 8h12v2H6V8zm0 5h12v2H6v-2z"/></svg>',toilets:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4zM4 7h4l2 7H8v8H4v-8H2l2-7zm12-5a2 2 0 1 1 0 4 2 2 0 0 1 0-4zm-3 5h6l1 8h-2v7h-4v-7h-2l1-8z"/></svg>',drinking_water:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c4 5 6 8 6 11a6 6 0 0 1-12 0c0-3 2-6 6-11zm0 5c-2 3-3 4.6-3 6a3 3 0 0 0 6 0c0-1.4-1-3-3-6z"/></svg>',waste_basket:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 2h6l1 2h4v3H4V4h4l1-2zM5 8h14l-1 14H6L5 8zm4 3v8h2v-8H9zm4 0v8h2v-8h-2z"/></svg>',recycling:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l4 7h-3v4h-2V9H8l4-7zM3 18l3-6 2 1-1.4 2.5H10v2H6.6L8 20l-2 1-3-3zm18 0-3 3-2-1 1.4-2.5H14v-2h3.4L16 13l2-1 3 6z"/></svg>',campsite:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l9 18h-4l-5-10-5 10H3L12 2zm0 9 5 9H7l5-9z"/></svg>',shelter:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l10 8-1.5 2L19 11v9H5v-9l-1.5 1L2 10l10-8zm0 3.5L7 9.5V18h10V9.5l-5-4z"/></svg>',fire_station:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M13 2c0 3-4 4-4 8 0 1 .4 2 1 2.6C9.4 11 10 9.5 11 9c0 2 3 3 3 6a3.5 3.5 0 0 1-1 2.5c2.5-.6 4-2.8 4-5.5 0-5-4-7-4-10zM7 15c0 4 2.5 7 5 7s5-3 5-7c0 2-1 3-2 3.5.3-.6.5-1.2.5-2 0-2.5-2-3.5-2.5-5.5-1 1-2 2.5-2 4 0 .8.2 1.5.6 2C10.2 17.5 9 16.5 9 15H7z"/></svg>',prison:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 3h2v18H3V3zm4 0h2v18H7V3zm4 0h2v18h-2V3zm4 0h2v18h-2V3zm4 0h2v18h-2V3zM2 10h20v2H2v-2z"/></svg>',cemetery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c3 0 5 2 5 5v13H7V7c0-3 2-5 5-5zm-1 3v2H9v2h2v7h2v-7h2V7h-2V5h-2zM5 21h14v2H5v-2z"/></svg>',basin:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 8c2 0 2 2 5 2s3-2 5-2 3 2 5 2 3-2 5-2v3c-2 0-2 2-5 2s-3-2-5-2-3 2-5 2-3-2-5-2V8zm0 7c2 0 2 2 5 2s3-2 5-2 3 2 5 2 3-2 5-2v3c-2 0-2 2-5 2s-3-2-5-2-3 2-5 2-3-2-5-2v-3z"/></svg>',"shield-2":'<svg viewBox="0 0 32 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="30" height="18" rx="4"/></svg>',"shield-3":'<svg viewBox="0 0 41 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="39" height="18" rx="4"/></svg>',"shield-4":'<svg viewBox="0 0 50 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="48" height="18" rx="4"/></svg>',"shield-5":'<svg viewBox="0 0 59 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="57" height="18" rx="4"/></svg>',"shield-6":'<svg viewBox="0 0 68 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="66" height="18" rx="4"/></svg>',"shield-7":'<svg viewBox="0 0 77 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="75" height="18" rx="4"/></svg>',"shield-8":'<svg viewBox="0 0 86 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="84" height="18" rx="4"/></svg>'},jh={lodging:"hotel",beer:"bar",pub:"bar",kindergarten:"school",university:"college",lift_gate:"gate",toll_booth:"gate",border_control:"gate",bollard:"gate",picnic_site:"campsite",motorcycle_parking:"parking",bicycle_rental:"bicycle",harbor:"ferry_terminal",reservoir:"basin",water_park:"swimming_pool",volleyball:"pitch",basketball:"pitch",tennis:"pitch",horse_racing:"pitch",athletics:"sports_centre",running:"sports_centre",cycling:"bicycle",climbing:"sports_centre",climbing_adventure:"sports_centre",winter_sports:"sports_centre",ice_rink:"sports_centre",karting:"car",motor:"car",escape_game:"attraction"};for(let[n,e]of Object.entries(jh)){let t=At[e];t?At[n]=t:console.warn(`[osmgl] \u043F\u0441\u0435\u0432\u0434\u043E\u043D\u0438\u043C \u0438\u043A\u043E\u043D\u043A\u0438 \xAB${n}\xBB \u0441\u0441\u044B\u043B\u0430\u0435\u0442\u0441\u044F \u043D\u0430 \u043D\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0443\u044E \xAB${e}\xBB`);}var Yh=1.2;function fi(n,e,t=16,o=0){let r=Zh(n,t),i=[],a=[],l=0;for(let h of r){let u=0,f=0;for(let d of h){let p=d.codePointAt(0);if(p===void 0)continue;let b=e.get(p);b&&(u+=b.advance,f++);}f>1&&(u+=o*(f-1)),a.push(u),u>l&&(l=u);}if(l===0)return null;let s=qe*Yh,c=r.length*s;for(let h=0;h<r.length;h++){let u=-a[h]/2,f=-c/2+h*s+s/2;for(let d of r[h]){let p=d.codePointAt(0);if(p===void 0)continue;let b=e.get(p);b&&(b.width>0&&b.height>0&&b.bitmap&&i.push({glyph:b,x:u,y:f}),u+=b.advance+o);}}return i.length?{glyphs:i,width:l,height:c}:null}function Zh(n,e){let t=n.replace(/\s+/g," ").trim();if(t.length<=e)return [t];let o=t.split(" "),r=[],i="";for(let a of o)i?i.length+1+a.length<=e?i+=" "+a:(r.push(i),i=a):i=a;return i&&r.push(i),r.slice(0,3)}function ui(n,e,t,o){if(n.length<2)return [];let r=-o,i=-o,a=e+o,l=t+o,s=f=>f.x>=r&&f.x<=a&&f.y>=i&&f.y<=l,c=[],h=[],u=()=>{h.length>=2&&c.push(h),h=[];};for(let f=0;f+1<n.length;f++){let d=n[f],p=n[f+1],b=s(d),m=s(p);if(b&&m){h.length||h.push(d),h.push(p);continue}let g=Qh(d,p,r,i,a,l);if(!g){u();continue}h.length||h.push(g[0]),h.push(g[1]),m||u();}return u(),c}function Qh(n,e,t,o,r,i){let a=e.x-n.x,l=e.y-n.y,s=0,c=1,h=[[-a,n.x-t],[a,r-n.x],[-l,n.y-o],[l,i-n.y]];for(let[u,f]of h){if(u===0){if(f<0)return null;continue}let d=f/u;if(u<0){if(d>c)return null;d>s&&(s=d);}else {if(d<s)return null;d<c&&(c=d);}}return [{x:n.x+a*s,y:n.y+l*s},{x:n.x+a*c,y:n.y+l*c}]}var qh=[0,.25,-0.25,.5,-0.5,.75,-0.75,1,-1];function di(n,e,t,o={}){if(n.length<2||!e.length||t<=0)return [];let r=od(n),i=r[r.length-1];if(i<t)return [];let a=o.maxAngle??25,l=o.stableScale&&o.stableScale>0?o.stableScale:1,s=i*l,c=o.fontSize?o.fontSize*.6:t/e.length,h=(o.fontSize??0)*.85,u=[],f=o.spacing??250,d=f>0&&f-t<f*.25?t+f*.25:f;if(o.accept)return $h(n,r,e,t,d,c,a,h,o.accept);if(d>0&&s>=t+d){let b=Math.min(Math.floor((s-t)/d)+1,24),m=t+d*(b-1),g=(s-m)/2;for(let y=0;y<b;y++,g+=d){let A=g/l,B=hi(n,r,e,t,A,c,a,h);B&&u.push({glyphs:B,path:B.map(x=>({x:x.x,y:x.y})),at:A});}if(u.length)return u}let p=(i-t)/2;for(let b of qh){let m=p+p*b,g=hi(n,r,e,t,m,c,a,h);if(g)return [{glyphs:g,path:g.map(y=>({x:y.x,y:y.y})),at:m}];if(p===0)break}return []}function $h(n,e,t,o,r,i,a,l,s){let c=e[e.length-1],h=Math.max(o/3,r/8,12),u=[],f=-1/0;for(let d=0;d+o<=c;d+=h){if(d-f<r)continue;let p=hi(n,e,t,o,d,i,a,l);if(!p)continue;let b={glyphs:p,path:p.map(m=>({x:m.x,y:m.y})),at:d};if(s(b)&&(u.push(b),f=d,u.length>=24))break}return u}function hi(n,e,t,o,r,i,a,l){if(r<0||r+o>e[e.length-1]||!ed(n,e,r,r+o,i,a))return null;let s=Do(n,e,r),c=Do(n,e,r+o);if(!s||!c)return null;if(c.x>=s.x)return Hs(n,e,t,r,l);let h=e[e.length-1];return Hs([...n].reverse(),rd(e),t,h-(r+o),l)}function ed(n,e,t,o,r,i){if(r<=0)return true;let a=[],l=0;for(let s=1;s+1<n.length;s++){let c=e[s];if(c<=t)continue;if(c>=o)break;let h=Math.atan2(n[s].y-n[s-1].y,n[s].x-n[s-1].x),u=Math.atan2(n[s+1].y-n[s].y,n[s+1].x-n[s].x),f=Math.abs((u-h)*180/Math.PI+540)%360-180,d=Math.abs(f);for(a.push({at:c,delta:d}),l+=d;a.length&&c-a[0].at>r;)l-=a.shift().delta;if(l>i)return false}return true}function Hs(n,e,t,o,r){let i=[];for(let c of t){let h=ks(n,e,o+c.offset,c.width);if(!h)return null;i.push(h);}if(!i.length)return null;if(r<=0)return i;let a=[],l=o,s=0;for(let c=0;c<t.length;c++){if(c>0){let u=Math.abs(td(i[c].angle,i[c-1].angle))*(Math.PI/180);s+=r*2*Math.tan(Math.min(u,Math.PI/3)/2);}l=o+t[c].offset+s;let h=ks(n,e,l,t[c].width);if(!h)return null;a.push(h);}return a}function ks(n,e,t,o){let r=Do(n,e,t+o/2);if(!r)return null;let i=Do(n,e,t),a=Do(n,e,t+o);if(!i||!a)return r;let l=a.x-i.x,s=a.y-i.y;return l===0&&s===0?r:{x:r.x,y:r.y,angle:Math.atan2(s,l)*180/Math.PI}}function td(n,e){let t=n-e;for(;t>180;)t-=360;for(;t<=-180;)t+=360;return t}function od(n){let e=new Array(n.length);e[0]=0;for(let t=1;t<n.length;t++)e[t]=e[t-1]+Math.hypot(n[t].x-n[t-1].x,n[t].y-n[t-1].y);return e}function rd(n){let e=n[n.length-1];return n.map(t=>e-t).reverse()}function Do(n,e,t){if(t<0||t>e[e.length-1])return null;let o=1;for(;o<e.length-1&&e[o]<t;)o++;let r=e[o]-e[o-1];if(r<=0)return null;let i=(t-e[o-1])/r,a=n[o-1],l=n[o],s=l.x-a.x,c=l.y-a.y;return {x:a.x+s*i,y:a.y+c*i,angle:Math.atan2(c,s)*180/Math.PI}}var mi=20,Ps={stride:mi,attribs:[{name:"a_pos",size:2,type:5126,offset:0},{name:"a_tex",size:2,type:5123,offset:8},{name:"a_scale",size:1,type:5126,offset:12},{name:"a_fade",size:1,type:5126,offset:16}]},nd=220,lt=64,Rs=2,id=1.22,ad=128,ld=.7;function sd(n,e,t){let o=n.layout?.letterSpacing;if(o!==void 0)return V(o,e,0)*qe;let r=V(n.paint?.haloWidth,e,0);return r<=0||t<=0?0:r*ld/(t/qe)}var cd=256,fd=200,pi="frame-circle",Vt=class n{constructor(e,t){this.shader=null;this.locations=new z;this.atlas=new _o(1024);this.vbo=null;this.ibo=null;this.vao=null;this.capacityQuads=0;this.onAssetsReady=null;this.pendingText=new Set;this.pendingIcons=new Set;this.highlightFootprint=null;this.placedCount=0;this.placed=[];this.hoverKey=null;this.hiddenKey=null;this.padding={top:0,right:0,bottom:0,left:0};this.viewport={width:0,height:0};this.stickyKeys=new Set;this.now=0;this.shownAt=new z;this.fading=false;this.styleOrder=new z;this.glyphs=new Eo(e,t),this.icons=new Fo(At);}init(e){this.shader=new Ae(e,"symbol",ns,is);for(let t of Ps.attribs)this.locations.set(t.name,this.shader.attribLocation(t.name));}static keyOf(e){return `${e.layerId}|${e.mercX.toFixed(9)}|${e.mercY.toFixed(9)}`}setHover(e){return this.hoverKey===e?false:(this.hoverKey=e,true)}setHidden(e){return this.hiddenKey===e?false:(this.hiddenKey=e,true)}querySymbol(e,t=2){let o=null;for(let r of this.placed)e.x<r.box.x1-t||e.x>r.box.x2+t||e.y<r.box.y1-t||e.y>r.box.y2+t||(!o||r.order>=o.order)&&(o=r);return o}fadeOf(e,t){let o=this.shownAt.get(e);if(o===void 0)return this.shownAt.set(e,t),this.fading=true,0;let r=(t-o)/nd;return r<1?(this.fading=true,r):1}order(e){let t=o=>o.priority+(this.stickyKeys.has(n.keyOf({layerId:o.layer.id,mercX:o.mercX,mercY:o.mercY}))?fd:0);e.sort((o,r)=>t(r)-t(o));}rememberPlaced(){this.stickyKeys=new Set(this.placed.map(e=>n.keyOf(e)));for(let e of [...this.shownAt.keys()])this.stickyKeys.has(e)||this.shownAt.delete(e);}render(e,t,o,r){let i=this.shader;if(this.placedCount=0,this.placed=[],this.viewport={width:t.width,height:t.height},!i)return;let a=t.zoom,l=r.layers.filter(d=>d.type==="symbol"&&r.layerVisibleAt(d,a));if(!l.length)return;let s=this.collect(t,o,r,l);if(!s.length)return;this.now=performance.now(),this.fading=false,this.order(s);let c=new z,h=new z,u=new z;l.forEach((d,p)=>u.set(d.id,p));let f=0;for(let d of s){let p=this.place(d,a,c);if(!p)continue;this.placed.push({layerId:d.layer.id,text:d.text,icon:d.icon,mercX:d.mercX,mercY:d.mercY,box:p.box,order:u.get(d.layer.id)??0});let b=h.get(d.layer.id);b||h.set(d.layer.id,b={layer:d.layer,verts:[],texs:[],iconVerts:[],iconTexs:[],frameVerts:[],frameTexs:[]}),b.verts.push(...p.verts),b.texs.push(...p.texs),b.iconVerts.push(...p.iconVerts),b.iconTexs.push(...p.iconTexs),b.frameVerts.push(...p.frameVerts),b.frameTexs.push(...p.frameTexs),f+=p.quads,this.placedCount++;}this.rememberPlaced(),this.fading&&this.onAssetsReady?.(),this.requestMissing(),f&&(this.styleOrder=u,this.draw(e,t,h,f,a));}collect(e,t,o,r){let i=[],l=this.padding,s=kt(e,o).far,[c,h,u]=e.cameraPositionPx;for(let f of r){let d=(f.layout?.priority??0)*cd,p=t.get(f.source??Y);if(!p)continue;let b=f.layout?.showFor==="highlight",m=f.layout?.placement==="map",{shift:g,drop:y}=m?Vs(f,e.zoom,e.pixelsPerMeter):{shift:0,drop:0};if(b&&!this.highlightFootprint)continue;let A=e.worldSize>0?e.pixelsPerMeter/e.worldSize*1.5:0,B=o.bucketKeyFor(f);if(B!==null)for(let x of p.visibleTiles){if(!o.layerVisibleAt(f,e.detailZoom(e.distanceToTile(x))))continue;let _=p.getTile(x)?.data?.buckets?.[B];if(!_||!gr(_))continue;let C=new Int16Array(_.anchors),v=new Uint8Array(_.priorities),E=_.rotations?new Int16Array(_.rotations):null,D=_.lines?new Int16Array(_.lines):null,F=_.lineStarts?new Uint32Array(_.lineStarts):null,H=x.bounds(),S=e.worldSize,L=(H.maxX-H.minX)*S/_.extent,M=H.minX*S,T=H.minY*S;for(let P=0;P<v.length;P++){let k=M+C[P*2]*L,O=T+C[P*2+1]*L;if(s!==1/0&&Math.hypot(k-c,O-h,u)>s||b&&!Qe(this.highlightFootprint,k/S,O/S,A))continue;let N=k,G=O;if(m&&E){let Z=E[P]*Math.PI/180,ee=g;N-=Math.sin(Z)*ee,G+=Math.cos(Z)*ee;}let R=e.worldPxToPoint(N,G),W=D&&F?ud(e,D,F,P,M,T,L):void 0;if(f.layout?.textPlacement==="line"){if(!W)continue}else if(!R||R.x<l.left-64||R.y<l.top-64||R.x>e.width-l.right+64||R.y>e.height-l.bottom+64)continue;i.push({layer:f,screenX:R?R.x:W[0].x,screenY:(R?R.y:W[0].y)+y,text:_.texts[P]??"",icon:_.icons[P]??"",priority:v[P]+d,rotate:Ws(f,E,P,e.bearing),mercX:k/S,mercY:O/S,line:W});}}}return i}place(e,t,o){let r=e.layer.layout??{},i=n.keyOf({layerId:e.layer.id,mercX:e.mercX,mercY:e.mercY});if(this.hiddenKey!==null&&this.hiddenKey===i)return null;let a=this.fadeOf(i,this.now),l=this.hoverKey!==null&&this.hoverKey===i,s=V(r.textSize,t,13),c=V(r.iconSize,t,16),h=r.iconTextGap??5,[u,f]=r.offset??[0,0],d=r.placement==="map",p=null;if(e.icon&&!d){this.icons.isDefined(e.icon)||(e.icon="dot");let q=`icon:${e.icon}`,U=this.atlas.get(q);if(!U){let J=this.icons.get(e.icon);J?U=this.atlas.add(q,J.data,J.width,J.height)??void 0:this.pendingIcons.add(e.icon);}U&&(p=U);}let b=null;if(p&&r.iconFrame==="circle"){let q=`icon:${pi}`,U=this.atlas.get(q);if(!U){let J=this.icons.get(pi);J?U=this.atlas.add(q,J.data,J.width,J.height)??void 0:this.pendingIcons.add(pi);}U&&(b=U);}let m=b?Math.max(r.iconFrameScale??1.6,1):1,g=null;if(e.text&&(this.glyphs.needsLoad(e.text)&&this.pendingText.add(e.text),g=fi(e.text,this.glyphs,r.textPlacement==="line"?Number.MAX_SAFE_INTEGER:r.maxLineChars??15,sd(e.layer,t,s)),!g&&!p)||!g&&!p)return null;let y=s/qe,A=g?g.width*y:0,B=g?g.height*y:0;if(e.layer.layout?.textPlacement==="line")return g&&e.line?this.placeOnLine(e,g,y,B,o,t,a):null;let x=r.iconPlacement??"top",w=x==="behind"&&!!p&&!!g,_=x==="top"&&!!p&&!!g,C=p?p.width/Math.max(p.height,1):1,v=w?B+h*2:c,E=p?v*C:0,D=Math.max(E,p?c*m:0),F=Math.max(v,p?c*m:0),H=w?Math.max(E,A+h*2):_?Math.max(D,A):D+(p&&g?h:0)+A,S=w?Math.max(v,B):_?F+h+B:Math.max(p?F:0,B),L=e.screenX+u,M=e.screenY+f,T=Rs+(r.collisionPadding??0),P={x1:L-H/2-T,y1:M-S/2-T,x2:L+H/2+T,y2:M+S/2+T},k=this.padding;if(P.x1<k.left||P.y1<k.top||P.x2>this.viewport.width-k.right||P.y2>this.viewport.height-k.bottom)return null;if(!r.allowOverlap){if(Gs(o,P))return null;Os(o,P);}let O=[],N=[],G=[],R=[],W=[],j=[],Z=0,ee=L-H/2,ge=_?(F+h)/2:0,te=1/0,X=1/0,re=-1/0,le=-1/0;if(g){let q=_||w?L:ee+(p?D+h:0)+A/2;for(let U of g.glyphs){let J=U.glyph,fe=`g:${J.id}`,se=this.atlas.get(fe);if(!se&&(!J.bitmap||(se=this.atlas.add(fe,J.bitmap,J.width+Ce*2,J.height+Ce*2)??void 0,!se)))continue;let ue=q+(U.x+J.left-Ce)*y,ae=M+ge+(U.y-J.top-Ce)*y,xe=se.width*y,Te=se.height*y;Fr(O,N,ue,ae,xe,Te,se,0,a),Z++;let we=Ce*y;te=Math.min(te,ue+we),X=Math.min(X,ae+we),re=Math.max(re,ue+xe-we),le=Math.max(le,ae+Te-we);}if(_&&p&&X<1/0){let U=M-S/2+F+h-X;if(U!==0){for(let J=1;J<O.length;J+=4)O[J]+=U;X+=U,le+=U;}}}if(p){let q=l?id:1,U=E*q,J=v*q,fe=(_?L-E/2:ee+(D-E)/2)-(U-E)/2,se=(_?M-S/2+(F-v)/2:M-v/2)-(J-v)/2;if(b){let ae=c*m*q,xe=fe+U/2-ae/2,Te=se+J/2-ae/2,we=Ce/Math.max(b.height-Ce*2,1)*ae;Fr(W,j,xe-we,Te-we,ae+we*2,ae+we*2,b,0,a),Z++;}if(w&&re>te){let ae=h*1.6,xe=h;U=(re-te+ae*2)*q,J=(le-X+xe*2)*q,fe=te-ae,se=X-xe;}let ue=Ce/Math.max(p.height-Ce*2,1)*J;Fr(G,R,fe-ue,se-ue,U+ue*2,J+ue*2,p,e.rotate,a),Z++;}return Z?{verts:O,texs:N,iconVerts:G,iconTexs:R,frameVerts:W,frameTexs:j,quads:Z,box:P}:null}placeOnLine(e,t,o,r,i,a,l){let s=e.line,c=t.glyphs.map(E=>({offset:(E.x+t.width/2)*o,width:Math.max(E.glyph.advance,1)*o})),h=c.length?c[c.length-1].offset+c[c.length-1].width:0,u=e.layer.layout??{},f=[],d=[],p=[],b=0,m=r/2+Rs,g=this.padding,y=E=>{let D=E.path.map(F=>({x1:F.x-m,y1:F.y-m,x2:F.x+m,y2:F.y+m}));for(let F of D)if(F.x1<g.left||F.y1<g.top||F.x2>this.viewport.width-g.right||F.y2>this.viewport.height-g.bottom||!u.allowOverlap&&Gs(i,F))return false;if(!u.allowOverlap)for(let F of D)Os(i,F);return p.push(...D),true},A=-1/0,B=1/0;for(let E of t.glyphs)E.glyph.height<=0||(A=Math.max(A,E.glyph.top),B=Math.min(B,E.glyph.top-E.glyph.height));let x=Number.isFinite(A)?(A+B)/2*o:0,_=ui(s,this.viewport.width,this.viewport.height,ad).flatMap(E=>di(E,c,h,{spacing:u.symbolSpacing,fontSize:qe*o,stableScale:Math.pow(2,Math.round(a)-a),accept:y}));if(!_.length)return null;for(let E of _)for(let D=0;D<t.glyphs.length;D++){let F=t.glyphs[D].glyph,H=E.glyphs[D],S=`g:${F.id}`,L=this.atlas.get(S);if(!L&&(!F.bitmap||(L=this.atlas.add(S,F.bitmap,F.width+Ce*2,F.height+Ce*2)??void 0,!L)))continue;let M=L.width*o,T=L.height*o,P=(F.height/2-F.top)*o+x,k=H.angle*Math.PI/180;Fr(f,d,H.x-M/2-Math.sin(k)*P,H.y-T/2+Math.cos(k)*P,M,T,L,H.angle,l),b++;}if(!b)return null;let C=p.map(E=>(E.x1+E.x2)/2),v=p.map(E=>(E.y1+E.y2)/2);return {verts:f,texs:d,iconVerts:[],iconTexs:[],frameVerts:[],frameTexs:[],quads:b,box:{x1:Math.min(...C)-m,y1:Math.min(...v)-m,x2:Math.max(...C)+m,y2:Math.max(...v)+m}}}inStyleOrder(e){return [...e.values()].sort((t,o)=>(this.styleOrder.get(t.layer.id)??0)-(this.styleOrder.get(o.layer.id)??0))}draw(e,t,o,r,i){let a=this.shader,l=e.gl;this.ensureBuffers(e,r);let s=this.vbo,c=this.vao;if(!s||!c||!this.ibo)return;let h=new ArrayBuffer(r*4*mi),u=new Float32Array(h),f=new Uint16Array(h),d=[],p=0,b=(m,g,y,A)=>{let B=m.length/16;if(B){d.push({layer:y,role:A,first:p/4*6,count:B*6});for(let x=0;x<B*4;x++){let w=p*5;u[w]=m[x*4],u[w+1]=m[x*4+1],f[w*2+4]=g[x*2],f[w*2+5]=g[x*2+1],u[w+3]=m[x*4+2],u[w+4]=m[x*4+3],p++;}}};for(let m of this.inStyleOrder(o))b(m.frameVerts,m.frameTexs,m.layer,"frame"),b(m.iconVerts,m.iconTexs,m.layer,"icon"),b(m.verts,m.texs,m.layer,"text");s.update(new Uint8Array(h)),a.use(),this.atlas.bind(e,0),a.setInt("u_atlas",0),a.setVec2("u_viewport",t.width,t.height),a.setFloat("u_atlas_size",this.atlas.size),a.setFloat("u_edge",si),a.setFloat("u_dpr",t.width>0?l.drawingBufferWidth/t.width:1),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),c.bind();for(let m of d){let g=m.layer.paint,y=V(g.opacity,i,1),A=m.role==="icon",B=m.role==="frame",x=(D,F,H)=>B?F??D??H:A?D??H:H,w=He(B?g.frameColor??g.haloColor??g.color:x(g.iconColor,void 0,g.color),i,[.15,.15,.15,1]),_=B?g.frameHaloColor:x(g.iconHaloColor,void 0,g.haloColor),C=He(_??(B?g.iconColor??g.color:g.haloColor),i,[1,1,1,1]);B&&g.frameHaloColor===void 0&&(C[3]*=.35),B&&(w[3]*=V(g.frameOpacity,i,1));let v=V(B?g.frameHaloWidth??1.1:x(g.iconHaloWidth,void 0,g.haloWidth),i,1.2),E=V(m.layer.layout?.textSize,i,13);a.setVec4v("u_color",Me([w[0],w[1],w[2],w[3]*y])),a.setVec4v("u_halo_color",Me([C[0],C[1],C[2],C[3]*y])),a.setFloat("u_halo",v/(Mo*(E/qe))),l.drawElements(l.TRIANGLES,m.count,l.UNSIGNED_INT,m.first*4);}e.bindVAO(null);}ensureBuffers(e,t){if(this.vao&&t<=this.capacityQuads)return;this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.capacityQuads=Math.max(1024,Math.ceil(t*1.5)),this.vbo=new ve(e,new Uint8Array(this.capacityQuads*4*mi),Ps,true);let o=new Uint32Array(this.capacityQuads*6);for(let r=0;r<this.capacityQuads;r++){let i=r*4;o.set([i,i+1,i+2,i,i+2,i+3],r*6);}this.ibo=new ye(e,o),this.vao=new pe(e,[{buffer:this.vbo,locations:this.locations}],this.ibo);}requestMissing(){if(this.pendingText.size){let e=[...this.pendingText].join("");this.pendingText.clear(),this.glyphs.ensure(e).then(t=>{t&&this.onAssetsReady?.();});}if(this.pendingIcons.size){let e=[...this.pendingIcons];this.pendingIcons.clear(),Promise.all(e.map(t=>this.icons.ensure(t))).then(t=>{t.some(Boolean)&&this.onAssetsReady?.();});}}destroy(e){this.shader?.destroy(),this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.atlas.destroy(e),this.shader=null,this.vao=null;}};function Fr(n,e,t,o,r,i,a,l=0,s=1){let c=i/Math.max(a.height,1);if(l){let h=l*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=t+r/2,p=o+i/2;for(let[b,m]of [[t,o],[t+r,o],[t+r,o+i],[t,o+i]]){let g=b-d,y=m-p;n.push(d+g*u-y*f,p+g*f+y*u,c,s);}}else n.push(t,o,c,s,t+r,o,c,s,t+r,o+i,c,s,t,o+i,c,s);e.push(a.x,a.y,a.x+a.width,a.y,a.x+a.width,a.y+a.height,a.x,a.y+a.height);}function ud(n,e,t,o,r,i,a){if(o+1>=t.length)return;let l=t[o],s=t[o+1],c=[];for(let h=l;h<s;h++){let u=n.worldPxToPoint(r+e[h*2]*a,i+e[h*2+1]*a);if(!u)break;c.push(u);}return c.length>=2?c:void 0}var zs=(n,e)=>n*4096+e;function Gs(n,e){let t=Math.floor(e.x1/lt),o=Math.floor(e.y1/lt),r=Math.floor(e.x2/lt),i=Math.floor(e.y2/lt);for(let a=t;a<=r;a++)for(let l=o;l<=i;l++){let s=n.get(zs(a,l));if(s){for(let c of s)if(e.x1<c.x2&&e.x2>c.x1&&e.y1<c.y2&&e.y2>c.y1)return true}}return false}function Os(n,e){let t=Math.floor(e.x1/lt),o=Math.floor(e.y1/lt),r=Math.floor(e.x2/lt),i=Math.floor(e.y2/lt);for(let a=t;a<=r;a++)for(let l=o;l<=i;l++){let s=zs(a,l),c=n.get(s);c||n.set(s,c=[]),c.push(e);}}function Vs(n,e,t){let r=n.layout?.arrowUnits!=="meters"?1:t,i=V(n.layout?.arrowLength,e,50)*r;return {shift:V(n.layout?.arrowGap,e,20)*r+i/2,drop:i/2+(n.layout?.iconTextGap??4)}}function Ws(n,e,t,o){return !n.layout?.iconRotate||!e?0:e[t]-o}var Wt=class{constructor(e,t){this.capacity=e;this.onEvict=t;this.map=new z;}get size(){return this.map.size}has(e){return this.map.has(e)}get(e){let t=this.map.get(e);if(t!==void 0)return this.map.delete(e),this.map.set(e,t),t}peek(e){return this.map.get(e)}set(e,t){let o=this.map.get(e);o!==void 0&&(this.map.delete(e),o!==t&&this.onEvict?.(e,o)),this.map.set(e,t),this.trim();}delete(e){let t=this.map.get(e);return t===void 0?false:(this.map.delete(e),this.onEvict?.(e,t),true)}setCapacity(e){this.capacity=e,this.trim();}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}clear(){for(let[e,t]of this.map)this.onEvict?.(e,t);this.map.clear();}trim(){for(;this.map.size>this.capacity;){let e=this.map.keys().next();if(e.done)break;let t=e.value,o=this.map.get(t);this.map.delete(t),this.onEvict?.(t,o);}}};var Nt=class n{constructor(e,t,o,r=0){this.z=e;this.x=t;this.y=o;this.wrap=r;this.dataKey=`${e}/${t}/${o}`,this.key=r===0?this.dataKey:`${this.dataKey}@${r}`;}parent(){return this.z===0?null:new n(this.z-1,this.x>>1,this.y>>1,this.wrap)}children(){let e=this.z+1,t=this.x*2,o=this.y*2;return [new n(e,t,o,this.wrap),new n(e,t+1,o,this.wrap),new n(e,t,o+1,this.wrap),new n(e,t+1,o+1,this.wrap)]}scaledTo(e){if(e>=this.z)return this;let t=this.z-e;return new n(e,this.x>>t,this.y>>t,this.wrap)}isAncestorOf(e){if(e.z<=this.z||e.wrap!==this.wrap)return false;let t=e.z-this.z;return e.x>>t===this.x&&e.y>>t===this.y}bounds(){let t=1/Math.pow(2,this.z);return {minX:this.x*t+this.wrap,minY:this.y*t,maxX:(this.x+1)*t+this.wrap,maxY:(this.y+1)*t}}toString(){return this.key}};function hd(n,e,t){let o=Math.pow(2,t),r=e.maxTiles??512,i=[],a=128;for(let l=0;l<o;l++)for(let s=0;s<o;s++){let c=new Nt(t,s,l),h=c.bounds(),u=(h.minX+h.maxX)/2,f=(h.minY+h.maxY)/2,d=[[u,f],[h.minX,h.minY],[h.maxX,h.minY],[h.minX,h.maxY],[h.maxX,h.maxY]],p=false;for(let[m,g]of d)if(n.isOnGlobeFront(Se(m),Fe(g))){p=true;break}if(!p)continue;let b=false;for(let[m,g]of d){let y=n.localToPoint(n.globeLocal(m,g));if(y&&y.x>-a&&y.y>-a&&y.x<n.width+a&&y.y<n.height+a){b=true;break}}if(b&&(i.push(c),i.length>=r))return i}return i}function So(n,e){let t=Math.min(e.maxzoom,24),o=Math.max(0,Math.min(e.minzoom,t)),r=e.detailBias??1,i=e.maxTiles??512,a=512*r,l=Math.min(Math.round(n.zoom),t);if(l<o)return [];if(n.globeActive)return hd(n,e,l);let{min:s,max:c}=n.visibleWrapRange(),h=[],u=[];for(let d=s;d<=c;d++)u.push(new Nt(0,0,0,d));let f=0;for(;u.length&&!(++f>2e4||h.length>=i);){let d=u.pop();if(!n.isTileVisible(d))continue;if(d.z>=l){d.z>=o&&h.push(d);continue}if(n.tileScreenSize(d.z,n.distanceToTile(d))<=a&&d.z>=o){h.push(d);continue}for(let b of d.children())u.push(b);}return h.sort((d,p)=>n.distanceToTile(d)-n.distanceToTile(p)),h}var bi=class{constructor(e){this.id=e;this.state="loading";this.data=null;this.error=null;this.requestId=0;this.buckets=new z;}get hasGeometry(){return this.state==="loaded"&&!!this.data&&Object.keys(this.data.buckets).length>0}destroy(){for(let e of this.buckets.values())e.destroy();this.buckets.clear(),this.data=null;}},dd=1500,Dr=class extends $e{constructor(t,o){super();this.pool=t;this.visible=[];this.holdSince=0;this.warmed=false;this.version=0;this.opts={cacheSize:160,detailBias:1,maxTiles:512,...o},this.cache=new Wt(this.opts.cacheSize,(r,i)=>{i.state==="loading"&&this.pool.abort(i.requestId),i.destroy();});}get visibleTiles(){return this.visible}get dataVersion(){return this.version+this.visible.length*1e6}get warm(){return this.warmed}getTile(t){return this.cache.peek(t.dataKey)}splitValues(t){let o=[];for(let r of this.visible){let i=this.getTile(r)?.data?.splits?.[t];if(i)for(let a of i)o.includes(a)||o.push(a);}return o.sort((r,i)=>typeof r=="number"&&typeof i=="number"?r-i:String(r).localeCompare(String(i))),o}get pendingCount(){let t=0;for(let o of this.cache.values())o.state==="loading"&&t++;return t}update(t){let o=So(t,this.opts),r=new oe;for(let s of o)r.add(s.dataKey);for(let[s,c]of this.cache.entries())c.state==="loading"&&!r.has(s)&&(this.pool.abort(c.requestId),this.cache.delete(s));let i=Math.max(this.opts.cacheSize,r.size*2);this.cache.setCapacity(i);for(let s of o)this.cache.get(s.dataKey)||this.loadTile(s);let a=this.visible.length>0&&this.covers(o),l=performance.now();this.readyFor(o)||!a||this.holdSince&&l-this.holdSince>dd?(this.visible=o,this.holdSince=0,this.readyFor(o)&&o.length&&(this.warmed=true)):this.holdSince||(this.holdSince=l);}readyFor(t){for(let o of t){let r=this.cache.peek(o.dataKey);if(!r||r.state==="loading")return false}return true}covers(t){let o=new oe;for(let r of this.visible)o.add(r.dataKey);for(let r of t){if(o.has(r.dataKey))continue;let i=r.parent(),a=false;for(let l=0;i&&l<4;l++){if(o.has(i.dataKey)){a=true;break}i=i.parent();}if(!a)for(let l of this.visible){let s=l.parent();for(let c=0;s&&c<4;c++){if(s.dataKey===r.dataKey){a=true;break}s=s.parent();}if(a)break}if(!a)return false}return true}loadTile(t){let o=new bi(t);this.cache.set(t.dataKey,o);let r=pd(this.opts.url.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y)));o.requestId=this.pool.load({url:r,zoom:t.z,metersPerTile:Vi(t.z,t.y),sourceMaxZoom:this.opts.maxzoom,plan:this.opts.plan},i=>{if(this.cache.peek(t.dataKey)===o){if(i.type==="error"){if(i.aborted)return;o.state="error",o.error=i.message,this.emit("error",{tile:t,message:i.message});}else o.data=i,o.state=Object.keys(i.buckets).length?"loaded":"empty",this.version++,i.diag?.failed?.length&&console.warn(`[osmgl] \u0442\u0430\u0439\u043B ${t.z}/${t.x}/${t.y}: \u0441\u043B\u043E\u0438 \u043D\u0435 \u0441\u043E\u0431\u0440\u0430\u043B\u0438\u0441\u044C \u2014 ${i.diag.failed.join("; ")}`),this.emit("data",{tile:o});this.pendingCount===0&&this.emit("idle",void 0);}});}findReadyAncestor(t,o=5){let r=t.parent();for(let i=0;r&&i<o;i++){let a=this.cache.peek(r.dataKey);if(a&&a.hasGeometry)return a;r=r.parent();}return null}setCoverOptions(t){t.detailBias!==void 0&&(this.opts.detailBias=t.detailBias),t.maxTiles!==void 0&&(this.opts.maxTiles=t.maxTiles);}setPlan(t){this.opts.plan=t,this.cache.clear();}reload(){this.cache.clear();}destroy(){this.cache.clear(),this.removeAllListeners();}};function pd(n){if(typeof location>"u")return n;try{return new URL(n,location.href).href}catch{return n}}var Sr=class{constructor(e){this.id=e;this.state="loading";this.image=null;this.error=null;this.texture=null;}destroy(){this.texture?.destroy(),this.texture=null,this.image?.close(),this.image=null;}},Io=class extends $e{constructor(t){super();this.visible=[];this.aborts=new Map;this.opts={cacheSize:128,detailBias:1,maxTiles:256,...t},this.cache=new Wt(this.opts.cacheSize,(o,r)=>{this.aborts.get(o)?.abort(),this.aborts.delete(o),r.destroy();});}get visibleTiles(){return this.visible}getTile(t){return this.cache.peek(t.dataKey)}update(t){this.visible=So(t,this.opts);let o=new oe;for(let r of this.visible)o.add(r.dataKey);for(let[r,i]of this.cache.entries())i.state==="loading"&&!o.has(r)&&(this.aborts.get(r)?.abort(),this.aborts.delete(r),this.cache.delete(r));this.cache.setCapacity(Math.max(this.opts.cacheSize,o.size*2));for(let r of this.visible)this.cache.get(r.dataKey)||this.loadTile(r);}reload(){for(let t of this.aborts.values())t.abort();this.aborts.clear(),this.cache.clear();}destroy(){this.reload(),this.removeAllListeners();}loadTile(t){let o=new Sr(t);this.cache.set(t.dataKey,o);let r=new AbortController;this.aborts.set(t.dataKey,r),this.fetchImage(Ns(this.opts.url,t),r.signal).then(i=>{if(this.aborts.delete(t.dataKey),this.cache.peek(t.dataKey)!==o){i.close();return}o.image=i,o.state="loaded",this.emit("data",{tile:o});}).catch(i=>{this.aborts.delete(t.dataKey),!r.signal.aborted&&this.cache.peek(t.dataKey)===o&&(o.state="error",o.error=i instanceof Error?i.message:String(i),this.emit("error",{tile:t,message:o.error}));});}async fetchImage(t,o){let r=await fetch(t,{signal:o});if(!r.ok)throw new Error(`\u0442\u0430\u0439\u043B \u043F\u043E\u0434\u043B\u043E\u0436\u043A\u0438 ${r.status} ${r.statusText}`);return createImageBitmap(await r.blob())}};function Ns(n,e){let t=n.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));if(typeof location>"u")return t;try{return new URL(t,location.href).href}catch{return t}}var md="osmgl-assets",Kt="assets";var Ir=null;function Us(){return Ir||(Ir=new Promise(n=>{if(typeof indexedDB>"u")return n(null);try{let e=indexedDB.open(md,1);e.onupgradeneeded=()=>{let t=e.result;t.objectStoreNames.contains(Kt)||t.createObjectStore(Kt,{keyPath:"key"});},e.onsuccess=()=>n(e.result),e.onerror=()=>n(null);}catch{n(null);}}),Ir)}function bd(n){return Us().then(e=>new Promise(t=>{if(!e)return t(null);try{let o=e.transaction(Kt,"readonly").objectStore(Kt).get(n);o.onsuccess=()=>t(o.result??null),o.onerror=()=>t(null);}catch{t(null);}}))}function gd(n){Us().then(e=>{if(e)try{e.transaction(Kt,"readwrite").objectStore(Kt).put(n);}catch{}});}var Ks=n=>{let e=atob(n),t=new Uint8Array(e.length);for(let o=0;o<e.length;o++)t[o]=e.charCodeAt(o);return t};async function yd(n,e,t){let o=await crypto.subtle.importKey("raw",Ks(e),"AES-GCM",false,["decrypt"]);return crypto.subtle.decrypt({name:"AES-GCM",iv:Ks(t),tagLength:128},o,n)}var Lo=class{constructor(e){this.keys=new Map;this.variants=null;this.inflight=new Map;this.endpoint=e.endpoint.replace(/\/+$/,""),this.apiKey=e.apiKey??null;}withKey(e){return this.apiKey?e+(e.includes("?")?"&":"?")+"key="+encodeURIComponent(this.apiKey):e}loadVariants(){return this.variants??(this.variants=fetch(this.withKey(`${this.endpoint}/variants`),{credentials:"same-origin"}).then(e=>e.ok?e.json():{}).catch(()=>({}))),this.variants}async resolve(e,t){return t?(await this.loadVariants())[String(e)]?.[t]??e:e}async load(e,t,o="",r){let i=await this.resolve(e,o),a=`${i}:${t}`,l=this.inflight.get(a);if(l)return l;let s=this.fetchAsset(a,i,t,r).finally(()=>this.inflight.delete(a));return this.inflight.set(a,s),s}async fetchAsset(e,t,o,r){let i,a,l=await bd(e);if(l)i=l.bytes,a=l.encrypted;else {let c=await fetch(this.withKey(`${this.endpoint}/files/${t}/data?lod=${o}`),{signal:r,credentials:"same-origin"});if(!c.ok)throw new Error(`data ${c.status}`);a=(c.headers.get("X-Enc")??"none")!=="none",i=await c.arrayBuffer(),gd({key:e,bytes:i,encrypted:a,savedAt:Date.now()});}if(!a)return i;let s=await this.getKey(t,r);if(!s)throw new Error("\u043D\u0435\u0442 \u043A\u043B\u044E\u0447\u0430 \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043E\u0432\u043A\u0438");return yd(i,s.key,s.iv)}getKey(e,t){let o=this.keys.get(e);if(o)return o;let r=(async()=>{let i=await fetch(this.withKey(`${this.endpoint}/files/${e}/key`),{signal:t,credentials:"same-origin"});if(!i.ok)return null;let a=await i.json();return a.encrypted&&a.key&&a.iv?{key:a.key,iv:a.iv}:null})();return r.catch(()=>this.keys.delete(e)),this.keys.set(e,r),r}};var Ad=1,To=class{constructor(e){this.mesh=null;this.bitmaps=[];this.error=null;this.loading=null;this.matrix=K();this.grow=1;this.growTarget=1;this.animateIn=false;this.shrinkFrom=1;this.growStart=-1;this.fade=1;this.fadeTarget=1;this.fadeFrom=1;this.fadeStart=-1;this.matrix32=new Float32Array(16);this.nodeMatrix32=new Float32Array(16);this.normal32=new Float32Array(9);this.id=e.id??`model-${Ad++}`,this.url=e.url,this.fetchBytes=e.fetchBytes,this.coordinates=e.coordinates,this.altitude=e.altitude??0,this.rotation=e.rotation??0,this.rotationTiltX=e.rotationTiltX??0,this.rotationTiltZ=e.rotationTiltZ??0,e.growIn&&(this.animateIn=true,this.grow=0),this.scale=e.scale??1,this.fitHeight=e.fitHeight,this.visible=e.visible!==false,this.userData=e.userData??{};}get isLoaded(){return this.mesh!==null}load(e){return this.loading?(e&&this.loading.then(e),this.loading):(this.loading=(async()=>{try{let t=this.fetchBytes?await this.fetchBytes():await(async()=>{let r=await fetch(this.url);if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.arrayBuffer()})(),o=await $n(t);this.bitmaps=await Promise.all(o.images.map(async r=>{if(!r.length)return null;try{return await createImageBitmap(new Blob([r]))}catch{return null}})),this.mesh=o;}catch(t){this.error=t instanceof Error?t.message:String(t),console.warn(`[osmgl] \u043C\u043E\u0434\u0435\u043B\u044C ${this.url} \u043D\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043B\u0430\u0441\u044C: ${this.error}`);}e?.();})(),this.loading)}advanceGrow(e){if(!this.mesh)return false;if(!this.animateIn&&this.growTarget===1)return this.grow=1,false;if(e<=0)return this.grow=1,false;let t=performance.now()/1e3;this.growStart<0&&(this.growStart=t);let o=(t-this.growStart)/e;if(this.growTarget===0){if(o>=1)return this.grow=0,false;let i=Math.max(o,0);return this.grow=this.shrinkFrom*(1-i*i*(3-2*i)),true}if(o>=1)return this.grow=1,false;let r=Math.max(o,0)-1;return this.grow=1+r*r*(2.70158*r+1.70158),true}retire(){this.growTarget!==0&&(this.growTarget=0,this.shrinkFrom=this.grow,this.growStart=performance.now()/1e3);}setHidden(e){let t=e?0:1;this.fadeTarget!==t&&(this.fadeTarget=t,this.fadeFrom=this.fade,this.fadeStart=performance.now()/1e3);}advanceFade(e){if(this.fadeStart<0)return false;if(e<=0)return this.fade=this.fadeTarget,this.fadeStart=-1,false;let t=(performance.now()/1e3-this.fadeStart)/e;if(t>=1)return this.fade=this.fadeTarget,this.fadeStart=-1,false;let o=Math.max(t,0),r=o*o*(3-2*o);return this.fade=this.fadeFrom+(this.fadeTarget-this.fadeFrom)*r,true}markGrown(){this.grow=1,this.growTarget=1,this.growStart=-1/0;}revive(){this.growTarget!==1&&(this.growTarget=1,this.growStart=performance.now()/1e3-(this.animateIn?0:1e9));}effectiveScale(){if(!this.mesh||this.fitHeight===void 0)return this.scale;let e=this.mesh.max[1]-this.mesh.min[1];return e>1e-6?this.fitHeight/e:this.scale}boundingRadiusM(){let e=this.mesh;if(!e)return 0;let t=this.effectiveScale(),o=Math.max(Math.abs(e.min[0]),Math.abs(e.max[0])),r=Math.max(Math.abs(e.min[1]),Math.abs(e.max[1])),i=Math.max(Math.abs(e.min[2]),Math.abs(e.max[2]));return Math.hypot(o,r,i)*t}origin(){let e=$(this.coordinates);return {x:ne(e.lng),y:ie(e.lat)}}localMatrix(e){let t=this.effectiveScale(),o=t/Oe(e),r=[o,0,0,0,0,t*this.grow,0,o,0],i=c=>c*Math.PI/180,a=yi(i(-this.rotation));this.rotationTiltX&&(a=st(gi(i(this.rotationTiltX)),a)),this.rotationTiltZ&&(a=st(Ai(i(this.rotationTiltZ)),a));let l=st(r,a),s=this.matrix;return je(s),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[4]=l[3],s[5]=l[4],s[6]=l[5],s[8]=l[6],s[9]=l[7],s[10]=l[8],s[15]=1,s}matrixInSpace(e,t){let o=$(this.coordinates),r=K();for(let a=0;a<16;a++)r[a]=e[a];let i=K();return Ee(i,r,this.localMatrix(o.lat)),Ye(t??this.matrix32,i)}cameraInModelSpace(e){let t=this.effectiveScale();if(!(t>0))return [0,0,0];let o=this.origin(),r=$(this.coordinates),i=Oe(r.lat),a=e.worldSize,l=e.cameraPositionPx,s=(l[0]/a-o.x)*i,c=(l[1]/a-o.y)*i,h=l[2]/e.pixelsPerMeter-this.altitude,u=s,f=h,d=c,p=m=>m*Math.PI/180,b=yi(p(-this.rotation));return this.rotationTiltX&&(b=st(gi(p(this.rotationTiltX)),b)),this.rotationTiltZ&&(b=st(Ai(p(this.rotationTiltZ)),b)),[(b[0]*u+b[1]*f+b[2]*d)/t,(b[3]*u+b[4]*f+b[5]*d)/t,(b[6]*u+b[7]*f+b[8]*d)/t]}matrixFor(e){let t=this.origin();return this.matrixInSpace(e.objectMatrix(t.x,t.y,this.altitude))}coversPoint(e,t){let o=this.mesh;if(!o)return false;let r=this.origin(),i=e-r.x,a=t-r.y,l=$(this.coordinates),s=this.localMatrix(l.lat),c=s[0],h=s[1],u=s[8],f=s[9],d=c*f-h*u;if(Math.abs(d)<1e-30)return false;let p=(i*f-a*u)/d,b=(c*a-h*i)/d,m=1.05,g=(o.min[0]+o.max[0])/2,y=(o.min[2]+o.max[2])/2,A=(o.max[0]-o.min[0])/2*m,B=(o.max[2]-o.min[2])/2*m;return Math.abs(p-g)<=A&&Math.abs(b-y)<=B}get isAnimated(){return this.mesh?.animation!=null}matrixForNode(e,t,o){let r=this.origin();return this.matrixInSpaceForNode(e.objectMatrix(r.x,r.y,this.altitude),t,o,this.nodeMatrix32)}matrixInSpaceForNode(e,t,o,r){let i=this.mesh?.animation;if(!i||!i.nodes.has(t))return this.matrixInSpace(e,r);let a=K();for(let u=0;u<16;u++)a[u]=e[u];let l=$(this.coordinates),s=K();Ee(s,a,this.localMatrix(l.lat));let c=K();ei(i,t,i.duration>0?o%i.duration:0,c);let h=K();return Ee(h,s,c),Ye(r,h)}normalMatrix(){let e=i=>i*Math.PI/180,t=yi(e(-this.rotation));this.rotationTiltX&&(t=st(gi(e(this.rotationTiltX)),t)),this.rotationTiltZ&&(t=st(Ai(e(this.rotationTiltZ)),t));let o=st([1,0,0,0,0,1,0,1,0],t),r=this.normal32;for(let i=0;i<9;i++)r[i]=o[i];return r}};function st(n,e){let t=new Array(9);for(let o=0;o<3;o++)for(let r=0;r<3;r++)t[o*3+r]=n[r]*e[o*3]+n[3+r]*e[o*3+1]+n[6+r]*e[o*3+2];return t}var gi=n=>{let e=Math.cos(n),t=Math.sin(n);return [1,0,0,0,e,t,0,-t,e]},yi=n=>{let e=Math.cos(n),t=Math.sin(n);return [e,0,-t,0,1,0,t,0,e]},Ai=n=>{let e=Math.cos(n),t=Math.sin(n);return [e,t,0,-t,e,0,0,0,1]};var Tr=class{constructor(){this.hit=new z;this.miss=new oe;this.stamp="";}find(e,t){if(!t)return null;let o=this.hit.get(e.id);if(o!==void 0)return o;let r=t.source.visibleTiles.map(i=>i.dataKey).join(",");if(r!==this.stamp&&(this.stamp=r,this.miss.clear()),this.miss.has(e.id))return null;for(let i of t.source.visibleTiles){let a=t.source.getTile(i)?.data?.buckets?.[t.key];if(!a||a.kind!=="fill-extrusion"||!a.featureIds)continue;let l=i.bounds();if(e.mercX<l.minX||e.mercX>l.maxX||e.mercY<l.minY||e.mercY>l.maxY)continue;let s=(e.mercX-l.minX)/(l.maxX-l.minX)*a.extent,c=(e.mercY-l.minY)/(l.maxY-l.minY)*a.extent,h=new Int16Array(a.vertices),u=new Uint32Array(a.indices),f=new Float64Array(a.featureIds),d=h.length/a.vertexCount;for(let p=0;p*3+2<u.length;p++){let b=u[p*3]*d,m=u[p*3+1]*d,g=u[p*3+2]*d;if(!Ed(s,c,h[b],h[b+1],h[m],h[m+1],h[g],h[g+1]))continue;let y=f[p];return this.hit.set(e.id,y),y}}return this.miss.add(e.id),null}clear(){this.hit.clear(),this.miss.clear(),this.stamp="";}},Bd=14,Cd=2e3,vd=4e3,Js=160,xd=50,wd=4e3,Bi=6,Hr=class{constructor(e){this.wantKey="";this.modelKey="";this.entries=new z;this.loading=0;this.pending=[];this.known=new z;this.underBuilding=new Tr;this.underVenue=new Tr;this.tilesStamp="";this.rulesInScan=0;this.found=[];this.foundStamp="";this.sortedAt=null;this.budgetScale=1;this.addModel=null;this.lod=0;this.budget=Js;this.replacedBuildings=new oe;this.replacedVenues=new oe;this.onReady=null;this.stats={found:0,kept:0,live:0,tooFar:0,overBudget:0,queued:0,rules:0,loadingNow:0,pendingNow:0,replaced:0};this.loader=new Lo(e);}get models(){let e=[];for(let t of this.entries.values())e.push(t.model);return e}update(e,t,o,r,i,a,l){this.wantKey!==this.modelKey&&(this.modelKey=this.wantKey,this.clear(i));let s=e.layout??{},c=s.minZoom??Bd,h=s.loadRadius??Cd,u=Math.max(s.keepRadius??vd,h),f=Math.min(1,Math.max(.25,(o.zoom-c)/3)),d=Math.max(8,Math.round((s.budget??Js)*this.budgetScale*f));this.budget=d,this.addModel=r;let p=s.maskReplaced!==false,b=performance.now();if(o.zoom<c){for(let M of [...this.entries.values()])M.model.retire(),M.model.grow<=0&&this.release(M,i);this.replacedBuildings.clear(),this.replacedVenues.clear();return}let m=o.center,g=this.lodFor(o.zoom,c);this.lod=g;let y="";for(let M of t.visibleTiles)y+=M.dataKey+(t.getTile(M)?.data?"+":"-");let A=this.rulesInScan;if(y!==this.tilesStamp){this.tilesStamp=y;let M=new oe;A=0;for(let T of t.visibleTiles){let P=t.getTile(T)?.data?.buckets?.[e.id];if(!P||!as(P))continue;let k=new Int16Array(P.anchors),O=T.bounds(),N=O.maxX-O.minX,G=O.maxY-O.minY;for(let R=0;R<P.props.length;R++){let W=P.props[R],j=Bt(W.file,NaN);if(!Number.isFinite(j))continue;let Z=String(W.kind??"model"),ee=Z==="rule"?`t-${W.rid}-${W.oid}`:`m-${W.mid}`;if(M.has(ee))continue;M.add(ee),Z==="rule"&&A++;let ge=O.minX+k[R*2]/P.extent*N,te=O.minY+k[R*2+1]/P.extent*G,X=_d(ge,te);this.known.set(ee,{id:ee,fileId:j,lng:X.lng,lat:X.lat,mercX:ge,mercY:te,altitude:Bt(W.alt,0),scale:Bt(W.scale,1),rotation:Bt(W.rx,0),tiltX:Bt(W.rz,0),tiltZ:Bt(W.ry,0),kind:Z==="rule"?"rule":"model",target:Lr(Z==="rule"?W.oid:W.replaces),replaces:p?Z==="rule"?Lr(W.oid):String(W.anchor??"replace")==="replace"?Lr(W.replaces):null:null});}}this.rulesInScan=A;}y!==this.foundStamp&&(this.foundStamp=y,this.found=[...this.known.values()],this.sortedAt=null);let B=this.found,x=new oe;for(let M of B)M.kind==="model"&&M.target!==null&&x.add(M.target);let w=111320,_=Math.cos(m.lat*Math.PI/180),C=M=>Math.hypot((M.lng-m.lng)*w*_,(M.lat-m.lat)*w);this.replacedBuildings.clear(),this.replacedVenues.clear();let v=new oe,E=[],D=0,F=0;(this.sortedAt===null||Math.hypot((m.lng-this.sortedAt.lng)*w*_,(m.lat-this.sortedAt.lat)*w)>xd)&&(B.sort((M,T)=>C(M)-C(T)),this.sortedAt={lng:m.lng,lat:m.lat});let S=0;for(let M of B){let T=C(M);if(T>u){D++;continue}if(M.kind==="rule"&&M.target!==null&&x.has(M.target)){let N=this.entries.get(M.id);N&&N.model.retire();continue}let P=this.entries.get(M.id);if(S>=d){F++,P&&P.model.retire();continue}S++,v.add(M.id);let k=()=>{if(M.replaces===null)return;this.replacedBuildings.add(M.replaces);let N=this.underBuilding.find(M,a);N!==null&&this.replacedBuildings.add(N);let G=this.underVenue.find(M,l);G!==null&&this.replacedVenues.add(G);},O=P;if(O){k(),O.distance=T,O.leftAt=0,O.model.revive(),g<O.lod&&!O.upgrading&&this.loading<Bi&&this.upgrade(O,g,r,i);continue}if(T>h){D++;continue}if(this.loading>=Bi){E.push(M),k();continue}k(),this.spawn(M,T,g,r);}for(let M of [...this.entries.values()])if(!v.has(M.placement.id)){if(M.leftAt===0){M.leftAt=b;continue}b-M.leftAt>wd&&M.model.retire();}for(let M of [...this.entries.values()])M.model.growTarget===0&&M.model.grow<=0&&this.release(M,i);if(this.known.size>4e3)for(let[M,T]of [...this.known.entries()])C(T)>u*3&&this.known.delete(M);let L=this.stats;L.found=B.length,L.kept=v.size,L.live=this.entries.size,L.tooFar=D,L.overBudget=F,L.queued=E.length,L.rules=A,L.loadingNow=this.loading,L.pendingNow=E.length,L.replaced=this.replacedBuildings.size,this.pending=E;}pump(){let e=this.addModel;if(this.stats.loadingNow=this.loading,this.stats.pendingNow=this.pending.length,!!e)for(;this.pending.length&&this.loading<Bi&&this.entries.size<this.budget;){let t=this.pending.shift();this.entries.has(t.id)||this.spawn(t,0,this.lod,e);}}lodFor(e,t){return e>=t+2?0:1}upgrade(e,t,o,r){let i=this.makeModel(e.placement,t,true);e.upgrading=i,this.loading++,i.load(()=>{this.loading--,this.pump(),this.entries.get(e.placement.id)===e&&(e.upgrading=null,i.isLoaded&&(r(e.model),e.model=i,e.lod=t,o(i),this.onReady?.()));});}makeModel(e,t,o){let r=new To({id:`objects3d-${e.id}`,url:`objects3d:${e.fileId}/${this.modelKey}/lod${t}`,fetchBytes:()=>this.loader.load(e.fileId,t,this.modelKey),coordinates:[e.lng,e.lat],altitude:e.altitude,scale:e.scale,rotation:e.rotation,rotationTiltX:e.tiltX,rotationTiltZ:e.tiltZ,growIn:!o});return o&&r.markGrown(),r}spawn(e,t,o,r,i=false){let a=this.makeModel(e,o,i);this.entries.set(e.id,{placement:e,model:a,distance:t,leftAt:0,lod:o,upgrading:null}),this.loading++,r(a),a.load(()=>{this.loading--,this.pump(),this.onReady?.();});}release(e,t){this.entries.delete(e.placement.id),e.upgrading=null,t(e.model);}setModelKey(e){this.wantKey=e??"";}clear(e){for(let t of [...this.entries.values()])this.release(t,e);this.replacedBuildings.clear(),this.replacedVenues.clear(),this.underBuilding.clear(),this.underVenue.clear();for(let t of Object.keys(this.stats))this.stats[t]=0;}},Bt=(n,e)=>{let t=typeof n=="number"?n:Number(n);return Number.isFinite(t)?t:e},Lr=n=>{let e=Bt(n,NaN);return Number.isFinite(e)?e:null};function _d(n,e){let t=n*360-180,o=Math.PI*(1-2*e),r=Math.atan(Math.sinh(o))*180/Math.PI;return {lng:t,lat:r}}function Ed(n,e,t,o,r,i,a,l){let s=(n-r)*(o-i)-(t-r)*(e-i),c=(n-a)*(i-l)-(r-a)*(e-l),h=(n-t)*(l-o)-(a-t)*(e-o),u=s<0||c<0||h<0,f=s>0||c>0||h>0;return !(u&&f)}var Md=200,Fd={center:"translate(-50%, -50%)",top:"translate(-50%, 0)",bottom:"translate(-50%, -100%)",left:"translate(0, -50%)",right:"translate(-100%, -50%)"},Ho=class{constructor(e){this.attachedTo=null;this.culled=false;this._visible=true;this._coordinates=e.coordinates,this.altitude=e.altitude??0,this.offset=e.offset??[0,0],this.anchorTransform=Fd[e.anchor??"bottom"],this.userData=e.userData??{};let t=e.element??document.createElement("div");e.element||(t.className="osmgl-marker-default",t.innerHTML=e.html??Dd),t.classList.add("osmgl-marker"),e.className&&t.classList.add(e.className),t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.willChange="transform",e.zIndex!==void 0&&(t.style.zIndex=String(e.zIndex)),this.element=t;}get coordinates(){return this._coordinates}setCoordinates(e){return this._coordinates=e,this}setVisible(e){return this._visible=e,this.applyVisibility(),this}get visible(){return this._visible}attach(e){this.attachedTo!==e&&(e.appendChild(this.element),this.attachedTo=e);}detach(){this.element.remove(),this.attachedTo=null;}update(e){let t=$(this._coordinates),o=e.worldSize,r=e.worldPxToPoint(ne(t.lng)*o,ie(t.lat)*o,this.altitude);if(!r){this.culled=true,this.applyVisibility();return}let i=Md;if(r.x<-i||r.y<-i||r.x>e.width+i||r.y>e.height+i){this.culled=true,this.applyVisibility();return}this.culled=false,this.applyVisibility(),this.element.style.transform=`translate(${Math.round(r.x+this.offset[0])}px, ${Math.round(r.y+this.offset[1])}px) ${this.anchorTransform}`;}applyVisibility(){this.element.style.display=this._visible&&!this.culled?"":"none";}},Dd='<svg width="24" height="32" viewBox="0 0 24 32" xmlns="http://www.w3.org/2000/svg"><path d="M12 0C5.4 0 0 5.4 0 12c0 9 12 20 12 20s12-11 12-20c0-6.6-5.4-12-12-12z" fill="#2f6df6"/><circle cx="12" cy="12" r="4.5" fill="#fff"/></svg>';var ko=class extends Ho{constructor(t){let o=document.createElement("div");o.className="osmgl-popup",o.style.pointerEvents="auto";let r=document.createElement("div");if(r.className="osmgl-popup-content",t.element?r.appendChild(t.element):r.innerHTML=t.html??"",o.appendChild(r),t.closeButton!==false){let a=document.createElement("button");a.className="osmgl-popup-close",a.type="button",a.setAttribute("aria-label","\u0417\u0430\u043A\u0440\u044B\u0442\u044C"),a.textContent="\xD7",o.appendChild(a);}let i=document.createElement("div");i.className="osmgl-popup-tip",o.appendChild(i);super({coordinates:t.coordinates,element:o,anchor:t.anchor??"bottom",offset:t.offset??[0,-12],altitude:t.altitude,zIndex:t.zIndex??10,className:t.className,userData:t.userData});this.onClose=null;this.content=r,this.closeOnClick=t.closeOnClick!==false,o.querySelector(".osmgl-popup-close")?.addEventListener("click",()=>this.onClose?.());}onCloseRequest(t){return this.onClose=t,this}setHtml(t){return this.content.innerHTML=t,this}setContent(t){return this.content.replaceChildren(t),this}};var Sd=[["\u0443\u043B\u0438\u0446\u0430","\u0443\u043B."],["\u0443\u043B\u0438\u0446\u044B","\u0443\u043B."],["\u0443\u043B\u0438\u0446\u0435","\u0443\u043B."],["\u043F\u0440\u043E\u0441\u043F\u0435\u043A\u0442","\u043F\u0440\u043E\u0441\u043F."],["\u043F\u0440\u043E\u0441\u043F\u0435\u043A\u0442\u0430","\u043F\u0440\u043E\u0441\u043F."],["\u043F\u0435\u0440\u0435\u0443\u043B\u043E\u043A","\u043F\u0435\u0440."],["\u043F\u0435\u0440\u0435\u0443\u043B\u043A\u0430","\u043F\u0435\u0440."],["\u043F\u0440\u043E\u0435\u0437\u0434","\u043F\u0440-\u0434"],["\u043F\u0440\u043E\u0435\u0437\u0434\u0430","\u043F\u0440-\u0434"],["\u043F\u043B\u043E\u0449\u0430\u0434\u044C","\u043F\u043B."],["\u043F\u043B\u043E\u0449\u0430\u0434\u0438","\u043F\u043B."],["\u0431\u0443\u043B\u044C\u0432\u0430\u0440","\u0431\u0443\u043B."],["\u0431\u0443\u043B\u044C\u0432\u0430\u0440\u0430","\u0431\u0443\u043B."],["\u043D\u0430\u0431\u0435\u0440\u0435\u0436\u043D\u0430\u044F","\u043D\u0430\u0431."],["\u043D\u0430\u0431\u0435\u0440\u0435\u0436\u043D\u043E\u0439","\u043D\u0430\u0431."],["\u0448\u043E\u0441\u0441\u0435","\u0448."],["\u0442\u0443\u043F\u0438\u043A","\u0442\u0443\u043F."],["\u0442\u0443\u043F\u0438\u043A\u0430","\u0442\u0443\u043F."],["\u043C\u0438\u043A\u0440\u043E\u0440\u0430\u0439\u043E\u043D","\u043C\u043A\u0440."],["\u043C\u0438\u043A\u0440\u043E\u0440\u0430\u0439\u043E\u043D\u0430","\u043C\u043A\u0440."],["\u043A\u04EF\u0447\u0430\u0438","\u043A."],["\u043A\u0443\u0447\u0430\u0438","\u043A."],["\u0445\u0438\u0451\u0431\u043E\u043D\u0438","\u0445\u0438\u0451\u0431."],["\u0448\u043E\u04B3\u0440\u043E\u04B3\u0438","\u0448\u043E\u04B3."],["\u0433\u0443\u0437\u0430\u0440\u0433\u043E\u04B3\u0438","\u0433\u0443\u0437."],["\u043C\u0430\u0439\u0434\u043E\u043D\u0438","\u043C\u0430\u0439\u0434."]],Xs=new Map(Sd);function Ci(n){let e=n.split(" ");if(e.length<2)return n;let t=false,o=e.map(i=>{let a=Xs.get(i.toLowerCase());return a?(t=true,i[0]===i[0].toUpperCase()?a[0].toUpperCase()+a.slice(1):a):i});return !t||!e.filter(i=>Xs.get(i.toLowerCase())===void 0).length?n:o.join(" ")}function xi(n,e){let t=[],o=[],r=[],i=[],a=[],l=e.textPlacement==="line",s=[],c=[],h=[];for(let u of n.features()){if(!Be(e.filter,u.properties))continue;let f=u.loadGeometry(),d=Td(u.type,f);if(!d)continue;let p=e.textField?vi(e.textField,u.properties):"",b=p&&e.abbreviate?Ci(p):p,m=e.iconImage?vi(e.iconImage,u.properties):"";if(!(!b&&!m)){if(l){let g=Ld(u.type,f);if(!g)continue;h.push({text:b,line:g});continue}t.push(d[0],d[1]),o.push(b),r.push(m),i.push(Hd(u.properties)),a.push(e.iconRotate&&Math.round(Number(u.properties[e.iconRotate]??0))||0);}}if(l){for(let{text:u,line:f}of Id(h)){c.push(s.length/2);for(let d of f)s.push(d);t.push(Math.round(f[0]),Math.round(f[1])),o.push(u),r.push(""),i.push(128),a.push(0);}c.push(s.length/2);}return o.length?{anchors:new Int16Array(t).buffer,texts:o,icons:r,priorities:new Uint8Array(i).buffer,rotations:new Int16Array(a).buffer,...l?{lines:new Int16Array(s).buffer,lineStarts:new Uint32Array(c).buffer}:{}}:null}function Id(n){let e=[],t=new Map,o=new Map,r=(i,a,l)=>`${i}\u241F${a}\u241F${l}`;for(let{text:i,line:a}of n){let l=r(i,a[0],a[1]),s=r(i,a[a.length-2],a[a.length-1]),c=t.get(s),h=o.get(l);if(h!==void 0){let u=e[h];if(u.line.push(...a.slice(2)),o.delete(l),o.set(r(i,u.line[u.line.length-2],u.line[u.line.length-1]),h),c!==void 0&&c!==h){let f=e[c];u.line.push(...f.line.slice(2)),f.line=[],t.delete(s),o.set(r(i,u.line[u.line.length-2],u.line[u.line.length-1]),h);}continue}if(c!==void 0){let u=e[c];u.line.unshift(...a.slice(0,a.length-2)),t.delete(s),t.set(r(i,u.line[0],u.line[1]),c);continue}t.set(l,e.length),o.set(s,e.length),e.push({text:i,line:a});}return e.filter(i=>i.line.length>=4)}function Ld(n,e){if(n!==2)return null;let t=null,o=0;for(let r of e){if(r.length<4)continue;let i=0;for(let a=0;a+3<r.length;a+=2)i+=Math.hypot(r[a+2]-r[a],r[a+3]-r[a+1]);i>o&&(o=i,t=r);}return t}function Td(n,e){if(!e.length)return null;if(n===1){let a=e[0];return a.length>=2?[a[0],a[1]]:null}if(n===2){let a=-1,l=0,s=0;for(let c of e)for(let h=0;h+3<c.length;h+=2){let u=c[h+2]-c[h],f=c[h+3]-c[h+1],d=u*u+f*f;d>a&&(a=d,l=c[h]+u/2,s=c[h+1]+f/2);}return a>0?[Math.round(l),Math.round(s)]:null}let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let a of e)for(let l=0;l<a.length;l+=2)a[l]<t&&(t=a[l]),a[l]>r&&(r=a[l]),a[l+1]<o&&(o=a[l+1]),a[l+1]>i&&(i=a[l+1]);return isFinite(t)?[Math.round((t+r)/2),Math.round((o+i)/2)]:null}function Hd(n){let e=n.rank;return typeof e=="number"&&isFinite(e)?Math.max(0,255-Math.min(e,255)):128}function vi(n,e){let t=Array.isArray(n)?n:[n];for(let o of t){let r=true,a=o.replace(/\{([^}]+)\}/g,(l,s)=>{let c=e[s];return c==null||c===""?(r=false,""):String(c)}).trim();if(r&&a)return a}return ""}function js(n,e){let t=[],o=[];for(let r=0;r<n.length;r++){let i=n.feature(r);if(i.type===1&&Be(e,i.properties))for(let a of i.loadGeometry())for(let l=0;l+1<a.length;l+=2)t.push(a[l],a[l+1]),o.push(i.properties);}return o.length?{anchors:Int16Array.from(t).buffer,props:o}:null}function kd(){let n=typeof self<"u"?self.origin:void 0;return n&&n!=="null"&&!n.startsWith("blob:")?n+"/":void 0}async function Ys(n,e){let t=performance.now(),o=kd(),r=await fetch(n.url,{signal:e,credentials:"same-origin",...o?{referrer:o}:{}}),i=(g,y,A,B,x=0)=>({type:"loaded",id:n.id,buckets:{},timing:{fetchMs:B,parseMs:x},diag:{status:g,bytes:y,layers:A,built:0}});if(!r.ok){if(r.status===404||r.status===204)return i(r.status,0,[],performance.now()-t);throw new Error(`HTTP ${r.status} \u0434\u043B\u044F ${n.url}`)}let a=await r.arrayBuffer(),l=performance.now()-t;if(a.byteLength===0)return i(r.status,0,[],l);let s=performance.now(),c=new no(a),h=Object.keys(c.layers),u={},f={},d=new Set,p=[],m=n.plan.some(g=>g.type==="surface"&&(g.elevation??0)>0)&&n.plan.some(g=>g.type==="line"&&g.ground)?Sn(n.metersPerTile):void 0;for(let g of n.plan){if(!Rd(g,n.zoom,n.sourceMaxZoom))continue;let y=c.layers[g.sourceLayer];if(!y)continue;let A=Gd(n.zoom,y.extent);try{if(g.splitBy){let x=Od(y,g.splitBy,g.filter);if(!x.length)continue;let w=f[g.splitBy]??(f[g.splitBy]=[]);for(let _ of x){w.includes(_)||w.push(_);let C={...g,splitBy:void 0,filter:Vd(g.filter,g.splitBy,_)},v=wi(C,y,A,n.metersPerTile,m);v&&(u[Je(g.id,_)]=v);}continue}if(g.network&&g.type==="line"){for(let x of zd(y,g.filter)){let w=wi(g,y,A,n.metersPerTile,m,x);w&&(u[Je(g.id,x)]=w,d.add(x));}continue}let B=wi(g,y,A,n.metersPerTile,m);B&&(u[g.id]=B);}catch(B){p.push(`${g.id}: ${B instanceof Error?B.message:String(B)}`);}}return {type:"loaded",id:n.id,buckets:u,...Object.keys(f).length?{splits:f}:{},...d.size?{levels:[...d].sort((g,y)=>g-y)}:{},timing:{fetchMs:l,parseMs:performance.now()-s},diag:{status:r.status,bytes:a.byteLength,layers:h,built:Object.keys(u).length,...p.length?{failed:p}:{}}}}function Pd(n){return e=>{let t=e.on;if(typeof t!="string"||!t)return 0;let o=0;for(let r of t.split(",")){let i=n[r];typeof i=="number"&&i>o&&(o=i);}return o}}function Rd(n,e,t){let o=e-1,r=e<t?e+1:24;return !(n.maxzoom<o||n.minzoom>r)}function Gd(n,e){return n<=6?Math.max(64,e/24):0}function wi(n,e,t,o,r,i){{if(n.type==="fill"){let l=o>0?o/e.extent:0,s=n.cornerRadius&&l>0?{radius:n.cornerRadius/l,segments:n.cornerSegments,extent:e.extent,minCutRatio:0,maxChord:ya/l}:void 0,c=fn(e,n.filter,t,s,n.clipToTile===true,e.extent);return c?{kind:"fill",...c,extent:e.extent}:null}if(n.type==="surface"){let l=Dn(e,e.extent,n.filter,{metersPerUnit:o>0?o/e.extent:0,maxSegment:t,elevation:n.elevation??0,base:n.base,bevel:n.bevel,weld:n.weld,bevelDrop:n.bevelDrop,cornerRadius:n.cornerRadius,cornerSegments:n.cornerSegments,...r?{onShapes:s=>In(r,s,n.elevation??0,e.extent)}:{},...n.groundBy?{liftBy:Pd(n.groundBy)}:{}});return l?{kind:"surface",...l}:null}if(n.type==="line"){let l=Tn(e,n.filter,t,n.ground?r:void 0,o>0?o/e.extent:0,{level:i});return l?{kind:"line",...l,extent:e.extent}:null}if(n.type==="model"){let l=js(e,n.filter);return l?{kind:"placement",...l,extent:e.extent}:null}if(n.type==="symbol"){let l=xi(e,{filter:n.filter,textField:n.textField,iconImage:n.iconImage,iconRotate:n.iconRotate,textPlacement:n.textPlacement,abbreviate:n.abbreviate});return l?{kind:"symbol",...l,extent:e.extent}:null}let a=ln(e,e.extent,n.filter,{metersPerUnit:o>0?o/e.extent:0,cornerRadius:n.cornerRadius,cornerSegments:n.cornerSegments});return a?{kind:"fill-extrusion",vertices:a.vertices,indices:a.indices,featureIds:a.featureIds,vertexCount:a.vertexCount,indexCount:a.indexCount,extent:a.extent}:null}}function Od(n,e,t){let o=[];for(let r of n.features()){if(!Be(t,r.properties))continue;let i=r.properties[e];typeof i!="string"&&typeof i!="number"||o.includes(i)||o.push(i);}return o.sort((r,i)=>typeof r=="number"&&typeof i=="number"?r-i:String(r).localeCompare(String(i))),o}function zd(n,e){let t=[];for(let o of n.features()){if(!Be(e,o.properties))continue;let r=yt(o.properties);t.includes(r)||t.push(r);}return t.sort((o,r)=>o-r)}function Vd(n,e,t){let o=["==",e,t];return n?["all",n,o]:o}var _i='"use strict";(()=>{var ur=Object.create;var Kt=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var cr=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,ar=Object.prototype.hasOwnProperty;var hr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var pr=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of cr(e))!ar.call(t,i)&&i!==n&&Kt(t,i,{get:()=>e[i],enumerable:!(r=lr(e,i))||r.enumerable});return t};var mr=(t,e,n)=>(n=t!=null?ur(fr(t)):{},pr(e||!t||!t.__esModule?Kt(n,"default",{value:t,enumerable:!0}):n,t));var An=hr((Gt,Nt)=>{(function(t,e){typeof Gt=="object"&&typeof Nt<"u"?Nt.exports=e():typeof define=="function"&&define.amd?define(e):(t=typeof globalThis<"u"?globalThis:t||self,t.polygonClipping=e())})(Gt,function(){"use strict";function t(y,o){var u={label:0,sent:function(){if(h[0]&1)throw h[1];return h[1]},trys:[],ops:[]},f,p,h,S;return S={next:v(0),throw:v(1),return:v(2)},typeof Symbol=="function"&&(S[Symbol.iterator]=function(){return this}),S;function v(M){return function(V){return F([M,V])}}function F(M){if(f)throw new TypeError("Generator is already executing.");for(;u;)try{if(f=1,p&&(h=M[0]&2?p.return:M[0]?p.throw||((h=p.return)&&h.call(p),0):p.next)&&!(h=h.call(p,M[1])).done)return h;switch(p=0,h&&(M=[M[0]&2,h.value]),M[0]){case 0:case 1:h=M;break;case 4:return u.label++,{value:M[1],done:!1};case 5:u.label++,p=M[1],M=[0];continue;case 7:M=u.ops.pop(),u.trys.pop();continue;default:if(h=u.trys,!(h=h.length>0&&h[h.length-1])&&(M[0]===6||M[0]===2)){u=0;continue}if(M[0]===3&&(!h||M[1]>h[0]&&M[1]<h[3])){u.label=M[1];break}if(M[0]===6&&u.label<h[1]){u.label=h[1],h=M;break}if(h&&u.label<h[2]){u.label=h[2],u.ops.push(M);break}h[2]&&u.ops.pop(),u.trys.pop();continue}M=o.call(y,u)}catch(V){M=[6,V],p=0}finally{f=h=0}if(M[0]&5)throw M[1];return{value:M[0]?M[1]:void 0,done:!0}}}var e=function(){function y(o,u){this.next=null,this.key=o,this.data=u,this.left=null,this.right=null}return y}();function n(y,o){return y>o?1:y<o?-1:0}function r(y,o,u){for(var f=new e(null,null),p=f,h=f;;){var S=u(y,o.key);if(S<0){if(o.left===null)break;if(u(y,o.left.key)<0){var v=o.left;if(o.left=v.right,v.right=o,o=v,o.left===null)break}h.left=o,h=o,o=o.left}else if(S>0){if(o.right===null)break;if(u(y,o.right.key)>0){var v=o.right;if(o.right=v.left,v.left=o,o=v,o.right===null)break}p.right=o,p=o,o=o.right}else break}return p.right=o.left,h.left=o.right,o.left=f.right,o.right=f.left,o}function i(y,o,u,f){var p=new e(y,o);if(u===null)return p.left=p.right=null,p;u=r(y,u,f);var h=f(y,u.key);return h<0?(p.left=u.left,p.right=u,u.left=null):h>=0&&(p.right=u.right,p.left=u,u.right=null),p}function s(y,o,u){var f=null,p=null;if(o){o=r(y,o,u);var h=u(o.key,y);h===0?(f=o.left,p=o.right):h<0?(p=o.right,o.right=null,f=o):(f=o.left,o.left=null,p=o)}return{left:f,right:p}}function l(y,o,u){return o===null?y:(y===null||(o=r(y.key,o,u),o.left=y),o)}function c(y,o,u,f,p){if(y){f(""+o+(u?"\\u2514\\u2500\\u2500 ":"\\u251C\\u2500\\u2500 ")+p(y)+`\n`);var h=o+(u?" ":"\\u2502 ");y.left&&c(y.left,h,!1,f,p),y.right&&c(y.right,h,!0,f,p)}}var a=function(){function y(o){o===void 0&&(o=n),this._root=null,this._size=0,this._comparator=o}return y.prototype.insert=function(o,u){return this._size++,this._root=i(o,u,this._root,this._comparator)},y.prototype.add=function(o,u){var f=new e(o,u);this._root===null&&(f.left=f.right=null,this._size++,this._root=f);var p=this._comparator,h=r(o,this._root,p),S=p(o,h.key);return S===0?this._root=h:(S<0?(f.left=h.left,f.right=h,h.left=null):S>0&&(f.right=h.right,f.left=h,h.right=null),this._size++,this._root=f),this._root},y.prototype.remove=function(o){this._root=this._remove(o,this._root,this._comparator)},y.prototype._remove=function(o,u,f){var p;if(u===null)return null;u=r(o,u,f);var h=f(o,u.key);return h===0?(u.left===null?p=u.right:(p=r(o,u.left,f),p.right=u.right),this._size--,p):u},y.prototype.pop=function(){var o=this._root;if(o){for(;o.left;)o=o.left;return this._root=r(o.key,this._root,this._comparator),this._root=this._remove(o.key,this._root,this._comparator),{key:o.key,data:o.data}}return null},y.prototype.findStatic=function(o){for(var u=this._root,f=this._comparator;u;){var p=f(o,u.key);if(p===0)return u;p<0?u=u.left:u=u.right}return null},y.prototype.find=function(o){return this._root&&(this._root=r(o,this._root,this._comparator),this._comparator(o,this._root.key)!==0)?null:this._root},y.prototype.contains=function(o){for(var u=this._root,f=this._comparator;u;){var p=f(o,u.key);if(p===0)return!0;p<0?u=u.left:u=u.right}return!1},y.prototype.forEach=function(o,u){for(var f=this._root,p=[],h=!1;!h;)f!==null?(p.push(f),f=f.left):p.length!==0?(f=p.pop(),o.call(u,f),f=f.right):h=!0;return this},y.prototype.range=function(o,u,f,p){for(var h=[],S=this._comparator,v=this._root,F;h.length!==0||v;)if(v)h.push(v),v=v.left;else{if(v=h.pop(),F=S(v.key,u),F>0)break;if(S(v.key,o)>=0&&f.call(p,v))return this;v=v.right}return this},y.prototype.keys=function(){var o=[];return this.forEach(function(u){var f=u.key;return o.push(f)}),o},y.prototype.values=function(){var o=[];return this.forEach(function(u){var f=u.data;return o.push(f)}),o},y.prototype.min=function(){return this._root?this.minNode(this._root).key:null},y.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},y.prototype.minNode=function(o){if(o===void 0&&(o=this._root),o)for(;o.left;)o=o.left;return o},y.prototype.maxNode=function(o){if(o===void 0&&(o=this._root),o)for(;o.right;)o=o.right;return o},y.prototype.at=function(o){for(var u=this._root,f=!1,p=0,h=[];!f;)if(u)h.push(u),u=u.left;else if(h.length>0){if(u=h.pop(),p===o)return u;p++,u=u.right}else f=!0;return null},y.prototype.next=function(o){var u=this._root,f=null;if(o.right){for(f=o.right;f.left;)f=f.left;return f}for(var p=this._comparator;u;){var h=p(o.key,u.key);if(h===0)break;h<0?(f=u,u=u.left):u=u.right}return f},y.prototype.prev=function(o){var u=this._root,f=null;if(o.left!==null){for(f=o.left;f.right;)f=f.right;return f}for(var p=this._comparator;u;){var h=p(o.key,u.key);if(h===0)break;h<0?u=u.left:(f=u,u=u.right)}return f},y.prototype.clear=function(){return this._root=null,this._size=0,this},y.prototype.toList=function(){return g(this._root)},y.prototype.load=function(o,u,f){u===void 0&&(u=[]),f===void 0&&(f=!1);var p=o.length,h=this._comparator;if(f&&E(o,u,0,p-1,h),this._root===null)this._root=m(o,u,0,p),this._size=p;else{var S=b(this.toList(),x(o,u),h);p=this._size+p,this._root=d({head:S},0,p)}return this},y.prototype.isEmpty=function(){return this._root===null},Object.defineProperty(y.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(y.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),y.prototype.toString=function(o){o===void 0&&(o=function(f){return String(f.key)});var u=[];return c(this._root,"",!0,function(f){return u.push(f)},o),u.join("")},y.prototype.update=function(o,u,f){var p=this._comparator,h=s(o,this._root,p),S=h.left,v=h.right;p(o,u)<0?v=i(u,f,v,p):S=i(u,f,S,p),this._root=l(S,v,p)},y.prototype.split=function(o){return s(o,this._root,this._comparator)},y.prototype[Symbol.iterator]=function(){var o,u,f;return t(this,function(p){switch(p.label){case 0:o=this._root,u=[],f=!1,p.label=1;case 1:return f?[3,6]:o===null?[3,2]:(u.push(o),o=o.left,[3,5]);case 2:return u.length===0?[3,4]:(o=u.pop(),[4,o]);case 3:return p.sent(),o=o.right,[3,5];case 4:f=!0,p.label=5;case 5:return[3,1];case 6:return[2]}})},y}();function m(y,o,u,f){var p=f-u;if(p>0){var h=u+Math.floor(p/2),S=y[h],v=o[h],F=new e(S,v);return F.left=m(y,o,u,h),F.right=m(y,o,h+1,f),F}return null}function x(y,o){for(var u=new e(null,null),f=u,p=0;p<y.length;p++)f=f.next=new e(y[p],o[p]);return f.next=null,u.next}function g(y){for(var o=y,u=[],f=!1,p=new e(null,null),h=p;!f;)o?(u.push(o),o=o.left):u.length>0?(o=h=h.next=u.pop(),o=o.right):f=!0;return h.next=null,p.next}function d(y,o,u){var f=u-o;if(f>0){var p=o+Math.floor(f/2),h=d(y,o,p),S=y.head;return S.left=h,y.head=y.head.next,S.right=d(y,p+1,u),S}return null}function b(y,o,u){for(var f=new e(null,null),p=f,h=y,S=o;h!==null&&S!==null;)u(h.key,S.key)<0?(p.next=h,h=h.next):(p.next=S,S=S.next),p=p.next;return h!==null?p.next=h:S!==null&&(p.next=S),f.next}function E(y,o,u,f,p){if(!(u>=f)){for(var h=y[u+f>>1],S=u-1,v=f+1;;){do S++;while(p(y[S],h)<0);do v--;while(p(y[v],h)>0);if(S>=v)break;var F=y[S];y[S]=y[v],y[v]=F,F=o[S],o[S]=o[v],o[v]=F}E(y,o,u,v,p),E(y,o,v+1,f,p)}}let A=(y,o)=>y.ll.x<=o.x&&o.x<=y.ur.x&&y.ll.y<=o.y&&o.y<=y.ur.y,_=(y,o)=>{if(o.ur.x<y.ll.x||y.ur.x<o.ll.x||o.ur.y<y.ll.y||y.ur.y<o.ll.y)return null;let u=y.ll.x<o.ll.x?o.ll.x:y.ll.x,f=y.ur.x<o.ur.x?y.ur.x:o.ur.x,p=y.ll.y<o.ll.y?o.ll.y:y.ll.y,h=y.ur.y<o.ur.y?y.ur.y:o.ur.y;return{ll:{x:u,y:p},ur:{x:f,y:h}}},R=Number.EPSILON;R===void 0&&(R=Math.pow(2,-52));let L=R*R,k=(y,o)=>{if(-R<y&&y<R&&-R<o&&o<R)return 0;let u=y-o;return u*u<L*y*o?0:y<o?-1:1};class T{constructor(){this.reset()}reset(){this.xRounder=new O,this.yRounder=new O}round(o,u){return{x:this.xRounder.round(o),y:this.yRounder.round(u)}}}class O{constructor(){this.tree=new a,this.round(0)}round(o){let u=this.tree.add(o),f=this.tree.prev(u);if(f!==null&&k(u.key,f.key)===0)return this.tree.remove(o),f.key;let p=this.tree.next(u);return p!==null&&k(u.key,p.key)===0?(this.tree.remove(o),p.key):o}}let D=new T,U=11102230246251565e-32,P=134217729,C=(3+8*U)*U;function Y(y,o,u,f,p){let h,S,v,F,M=o[0],V=f[0],w=0,I=0;V>M==V>-M?(h=M,M=o[++w]):(h=V,V=f[++I]);let B=0;if(w<y&&I<u)for(V>M==V>-M?(S=M+h,v=h-(S-M),M=o[++w]):(S=V+h,v=h-(S-V),V=f[++I]),h=S,v!==0&&(p[B++]=v);w<y&&I<u;)V>M==V>-M?(S=h+M,F=S-h,v=h-(S-F)+(M-F),M=o[++w]):(S=h+V,F=S-h,v=h-(S-F)+(V-F),V=f[++I]),h=S,v!==0&&(p[B++]=v);for(;w<y;)S=h+M,F=S-h,v=h-(S-F)+(M-F),M=o[++w],h=S,v!==0&&(p[B++]=v);for(;I<u;)S=h+V,F=S-h,v=h-(S-F)+(V-F),V=f[++I],h=S,v!==0&&(p[B++]=v);return(h!==0||B===0)&&(p[B++]=h),B}function Q(y,o){let u=o[0];for(let f=1;f<y;f++)u+=o[f];return u}function Z(y){return new Float64Array(y)}let re=(3+16*U)*U,X=(2+12*U)*U,$=(9+64*U)*U*U,z=Z(4),N=Z(8),q=Z(12),te=Z(16),K=Z(4);function oe(y,o,u,f,p,h,S){let v,F,M,V,w,I,B,H,G,W,j,ne,ae,ue,he,pe,ge,me,Se=y-p,Ee=u-p,Me=o-h,Re=f-h;ue=Se*Re,I=P*Se,B=I-(I-Se),H=Se-B,I=P*Re,G=I-(I-Re),W=Re-G,he=H*W-(ue-B*G-H*G-B*W),pe=Me*Ee,I=P*Me,B=I-(I-Me),H=Me-B,I=P*Ee,G=I-(I-Ee),W=Ee-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,z[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,z[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,z[2]=ne-(me-w)+(j-w),z[3]=me;let ke=Q(4,z),Je=X*S;if(ke>=Je||-ke>=Je||(w=y-Se,v=y-(Se+w)+(w-p),w=u-Ee,M=u-(Ee+w)+(w-p),w=o-Me,F=o-(Me+w)+(w-h),w=f-Re,V=f-(Re+w)+(w-h),v===0&&F===0&&M===0&&V===0)||(Je=$*S+C*Math.abs(ke),ke+=Se*V+Re*v-(Me*M+Ee*F),ke>=Je||-ke>=Je))return ke;ue=v*Re,I=P*v,B=I-(I-v),H=v-B,I=P*Re,G=I-(I-Re),W=Re-G,he=H*W-(ue-B*G-H*G-B*W),pe=F*Ee,I=P*F,B=I-(I-F),H=F-B,I=P*Ee,G=I-(I-Ee),W=Ee-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,K[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,K[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,K[2]=ne-(me-w)+(j-w),K[3]=me;let ir=Y(4,z,4,K,N);ue=Se*V,I=P*Se,B=I-(I-Se),H=Se-B,I=P*V,G=I-(I-V),W=V-G,he=H*W-(ue-B*G-H*G-B*W),pe=Me*M,I=P*Me,B=I-(I-Me),H=Me-B,I=P*M,G=I-(I-M),W=M-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,K[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,K[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,K[2]=ne-(me-w)+(j-w),K[3]=me;let or=Y(ir,N,4,K,q);ue=v*V,I=P*v,B=I-(I-v),H=v-B,I=P*V,G=I-(I-V),W=V-G,he=H*W-(ue-B*G-H*G-B*W),pe=F*M,I=P*F,B=I-(I-F),H=F-B,I=P*M,G=I-(I-M),W=M-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,K[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,K[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,K[2]=ne-(me-w)+(j-w),K[3]=me;let sr=Y(or,q,4,K,te);return te[sr-1]}function ee(y,o,u,f,p,h){let S=(o-h)*(u-p),v=(y-p)*(f-h),F=S-v,M=Math.abs(S+v);return Math.abs(F)>=re*M?F:-oe(y,o,u,f,p,h,M)}let J=(y,o)=>y.x*o.y-y.y*o.x,fe=(y,o)=>y.x*o.x+y.y*o.y,be=(y,o,u)=>{let f=ee(y.x,y.y,o.x,o.y,u.x,u.y);return f>0?-1:f<0?1:0},de=y=>Math.sqrt(fe(y,y)),Fe=(y,o,u)=>{let f={x:o.x-y.x,y:o.y-y.y},p={x:u.x-y.x,y:u.y-y.y};return J(p,f)/de(p)/de(f)},Ce=(y,o,u)=>{let f={x:o.x-y.x,y:o.y-y.y},p={x:u.x-y.x,y:u.y-y.y};return fe(p,f)/de(p)/de(f)},Le=(y,o,u)=>o.y===0?null:{x:y.x+o.x/o.y*(u-y.y),y:u},Ve=(y,o,u)=>o.x===0?null:{x:u,y:y.y+o.y/o.x*(u-y.x)},we=(y,o,u,f)=>{if(o.x===0)return Ve(u,f,y.x);if(f.x===0)return Ve(y,o,u.x);if(o.y===0)return Le(u,f,y.y);if(f.y===0)return Le(y,o,u.y);let p=J(o,f);if(p==0)return null;let h={x:u.x-y.x,y:u.y-y.y},S=J(h,o)/p,v=J(h,f)/p,F=y.x+v*o.x,M=u.x+S*f.x,V=y.y+v*o.y,w=u.y+S*f.y,I=(F+M)/2,B=(V+w)/2;return{x:I,y:B}};class se{static compare(o,u){let f=se.comparePoints(o.point,u.point);return f!==0?f:(o.point!==u.point&&o.link(u),o.isLeft!==u.isLeft?o.isLeft?1:-1:xe.compare(o.segment,u.segment))}static comparePoints(o,u){return o.x<u.x?-1:o.x>u.x?1:o.y<u.y?-1:o.y>u.y?1:0}constructor(o,u){o.events===void 0?o.events=[this]:o.events.push(this),this.point=o,this.isLeft=u}link(o){if(o.point===this.point)throw new Error("Tried to link already linked events");let u=o.point.events;for(let f=0,p=u.length;f<p;f++){let h=u[f];this.point.events.push(h),h.point=this.point}this.checkForConsuming()}checkForConsuming(){let o=this.point.events.length;for(let u=0;u<o;u++){let f=this.point.events[u];if(f.segment.consumedBy===void 0)for(let p=u+1;p<o;p++){let h=this.point.events[p];h.consumedBy===void 0&&f.otherSE.point.events===h.otherSE.point.events&&f.segment.consume(h.segment)}}}getAvailableLinkedEvents(){let o=[];for(let u=0,f=this.point.events.length;u<f;u++){let p=this.point.events[u];p!==this&&!p.segment.ringOut&&p.segment.isInResult()&&o.push(p)}return o}getLeftmostComparator(o){let u=new Map,f=p=>{let h=p.otherSE;u.set(p,{sine:Fe(this.point,o.point,h.point),cosine:Ce(this.point,o.point,h.point)})};return(p,h)=>{u.has(p)||f(p),u.has(h)||f(h);let{sine:S,cosine:v}=u.get(p),{sine:F,cosine:M}=u.get(h);return S>=0&&F>=0?v<M?1:v>M?-1:0:S<0&&F<0?v<M?-1:v>M?1:0:F<S?-1:F>S?1:0}}}let Pe=0;class xe{static compare(o,u){let f=o.leftSE.point.x,p=u.leftSE.point.x,h=o.rightSE.point.x,S=u.rightSE.point.x;if(S<f)return 1;if(h<p)return-1;let v=o.leftSE.point.y,F=u.leftSE.point.y,M=o.rightSE.point.y,V=u.rightSE.point.y;if(f<p){if(F<v&&F<M)return 1;if(F>v&&F>M)return-1;let w=o.comparePoint(u.leftSE.point);if(w<0)return 1;if(w>0)return-1;let I=u.comparePoint(o.rightSE.point);return I!==0?I:-1}if(f>p){if(v<F&&v<V)return-1;if(v>F&&v>V)return 1;let w=u.comparePoint(o.leftSE.point);if(w!==0)return w;let I=o.comparePoint(u.rightSE.point);return I<0?1:I>0?-1:1}if(v<F)return-1;if(v>F)return 1;if(h<S){let w=u.comparePoint(o.rightSE.point);if(w!==0)return w}if(h>S){let w=o.comparePoint(u.rightSE.point);if(w<0)return 1;if(w>0)return-1}if(h!==S){let w=M-v,I=h-f,B=V-F,H=S-p;if(w>I&&B<H)return 1;if(w<I&&B>H)return-1}return h>S?1:h<S||M<V?-1:M>V?1:o.id<u.id?-1:o.id>u.id?1:0}constructor(o,u,f,p){this.id=++Pe,this.leftSE=o,o.segment=this,o.otherSE=u,this.rightSE=u,u.segment=this,u.otherSE=o,this.rings=f,this.windings=p}static fromRing(o,u,f){let p,h,S,v=se.comparePoints(o,u);if(v<0)p=o,h=u,S=1;else if(v>0)p=u,h=o,S=-1;else throw new Error(`Tried to create degenerate segment at [${o.x}, ${o.y}]`);let F=new se(p,!0),M=new se(h,!1);return new xe(F,M,[f],[S])}replaceRightSE(o){this.rightSE=o,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){let o=this.leftSE.point.y,u=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:o<u?o:u},ur:{x:this.rightSE.point.x,y:o>u?o:u}}}vector(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}isAnEndpoint(o){return o.x===this.leftSE.point.x&&o.y===this.leftSE.point.y||o.x===this.rightSE.point.x&&o.y===this.rightSE.point.y}comparePoint(o){if(this.isAnEndpoint(o))return 0;let u=this.leftSE.point,f=this.rightSE.point,p=this.vector();if(u.x===f.x)return o.x===u.x?0:o.x<u.x?1:-1;let h=(o.y-u.y)/p.y,S=u.x+h*p.x;if(o.x===S)return 0;let v=(o.x-u.x)/p.x,F=u.y+v*p.y;return o.y===F?0:o.y<F?-1:1}getIntersection(o){let u=this.bbox(),f=o.bbox(),p=_(u,f);if(p===null)return null;let h=this.leftSE.point,S=this.rightSE.point,v=o.leftSE.point,F=o.rightSE.point,M=A(u,v)&&this.comparePoint(v)===0,V=A(f,h)&&o.comparePoint(h)===0,w=A(u,F)&&this.comparePoint(F)===0,I=A(f,S)&&o.comparePoint(S)===0;if(V&&M)return I&&!w?S:!I&&w?F:null;if(V)return w&&h.x===F.x&&h.y===F.y?null:h;if(M)return I&&S.x===v.x&&S.y===v.y?null:v;if(I&&w)return null;if(I)return S;if(w)return F;let B=we(h,this.vector(),v,o.vector());return B===null||!A(p,B)?null:D.round(B.x,B.y)}split(o){let u=[],f=o.events!==void 0,p=new se(o,!0),h=new se(o,!1),S=this.rightSE;this.replaceRightSE(h),u.push(h),u.push(p);let v=new xe(p,S,this.rings.slice(),this.windings.slice());return se.comparePoints(v.leftSE.point,v.rightSE.point)>0&&v.swapEvents(),se.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),f&&(p.checkForConsuming(),h.checkForConsuming()),u}swapEvents(){let o=this.rightSE;this.rightSE=this.leftSE,this.leftSE=o,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let u=0,f=this.windings.length;u<f;u++)this.windings[u]*=-1}consume(o){let u=this,f=o;for(;u.consumedBy;)u=u.consumedBy;for(;f.consumedBy;)f=f.consumedBy;let p=xe.compare(u,f);if(p!==0){if(p>0){let h=u;u=f,f=h}if(u.prev===f){let h=u;u=f,f=h}for(let h=0,S=f.rings.length;h<S;h++){let v=f.rings[h],F=f.windings[h],M=u.rings.indexOf(v);M===-1?(u.rings.push(v),u.windings.push(F)):u.windings[M]+=F}f.rings=null,f.windings=null,f.consumedBy=u,f.leftSE.consumedBy=u.leftSE,f.rightSE.consumedBy=u.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{let o=this.prev.consumedBy||this.prev;this._beforeState=o.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;let o=this.beforeState();this._afterState={rings:o.rings.slice(0),windings:o.windings.slice(0),multiPolys:[]};let u=this._afterState.rings,f=this._afterState.windings,p=this._afterState.multiPolys;for(let v=0,F=this.rings.length;v<F;v++){let M=this.rings[v],V=this.windings[v],w=u.indexOf(M);w===-1?(u.push(M),f.push(V)):f[w]+=V}let h=[],S=[];for(let v=0,F=u.length;v<F;v++){if(f[v]===0)continue;let M=u[v],V=M.poly;if(S.indexOf(V)===-1)if(M.isExterior)h.push(V);else{S.indexOf(V)===-1&&S.push(V);let w=h.indexOf(M.poly);w!==-1&&h.splice(w,1)}}for(let v=0,F=h.length;v<F;v++){let M=h[v].multiPoly;p.indexOf(M)===-1&&p.push(M)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;let o=this.beforeState().multiPolys,u=this.afterState().multiPolys;switch(ve.type){case"union":{let f=o.length===0,p=u.length===0;this._isInResult=f!==p;break}case"intersection":{let f,p;o.length<u.length?(f=o.length,p=u.length):(f=u.length,p=o.length),this._isInResult=p===ve.numMultiPolys&&f<p;break}case"xor":{let f=Math.abs(o.length-u.length);this._isInResult=f%2===1;break}case"difference":{let f=p=>p.length===1&&p[0].isSubject;this._isInResult=f(o)!==f(u);break}default:throw new Error(`Unrecognized operation type found ${ve.type}`)}return this._isInResult}}class Be{constructor(o,u,f){if(!Array.isArray(o)||o.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=u,this.isExterior=f,this.segments=[],typeof o[0][0]!="number"||typeof o[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let p=D.round(o[0][0],o[0][1]);this.bbox={ll:{x:p.x,y:p.y},ur:{x:p.x,y:p.y}};let h=p;for(let S=1,v=o.length;S<v;S++){if(typeof o[S][0]!="number"||typeof o[S][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let F=D.round(o[S][0],o[S][1]);F.x===h.x&&F.y===h.y||(this.segments.push(xe.fromRing(h,F,this)),F.x<this.bbox.ll.x&&(this.bbox.ll.x=F.x),F.y<this.bbox.ll.y&&(this.bbox.ll.y=F.y),F.x>this.bbox.ur.x&&(this.bbox.ur.x=F.x),F.y>this.bbox.ur.y&&(this.bbox.ur.y=F.y),h=F)}(p.x!==h.x||p.y!==h.y)&&this.segments.push(xe.fromRing(h,p,this))}getSweepEvents(){let o=[];for(let u=0,f=this.segments.length;u<f;u++){let p=this.segments[u];o.push(p.leftSE),o.push(p.rightSE)}return o}}class Oe{constructor(o,u){if(!Array.isArray(o))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new Be(o[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let f=1,p=o.length;f<p;f++){let h=new Be(o[f],this,!1);h.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=h.bbox.ll.x),h.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=h.bbox.ll.y),h.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=h.bbox.ur.x),h.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=h.bbox.ur.y),this.interiorRings.push(h)}this.multiPoly=u}getSweepEvents(){let o=this.exteriorRing.getSweepEvents();for(let u=0,f=this.interiorRings.length;u<f;u++){let p=this.interiorRings[u].getSweepEvents();for(let h=0,S=p.length;h<S;h++)o.push(p[h])}return o}}class De{constructor(o,u){if(!Array.isArray(o))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof o[0][0][0]=="number"&&(o=[o])}catch{}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(let f=0,p=o.length;f<p;f++){let h=new Oe(o[f],this);h.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=h.bbox.ll.x),h.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=h.bbox.ll.y),h.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=h.bbox.ur.x),h.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=h.bbox.ur.y),this.polys.push(h)}this.isSubject=u}getSweepEvents(){let o=[];for(let u=0,f=this.polys.length;u<f;u++){let p=this.polys[u].getSweepEvents();for(let h=0,S=p.length;h<S;h++)o.push(p[h])}return o}}class Ie{static factory(o){let u=[];for(let f=0,p=o.length;f<p;f++){let h=o[f];if(!h.isInResult()||h.ringOut)continue;let S=null,v=h.leftSE,F=h.rightSE,M=[v],V=v.point,w=[];for(;S=v,v=F,M.push(v),v.point!==V;)for(;;){let I=v.getAvailableLinkedEvents();if(I.length===0){let G=M[0].point,W=M[M.length-1].point;throw new Error(`Unable to complete output ring starting at [${G.x}, ${G.y}]. Last matching segment found ends at [${W.x}, ${W.y}].`)}if(I.length===1){F=I[0].otherSE;break}let B=null;for(let G=0,W=w.length;G<W;G++)if(w[G].point===v.point){B=G;break}if(B!==null){let G=w.splice(B)[0],W=M.splice(G.index);W.unshift(W[0].otherSE),u.push(new Ie(W.reverse()));continue}w.push({index:M.length,point:v.point});let H=v.getLeftmostComparator(S);F=I.sort(H)[0].otherSE;break}u.push(new Ie(M))}return u}constructor(o){this.events=o;for(let u=0,f=o.length;u<f;u++)o[u].segment.ringOut=this;this.poly=null}getGeom(){let o=this.events[0].point,u=[o];for(let M=1,V=this.events.length-1;M<V;M++){let w=this.events[M].point,I=this.events[M+1].point;be(w,o,I)!==0&&(u.push(w),o=w)}if(u.length===1)return null;let f=u[0],p=u[1];be(f,o,p)===0&&u.shift(),u.push(u[0]);let h=this.isExteriorRing()?1:-1,S=this.isExteriorRing()?0:u.length-1,v=this.isExteriorRing()?u.length:-1,F=[];for(let M=S;M!=v;M+=h)F.push([u[M].x,u[M].y]);return F}isExteriorRing(){if(this._isExteriorRing===void 0){let o=this.enclosingRing();this._isExteriorRing=o?!o.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let o=this.events[0];for(let p=1,h=this.events.length;p<h;p++){let S=this.events[p];se.compare(o,S)>0&&(o=S)}let u=o.segment.prevInResult(),f=u?u.prevInResult():null;for(;;){if(!u)return null;if(!f)return u.ringOut;if(f.ringOut!==u.ringOut)return f.ringOut.enclosingRing()!==u.ringOut?u.ringOut:u.ringOut.enclosingRing();u=f.prevInResult(),f=u?u.prevInResult():null}}}class ze{constructor(o){this.exteriorRing=o,o.poly=this,this.interiorRings=[]}addInterior(o){this.interiorRings.push(o),o.poly=this}getGeom(){let o=[this.exteriorRing.getGeom()];if(o[0]===null)return null;for(let u=0,f=this.interiorRings.length;u<f;u++){let p=this.interiorRings[u].getGeom();p!==null&&o.push(p)}return o}}class vt{constructor(o){this.rings=o,this.polys=this._composePolys(o)}getGeom(){let o=[];for(let u=0,f=this.polys.length;u<f;u++){let p=this.polys[u].getGeom();p!==null&&o.push(p)}return o}_composePolys(o){let u=[];for(let f=0,p=o.length;f<p;f++){let h=o[f];if(!h.poly)if(h.isExteriorRing())u.push(new ze(h));else{let S=h.enclosingRing();S.poly||u.push(new ze(S)),S.poly.addInterior(h)}}return u}}class ft{constructor(o){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe.compare;this.queue=o,this.tree=new a(u),this.segments=[]}process(o){let u=o.segment,f=[];if(o.consumedBy)return o.isLeft?this.queue.remove(o.otherSE):this.tree.remove(u),f;let p=o.isLeft?this.tree.add(u):this.tree.find(u);if(!p)throw new Error(`Unable to find segment #${u.id} [${u.leftSE.point.x}, ${u.leftSE.point.y}] -> [${u.rightSE.point.x}, ${u.rightSE.point.y}] in SweepLine tree.`);let h=p,S=p,v,F;for(;v===void 0;)h=this.tree.prev(h),h===null?v=null:h.key.consumedBy===void 0&&(v=h.key);for(;F===void 0;)S=this.tree.next(S),S===null?F=null:S.key.consumedBy===void 0&&(F=S.key);if(o.isLeft){let M=null;if(v){let w=v.getIntersection(u);if(w!==null&&(u.isAnEndpoint(w)||(M=w),!v.isAnEndpoint(w))){let I=this._splitSafely(v,w);for(let B=0,H=I.length;B<H;B++)f.push(I[B])}}let V=null;if(F){let w=F.getIntersection(u);if(w!==null&&(u.isAnEndpoint(w)||(V=w),!F.isAnEndpoint(w))){let I=this._splitSafely(F,w);for(let B=0,H=I.length;B<H;B++)f.push(I[B])}}if(M!==null||V!==null){let w=null;M===null?w=V:V===null?w=M:w=se.comparePoints(M,V)<=0?M:V,this.queue.remove(u.rightSE),f.push(u.rightSE);let I=u.split(w);for(let B=0,H=I.length;B<H;B++)f.push(I[B])}f.length>0?(this.tree.remove(u),f.push(o)):(this.segments.push(u),u.prev=v)}else{if(v&&F){let M=v.getIntersection(F);if(M!==null){if(!v.isAnEndpoint(M)){let V=this._splitSafely(v,M);for(let w=0,I=V.length;w<I;w++)f.push(V[w])}if(!F.isAnEndpoint(M)){let V=this._splitSafely(F,M);for(let w=0,I=V.length;w<I;w++)f.push(V[w])}}}this.tree.remove(u)}return f}_splitSafely(o,u){this.tree.remove(o);let f=o.rightSE;this.queue.remove(f);let p=o.split(u);return p.push(f),o.consumedBy===void 0&&this.tree.add(o),p}}let Qt=typeof process<"u"&&process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,tr=typeof process<"u"&&process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6;class nr{run(o,u,f){ve.type=o,D.reset();let p=[new De(u,!0)];for(let w=0,I=f.length;w<I;w++)p.push(new De(f[w],!1));if(ve.numMultiPolys=p.length,ve.type==="difference"){let w=p[0],I=1;for(;I<p.length;)_(p[I].bbox,w.bbox)!==null?I++:p.splice(I,1)}if(ve.type==="intersection")for(let w=0,I=p.length;w<I;w++){let B=p[w];for(let H=w+1,G=p.length;H<G;H++)if(_(B.bbox,p[H].bbox)===null)return[]}let h=new a(se.compare);for(let w=0,I=p.length;w<I;w++){let B=p[w].getSweepEvents();for(let H=0,G=B.length;H<G;H++)if(h.insert(B[H]),h.size>Qt)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).")}let S=new ft(h),v=h.size,F=h.pop();for(;F;){let w=F.key;if(h.size===v){let B=w.segment;throw new Error(`Unable to pop() ${w.isLeft?"left":"right"} SweepEvent [${w.point.x}, ${w.point.y}] from segment #${B.id} [${B.leftSE.point.x}, ${B.leftSE.point.y}] -> [${B.rightSE.point.x}, ${B.rightSE.point.y}] from queue.`)}if(h.size>Qt)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");if(S.segments.length>tr)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");let I=S.process(w);for(let B=0,H=I.length;B<H;B++){let G=I[B];G.consumedBy===void 0&&h.insert(G)}v=h.size,F=h.pop()}D.reset();let M=Ie.factory(S.segments);return new vt(M).getGeom()}}let ve=new nr;var rr={union:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("union",y,u)},intersection:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("intersection",y,u)},xor:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("xor",y,u)},difference:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("difference",y,u)}};return rr})});var nt=new Set,St=!1;function Te(t,e,n=2){let r=e&&e.length,i=r?e[0]*n:t.length;nt.size&&nt.clear();let s=tn(t,0,i,n,!0),l=[];if(!s||s.next===s.prev)return l;let c=0,a=0,m=0;if(r&&(s=br(t,e,s,n)),t.length>80*n){c=t[0],a=t[1];let x=c,g=a;for(let d=n;d<i;d+=n){let b=t[d],E=t[d+1];b<c&&(c=b),E<a&&(a=E),b>x&&(x=b),E>g&&(g=E)}m=Math.max(x-c,g-a),m=m!==0?32767/m:0}return Et(s,l,c,a,m),l}function tn(t,e,n,r,i){let s=null;if(i===Lr(t,e,n,r)>0)for(let l=e;l<n;l+=r)s=en(l/r|0,t[l],t[l+1],s);else for(let l=n-r;l>=e;l-=r)s=en(l/r|0,t[l],t[l+1],s);return s&&rt(s,s.next)&&(ot(s),s=s.next),s}function Ge(t,e=t){let n=e===t,r=t,i;do i=!1,r!==r.next&&(nt.size===0||!nt.has(r))&&(rt(r,r.next)||le(r.prev,r,r.next)===0)?((n||r===e)&&(e=r.prev),St=!0,ot(r),r=r.prev,i=!0):(n||r!==e)&&(r=r.next,i=!n);while(i||r!==e);return e}function Et(t,e,n,r,i){i&&Fr(t,n,r,i);let s=t,l=!1;for(;t.prev!==t.next;){let c=t.prev,a=t.next;if(le(c,t,a)<0&&(i?dr(t,n,r,i):xr(t))){e.push(c.i,t.i,a.i),ot(t),t=a,s=a;continue}if(t=a,t===s){if(St=!1,t=Ge(t),St){s=t;continue}if(!l){t=gr(t,e),s=t,l=!0;continue}yr(t,e,n,r,i);break}}}function xr(t){let e=t.prev,n=t,r=t.next,i=e.x,s=n.x,l=r.x,c=e.y,a=n.y,m=r.y,x=Math.min(i,s,l),g=Math.min(c,a,m),d=Math.max(i,s,l),b=Math.max(c,a,m),E=r.next;for(;E!==e;){if(E.x>=x&&E.x<=d&&E.y>=g&&E.y<=b&&!(i===E.x&&c===E.y)&&mt(i,c,s,a,l,m,E.x,E.y)&&le(E.prev,E,E.next)>=0)return!1;E=E.next}return!0}function dr(t,e,n,r){let i=t.prev,s=t,l=t.next,c=i.x,a=s.x,m=l.x,x=i.y,g=s.y,d=l.y,b=Math.min(c,a,m),E=Math.min(x,g,d),A=Math.max(c,a,m),_=Math.max(x,g,d),R=It(b,E,e,n,r),L=It(A,_,e,n,r),k=t.prevZ;for(;k&&k.z>=R;){if(k.x>=b&&k.x<=A&&k.y>=E&&k.y<=_&&k!==l&&!(c===k.x&&x===k.y)&&mt(c,x,a,g,m,d,k.x,k.y)&&le(k.prev,k,k.next)>=0)return!1;k=k.prevZ}let T=t.nextZ;for(;T&&T.z<=L;){if(T.x>=b&&T.x<=A&&T.y>=E&&T.y<=_&&T!==l&&!(c===T.x&&x===T.y)&&mt(c,x,a,g,m,d,T.x,T.y)&&le(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function gr(t,e){let n=t,r=!1;do{let i=n.prev,s=n.next.next;on(i,n,n.next,s,!1)&&it(i,s)&&it(s,i)&&(e.push(i.i,n.i,s.i),ot(n),ot(n.next),n=t=s,r=!0),n=n.next}while(n!==t);return r?Ge(n):n}function yr(t,e,n,r,i){let s=t;do{let l=s.next.next;for(;l!==s.prev;){if(s.i!==l.i&&kr(s,l)){let c=sn(s,l);s=Ge(s,s.next),c=Ge(c,c.next),Et(s,e,n,r,i),Et(c,e,n,r,i);return}l=l.next}s=s.next}while(s!==t)}var Mt=!1;function br(t,e,n,r){let i=[];for(let s=0,l=e.length;s<l;s++){let c=e[s]*r,a=s<l-1?e[s+1]*r:t.length,m=tn(t,c,a,r,!1);m===m.next&&nt.add(m),i.push(Pr(m))}i.sort(wr),Sr(t.length/r,e.length),rn(n,n),Mt=!0;for(let s=0;s<i.length;s++)n=vr(i[s],n);return Mt=!1,Ge(n)}function wr(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function vr(t,e){let n=Mr(t,e);if(!n)return e;let r=sn(n,t),i=r.next;return rn(n,i.next),Ge(r,r.next),Ge(n,n.next)}var nn=16,ie=new Float64Array(0),pt=0,Rt=[],Ft=[];function Sr(t,e){let n=Math.ceil((t+2*e)/nn)+e+2;ie.length<n*4&&(ie=new Float64Array(n*4)),pt=0}function rn(t,e){let n=t;do{let r=pt++;Rt[r]=n;let i=1/0,s=1/0,l=-1/0,c=-1/0,a=0;do{let x=n.next;n.z=r,n.x<i&&(i=n.x),n.x>l&&(l=n.x),n.y<s&&(s=n.y),n.y>c&&(c=n.y),x.x<i&&(i=x.x),x.x>l&&(l=x.x),x.y<s&&(s=x.y),x.y>c&&(c=x.y),n=x}while(++a<nn&&n!==e);Ft[r]=n;let m=r*4;ie[m]=i,ie[m+1]=s,ie[m+2]=l,ie[m+3]=c}while(n!==e)}function Er(t,e){let n=t.z*4;e.x<ie[n]&&(ie[n]=e.x),e.y<ie[n+1]&&(ie[n+1]=e.y),e.x>ie[n+2]&&(ie[n+2]=e.x),e.y>ie[n+3]&&(ie[n+3]=e.y)}function Jt(t){let e=Ft[t];for(;e.prev.next!==e;)e=e.next;return Ft[t]=e,e}function qt(t){let e=Rt[t];for(;e.prev.next!==e;)e=e.next;return Rt[t]=e,e}function Mr(t,e){let n=e,r=t.x,i=t.y,s=-1/0,l;if(rt(t,n))return n;for(let d=0,b=0;d<pt;d++,b+=4){if(i<ie[b+1]||i>ie[b+3]||ie[b]>r||ie[b+2]<=s)continue;let E=Jt(d);n=qt(d);do{if(n.prev.next===n){if(rt(t,n.next))return n.next;if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){let A=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(A<=r&&A>s&&(s=A,l=n.x<n.next.x?n:n.next,A===r))return l}}n=n.next}while(n!==E)}if(!l)return null;let c=l.x,a=l.y,m=Math.min(i,a),x=Math.max(i,a),g=1/0;for(let d=0,b=0;d<pt;d++,b+=4){if(ie[b+2]<c||ie[b]>r||ie[b+3]<m||ie[b+1]>x)continue;let E=Jt(d);n=qt(d);do{if(n.prev.next===n&&r>=n.x&&n.x>=c&&r!==n.x&&mt(i<a?r:s,i,c,a,i<a?s:r,i,n.x,n.y)){let A=Math.abs(i-n.y)/(r-n.x);(it(n,t)||n.y===i&&n.next.y===i&&n.next.x>r)&&(A<g||A===g&&(n.x>l.x||n.x===l.x&&Rr(l,n)))&&(l=n,g=A)}n=n.next}while(n!==E)}return l}function Rr(t,e){return le(t.prev,t,e.prev)<0&&le(e.next,t,t.next)<0}var ye=[],qe=[],Ue=new Uint32Array(0),et=new Uint32Array(0),tt=new Uint32Array(256);function Fr(t,e,n,r){let i=t,s=0;do i.z=It(i.x,i.y,e,n,r),ye[s++]=i,i=i.next;while(i!==t);Ir(s);let l=null;for(let c=0;c<s;c++){let a=ye[c];a.prevZ=l,l&&(l.nextZ=a),l=a}l.nextZ=null}function Ir(t){if(t<=32){for(let e=1;e<t;e++){let n=ye[e],r=n.z,i=e-1;for(;i>=0&&ye[i].z>r;)ye[i+1]=ye[i],i--;ye[i+1]=n}return}Ue.length<t&&(Ue=new Uint32Array(t),et=new Uint32Array(t),qe=new Array(t));for(let e=0;e<t;e++)Ue[e]=ye[e].z;at(t,ye,Ue,qe,et,0),at(t,qe,et,ye,Ue,8),at(t,ye,Ue,qe,et,16),at(t,qe,et,ye,Ue,24)}function at(t,e,n,r,i,s){tt.fill(0);for(let c=0;c<t;c++)tt[n[c]>>>s&255]++;let l=0;for(let c=0;c<256;c++){let a=tt[c];tt[c]=l,l+=a}for(let c=0;c<t;c++){let a=n[c],m=tt[a>>>s&255]++;r[m]=e[c],i[m]=a}}function It(t,e,n,r,i){return t=(t-n)*i|0,e=(e-r)*i|0,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t|e<<1}function Pr(t){let e=t,n=t;do(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next;while(e!==t);return n}function mt(t,e,n,r,i,s,l,c){return(i-l)*(e-c)>=(t-l)*(s-c)&&(t-l)*(r-c)>=(n-l)*(e-c)&&(n-l)*(s-c)>=(i-l)*(r-c)}function kr(t,e){let n=rt(t,e)&&le(t.prev,t,t.next)>0&&le(e.prev,e,e.next)>0;return t.next.i!==e.i&&(n||it(t,e)&&it(e,t)&&(le(t.prev,t,e.prev)!==0||le(t,e.prev,e)!==0))&&!_r(t,e)&&(n||Ar(t,e))}function le(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function rt(t,e){return t.x===e.x&&t.y===e.y}function on(t,e,n,r,i=!0){let s=le(t,e,n),l=le(t,e,r),c=le(n,r,t),a=le(n,r,e);return(s>0&&l<0||s<0&&l>0)&&(c>0&&a<0||c<0&&a>0)?!0:i?!!(s===0&&ht(t,n,e)||l===0&&ht(t,r,e)||c===0&&ht(n,t,r)||a===0&&ht(n,e,r)):!1}function ht(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function _r(t,e){let n=Math.min(t.x,e.x),r=Math.max(t.x,e.x),i=Math.min(t.y,e.y),s=Math.max(t.y,e.y),l=t;do{let c=l.next;if(l.x>r&&c.x>r||l.x<n&&c.x<n||l.y>s&&c.y>s||l.y<i&&c.y<i){l=c;continue}if(l.i!==t.i&&c.i!==t.i&&l.i!==e.i&&c.i!==e.i&&on(l,c,t,e))return!0;l=c}while(l!==t);return!1}function it(t,e){return le(t.prev,t,t.next)<0?le(t,e,t.next)>=0&&le(t,t.prev,e)>=0:le(t,e,t.prev)<0||le(t,t.next,e)<0}function Ar(t,e){let n=t,r=!1,i=(t.x+e.x)/2,s=(t.y+e.y)/2;do{let l=n.next;n.y>s!=l.y>s&&i<(l.x-n.x)*(s-n.y)/(l.y-n.y)+n.x&&(r=!r),n=l}while(n!==t);return r}function sn(t,e){let n=Pt(t.i,t.x,t.y),r=Pt(e.i,e.x,e.y),i=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=i,i.prev=n,r.next=n,n.prev=r,s.next=r,r.prev=s,r}function en(t,e,n,r){let i=Pt(t,e,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function ot(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),Mt&&Er(t.prev,t.next)}function Pt(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function Lr(t,e,n,r){let i=0;for(let s=e,l=n-r;s<n;s+=r)i+=(t[l]-t[s])*(t[s+1]+t[l+1]),l=s;return i}var un=23283064365386963e-26,Br=12,ln=typeof TextDecoder>"u"?null:new TextDecoder("utf-8"),kt=0,xt=1,st=2,dt=5,ut=class{constructor(e=new Uint8Array(16)){this.buf=ArrayBuffer.isView(e)?e:new Uint8Array(e),this.dataView=new DataView(this.buf.buffer),this.pos=0,this.type=0,this.length=this.buf.length}readFields(e,n,r=this.length){for(;this.pos<r;){let i=this.readVarint(),s=i>>3,l=this.pos;this.type=i&7,e(s,n,this),this.pos===l&&this.skip(i)}return n}readMessage(e,n){return this.readFields(e,n,this.readVarint()+this.pos)}readFixed32(){let e=this.dataView.getUint32(this.pos,!0);return this.pos+=4,e}readSFixed32(){let e=this.dataView.getInt32(this.pos,!0);return this.pos+=4,e}readFixed64(){let e=this.dataView.getUint32(this.pos,!0)+this.dataView.getUint32(this.pos+4,!0)*4294967296;return this.pos+=8,e}readSFixed64(){let e=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*4294967296;return this.pos+=8,e}readFloat(){let e=this.dataView.getFloat32(this.pos,!0);return this.pos+=4,e}readDouble(){let e=this.dataView.getFloat64(this.pos,!0);return this.pos+=8,e}readVarint(e){let n=this.buf,r,i;return i=n[this.pos++],r=i&127,i<128||(i=n[this.pos++],r|=(i&127)<<7,i<128)||(i=n[this.pos++],r|=(i&127)<<14,i<128)||(i=n[this.pos++],r|=(i&127)<<21,i<128)?r:(i=n[this.pos],r|=(i&15)<<28,Tr(r,e,this))}readVarint64(){return this.readVarint(!0)}readSVarint(){let e=this.readVarint();return e%2===1?(e+1)/-2:e/2}readBoolean(){return!!this.readVarint()}readString(){let e=this.readVarint()+this.pos,n=this.pos;return this.pos=e,e-n>=Br&&ln?ln.decode(this.buf.subarray(n,e)):Yr(this.buf,n,e)}readBytes(){let e=this.readVarint()+this.pos,n=this.buf.subarray(this.pos,e);return this.pos=e,n}readPackedVarint(e=[],n){let r=this.readPackedEnd();for(;this.pos<r;)e.push(this.readVarint(n));return e}readPackedSVarint(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readSVarint());return e}readPackedBoolean(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readBoolean());return e}readPackedFloat(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readFloat());return e}readPackedDouble(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readDouble());return e}readPackedFixed32(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readFixed32());return e}readPackedSFixed32(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readSFixed32());return e}readPackedFixed64(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readFixed64());return e}readPackedSFixed64(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readSFixed64());return e}readPackedEnd(){return this.type===st?this.readVarint()+this.pos:this.pos+1}skip(e){let n=e&7;if(n===kt)for(;this.buf[this.pos++]>127;);else if(n===st)this.pos=this.readVarint()+this.pos;else if(n===dt)this.pos+=4;else if(n===xt)this.pos+=8;else throw new Error(`Unimplemented type: ${n}`)}writeTag(e,n){this.writeVarint(e<<3|n)}realloc(e){let n=this.length||16;for(;n<this.pos+e;)n*=2;if(n!==this.length){let r=new Uint8Array(n);r.set(this.buf),this.buf=r,this.dataView=new DataView(r.buffer),this.length=n}}finish(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)}writeFixed32(e){this.realloc(4),this.dataView.setInt32(this.pos,e,!0),this.pos+=4}writeSFixed32(e){this.realloc(4),this.dataView.setInt32(this.pos,e,!0),this.pos+=4}writeFixed64(e){this.realloc(8),this.dataView.setInt32(this.pos,e&-1,!0),this.dataView.setInt32(this.pos+4,Math.floor(e*un),!0),this.pos+=8}writeSFixed64(e){this.realloc(8),this.dataView.setInt32(this.pos,e&-1,!0),this.dataView.setInt32(this.pos+4,Math.floor(e*un),!0),this.pos+=8}writeVarint(e){if(e=+e||0,e>268435455||e<0){Cr(e,this);return}this.realloc(4),this.buf[this.pos++]=e&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=e>>>7&127)))}writeSVarint(e){this.writeVarint(e<0?-e*2-1:e*2)}writeBoolean(e){this.writeVarint(+e)}writeString(e){e=String(e),this.realloc(e.length*4),this.pos++;let n=this.pos;this.pos=Zr(this.buf,e,this.pos);let r=this.pos-n;r>=128&&cn(n,r,this),this.pos=n-1,this.writeVarint(r),this.pos+=r}writeFloat(e){this.realloc(4),this.dataView.setFloat32(this.pos,e,!0),this.pos+=4}writeDouble(e){this.realloc(8),this.dataView.setFloat64(this.pos,e,!0),this.pos+=8}writeBytes(e){let n=e.length;this.writeVarint(n),this.realloc(n);for(let r=0;r<n;r++)this.buf[this.pos++]=e[r]}writeRawMessage(e,n){this.pos++;let r=this.pos;e(n,this);let i=this.pos-r;i>=128&&cn(r,i,this),this.pos=r-1,this.writeVarint(i),this.pos+=i}writeMessage(e,n,r){this.writeTag(e,st),this.writeRawMessage(n,r)}writePackedVarint(e,n){n.length&&this.writeMessage(e,Dr,n)}writePackedSVarint(e,n){n.length&&this.writeMessage(e,Ur,n)}writePackedBoolean(e,n){n.length&&this.writeMessage(e,zr,n)}writePackedFloat(e,n){n.length&&this.writeMessage(e,Gr,n)}writePackedDouble(e,n){n.length&&this.writeMessage(e,Nr,n)}writePackedFixed32(e,n){n.length&&this.writeMessage(e,Hr,n)}writePackedSFixed32(e,n){n.length&&this.writeMessage(e,$r,n)}writePackedFixed64(e,n){n.length&&this.writeMessage(e,jr,n)}writePackedSFixed64(e,n){n.length&&this.writeMessage(e,Xr,n)}writeBytesField(e,n){this.writeTag(e,st),this.writeBytes(n)}writeFixed32Field(e,n){this.writeTag(e,dt),this.writeFixed32(n)}writeSFixed32Field(e,n){this.writeTag(e,dt),this.writeSFixed32(n)}writeFixed64Field(e,n){this.writeTag(e,xt),this.writeFixed64(n)}writeSFixed64Field(e,n){this.writeTag(e,xt),this.writeSFixed64(n)}writeVarintField(e,n){this.writeTag(e,kt),this.writeVarint(n)}writeSVarintField(e,n){this.writeTag(e,kt),this.writeSVarint(n)}writeStringField(e,n){this.writeTag(e,st),this.writeString(n)}writeFloatField(e,n){this.writeTag(e,dt),this.writeFloat(n)}writeDoubleField(e,n){this.writeTag(e,xt),this.writeDouble(n)}writeBooleanField(e,n){this.writeVarintField(e,+n)}};function Tr(t,e,n){let r=n.buf,i,s;if(s=r[n.pos++],i=(s&112)>>4,s<128||(s=r[n.pos++],i|=(s&127)<<3,s<128)||(s=r[n.pos++],i|=(s&127)<<10,s<128)||(s=r[n.pos++],i|=(s&127)<<17,s<128)||(s=r[n.pos++],i|=(s&127)<<24,s<128)||(s=r[n.pos++],i|=(s&1)<<31,s<128))return He(t,i,e);throw new Error("Expected varint not more than 10 bytes")}function He(t,e,n){return n?e*4294967296+(t>>>0):(e>>>0)*4294967296+(t>>>0)}function Cr(t,e){let n,r;if(t>=0?(n=t%4294967296|0,r=t/4294967296|0):(n=~(-t%4294967296),r=~(-t/4294967296),n^4294967295?n=n+1|0:(n=0,r=r+1|0)),t>=18446744073709552e3||t<-18446744073709552e3)throw new Error("Given varint doesn\'t fit into 10 bytes");e.realloc(10),Vr(n,r,e),Or(r,e)}function Vr(t,e,n){n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos]=t&127}function Or(t,e){let n=(t&7)<<4;e.buf[e.pos++]|=n|((t>>>=3)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127)))))}function cn(t,e,n){let r=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(Math.LN2*7));n.realloc(r);for(let i=n.pos-1;i>=t;i--)n.buf[i+r]=n.buf[i]}function Dr(t,e){for(let n=0;n<t.length;n++)e.writeVarint(t[n])}function Ur(t,e){for(let n=0;n<t.length;n++)e.writeSVarint(t[n])}function Gr(t,e){for(let n=0;n<t.length;n++)e.writeFloat(t[n])}function Nr(t,e){for(let n=0;n<t.length;n++)e.writeDouble(t[n])}function zr(t,e){for(let n=0;n<t.length;n++)e.writeBoolean(t[n])}function Hr(t,e){for(let n=0;n<t.length;n++)e.writeFixed32(t[n])}function $r(t,e){for(let n=0;n<t.length;n++)e.writeSFixed32(t[n])}function jr(t,e){for(let n=0;n<t.length;n++)e.writeFixed64(t[n])}function Xr(t,e){for(let n=0;n<t.length;n++)e.writeSFixed64(t[n])}function Yr(t,e,n){let r="",i=e;for(;i<n;){let s=t[i],l=null,c=s>239?4:s>223?3:s>191?2:1;if(i+c>n)break;let a,m,x;c===1?s<128&&(l=s):c===2?(a=t[i+1],(a&192)===128&&(l=(s&31)<<6|a&63,l<=127&&(l=null))):c===3?(a=t[i+1],m=t[i+2],(a&192)===128&&(m&192)===128&&(l=(s&15)<<12|(a&63)<<6|m&63,(l<=2047||l>=55296&&l<=57343)&&(l=null))):c===4&&(a=t[i+1],m=t[i+2],x=t[i+3],(a&192)===128&&(m&192)===128&&(x&192)===128&&(l=(s&15)<<18|(a&63)<<12|(m&63)<<6|x&63,(l<=65535||l>=1114112)&&(l=null))),l===null?(l=65533,c=1):l>65535&&(l-=65536,r+=String.fromCharCode(l>>>10&1023|55296),l=56320|l&1023),r+=String.fromCharCode(l),i+=c}return r}function Zr(t,e,n){for(let r=0,i,s;r<e.length;r++){if(i=e.charCodeAt(r),i>55295&&i<57344)if(s)if(i<56320){t[n++]=239,t[n++]=191,t[n++]=189,s=i;continue}else i=s-55296<<10|i-56320|65536,s=null;else{i>56319||r+1===e.length?(t[n++]=239,t[n++]=191,t[n++]=189):s=i;continue}else s&&(t[n++]=239,t[n++]=191,t[n++]=189,s=null);i<128?t[n++]=i:(i<2048?t[n++]=i>>6|192:(i<65536?t[n++]=i>>12|224:(t[n++]=i>>18|240,t[n++]=i>>12&63|128),t[n++]=i>>6&63|128),t[n++]=i&63|128)}return n}var _t=class t{constructor(e,n,r,i){this.pbf=e;this.keys=n;this.values=r;this.extent=i;this.type=0;this.properties={};this.geomOffset=-1}static read(e,n,r,i,s){let l=new t(e,r,i,s);return e.readFields(Wr,l,n),l}loadGeometry(){if(this.geomOffset<0)return[];let e=this.pbf,n=e.pos;e.pos=this.geomOffset;let r=e.readVarint()+e.pos,i=1,s=0,l=0,c=0,a=[],m=[];for(;e.pos<r;){if(s<=0){let x=e.readVarint();i=x&7,s=x>>3}if(s--,i===1||i===2)l+=e.readSVarint(),c+=e.readSVarint(),i===1&&(m.length&&a.push(m),m=[]),m.push(l,c);else if(i===7)m.length>=2&&m.push(m[0],m[1]);else throw new Error(`[osmgl] \\u043D\\u0435\\u0438\\u0437\\u0432\\u0435\\u0441\\u0442\\u043D\\u0430\\u044F \\u043A\\u043E\\u043C\\u0430\\u043D\\u0434\\u0430 \\u0433\\u0435\\u043E\\u043C\\u0435\\u0442\\u0440\\u0438\\u0438 MVT: ${i}`)}return m.length&&a.push(m),e.pos=n,a}bbox(){let e=this.loadGeometry(),n=1/0,r=1/0,i=-1/0,s=-1/0;for(let l of e)for(let c=0;c<l.length;c+=2)l[c]<n&&(n=l[c]),l[c]>i&&(i=l[c]),l[c+1]<r&&(r=l[c+1]),l[c+1]>s&&(s=l[c+1]);return[n,r,i,s]}};function Wr(t,e,n){n&&(t===1?e.id=n.readVarint():t===2?Qr(n,e):t===3?e.type=n.readVarint():t===4&&(e.geomOffset=n.pos,n.skip(2)))}function Qr(t,e){let n=t.readVarint()+t.pos;for(;t.pos<n;){let r=e.keys[t.readVarint()],i=e.values[t.readVarint()];r!==void 0&&(e.properties[r]=i)}}var At=class t{constructor(e){this.pbf=e;this.version=1;this.name="";this.extent=4096;this.featureOffsets=[];this.keys=[];this.values=[]}static read(e,n){let r=new t(e);return e.readFields(Kr,r,n),r}get length(){return this.featureOffsets.length}feature(e){let n=this.pbf;n.pos=this.featureOffsets[e];let r=n.readVarint()+n.pos;return _t.read(n,r,this.keys,this.values,this.extent)}*features(){for(let e=0;e<this.featureOffsets.length;e++)yield this.feature(e)}};function Kr(t,e,n){n&&(t===15?e.version=n.readVarint():t===1?e.name=n.readString():t===5?e.extent=n.readVarint():t===2?e.featureOffsets.push(n.pos):t===3?e.keys.push(n.readString()):t===4&&e.values.push(Jr(n)))}function Jr(t){let e=t.readVarint()+t.pos,n=null;for(;t.pos<e;){let r=t.readVarint()>>3;r===1?n=t.readString():r===2?n=t.readFloat():r===3?n=t.readDouble():r===4?n=t.readVarint64():r===5?n=t.readVarint():r===6?n=t.readSVarint():r===7?n=t.readBoolean():t.skip(r)}return n}var gt=class{constructor(e){this.layers={};new ut(e instanceof Uint8Array?e:new Uint8Array(e)).readFields((r,i,s)=>{if(r===3&&s){let l=At.read(s,s.readVarint()+s.pos);l.length&&(this.layers[l.name]=l)}},null)}};function $e(t){let e=[],n=null;for(let r of t){if(r.length<6)continue;let i=qr(r);i!==0&&(i>0?(n&&e.push(n),n={outer:r,holes:[]}):n&&n.holes.push(r))}return n&&e.push(n),e}function qr(t){let e=0;for(let n=0,r=t.length-2;n<t.length;r=n,n+=2)e+=(t[r]-t[n])*(t[n+1]+t[r+1]);return e/2}function ce(t,e){if(!t)return!0;let n=t[0];switch(n){case"all":return t.slice(1).every(r=>ce(r,e));case"any":return t.slice(1).some(r=>ce(r,e));case"!":return!ce(t[1],e);case"has":return e[t[1]]!=null;case"!has":return e[t[1]]==null;case"in":{let r=e[t[1]];return r==null?!1:t.slice(2).includes(r)}case"!in":{let r=e[t[1]];return r==null?!0:!t.slice(2).includes(r)}default:{let r=e[t[1]],i=t[2];if(r==null)return n==="!=";switch(n){case"==":return r===i;case"!=":return r!==i;case">":return r>i;case">=":return r>=i;case"<":return r<i;case"<=":return r<=i;default:return!0}}}}var ei=Math.PI/8,ti=.35,ni=32,fn=.25,an=.5,hn=.07;function _e(t,e){let n=e.radius;if(!(n>0))return t;let r=t.length/2-1;if(r<3)return t;let i=Math.max(2,Math.round(e.segments??4)),s=Math.max(e.minCutRatio??ti,0),l=e.extent,c=e.margin??0,a=[];for(let m=0;m<r;m++){let x=t[m*2],g=t[m*2+1],d=t[(m+r-1)%r*2],b=t[(m+r-1)%r*2+1],E=t[(m+1)%r*2],A=t[(m+1)%r*2+1],_=x-d,R=g-b,L=E-x,k=A-g,T=Math.hypot(_,R),O=Math.hypot(L,k);if(T<1e-6||O<1e-6){a.push(x,g);continue}let D=_/T,U=R/T,P=L/O,C=k/O;if(e.keep?.[m]){a.push(x,g);continue}let Y=D*P+U*C;if(Y>.985){a.push(x,g);continue}if(l!==void 0&&(Lt(x,g,l,c)||Lt(d,b,l,c)||Lt(E,A,l,c))){a.push(x,g);continue}let Q=Math.min(n,T*.4,O*.4);if(Q<n*s){a.push(x,g);continue}let Z=x-D*Q,re=g-U*Q,X=x+P*Q,$=g+C*Q,z=Math.acos(Math.max(-1,Math.min(1,Y))),N=Math.min(ei,Math.PI/2/i),q=Math.ceil(z/N-1e-6),te=e.maxChord&&e.maxChord>0?Math.ceil(Q/Math.tan(z/2)*z/e.maxChord):0,K=Math.max(1,Math.min(ni,Math.max(Math.min(i,q),te)));a.push(Z,re);for(let oe=1;oe<K;oe++){let ee=oe/K,J=1-ee;a.push(J*J*Z+2*J*ee*x+ee*ee*X,J*J*re+2*J*ee*g+ee*ee*$)}a.push(X,$)}return a.length<6?t:(a.push(a[0],a[1]),a)}var Lt=(t,e,n,r)=>t<=-r||e<=-r||t>=n+r||e>=n+r;var Ae=t=>t/64;function je(t,e,n=0){let r=pn(t.outer,e,n);if(!r)return null;let i=[];for(let s of t.holes){let l=pn(s,e,n);l&&i.push(l)}return{outer:r,holes:i}}function pn(t,e,n){let r=[];for(let i=0;i<t.length-2;i+=2)r.push(t[i],t[i+1]);if(r.length<6)return null;for(let i=0;i<4;i++){let s=r;r=[];let l=s.length/2;if(l===0)return null;for(let c=0;c<l;c++){let a=s[c*2],m=s[c*2+1],x=s[(c+l-1)%l*2],g=s[(c+l-1)%l*2+1],d=mn(a,m,i,e,n),b=mn(x,g,i,e,n);if(d!==b){let E=ri(x,g,a,m,i,e,n);r.push(x+(a-x)*E,g+(m-g)*E)}d&&r.push(a,m)}}return r.length<6?null:(r.push(r[0],r[1]),r)}function mn(t,e,n,r,i){return n===0?t>=-i:n===1?t<=r+i:n===2?e>=-i:e<=r+i}function ri(t,e,n,r,i,s,l){return i===0?(-l-t)/(n-t):i===1?(s+l-t)/(n-t):i===2?(-l-e)/(r-e):(s+l-e)/(r-e)}function yt(t,e,n,r,i,s=0){let l=-s,c=i+s;return t===l&&n===l||t===c&&n===c||e===l&&r===l||e===c&&r===c}function xn(t,e){for(let n=0;n<t.length;n+=2)if(t[n]<=0||t[n]>=e||t[n+1]<=0||t[n+1]>=e)return!0;return!1}var Ct=18,Vt=32,dn=8,Sn=65535/Vt,ii=9,oi=1,si=0,ui=1,li=2;var gn=0,ci=1,yn=2,fi=3,ai=.47;function En(t,e,n,r={}){let i=r.metersPerUnit&&r.metersPerUnit>0?r.metersPerUnit:ai,s=Math.max(1024,t.length*48),l=new ArrayBuffer(s*Ct),c={verts:new DataView(l),vertsU8:new Uint8Array(l),vertOffset:0,vertexCount:0,indices:[],featureIds:[],ensure:()=>{}};c.ensure=d=>a(d);let a=d=>{if(c.vertexCount+d<=s)return;s=Math.max(s*2,c.vertexCount+d);let b=new ArrayBuffer(s*Ct);new Uint8Array(b).set(c.vertsU8.subarray(0,c.vertOffset)),l=b,c.verts=new DataView(b),c.vertsU8=new Uint8Array(b)};for(let d of t.features()){if(d.type!==3||!ce(n,d.properties))continue;let b=Li(d.properties),E=Bi(d.properties,b);if(b<=E)continue;let A=Ci(d.properties)??Number(d.id??0),_=Ai(A>>>0),R=_i(_,d.properties),L=ki(d.properties,b),k=$e(d.loadGeometry());for(let T of k){let O=je(T,e);if(!O)continue;let D=xn(O.outer,e),U=(r.cornerRadius??0)/i,P={radius:U,segments:r.cornerSegments,extent:e,minCutRatio:0,maxChord:i>0?an/i:0},C=U>0?{outer:_e(O.outer,P),holes:O.holes.map($=>_e($,P))}:O,Y=C.outer.length/2+C.holes.reduce(($,z)=>$+z.length/2,0);a(Y*5+32);let Q=C.holes.length||D?null:xi(C.outer),Z=Q?vi(d.properties,Q,b,_,i):null,re=null,X=[];if(Z&&Q){let $=Mn(Mi(C.outer,i),Q,Z.shape);X=Ri($,C.outer);let z=Fi($,X);if(z>1e-6){let N=Math.min(Math.max(z*i*yi,wi),bi);re=Ii($,N/z,b)}}wn(c,C.outer,E,b,A,R,L,i,e,re);for(let $ of C.holes)wn(c,$,E,b,A,R,L,i,e,null);re?Pi(c,X,re,b,A,R,L,i):mi(c,C.outer,C.holes,b,A,R,L)}}if(!c.indices.length)return null;let m=new Uint32Array(c.indices),x=new Float64Array(c.featureIds);return{vertices:l.slice(0,c.vertOffset),indices:m.buffer,featureIds:x.buffer,vertexCount:c.vertexCount,indexCount:m.length,extent:e}}var Ot=(t,e)=>t|e<<2,bn=t=>Math.max(-32768,Math.min(32767,t)),Bt=t=>Math.max(0,Math.min(65535,Math.round(Math.min(t,Sn)*Vt)));function Xe(t,e,n,r,i,s,l,c,a,m,x=0,g=0,d=0){let b=t.vertOffset;return t.verts.setInt16(b,bn(Math.round(e*dn)),!0),t.verts.setInt16(b+2,bn(Math.round(n*dn)),!0),t.verts.setUint16(b+4,Math.round(Math.min(r,Sn)*Vt),!0),t.vertsU8[b+6]=a,t.vertsU8[b+7]=c,t.verts.setInt8(b+8,Tt(Math.round(i*127))),t.verts.setInt8(b+9,Tt(Math.round(s*127))),t.verts.setInt8(b+10,Tt(Math.round(l*127))),t.vertsU8[b+11]=m,t.verts.setUint16(b+12,Bt(x),!0),t.verts.setUint16(b+14,Bt(g),!0),t.verts.setUint16(b+16,Bt(d),!0),t.vertOffset+=Ct,t.vertexCount++}function wn(t,e,n,r,i,s,l,c,a,m=null){let x=e.length/2;if(x<3)return;let g=Ot(si,l),d=pi(e,c),b=r-n,E=new Float64Array(x*2),A=new Uint8Array(x);{let _=new Float64Array(x*2);for(let R=0;R<x-1;R++){let L=e[R*2+2]-e[R*2],k=e[R*2+3]-e[R*2+1],T=Math.hypot(L,k)||1;_[R*2]=k/T,_[R*2+1]=-L/T}for(let R=0;R<x-1;R++){let L=(R+x-2)%(x-1),k=_[L*2]*_[R*2]+_[L*2+1]*_[R*2+1],T=_[L*2]+_[R*2],O=_[L*2+1]+_[R*2+1],D=Math.hypot(T,O);k>.5&&D>1e-6&&(E[R*2]=T/D,E[R*2+1]=O/D,A[R]=1)}}for(let _=0;_<x-1;_++){let R=e[_*2],L=e[_*2+1],k=e[_*2+2],T=e[_*2+3];if(R===k&&L===T||yt(R,L,k,T,a))continue;let O=k-R,D=T-L,U=Math.hypot(O,D)||1,P=D/U,C=-O/U,Y=d.offset[_],Q=d.width[_],Z=[0,1];if(m){for(let X=0;X<m.length;X++)for(let $=X+1;$<m.length;$++){let z=Ne(m[X],R,L)-Ne(m[$],R,L),N=Ne(m[X],k,T)-Ne(m[$],k,T);if(z===N)continue;let q=z/(z-N);q>1e-4&&q<1-1e-4&&Z.push(q)}Z.sort((X,$)=>X-$)}let re=(X,$)=>{if(!m)return r;let z=1/0;for(let N of m)z=Math.min(z,Ne(N,X,$));return Math.max(r,z)};for(let X=0;X+1<Z.length;X++){let $=Z[X],z=Z[X+1];if(z-$<1e-6)continue;let N=R+O*$,q=L+D*$,te=R+O*z,K=L+D*z,oe=Y+U*$*c,ee=Y+U*z*c,J=(_+1)%(x-1),fe=A[_]?E[_*2]:P,be=A[_]?E[_*2+1]:C,de=A[J]?E[J*2]:P,Fe=A[J]?E[J*2+1]:C,Ce=P+(fe-P)*(1-$),Le=C+(be-C)*(1-$),Ve=P+(de-P)*z,we=C+(Fe-C)*z,se=Math.hypot(Ce,Le)||1,Pe=Math.hypot(Ve,we)||1,xe=Ce/se,Be=Le/se,Oe=Ve/Pe,De=we/Pe;t.ensure(4);let Ie=Xe(t,N,q,n,xe,Be,0,0,s,g,oe,Q,b),ze=Xe(t,te,K,n,Oe,De,0,0,s,g,ee,Q,b),vt=Xe(t,N,q,re(N,q),xe,Be,0,255,s,g,oe,Q,b),ft=Xe(t,te,K,re(te,K),Oe,De,0,255,s,g,ee,Q,b);t.indices.push(Ie,ft,ze,Ie,vt,ft),t.featureIds.push(i,i)}}}var hi=.9976;function pi(t,e){let n=t.length/2-1,r=[];for(let a=0;a<n;a++){let m=t[a*2+2]-t[a*2],x=t[a*2+3]-t[a*2+1],g=Math.hypot(m,x);r.push(g>0?{x:m/g,y:x/g,len:g*e}:{x:0,y:0,len:0})}let i=(a,m)=>r[a].len>0&&r[m].len>0&&r[a].x*r[m].x+r[a].y*r[m].y>=hi,s=0;for(;s<n&&i((s-1+n)%n,s);)s++;s>=n&&(s=0);let l=new Array(n).fill(0),c=new Array(n).fill(0);for(let a=0;a<n;){let m=(s+a)%n,x=[m],g=r[m].len,d=a+1;for(;d<n;){let E=(s+d)%n;if(!i((s+d-1)%n,E))break;x.push(E),g+=r[E].len,d++}let b=0;for(let E of x)l[E]=b,c[E]=g,b+=r[E].len;a=d}return{offset:l,width:c}}function mi(t,e,n,r,i,s,l){let c=[],a=[];for(let d=0;d<e.length;d++)c.push(e[d]);for(let d of n){a.push(c.length/2);for(let b=0;b<d.length;b++)c.push(d[b])}let m=Te(c,a.length?a:void 0,2);if(!m.length)return;let x=Ot(ui,l),g=t.vertexCount;for(let d=0;d<c.length;d+=2)Xe(t,c[d],c[d+1],r,0,0,1,255,s,x);for(let d=0;d<m.length;d+=3)t.indices.push(g+m[d],g+m[d+2],g+m[d+1]),t.featureIds.push(i)}function xi(t){let e=di(t);if(e.length<3)return null;let n=Math.abs(gi(t));if(n<=0)return null;let r=null,i=1/0;for(let s=0;s<e.length;s++){let l=(s+1)%e.length,c=e[l].x-e[s].x,a=e[l].y-e[s].y,m=Math.hypot(c,a);if(m<1e-6)continue;c/=m,a/=m;let x=1/0,g=-1/0,d=1/0,b=-1/0;for(let T of e){let O=T.x*c+T.y*a,D=-T.x*a+T.y*c;O<x&&(x=O),O>g&&(g=O),D<d&&(d=D),D>b&&(b=D)}let E=g-x,A=b-d,_=E*A;if(_<=0||_>=i)continue;i=_;let R=(x+g)/2,L=(d+b)/2,k=E>=A;r={cx:R*c-L*a,cy:R*a+L*c,ax:k?c:-a,ay:k?a:c,halfLong:(k?E:A)/2,halfShort:(k?A:E)/2,fill:n/_}}return r}function di(t){let e=[];for(let s=0;s<t.length-2;s+=2)e.push({x:t[s],y:t[s+1]});if(e.length<3)return e;e.sort((s,l)=>s.x===l.x?s.y-l.y:s.x-l.x);let n=(s,l,c)=>(l.x-s.x)*(c.y-s.y)-(l.y-s.y)*(c.x-s.x),r=[];for(let s of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=e.length-1;s>=0;s--){let l=e[s];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],l)<=0;)i.pop();i.push(l)}return r.pop(),i.pop(),r.concat(i)}function gi(t){let e=0;for(let n=0;n<t.length-2;n+=2)e+=t[n]*t[n+3]-t[n+2]*t[n+1];return e/2}var yi=Math.tan(30*Math.PI/180),bi=3.5,wi=.9;function vi(t,e,n,r,i){if(e.fill<.86)return null;let s=e.halfShort*2*i,l=e.halfLong*2*i,c=s*l,a=e.halfShort>0?e.halfLong/e.halfShort:99,m=Si(t);if(!m){if(n>15||c>600||s<3)return null;let x=r%1e3/1e3;c<30?m=x<.5?"skillion":"gabled":a<1.25?m=x<.35?"pyramidal":"hipped":m=x<.8?"gabled":"hipped"}return m==="flat"?null:{shape:m}}function Si(t){let e=String(t.roof_shape??t["roof:shape"]??"").toLowerCase();return e?e==="flat"?"flat":e==="skillion"||e==="lean_to"||e==="shed"?"skillion":e==="hipped"||e==="half-hipped"||e==="gambrel"?"hipped":e==="pyramidal"||e==="dome"||e==="conical"||e==="onion"?"pyramidal":e==="gabled"||e==="mansard"||e==="round"?"gabled":null:null}var Ne=(t,e,n)=>t.a*e+t.b*n+t.c;function Ei(t,e,n,r){let i=t.length/2;if(i<3)return[];let s=[],l=c=>[t[c*2],t[c*2+1]];for(let c=0;c<i;c++){let[a,m]=l(c),[x,g]=l((c+i-1)%i),d=e*a+n*m+r,b=e*x+n*g+r;if(d<=0!=b<=0){let E=b/(b-d);s.push(x+(a-x)*E,g+(m-g)*E)}d<=0&&s.push(a,m)}return s}function Mi(t,e){let n=.5/Math.max(e,1e-6),r=t.length/2-1;if(r<5)return t;let i=[],s=0;i.push(t[0],t[1]);for(let l=1;l<r;l++){let c=t[s*2],a=t[s*2+1],m=t[l*2],x=t[l*2+1],g=m-c,d=x-a,b=Math.hypot(g,d),E=b>1e-6;if(E){for(let A=s+1;A<l;A++)if(Math.abs((t[A*2]-c)*d-(t[A*2+1]-a)*g)/b>=n){E=!1;break}}E||(i.push(t[(l-1)*2],t[(l-1)*2+1]),s=l-1)}return i.length/2<3?t:(i.push(i[0],i[1]),i)}function Mn(t,e,n){let{ax:r,ay:i,halfLong:s}=e;if(n==="skillion"){let a=-i,m=r;return[{a,b:m,c:-(a*e.cx+m*e.cy)+e.halfShort}]}let l=[],c=t.length/2-1;for(let a=0;a<c;a++){let m=t[a*2],x=t[a*2+1],g=t[(a+1)%c*2],d=t[(a+1)%c*2+1],b=g-m,E=d-x,A=Math.hypot(b,E);if(A<1e-6||n==="gabled"&&Math.abs((b*r+E*i)/A)<.86)continue;let _=-E/A,R=b/A;l.push({a:_,b:R,c:-(_*m+R*x)})}return!l.length&&s>0?Mn(t,e,"hipped"):l}function Ri(t,e){let n=[];for(let i=0;i<e.length-2;i+=2)n.push(e[i],e[i+1]);if(n.length<6)return[];let r=[];for(let i=0;i<t.length;i++){let s=n;for(let l=0;l<t.length&&s.length>=6;l++)l!==i&&(s=Ei(s,t[i].a-t[l].a,t[i].b-t[l].b,t[i].c-t[l].c));r.push(s.length>=6?s:[])}return r}function Fi(t,e){let n=0;for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<i.length;s+=2){let l=Ne(t[r],i[s],i[s+1]);l>n&&(n=l)}}return n}function Ii(t,e,n){return t.map(r=>({a:r.a*e,b:r.b*e,c:r.c*e+n}))}function Pi(t,e,n,r,i,s,l,c){let a=Ot(li,l);for(let m=0;m<n.length;m++){let x=e[m];if(!x||x.length<6)continue;let g=Te(x,void 0,2);if(!g.length)continue;let d=-n[m].a/c,b=-n[m].b/c,E=Math.hypot(d,b,1),A={x:d/E,y:b/E,z:1/E};t.ensure(x.length/2);let _=t.vertexCount;for(let R=0;R<x.length;R+=2){let L=Math.max(r,Ne(n[m],x[R],x[R+1]));Xe(t,x[R],x[R+1],L,A.x,A.y,A.z,255,s,a)}for(let R=0;R<g.length;R+=3)t.indices.push(_+g[R],_+g[R+2],_+g[R+1]),t.featureIds.push(i)}}function ki(t,e){let n=String(t.class??"").toLowerCase();return n==="industrial"||n==="warehouse"||n==="hangar"||n==="construction"?fi:n==="commercial"||n==="office"||n==="retail"||n==="supermarket"?yn:n==="house"||n==="detached"||n==="garage"||n==="hut"||n==="shed"||e<=7?gn:e>=40?yn:ci}function _i(t,e){let n=String(e.class??""),r=128;return n==="industrial"||n==="warehouse"||n==="construction"?r=96:n==="commercial"||n==="office"||n==="retail"?r=150:(n==="apartments"||n==="residential"||n==="house")&&(r=134),Math.max(0,Math.min(255,r+(t%121-60)))}function Ai(t){let e=t>>>0;return e=(e>>>16^e)*73244475,e=(e>>>16^e)*73244475,e=e>>>16^e,e>>>0}function Li(t){let e=Ye(t.render_height)??Ye(t.height)??Ti(t.levels??t.building_levels??t["building:levels"]);return e&&e>0?Math.max(e,oi):ii}function Bi(t,e){let n=Ye(t.render_min_height)??Ye(t.min_height)??Ye(t.base)??0;return n>0&&n<e?n:0}function Ti(t){let e=Ye(t);return e&&e>0?e*3:null}function Ye(t){if(typeof t=="number"&&isFinite(t))return t;if(typeof t=="string"){let e=parseFloat(t);if(isFinite(e))return e}return null}var Tt=t=>t>127?127:t<-127?-127:t;function Ci(t){let e=t.osm_id;if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let n=Number(e);if(Number.isFinite(n))return n}return null}function Dt(t,e,n,r,i){let s=r*r,l=[],c=x=>t[x*2],a=x=>t[x*2+1],m=(x,g)=>{let d=t.length/2;return t.push((c(x)+c(g))/2,(a(x)+a(g))/2),d};for(let x=0;x<e.length;x+=3){l.push([n+e[x],n+e[x+1],n+e[x+2]]);let g=0;for(;l.length&&!(++g>2e4);){let[d,b,E]=l.pop(),A=(c(d)-c(b))**2+(a(d)-a(b))**2,_=(c(b)-c(E))**2+(a(b)-a(E))**2,R=(c(E)-c(d))**2+(a(E)-a(d))**2,L=Math.max(A,_,R);if(L<=s){i.push(d,b,E);continue}if(L===A){let k=m(d,b);l.push([d,k,E],[k,b,E])}else if(L===_){let k=m(b,E);l.push([b,k,d],[k,E,d])}else{let k=m(E,d);l.push([E,k,b],[k,d,b])}}}}function Rn(t,e,n=0,r,i=!1,s=4096){let l=[],c=[],a=[];for(let b of t.features()){if(b.type!==3||!ce(e,b.properties))continue;let E=b.properties.osm_id,A=typeof E=="number"?E:typeof E=="string"?Number(E):NaN,_=Number.isFinite(A)?A:Number(b.id??0);for(let R of $e(b.loadGeometry())){let L=i?je(R,s):R;if(!L)continue;let k=[],T=[],O=r?_e(L.outer,r):L.outer;for(let P=0;P<O.length;P++)k.push(O[P]);for(let P of L.holes){let C=r?_e(P,r):P;T.push(k.length/2);for(let Y=0;Y<C.length;Y++)k.push(C[Y])}let D=Te(k,T.length?T:void 0,2);if(!D.length)continue;let U=l.length/2;for(let P=0;P<k.length;P++)l.push(k[P]);if(n>0){let P=[];Dt(l,D,U,n,P);for(let C=0;C<P.length;C+=3)c.push(P[C],P[C+2],P[C+1]),a.push(_);continue}for(let P=0;P<D.length;P+=3)c.push(U+D[P],U+D[P+2],U+D[P+1]),a.push(_)}}if(!c.length)return null;let m=l.length/2,x=new Int16Array(l),g=new Uint32Array(c);return{featureIds:new Float64Array(a).buffer,vertices:x.buffer,indices:g.buffer,vertexCount:m,indexCount:g.length}}function In(t){return{shapes:[],cells:[],extent:0,metersPerTile:t}}function Pn(t,e,n,r){if(!(n<=0)){t.extent=r;for(let i of e){let s=i.outer;if(s.length<6)continue;let l=1/0,c=1/0,a=-1/0,m=-1/0;for(let x=0;x<s.length;x+=2)s[x]<l&&(l=s[x]),s[x]>a&&(a=s[x]),s[x+1]<c&&(c=s[x+1]),s[x+1]>m&&(m=s[x+1]);t.shapes.push({outer:s,holes:i.holes,level:n,minX:l,minY:c,maxX:a,maxY:m})}t.cells=[]}}function Vi(t){t.cells=Array.from({length:32*32},()=>[]);let e=t.extent/32;for(let n=0;n<t.shapes.length;n++){let r=t.shapes[n],i=Ze(Math.floor(r.minX/e)),s=Ze(Math.floor(r.maxX/e)),l=Ze(Math.floor(r.minY/e)),c=Ze(Math.floor(r.maxY/e));for(let a=l;a<=c;a++)for(let m=i;m<=s;m++)t.cells[a*32+m].push(n)}}var kn=t=>t.shapes.length===0;function Ut(t,e,n){!t.cells.length&&t.shapes.length&&Vi(t);let r=t.extent/32,i=t.cells[Ze(Math.floor(n/r))*32+Ze(Math.floor(e/r))];if(!i||!i.length)return 0;let s=0;for(let l of i){let c=t.shapes[l];if(c.level<=s||e<c.minX||e>c.maxX||n<c.minY||n>c.maxY||!Fn(c.outer,e,n))continue;let a=!1;for(let m of c.holes)if(Fn(m,e,n)){a=!0;break}a||(s=c.level)}return Math.min(Math.round(s*100),127)}function _n(t,e){let n=[],r=[],i=t.extent>0?t.metersPerTile/t.extent:0,s=i>0?2/i:0,l=Ut(t,e[0],e[1]);n.push(e[0],e[1]),r.push(l);for(let c=0;c+3<e.length;c+=2){let a=e[c],m=e[c+1],x=e[c+2],g=e[c+3],d=Ut(t,x,g);if(d!==l&&s>0){let b=Math.hypot(x-a,g-m),E=Math.min(Math.ceil(b/s),64),A=l;for(let _=1;_<E;_++){let R=_/E,L=a+(x-a)*R,k=m+(g-m)*R,T=Ut(t,L,k);T!==A&&(n.push(L,k),r.push(T),A=T)}}n.push(x,g),r.push(d),l=d}return{pts:n,levels:r}}var Ze=t=>t<0?0:t>31?31:t;function Fn(t,e,n){let r=!1,i=t.length/2;for(let s=0,l=i-1;s<i;l=s++){let c=t[s*2],a=t[s*2+1],m=t[l*2],x=t[l*2+1];a>n!=x>n&&e<(m-c)*(n-a)/(x-a)+c&&(r=!r)}return r}var Tn=mr(An(),1);function Ln(t){let e=[];for(let n=0;n+1<t.length;n+=2)e.push([t[n],t[n+1]]);return e}function Bn(t){let e=[];for(let r of t)e.push(r[0],r[1]);let n=e.length;return n>=4&&(e[0]!==e[n-2]||e[1]!==e[n-1])&&e.push(e[0],e[1]),e}function Cn(t,e,n=0){if(t.length<2)return t;let r=new Map;for(let s of t){let l=s.lift??0,c=r.get(l);c?c.push(s):r.set(l,[s])}let i=[];for(let[s,l]of r){if(l.length<2){i.push(...l);continue}let a=(n>0&&e?l.map(g=>({outer:e(g.outer,-n)??g.outer,holes:g.holes.map(d=>e(d,n)??d)})):l).map(g=>[Ln(g.outer),...g.holes.map(Ln)]),m;try{m=Tn.union(a[0],...a.slice(1))}catch{i.push(...l);continue}let x=m;if(!Array.isArray(x)||x.length===0){i.push(...l);continue}for(let g of x){if(!g.length)continue;let d=Bn(g[0]);if(d.length<8)continue;let b=[];for(let E=1;E<g.length;E++){let A=Bn(g[E]);A.length>=8&&b.push(A)}i.push(s?{outer:d,holes:b,lift:s}:{outer:d,holes:b})}}return i}var Xt=16,Oi=64,Nn=0,Di=1,Vn=2,Ui=3,bt=1,Gi=.6;function zn(t,e,n,r){let i=r.metersPerUnit>0?r.metersPerUnit:.5,s=r.elevation,l=r.base??0,c=Math.max(r.bevel??0,0)/i,a=Math.max(r.bevelDrop??0,0),m=Math.max(r.cornerRadius??0,0)/i,x=Math.max(512,t.length*24),g=new ArrayBuffer(x*Xt),d={view:new DataView(g),bytes:new Uint8Array(g),offset:0,count:0,indices:[],extent:e,ensure(P){if(d.count+P<=x)return;x=Math.max(x*2,d.count+P);let C=new ArrayBuffer(x*Xt);new Uint8Array(C).set(d.bytes.subarray(0,d.offset)),g=C,d.view=new DataView(C),d.bytes=new Uint8Array(C)}},b=[],E=new Map;for(let P of t.features()){if(P.type!==3||!ce(n,P.properties))continue;let C=r.liftBy?.(P.properties)??0;for(let Y of $e(P.loadGeometry())){let Q=je(Y,e,Ae(e));Q&&b.push(C?{...Q,lift:C}:Q)}}let A=new Set,_=Math.max(r.weld??Gi,0),R=Cn(b,(P,C)=>Ht(P,C,e,A),_/i),L=_>0?R.map(P=>({...P,outer:Gn(P.outer,_/i,e),holes:P.holes.map(C=>Gn(C,_/i,e))})):R;for(let P of L){On(P.outer,E);for(let C of P.holes)On(C,E)}r.onShapes?.(L);let k=new Set;for(let[P,C]of E)C>1&&k.add(P);let T=[],O={radius:m,segments:r.cornerSegments,extent:e,margin:Ae(e),minCutRatio:0,maxChord:fn/i};for(let P of L){let C=m>0?{outer:_e(P.outer,{...O,keep:Dn(P.outer,k)}),holes:P.holes.map(N=>_e(N,{...O,keep:Dn(N,k)}))}:P,Y=c>0?Ht(C.outer,c,e,k):C.outer,Q=C.holes.map(N=>c>0?Ht(N,-c,e,k):N),Z=P.lift??0,re=s+Z,X=l+Z;Un(d,Y??C.outer,Q.map((N,q)=>N??C.holes[q]),re,Nn,r.maxSegment??0);let $=re,z=re-a;Y&&c>0&&a>0&&zt(d,Y,C.outer,$,z,Di,e,k),z!==X&&zt(d,C.outer,C.outer,z,X,Vn,e,k);for(let N of C.holes)if(z!==X&&zt(d,N,N,z,X,Vn,e,k),re<X){let q=d.indices.length;Un(d,N,[],X,Ui);for(let te=q;te<d.indices.length;te++)T.push(d.indices[te]);d.indices.length=q}}if(!d.indices.length&&!T.length)return null;let D=d.indices.length,U=new Uint32Array(D+T.length);return U.set(d.indices,0),U.set(T,D),{vertices:g.slice(0,d.offset),indices:U.buffer,vertexCount:d.count,indexCount:U.length,extent:e,capIndexOffset:D}}function We(t,e,n,r){let i=`${Math.round(t*100)},${Math.round(e*100)}`,s=`${Math.round(n*100)},${Math.round(r*100)}`;return i<s?`${i}|${s}`:`${s}|${i}`}function On(t,e){for(let n=0;n+3<t.length;n+=2){let r=We(t[n],t[n+1],t[n+2],t[n+3]);e.set(r,(e.get(r)??0)+1)}}function Dn(t,e){if(!e.size)return;let n=t.length/2-1,r=new Array(n).fill(!1);for(let i=0;i<n;i++){let s=We(t[(i+n-1)%n*2],t[(i+n-1)%n*2+1],t[i*2],t[i*2+1]),l=We(t[i*2],t[i*2+1],t[(i+1)%n*2],t[(i+1)%n*2+1]);(e.has(s)||e.has(l))&&(r[i]=!0)}return r}function lt(t,e,n,r,i,s,l,c){let a=t.offset;return t.view.setFloat32(a,e,!0),t.view.setFloat32(a+4,n,!0),t.view.setInt16(a+8,Ni(Math.round(r*Oi)),!0),t.view.setInt8(a+10,jt(Math.round(i*127))),t.view.setInt8(a+11,jt(Math.round(s*127))),t.view.setInt8(a+12,jt(Math.round(l*127))),t.bytes[a+13]=c,t.view.setInt8(a+14,e<=0?-bt:e>=t.extent?bt:0),t.view.setInt8(a+15,n<=0?-bt:n>=t.extent?bt:0),t.offset+=Xt,t.count++}function Un(t,e,n,r,i=Nn,s=0){let l=[],c=[];for(let g=0;g<e.length;g++)l.push(e[g]);for(let g of n){c.push(l.length/2);for(let d=0;d<g.length;d++)l.push(g[d])}let a=Te(l,c.length?c:void 0,2);if(!a.length)return;let m=a;if(s>0){let g=[];Dt(l,a,0,s,g),m=g}t.ensure(l.length/2);let x=t.count;for(let g=0;g<l.length;g+=2)lt(t,l[g],l[g+1],r,0,0,1,i);for(let g=0;g<m.length;g+=3)t.indices.push(x+m[g],x+m[g+2],x+m[g+1])}function zt(t,e,n,r,i,s,l,c){let a=Math.min(e.length,n.length)/2;if(!(a<3)){t.ensure((a-1)*4);for(let m=0;m<a-1;m++){let x=n[m*2],g=n[m*2+1],d=n[m*2+2],b=n[m*2+3];if(x===d&&g===b||yt(x,g,d,b,l,Ae(l))||c.has(We(x,g,d,b)))continue;let E=d-x,A=b-g,_=Math.hypot(E,A)||1,R=A/_,L=-E/_,k=r-i,T=Math.hypot(e[m*2]-x,e[m*2+1]-g)||0,O=0;if(T>1e-6&&k!==0){let Y=1/Math.hypot(1,k/T);O=T/Math.hypot(T,k)*Math.sign(k),R*=Y,L*=Y}let D=lt(t,e[m*2],e[m*2+1],r,R,L,O,s),U=lt(t,e[m*2+2],e[m*2+3],r,R,L,O,s),P=lt(t,x,g,i,R,L,O,s),C=lt(t,d,b,i,R,L,O,s);t.indices.push(P,U,C,P,D,U)}}}function Ht(t,e,n,r){let i=t.length/2-1;if(i<3)return null;let s=[];for(let x=0;x<i;x++){let g=t[x*2],d=t[x*2+1],b=t[(x+i-1)%i*2],E=t[(x+i-1)%i*2+1],A=t[(x+1)%i*2],_=t[(x+1)%i*2+1],R=Math.hypot(g-b,d-E)||1,L=Math.hypot(A-g,_-d)||1,k=(d-E)/R,T=-(g-b)/R,O=(_-d)/L,D=-(A-g)/L,U=k+O,P=T+D,C=Math.hypot(U,P);if(C<1e-6){s.push(g,d);continue}U/=C,P/=C;let Y=Math.min(1/Math.max(U*k+P*T,.35),3),Q=g-U*e*Y,Z=d-P*e*Y,re=We(b,E,g,d),X=We(g,d,A,_);if(r.has(re)||r.has(X)){s.push(g,d);continue}let $=-Ae(n),z=n+Ae(n),N=(q,te)=>q<=$||q>=z||te<=$||te>=z;(N(g,d)||N(b,E)||N(A,_))&&(Q=g,Z=d),s.push(Q,Z)}s.push(s[0],s[1]);let l=Math.abs($t(t)),c=$t(s);if(Math.sign(c)!==Math.sign($t(t))||Math.abs(c)<l*.25)return null;let a=-Ae(n),m=n+Ae(n);for(let x=0;x<s.length;x+=2)s[x]=Math.max(a,Math.min(m,s[x])),s[x+1]=Math.max(a,Math.min(m,s[x+1]));return s}function $t(t){let e=0;for(let n=0;n<t.length-2;n+=2)e+=t[n]*t[n+3]-t[n+2]*t[n+1];return e/2}var jt=t=>t>127?127:t<-127?-127:t,Ni=t=>t>32767?32767:t<-32768?-32768:t;function Gn(t,e,n){if(!(e>0))return t;let r=Ae(n),i=-r,s=n+r,l=t;for(let c=0;c<3;c++){let a=l.length/2-1;if(a<6)break;let m=new Array(a).fill(!0),x=a;for(let d=0;d<a&&!(x<=5);d++){let b=l[d*2],E=l[d*2+1];if(b<=i||b>=s||E<=i||E>=s)continue;let A=(d+a-1)%a;for(;!m[A]&&A!==d;)A=(A+a-1)%a;let _=(d+1)%a;for(;!m[_]&&_!==d;)_=(_+1)%a;if(A===d||_===d)break;let R=l[A*2],L=l[A*2+1],k=l[_*2]-R,T=l[_*2+1]-L,O=Math.hypot(k,T);O<1e-6||Math.abs((b-R)*T-(E-L)*k)/O<e&&(m[d]=!1,x--)}if(x===a)break;let g=[];for(let d=0;d<a;d++)m[d]&&g.push(l[d*2],l[d*2+1]);g.push(g[0],g[1]),l=g}return l}function Qe(t){let e=t.layer,n=typeof e=="number"?e:typeof e=="string"?Number(e):NaN;if(Number.isFinite(n)&&n!==0)return Math.max(-5,Math.min(5,Math.trunc(n)));let r=t.brunnel;return r==="bridge"?1:r==="tunnel"?-1:0}var ct=20;function jn(t,e,n=0,r,i=0,s={}){let{level:l}=s,c=Math.max(256,t.length*24),a=new ArrayBuffer(c*ct),m=new DataView(a),x=0,g=[],d=L=>{if(x+L<=c)return;c=Math.max(c*2,x+L);let k=new ArrayBuffer(c*ct);new Uint8Array(k).set(new Uint8Array(a,0,x*ct)),a=k,m=new DataView(k)},b=(L,k,T,O,D,U,P,C=0,Y=0,Q=0)=>{let Z=x*ct;return m.setInt16(Z,L,!0),m.setInt16(Z+2,k,!0),m.setInt16(Z+4,T,!0),m.setInt16(Z+6,O,!0),m.setInt8(Z+8,D),m.setInt8(Z+9,U),m.setInt8(Z+10,C),m.setInt8(Z+11,Y),m.setFloat32(Z+12,P,!0),m.setFloat32(Z+16,Q,!0),x++},E=0,A=i>0?12/i:0,_=A>0?Xi(t):null;for(let L of t.features()){if(L.type!==2&&L.type!==3||!ce(e,L.properties)||l!==void 0&&Qe(L.properties)!==l)continue;let k=L.properties.width;E=typeof k=="number"&&k>.5&&k<100?k:0;let T=L.type===3;for(let O of L.loadGeometry()){let D=n>0?Hi(Hn(O),n):Hn(O);if(D.length<4)continue;let U=r&&!kn(r)?_n(r,D):null,P=U?U.pts:D,C=U?.levels,Y=P.length/2;if(Y<2)continue;let Q=Qe(L.properties),Z=wt(Math.round(P[0]),Math.round(P[1])),re=wt(Math.round(P[Y*2-2]),Math.round(P[Y*2-1])),X=null,$=E;if(_&&E>0&&!T){let N=0;for(let ee=0;ee<Y-1;ee++)N+=Math.hypot(P[ee*2+2]-P[ee*2],P[ee*2+3]-P[ee*2+1]);$=Xn(Q,E,Z,re,_);let q=ee=>Math.min(_.width.get(ee)??0,$*2),te=q(Z)-$,K=q(re)-$,oe=Math.min(A,N/2);if(oe>0&&(te>0||K>0)){X=J=>{let fe=0;return te>0&&J<oe&&(fe=te*(1-J/oe)),K>0&&N-J<oe&&(fe=Math.max(fe,K*(1-(N-J)/oe))),$+fe};let ee=[];for(let J of[oe,N-oe])J>.01&&J<N-.01&&ee.push(J);if(ee.length){let J=zi(P,C,ee);P=J.pts,C=J.levels,Y=P.length/2}}}d((Y-1)*4);let z=0;for(let N=0;N<Y-1;N++){let q=P[N*2],te=P[N*2+1],K=P[N*2+2],oe=P[N*2+3],ee=Math.hypot(K-q,oe-te);if(T&&ji(q,te,K,oe,t.extent)){z+=ee;continue}let J=$i(q,te,K,oe,t.extent);if(!J){z+=ee;continue}let[fe,be,de,Fe]=J,Ce=Math.hypot(fe-q,be-te),Le=Math.hypot(de-fe,Fe-be),Ve=Math.hypot(K-de,oe-Fe),we=z+Ce,se=C?C[N]:0,Pe=C?C[N+1]:0,xe=X?X(we):$,Be=X?X(we+Le):$,Oe=b(fe,be,de,Fe,0,-1,we,se,Pe,xe),De=b(fe,be,de,Fe,0,1,we,se,Pe,xe),Ie=b(fe,be,de,Fe,1,1,we,se,Pe,Be),ze=b(fe,be,de,Fe,1,-1,we,se,Pe,Be);z+=Ce+Le+Ve,g.push(Oe,De,Ie,Oe,Ie,ze)}}}if(!g.length)return null;let R=new Uint32Array(g);return{vertices:a.slice(0,x*ct),indices:R.buffer,vertexCount:x,indexCount:R.length}}function zi(t,e,n){let r=[...n].sort((a,m)=>a-m),i=[t[0],t[1]],s=e?[e[0]]:void 0,l=0,c=0;for(let a=0;a+3<t.length;a+=2){let m=t[a],x=t[a+1],g=t[a+2],d=t[a+3],b=Math.hypot(g-m,d-x);for(;c<r.length&&r[c]<=l+.01;)c++;for(;c<r.length&&r[c]<l+b-.01;){let E=(r[c]-l)/b;i.push(m+(g-m)*E,x+(d-x)*E),s&&e&&s.push(Math.round(e[a/2]+(e[a/2+1]-e[a/2])*E)),c++}l+=b,i.push(g,d),s&&e&&s.push(e[a/2+1])}return{pts:i,levels:s}}function Hi(t,e){let n=[];for(let r=0;r+3<t.length;r+=2){let i=t[r],s=t[r+1],l=t[r+2],c=t[r+3];n.push(i,s);let a=Math.min(64,Math.floor(Math.hypot(l-i,c-s)/e));for(let m=1;m<a;m++){let x=m/a;n.push(i+(l-i)*x,s+(c-s)*x)}}return n.push(t[t.length-2],t[t.length-1]),n}function Hn(t){let e=[];for(let n=0;n<t.length;n+=2){let r=t[n],i=t[n+1],s=e.length;s>=2&&e[s-2]===r&&e[s-1]===i||e.push(r,i)}return e}function $i(t,e,n,r,i){let s=n-t,l=r-e,c=0,a=1,m=[[-s,t],[s,i-t],[-l,e],[l,i-e]];for(let[x,g]of m){if(x===0){if(g<0)return null;continue}let d=g/x;if(x<0){if(d>a)return null;d>c&&(c=d)}else{if(d<c)return null;d<a&&(a=d)}}return a-c<1e-6?null:[Math.round(t+s*c),Math.round(e+l*c),Math.round(t+s*a),Math.round(e+l*a)]}function ji(t,e,n,r,i){return t===n&&(t<=0||t>=i)?!0:e===r&&(e<=0||e>=i)}var $n=new WeakMap,wt=(t,e)=>(t+512)*65536+(e+512);function Xn(t,e,n,r,i){if(t===0||e<=0)return e;let s=8*4294967296,l=Math.max(i.raw.get(n+s)??0,i.raw.get(r+s)??0);return l>0&&e>l?l:e}function Xi(t){let e=$n.get(t);if(e)return e;let n={width:new Map,ends:new Map,raw:new Map},r=[];for(let i of t.features()){if(i.type!==2)continue;let s=i.properties.width,l=typeof s=="number"&&s>.5&&s<100?s:0,c=Qe(i.properties);for(let a of i.loadGeometry()){if(a.length<4)continue;let m=wt(Math.round(a[0]),Math.round(a[1])),x=wt(Math.round(a[a.length-2]),Math.round(a[a.length-1]));for(let g of[m,x]){let d=g+(c+8)*4294967296;n.ends.set(d,(n.ends.get(d)??0)+1),l>0&&n.raw.set(d,Math.max(n.raw.get(d)??0,l))}r.push({h:m,t:x,lv:c,w:l})}}for(let i of r){let s=Xn(i.lv,i.w,i.h,i.t,n);if(!(s<=0))for(let l of[i.h,i.t]){let c=n.width.get(l);(c===void 0||s>c)&&n.width.set(l,s)}}return $n.set(t,n),n}var Yi=[["\\u0443\\u043B\\u0438\\u0446\\u0430","\\u0443\\u043B."],["\\u0443\\u043B\\u0438\\u0446\\u044B","\\u0443\\u043B."],["\\u0443\\u043B\\u0438\\u0446\\u0435","\\u0443\\u043B."],["\\u043F\\u0440\\u043E\\u0441\\u043F\\u0435\\u043A\\u0442","\\u043F\\u0440\\u043E\\u0441\\u043F."],["\\u043F\\u0440\\u043E\\u0441\\u043F\\u0435\\u043A\\u0442\\u0430","\\u043F\\u0440\\u043E\\u0441\\u043F."],["\\u043F\\u0435\\u0440\\u0435\\u0443\\u043B\\u043E\\u043A","\\u043F\\u0435\\u0440."],["\\u043F\\u0435\\u0440\\u0435\\u0443\\u043B\\u043A\\u0430","\\u043F\\u0435\\u0440."],["\\u043F\\u0440\\u043E\\u0435\\u0437\\u0434","\\u043F\\u0440-\\u0434"],["\\u043F\\u0440\\u043E\\u0435\\u0437\\u0434\\u0430","\\u043F\\u0440-\\u0434"],["\\u043F\\u043B\\u043E\\u0449\\u0430\\u0434\\u044C","\\u043F\\u043B."],["\\u043F\\u043B\\u043E\\u0449\\u0430\\u0434\\u0438","\\u043F\\u043B."],["\\u0431\\u0443\\u043B\\u044C\\u0432\\u0430\\u0440","\\u0431\\u0443\\u043B."],["\\u0431\\u0443\\u043B\\u044C\\u0432\\u0430\\u0440\\u0430","\\u0431\\u0443\\u043B."],["\\u043D\\u0430\\u0431\\u0435\\u0440\\u0435\\u0436\\u043D\\u0430\\u044F","\\u043D\\u0430\\u0431."],["\\u043D\\u0430\\u0431\\u0435\\u0440\\u0435\\u0436\\u043D\\u043E\\u0439","\\u043D\\u0430\\u0431."],["\\u0448\\u043E\\u0441\\u0441\\u0435","\\u0448."],["\\u0442\\u0443\\u043F\\u0438\\u043A","\\u0442\\u0443\\u043F."],["\\u0442\\u0443\\u043F\\u0438\\u043A\\u0430","\\u0442\\u0443\\u043F."],["\\u043C\\u0438\\u043A\\u0440\\u043E\\u0440\\u0430\\u0439\\u043E\\u043D","\\u043C\\u043A\\u0440."],["\\u043C\\u0438\\u043A\\u0440\\u043E\\u0440\\u0430\\u0439\\u043E\\u043D\\u0430","\\u043C\\u043A\\u0440."],["\\u043A\\u04EF\\u0447\\u0430\\u0438","\\u043A."],["\\u043A\\u0443\\u0447\\u0430\\u0438","\\u043A."],["\\u0445\\u0438\\u0451\\u0431\\u043E\\u043D\\u0438","\\u0445\\u0438\\u0451\\u0431."],["\\u0448\\u043E\\u04B3\\u0440\\u043E\\u04B3\\u0438","\\u0448\\u043E\\u04B3."],["\\u0433\\u0443\\u0437\\u0430\\u0440\\u0433\\u043E\\u04B3\\u0438","\\u0433\\u0443\\u0437."],["\\u043C\\u0430\\u0439\\u0434\\u043E\\u043D\\u0438","\\u043C\\u0430\\u0439\\u0434."]],Yn=new Map(Yi);function Zn(t){let e=t.split(" ");if(e.length<2)return t;let n=!1,r=e.map(s=>{let l=Yn.get(s.toLowerCase());return l?(n=!0,s[0]===s[0].toUpperCase()?l[0].toUpperCase()+l.slice(1):l):s});return!n||!e.filter(s=>Yn.get(s.toLowerCase())===void 0).length?t:r.join(" ")}function Qn(t,e){let n=[],r=[],i=[],s=[],l=[],c=e.textPlacement==="line",a=[],m=[],x=[];for(let g of t.features()){if(!ce(e.filter,g.properties))continue;let d=g.loadGeometry(),b=Qi(g.type,d);if(!b)continue;let E=e.textField?Wn(e.textField,g.properties):"",A=E&&e.abbreviate?Zn(E):E,_=e.iconImage?Wn(e.iconImage,g.properties):"";if(!(!A&&!_)){if(c){let R=Wi(g.type,d);if(!R)continue;x.push({text:A,line:R});continue}n.push(b[0],b[1]),r.push(A),i.push(_),s.push(Ki(g.properties)),l.push(e.iconRotate&&Math.round(Number(g.properties[e.iconRotate]??0))||0)}}if(c){for(let{text:g,line:d}of Zi(x)){m.push(a.length/2);for(let b of d)a.push(b);n.push(Math.round(d[0]),Math.round(d[1])),r.push(g),i.push(""),s.push(128),l.push(0)}m.push(a.length/2)}return r.length?{anchors:new Int16Array(n).buffer,texts:r,icons:i,priorities:new Uint8Array(s).buffer,rotations:new Int16Array(l).buffer,...c?{lines:new Int16Array(a).buffer,lineStarts:new Uint32Array(m).buffer}:{}}:null}function Zi(t){let e=[],n=new Map,r=new Map,i=(s,l,c)=>`${s}\\u241F${l}\\u241F${c}`;for(let{text:s,line:l}of t){let c=i(s,l[0],l[1]),a=i(s,l[l.length-2],l[l.length-1]),m=n.get(a),x=r.get(c);if(x!==void 0){let g=e[x];if(g.line.push(...l.slice(2)),r.delete(c),r.set(i(s,g.line[g.line.length-2],g.line[g.line.length-1]),x),m!==void 0&&m!==x){let d=e[m];g.line.push(...d.line.slice(2)),d.line=[],n.delete(a),r.set(i(s,g.line[g.line.length-2],g.line[g.line.length-1]),x)}continue}if(m!==void 0){let g=e[m];g.line.unshift(...l.slice(0,l.length-2)),n.delete(a),n.set(i(s,g.line[0],g.line[1]),m);continue}n.set(c,e.length),r.set(a,e.length),e.push({text:s,line:l})}return e.filter(s=>s.line.length>=4)}function Wi(t,e){if(t!==2)return null;let n=null,r=0;for(let i of e){if(i.length<4)continue;let s=0;for(let l=0;l+3<i.length;l+=2)s+=Math.hypot(i[l+2]-i[l],i[l+3]-i[l+1]);s>r&&(r=s,n=i)}return n}function Qi(t,e){if(!e.length)return null;if(t===1){let l=e[0];return l.length>=2?[l[0],l[1]]:null}if(t===2){let l=-1,c=0,a=0;for(let m of e)for(let x=0;x+3<m.length;x+=2){let g=m[x+2]-m[x],d=m[x+3]-m[x+1],b=g*g+d*d;b>l&&(l=b,c=m[x]+g/2,a=m[x+1]+d/2)}return l>0?[Math.round(c),Math.round(a)]:null}let n=1/0,r=1/0,i=-1/0,s=-1/0;for(let l of e)for(let c=0;c<l.length;c+=2)l[c]<n&&(n=l[c]),l[c]>i&&(i=l[c]),l[c+1]<r&&(r=l[c+1]),l[c+1]>s&&(s=l[c+1]);return isFinite(n)?[Math.round((n+i)/2),Math.round((r+s)/2)]:null}function Ki(t){let e=t.rank;return typeof e=="number"&&isFinite(e)?Math.max(0,255-Math.min(e,255)):128}function Wn(t,e){let n=Array.isArray(t)?t:[t];for(let r of n){let i=!0,l=r.replace(/\\{([^}]+)\\}/g,(c,a)=>{let m=e[a];return m==null||m===""?(i=!1,""):String(m)}).trim();if(i&&l)return l}return""}function Kn(t,e){let n=[],r=[];for(let i=0;i<t.length;i++){let s=t.feature(i);if(s.type===1&&ce(e,s.properties))for(let l of s.loadGeometry())for(let c=0;c+1<l.length;c+=2)n.push(l[c],l[c+1]),r.push(s.properties)}return r.length?{anchors:Int16Array.from(n).buffer,props:r}:null}var Ji="\\u241F",Yt=(t,e)=>t+Ji+String(e);function qi(){let t=typeof self<"u"?self.origin:void 0;return t&&t!=="null"&&!t.startsWith("blob:")?t+"/":void 0}async function Jn(t,e){let n=performance.now(),r=qi(),i=await fetch(t.url,{signal:e,credentials:"same-origin",...r?{referrer:r}:{}}),s=(R,L,k,T,O=0)=>({type:"loaded",id:t.id,buckets:{},timing:{fetchMs:T,parseMs:O},diag:{status:R,bytes:L,layers:k,built:0}});if(!i.ok){if(i.status===404||i.status===204)return s(i.status,0,[],performance.now()-n);throw new Error(`HTTP ${i.status} \\u0434\\u043B\\u044F ${t.url}`)}let l=await i.arrayBuffer(),c=performance.now()-n;if(l.byteLength===0)return s(i.status,0,[],c);let a=performance.now(),m=new gt(l),x=Object.keys(m.layers),g={},d={},b=new Set,E=[],_=t.plan.some(R=>R.type==="surface"&&(R.elevation??0)>0)&&t.plan.some(R=>R.type==="line"&&R.ground)?In(t.metersPerTile):void 0;for(let R of t.plan){if(!to(R,t.zoom,t.sourceMaxZoom))continue;let L=m.layers[R.sourceLayer];if(!L)continue;let k=no(t.zoom,L.extent);try{if(R.splitBy){let O=ro(L,R.splitBy,R.filter);if(!O.length)continue;let D=d[R.splitBy]??(d[R.splitBy]=[]);for(let U of O){D.includes(U)||D.push(U);let P={...R,splitBy:void 0,filter:oo(R.filter,R.splitBy,U)},C=Zt(P,L,k,t.metersPerTile,_);C&&(g[Yt(R.id,U)]=C)}continue}if(R.network&&R.type==="line"){for(let O of io(L,R.filter)){let D=Zt(R,L,k,t.metersPerTile,_,O);D&&(g[Yt(R.id,O)]=D,b.add(O))}continue}let T=Zt(R,L,k,t.metersPerTile,_);T&&(g[R.id]=T)}catch(T){E.push(`${R.id}: ${T instanceof Error?T.message:String(T)}`)}}return{type:"loaded",id:t.id,buckets:g,...Object.keys(d).length?{splits:d}:{},...b.size?{levels:[...b].sort((R,L)=>R-L)}:{},timing:{fetchMs:c,parseMs:performance.now()-a},diag:{status:i.status,bytes:l.byteLength,layers:x,built:Object.keys(g).length,...E.length?{failed:E}:{}}}}function eo(t){return e=>{let n=e.on;if(typeof n!="string"||!n)return 0;let r=0;for(let i of n.split(",")){let s=t[i];typeof s=="number"&&s>r&&(r=s)}return r}}function to(t,e,n){let r=e-1,i=e<n?e+1:24;return!(t.maxzoom<r||t.minzoom>i)}function no(t,e){return t<=6?Math.max(64,e/24):0}function Zt(t,e,n,r,i,s){{if(t.type==="fill"){let c=r>0?r/e.extent:0,a=t.cornerRadius&&c>0?{radius:t.cornerRadius/c,segments:t.cornerSegments,extent:e.extent,minCutRatio:0,maxChord:hn/c}:void 0,m=Rn(e,t.filter,n,a,t.clipToTile===!0,e.extent);return m?{kind:"fill",...m,extent:e.extent}:null}if(t.type==="surface"){let c=zn(e,e.extent,t.filter,{metersPerUnit:r>0?r/e.extent:0,maxSegment:n,elevation:t.elevation??0,base:t.base,bevel:t.bevel,weld:t.weld,bevelDrop:t.bevelDrop,cornerRadius:t.cornerRadius,cornerSegments:t.cornerSegments,...i?{onShapes:a=>Pn(i,a,t.elevation??0,e.extent)}:{},...t.groundBy?{liftBy:eo(t.groundBy)}:{}});return c?{kind:"surface",...c}:null}if(t.type==="line"){let c=jn(e,t.filter,n,t.ground?i:void 0,r>0?r/e.extent:0,{level:s});return c?{kind:"line",...c,extent:e.extent}:null}if(t.type==="model"){let c=Kn(e,t.filter);return c?{kind:"placement",...c,extent:e.extent}:null}if(t.type==="symbol"){let c=Qn(e,{filter:t.filter,textField:t.textField,iconImage:t.iconImage,iconRotate:t.iconRotate,textPlacement:t.textPlacement,abbreviate:t.abbreviate});return c?{kind:"symbol",...c,extent:e.extent}:null}let l=En(e,e.extent,t.filter,{metersPerUnit:r>0?r/e.extent:0,cornerRadius:t.cornerRadius,cornerSegments:t.cornerSegments});return l?{kind:"fill-extrusion",vertices:l.vertices,indices:l.indices,featureIds:l.featureIds,vertexCount:l.vertexCount,indexCount:l.indexCount,extent:l.extent}:null}}function ro(t,e,n){let r=[];for(let i of t.features()){if(!ce(n,i.properties))continue;let s=i.properties[e];typeof s!="string"&&typeof s!="number"||r.includes(s)||r.push(s)}return r.sort((i,s)=>typeof i=="number"&&typeof s=="number"?i-s:String(i).localeCompare(String(s))),r}function io(t,e){let n=[];for(let r of t.features()){if(!ce(e,r.properties))continue;let i=Qe(r.properties);n.includes(i)||n.push(i)}return n.sort((r,i)=>r-i)}function oo(t,e,n){let r=["==",e,n];return t?["all",t,r]:r}var so=t=>t.kind==="symbol",uo=t=>t.kind==="placement";function qn(t){let e=[];for(let n of Object.values(t.buckets)){if(uo(n)){e.push(n.anchors);continue}if(so(n)){e.push(n.anchors,n.priorities),n.lines&&e.push(n.lines),n.lineStarts&&e.push(n.lineStarts);continue}e.push(n.vertices,n.indices),n.featureIds&&e.push(n.featureIds)}return e}var er=Map;var Ke=new er,Wt=self;Wt.onmessage=t=>{let e=t.data;if(e.type==="abort"){Ke.get(e.id)?.abort(),Ke.delete(e.id);return}let n=new AbortController;Ke.set(e.id,n),Jn(e,n.signal).then(r=>{Ke.has(e.id)&&(Ke.delete(e.id),Wt.postMessage(r,qn(r)))}).catch(r=>{let i=n.signal.aborted;Ke.delete(e.id);let s={type:"error",id:e.id,message:r instanceof Error?r.message:String(r),aborted:i};Wt.postMessage(s)})};})();\n';var kr=class{constructor(e=Ei()){this.workers=[];this.blobUrl=null;this.pending=new z;this.nextId=1;this.cursor=0;this.mainThreadAborts=new z;this.destroyed=false;try{let t=new Blob([_i],{type:"text/javascript"});this.blobUrl=URL.createObjectURL(t);for(let o=0;o<e;o++){let r=new Worker(this.blobUrl);r.onmessage=i=>this.onMessage(i.data),r.onerror=i=>console.error("[osmgl] \u0432\u043E\u0440\u043A\u0435\u0440 \u0443\u043F\u0430\u043B:",i.message),this.workers.push(r);}}catch(t){console.warn("[osmgl] \u0432\u043E\u0440\u043A\u0435\u0440\u044B \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u044B, \u0440\u0430\u0437\u0431\u043E\u0440 \u0442\u0430\u0439\u043B\u043E\u0432 \u043F\u043E\u0439\u0434\u0451\u0442 \u0432 \u0433\u043B\u0430\u0432\u043D\u043E\u043C \u043F\u043E\u0442\u043E\u043A\u0435:",t),this.disposeWorkers();}this.usingWorkers=this.workers.length>0;}get size(){return this.workers.length}load(e,t){let o=this.nextId++,r={type:"load",id:o,...e};if(!this.usingWorkers){let a=new AbortController;return this.mainThreadAborts.set(o,a),Ys(r,a.signal).then(l=>{this.mainThreadAborts.has(o)&&(this.mainThreadAborts.delete(o),t(l));}).catch(l=>{let s=a.signal.aborted;this.mainThreadAborts.delete(o),t({type:"error",id:o,message:l instanceof Error?l.message:String(l),aborted:s});}),o}let i=this.cursor++%this.workers.length;return this.pending.set(o,{resolve:t,workerIndex:i}),this.workers[i].postMessage(r),o}abort(e){if(!this.usingWorkers){this.mainThreadAborts.get(e)?.abort(),this.mainThreadAborts.delete(e);return}let t=this.pending.get(e);if(!t)return;this.pending.delete(e);let o={type:"abort",id:e};this.workers[t.workerIndex].postMessage(o);}onMessage(e){if(this.destroyed)return;let t=this.pending.get(e.id);t&&(this.pending.delete(e.id),t.resolve(e));}disposeWorkers(){for(let e of this.workers)e.terminate();this.workers=[],this.blobUrl&&URL.revokeObjectURL(this.blobUrl),this.blobUrl=null;}destroy(){this.destroyed=true;for(let e of this.mainThreadAborts.values())e.abort();this.mainThreadAborts.clear(),this.pending.clear(),this.disposeWorkers();}};function Ei(){let n=typeof navigator<"u"&&navigator.hardwareConcurrency||4;return Math.max(1,Math.min(n-1,6))}function Zs(n){return Math.max(0,Math.ceil((n*Math.LN2+Math.log(512/360/.5))/Math.LN10))}function Mi(n,e){let t=Zs(n.zoom),o=[Math.round(n.zoom*100)/100,n.center.lat.toFixed(t),n.center.lng.toFixed(t)],r=Math.round(n.bearing*10)/10,i=Math.round(n.pitch*10)/10;(r!==0||i!==0)&&(o.push(r),i!==0&&o.push(i));let a=o.join("/");return e?`${e}=${a}`:a}function Fi(n,e){let t=n.replace(/^#/,"");if(!t)return null;if(e){let s=t.split("&").map(c=>c.split("=")).find(([c])=>c===e);if(!s||s.length<2)return null;t=s[1];}let o=t.split("/");if(o.length<3)return null;let r=Number(o[0]),i=Number(o[1]),a=Number(o[2]);if(!isFinite(r)||!isFinite(i)||!isFinite(a)||Math.abs(i)>90||Math.abs(a)>180)return null;let l={center:{lng:a,lat:i},zoom:r};return o.length>3&&isFinite(Number(o[3]))&&(l.bearing=Number(o[3])),o.length>4&&isFinite(Number(o[4]))&&(l.pitch=Number(o[4])),l}function Qs(n){if(typeof window>"u"||!window.history?.replaceState)return;let e=new URL(window.location.href);e.hash=n,window.history.replaceState(window.history.state,"",e.toString());}var qs={high:{name:"high",maxPixelRatio:2,maxCanvasPixels:16777216,antialias:true,maxWorkers:6,shadowMapSize:1024,detail:1,tileCacheSize:64,allowShadows:true,detailBias:1,maxTiles:512,modelBudget:1,simpleGeometry:false},balanced:{name:"balanced",maxPixelRatio:1.75,maxCanvasPixels:5529600,antialias:true,maxWorkers:4,shadowMapSize:1024,detail:.85,tileCacheSize:40,allowShadows:true,detailBias:1.1,maxTiles:192,modelBudget:.7,simpleGeometry:false},low:{name:"low",maxPixelRatio:1.25,maxCanvasPixels:2592e3,antialias:true,maxWorkers:2,shadowMapSize:512,detail:.5,tileCacheSize:24,allowShadows:false,detailBias:1.25,maxTiles:96,modelBudget:.4,simpleGeometry:true},minimal:{name:"minimal",maxPixelRatio:1,maxCanvasPixels:1152e3,antialias:false,maxWorkers:2,shadowMapSize:512,detail:0,tileCacheSize:16,allowShadows:false,detailBias:1.7,maxTiles:48,modelBudget:.2,simpleGeometry:true}},Ut=n=>qs[n]??qs.high;function Pr(n){let{cores:e,memory:t,mobile:o,devicePixelRatio:r}=n;return e<=2||t!==void 0&&t<=2?"minimal":o?e<=4||t!==void 0&&t<=3?"minimal":e<=6||t!==void 0&&t<=4||r>=3?"low":"balanced":e<=4||t!==void 0&&t<=4?"balanced":"high"}function Rr(){if(typeof navigator>"u")return {cores:4,mobile:false,devicePixelRatio:1};let n=navigator,e=typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches&&typeof screen<"u"&&Math.min(screen.width,screen.height)<=820,t=n.userAgentData?.mobile===true||e;return {cores:n.hardwareConcurrency||4,memory:n.deviceMemory,mobile:t,devicePixelRatio:typeof devicePixelRatio=="number"?devicePixelRatio:1}}function Di(n,e,t,o){let r=Math.min(t||1,o.maxPixelRatio),i=Math.max(n*e,1),a=Math.sqrt(o.maxCanvasPixels/i);return Math.max(Math.min(r,a),1)}function Si(n){return n==="high"?3:n==="balanced"?2:n==="low"?1:0}function $s(n){return n==="minimal"?"low":n==="low"?"balanced":n==="balanced"?"high":null}function Ii(n){return n==="high"?"balanced":n==="balanced"?"low":n==="low"?"minimal":null}var Wd=1,Po=class{constructor(e){this.originX=0;this.originY=0;this._revision=0;this.id=e.id??`obj-${Wd++}`,this.zIndex=e.zIndex??0,this.altitude=e.altitude??0,this.visible=e.visible!==false,this.userData=e.userData??{},this.paint=e;}get ghostOpacity(){return this.paint.ghostOpacity??0}get revision(){return this._revision}invalidate(){this._revision++;}setPaint(e){return Object.assign(this.paint,e),this.invalidate(),this}setOriginFromCoords(e){let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let a of e)for(let l of a){let s=$(l),c=ne(s.lng),h=ie(s.lat);c<t&&(t=c),c>r&&(r=c),h<o&&(o=h),h>i&&(i=h);}if(!isFinite(t)){this.originX=0,this.originY=0;return}this.originX=(t+r)/2,this.originY=(o+i)/2;}toLocal(e){let t=[];for(let o of e){let r=$(o);t.push(ne(r.lng)-this.originX,ie(r.lat)-this.originY);}return t}color(e,t){let o=he(this.paint[e]??t),r=this.paint.opacity??1;return [o[0],o[1],o[2],o[3]*r]}linePaint(e){return e.dashArray=this.paint.dashArray,e.offset=this.paint.offset,this.paint.arrow&&(e.arrow=true,e.arrowColor=this.color("arrowColor","#ffffff"),e.arrowPeriod=this.paint.arrowPeriod??46,e.arrowSize=this.paint.arrowSize??5),e}},Ti=class extends Po{constructor(e){super(e),this.coordinates=e.coordinates,this.segments=e.segments??[],this.setOriginFromCoords([this.coordinates]);}setCoordinates(e){return this.coordinates=e,this.setOriginFromCoords([e]),this.invalidate(),this}setSegments(e){return this.segments=e,this.invalidate(),this}getCoordinates(){return this.coordinates}rings(){return [this.coordinates]}build(){let e=go([this.toLocal(this.coordinates)]);if(!e)return [];let t=this.paint.width??6,o=[],r=this.paint.strokeWidth??0;r>0&&o.push({kind:"line",mesh:e,color:this.color("strokeColor","#ffffff"),width:t+r*2,offset:this.paint.offset});let i=this.colorRuns();if(!i.length)return o.push(this.linePaint({kind:"line",mesh:e,color:this.color("color","#2f6df6"),width:t})),o;let a=this.paint.opacity??1;for(let l of i){let s=go([this.toLocal(this.coordinates.slice(l.from,l.to+1))]);if(!s)continue;let c=he(l.color);o.push(this.linePaint({kind:"line",mesh:s,color:[c[0],c[1],c[2],c[3]*a],width:t}));}return o}colorRuns(){if(this.segments.length===0||this.coordinates.length<2)return [];let e=this.coordinates.length-1,t=this.segments.filter(r=>Number.isInteger(r.at)&&r.at>=0&&r.at<e).sort((r,i)=>r.at-i.at);if(!t.length)return [];let o=[];for(let r=0;r<t.length;r++){let i=r===0?0:t[r].at,a=r+1<t.length?t[r+1].at:e;a>i&&o.push({from:i,to:a,color:t[r].color});}return o}hitTest(e,t,o){let r=(this.paint.width??6)/2+(this.paint.strokeWidth??0)+o,i=ki(this.coordinates,this.altitude,t);for(let a=0;a+1<i.length;a++)if(ec(e,i[a],i[a+1])<=r)return true;return false}},Gr=class extends Po{constructor(e){super(e),this.coordinates=e.coordinates,this.setOriginFromCoords(this.coordinates);}setCoordinates(e){return this.coordinates=e,this.setOriginFromCoords(e),this.invalidate(),this}rings(){return this.coordinates}build(){let e=[],t=Zn(this.coordinates.map(r=>this.toLocal(r)));t&&e.push({kind:"fill",mesh:t,color:this.color("color","#2f6df6"),width:0});let o=this.paint.strokeWidth??this.paint.width??0;if(o>0){let r=this.coordinates.map(a=>this.toLocal(Li(a))),i=go(r);i&&e.push(this.linePaint({kind:"line",mesh:i,color:this.color("strokeColor","#2f6df6"),width:o}));}return e}hitTest(e,t){let o=ki(Li(this.coordinates[0]??[]),this.altitude,t);if(!Pi(e,o))return false;for(let r=1;r<this.coordinates.length;r++)if(Pi(e,ki(Li(this.coordinates[r]),this.altitude,t)))return false;return true}},Hi=class extends Gr{constructor(e){super({...e,coordinates:[Nd(e.center,e.radius,e.segments)]});}};function Nd(n,e,t){let o=$(n),r=e/Oe(o.lat),i=ne(o.lng),a=ie(o.lat),l=Math.max(12,t??Math.min(128,Math.round(24+e/20))),s=[];for(let c=0;c<l;c++){let h=c/l*Math.PI*2;s.push([Se(i+Math.cos(h)*r),Fe(a+Math.sin(h)*r)]);}return s}function ki(n,e,t){let o=[];for(let r of n){let i=$(r),a=t(i.lng,i.lat,e);a&&o.push(a);}return o}function Li(n){if(n.length<2)return n;let e=$(n[0]),t=$(n[n.length-1]);return e.lng===t.lng&&e.lat===t.lat?n:[...n,n[0]]}function ec(n,e,t){let o=t.x-e.x,r=t.y-e.y,i=o*o+r*r;if(i<1e-12)return Math.hypot(n.x-e.x,n.y-e.y);let a=((n.x-e.x)*o+(n.y-e.y)*r)/i;return a=a<0?0:a>1?1:a,Math.hypot(n.x-(e.x+a*o),n.y-(e.y+a*r))}function Pi(n,e){let t=false;for(let o=0,r=e.length-1;o<e.length;r=o++){let i=e[o].x,a=e[o].y,l=e[r].x,s=e[r].y;a>n.y!=s>n.y&&n.x<(l-i)*(n.y-a)/(s-a)+i&&(t=!t);}return t}var tc="objects3d",Jt="level",Kd=32,Ud=100,Ri=120,Jd=40,Xd=.35,jd=.02,Yd=150,Zd=250;function oc(n){return typeof n=="number"?{top:n,right:n,bottom:n,left:n}:{top:n?.top??0,right:n?.right??0,bottom:n?.bottom??0,left:n?.left??0}}function Qd(n){let e={...n};return delete e.cornerRadius,delete e.cornerSegments,e.type==="surface"&&(e.type="fill",delete e.elevation,delete e.base,delete e.bevel,delete e.bevelDrop),e}var Gi=class extends $e{constructor(t){super();this.options=t;this.transform=new Yt;this.ctx=null;this.sources=new z;this.rasterSources=new z;this.renderer=new wo;this.objects=new Ao;this.markerHost=null;this.gestures=null;this.resizeObserver=null;this.frameHandle=0;this.needsRepaint=true;this.padding={top:0,right:0,bottom:0,left:0};this.animation=null;this.loaded=false;this.destroyed=false;this.objects3d=null;this.objects3dEnabled=true;this.frameRing=new Uint8Array(Ri);this.ringAt=0;this.ringSum=0;this.ringFilled=0;this.steadyFrames=0;this.lastFrameAt=0;this.continuousFrames=0;this.onHashChange=null;this.lastMoveEmit=0;this.lastIndoorKey="";this.writingHash=false;this.hashTimer=0;this.layerOverrides=new z;this.autoIndoorLevel=true;this.debugFB=null;let o=typeof t.container=="string"?document.getElementById(t.container):t.container;if(!o)throw new Error(`[osmgl] \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${String(t.container)}`);this.container=o,this.qualityAuto=(t.quality??"auto")==="auto";let r=this.qualityAuto?Pr(Rr()):t.quality;this.qualityCeiling=r,this.quality=Ut(r),this.densityQuality=this.quality,this.maxPixelRatio=t.maxPixelRatio??this.quality.maxPixelRatio,this._style=new Ht(t.theme?mr(t.theme,t.style):t.style),this.background=t.background?he(t.background):null,this.canvas=document.createElement("canvas"),this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.display="block",this.canvas.style.outline="none",getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.container.appendChild(this.canvas);let i=document.createElement("div");i.className="osmgl-markers",i.style.cssText="position:absolute;inset:0;overflow:hidden;pointer-events:none",this.container.appendChild(i),this.markerHost=i,this.objects.setMarkerHost(i);let a=this.transform;a.minZoom=t.minZoom??0,a.maxZoom=t.maxZoom??22,a.maxPitch=t.maxPitch??75,a.projection=t.projection??"mercator",a.center=$(t.center??[0,0]),a.zoom=t.zoom??2,a.bearing=t.bearing??0,a.pitch=t.pitch??0,this.hashName=typeof t.hash=="string"?t.hash:void 0,t.hash&&this.applyHash(false),this.pool=new kr(t.workerCount??Math.min(Ei(),this.quality.maxWorkers)),this.initGL(),this.initSource(),this.initInput(),this.initResize(),queueMicrotask(()=>{this.destroyed||(this.loaded=true,this.emit("load",void 0),this.triggerRepaint());});}initGL(){let t=this.canvas.getContext("webgl2",{alpha:false,antialias:this.quality.antialias,depth:true,stencil:true,preserveDrawingBuffer:false,powerPreference:"high-performance",failIfMajorPerformanceCaveat:false});if(!t)throw new Error("[osmgl] WebGL2 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0432 \u044D\u0442\u043E\u043C \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435");this.ctx=new Wo(t);let o=new Vt(this.options.fonts??"/tileserver/fonts/{fontstack}/{range}.pbf",this.options.fontstack);this.options.icons&&o.icons.setIcons({...At,...this.options.icons}),o.onAssetsReady=()=>this.triggerRepaint(),this.renderer.symbols=o,this.renderer.objects=this.objects,this.renderer.models.onLoaded=()=>this.triggerRepaint(),this.renderer.init(this.ctx),this.canvas.addEventListener("webglcontextlost",r=>{r.preventDefault(),this.stopFrameLoop(),this.emit("contextlost",void 0),this.emit("error",{message:"\u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 WebGL \u043F\u043E\u0442\u0435\u0440\u044F\u043D"});});}initSource(){this.options.tiles&&this.addSource(Y,{url:this.options.tiles,minzoom:this.options.sourceMinZoom??0,maxzoom:this.options.sourceMaxZoom??14});for(let[o,r]of Object.entries({...this._style.spec.sources??{},...this.options.sources??{}}))this.addSource(o,r);let t=this.options.objects3d;if(t){this.objects3d=new Hr({endpoint:t.endpoint??"/objects3d",apiKey:t.apiKey??null}),this.objects3d.onReady=()=>this.triggerRepaint(),this.objects3d.setModelKey(this._style.spec.model3dKey??"");let o=t.sourceMaxZoom??14;this.addSource(this.objects3dSource,{url:t.tiles,minzoom:o,maxzoom:o});}}get objects3dSource(){return this.options.objects3d?this.options.objects3d.source??"model3d":null}objects3dPlan(){let t=this.options.objects3d;return {id:tc,type:"model",sourceLayer:t.sourceLayer??"model3d",minzoom:0,maxzoom:24}}planFor(t,o=this._style){let r=o.workerPlan(t),i=t===this.objects3dSource?[...r,this.objects3dPlan()]:r;return this.quality.simpleGeometry?i.map(Qd):i}updateObjects3D(){let t=this.objects3d,o=this.objects3dSource;if(!t||!o)return;let r=this.sources.get(o);if(!r)return;if(!this.objects3dEnabled){t.models.length&&t.clear(l=>this.renderer.models.remove(l,this.ctx?.gl)),this.renderer.hiddenBuildings=t.replacedBuildings,this.renderer.hiddenVenues=t.replacedVenues,this.renderer.hiddenVenueLayer=null;return}let i=this.venuesForMask();t.update({id:tc,"source-layer":this.options.objects3d.sourceLayer??"model3d",layout:this.options.objects3d.layout},r,this.transform,l=>this.renderer.models.add(l),l=>this.renderer.models.remove(l,this.ctx?.gl),this.buildingsForMask(),i),this.renderer.hiddenBuildings=t.replacedBuildings,this.renderer.hiddenVenues=t.replacedVenues,this.renderer.hiddenVenueLayer=i?.key??null;let a=this.renderer.indoorMask.footprint();if(a){let l=this.transform.worldSize>0?this.transform.pixelsPerMeter/this.transform.worldSize*1.5:0;for(let s of t.models){let c=s.origin();s.setHidden(Qe(a,c.x,c.y,l));}}else for(let l of t.models)l.setHidden(false);}buildingsForMask(){let t=this.sources.get(Y);if(!t)return null;for(let o of this._style.layers){if(o.type!=="fill-extrusion"||(o.source??Y)!==Y)continue;let r=this._style.bucketKeyFor(o);if(r!==null)return {source:t,key:r}}return null}venuesForMask(){let t=new Set;for(let o of this._style.layers)"splitBy"in o&&o.splitBy===Jt&&t.add(o.source??Y);for(let o of this._style.layers){if(o.type!=="fill-extrusion"||"splitBy"in o&&o.splitBy)continue;let r=o.source??Y;if(!t.has(r))continue;let i=this.sources.get(r),a=this._style.bucketKeyFor(o);if(i&&a!==null)return {source:i,key:a}}return null}addSource(t,o){if(this.sources.get(t)?.destroy(),this.sources.delete(t),this.rasterSources.get(t)?.destroy(),this.rasterSources.delete(t),o.type==="raster"){let i=new Io({url:o.url,minzoom:o.minzoom??0,maxzoom:o.maxzoom??19,cacheSize:this.quality.tileCacheSize*2});return i.on("data",()=>this.triggerRepaint()),i.on("error",({message:a})=>this.emit("error",{message:a})),this.rasterSources.set(t,i),this.triggerRepaint(),this}let r=new Dr(this.pool,{url:o.url,minzoom:o.minzoom??0,maxzoom:o.maxzoom??14,cacheSize:this.quality.tileCacheSize*2,plan:this.planFor(t)});return r.on("data",()=>this.triggerRepaint()),r.on("error",({message:i})=>this.emit("error",{message:i})),t===Y&&r.on("idle",()=>this.emit("idle",void 0)),this.sources.set(t,r),this.triggerRepaint(),this}initInput(){this.gestures=new Zo(this.canvas,this.transform,t=>{this.animation=null,t==="zoom"&&this.emit("zoom",void 0),this.emitMove(),this.triggerRepaint();},()=>this.emit("moveend",void 0),this.options.gestures),this.initClicks(),this.initHash();}initClicks(){let t=null;this.canvas.addEventListener("pointerdown",r=>{r.button===0&&(t={x:r.clientX,y:r.clientY,t:performance.now()});}),this.canvas.addEventListener("pointerup",r=>{let i=t;if(t=null,r.button!==0||!i||Math.hypot(r.clientX-i.x,r.clientY-i.y)>4||performance.now()-i.t>500)return;let a=this.canvas.getBoundingClientRect(),l={x:r.clientX-a.left,y:r.clientY-a.top},s=this.objects.hitTest(this.transform,l),c=s?null:this.queryRoom(l),h=s||c?null:this.queryBuilding(l);this.options.highlightBuildings!==false&&(this.setHighlight(h),this.setRoomHighlight(c));for(let u of this.getPopups())u.closeOnClick&&this.removePopup(u);this.emit("click",{point:l,lngLat:this.transform.unproject(l),object:s,building:h,symbol:this.querySymbol(l,4)});}),this.canvas.addEventListener("dblclick",r=>{let i=this.pointOf(r);this.emit("dblclick",{point:i,lngLat:this.transform.unproject(i)});}),this.canvas.addEventListener("contextmenu",r=>{r.preventDefault();let i=this.pointOf(r);this.emit("contextmenu",{point:i,lngLat:this.transform.unproject(i)});});let o=0;this.canvas.addEventListener("pointermove",r=>{if(r.pointerType==="touch")return;let i=performance.now();if(i-o<16)return;o=i;let a=this.pointOf(r),l=this.querySymbol(a);this.setSymbolHover(l),this.emit("mousemove",{point:a,lngLat:this.transform.unproject(a),object:this.objects.hitTest(this.transform,a),symbol:l});});}pointOf(t){let o=this.canvas.getBoundingClientRect();return {x:t.clientX-o.left,y:t.clientY-o.top}}initResize(){this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.container),this.resize();}resize(){if(this.destroyed)return;let t=this.container.clientWidth||1,o=this.container.clientHeight||1,r=Di(t,o,Math.min(window.devicePixelRatio||1,this.maxPixelRatio),this.densityQuality);this.canvas.width=Math.round(t*r),this.canvas.height=Math.round(o*r),this.transform.resize(t,o),this.triggerRepaint();}getCenter(){return this.transform.center}getZoom(){return this.transform.zoom}getBearing(){return this.transform.bearing}getPitch(){return this.transform.pitch}setCenter(t){return this.transform.center=$(t),this.afterCameraChange()}setZoom(t){return this.transform.zoom=t,this.emit("zoom",void 0),this.afterCameraChange()}setBearing(t){return this.transform.bearing=t,this.afterCameraChange()}setPitch(t){return this.transform.pitch=t,this.afterCameraChange()}jumpTo(t){let o=this.transform;return t.center!==void 0&&(o.center=$(t.center)),t.zoom!==void 0&&(o.zoom=t.zoom),t.bearing!==void 0&&(o.bearing=t.bearing),t.pitch!==void 0&&(o.pitch=t.pitch),this.animation=null,this.afterCameraChange()}easeTo(t){let o=t.duration??0;if(o<=0)return this.jumpTo(t);let r=this.transform,i={center:r.center,zoom:r.zoom,bearing:r.bearing,pitch:r.pitch},l={center:t.center!==void 0?$(t.center):r.center,zoom:t.zoom??r.zoom,bearing:i.bearing+Ct((t.bearing??r.bearing)-i.bearing),pitch:t.pitch??r.pitch};return this.animation={start:performance.now(),duration:o,from:i,to:l},this.triggerRepaint(),this}flyTo(t){let o=this.transform,r={center:o.center,zoom:o.zoom,bearing:o.bearing,pitch:o.pitch},a={center:t.center!==void 0?$(t.center):o.center,zoom:t.zoom??o.zoom,bearing:r.bearing+Ct((t.bearing??o.bearing)-r.bearing),pitch:t.pitch??o.pitch},l=et(r.zoom),s=(ne(a.center.lng)-ne(r.center.lng))*l,c=(ie(a.center.lat)-ie(r.center.lat))*l,h=Math.hypot(s,c),u=Math.max(o.width,o.height),f=u*Math.pow(2,r.zoom-a.zoom),d=1.42,p=d*d,b,m=null;if(h<1e-6){let y=Math.log(f/u);b=Math.abs(y)/d,m=A=>({u:0,w:u*Math.exp(d*Math.sign(y)*A)});}else {let y=C=>{let v=C===0?u:f,E=C===0?f:u;return (E*E-v*v+(C===0?1:-1)*p*p*h*h)/(2*v*p*h)},A=C=>Math.log(-y(C)+Math.sqrt(y(C)*y(C)+1)),B=A(0);b=(A(1)-B)/d;let w=C=>(Math.exp(C)+Math.exp(-C))/2,_=C=>(Math.exp(2*C)-1)/(Math.exp(2*C)+1);m=C=>{let v=d*C+B;return {u:u*w(B)*_(v)/p-u*Math.sinh(B)/p,w:u*w(B)/w(v)}};}if(!Number.isFinite(b)||b<=0)return this.jumpTo(t);let g=t.duration??Math.min(3e3,b/1.2*1e3);return this.animation={start:performance.now(),duration:g,from:r,to:a,fly:{S:b,u1:h,curve:m,w0:u}},this.triggerRepaint(),this}setPadding(t){return this.padding=oc(t),this.renderer.symbols&&(this.renderer.symbols.padding=this.padding),this.triggerRepaint(),this}getPadding(){return {...this.padding}}getBounds(){let t=this.transform,o=new Xt;for(let[r,i]of [[0,0],[t.width,0],[t.width,t.height],[0,t.height]])o.extend(t.unproject({x:r,y:i}));return o}cameraForBounds(t,o={}){let r=this.transform,i=Vr(t,{width:r.width,height:r.height,bearing:o.bearing??r.bearing,padding:o.padding!==void 0?oc(o.padding):this.padding,maxZoom:Math.min(o.maxZoom??r.maxZoom,r.maxZoom),minZoom:r.minZoom});return i?{...i,pitch:o.pitch??r.pitch}:null}fitBounds(t,o={}){let r=this.cameraForBounds(t,o);if(!r)return this;let i={...r,duration:o.duration??600};return o.fly?this.flyTo(i):this.easeTo(i)}stepAnimation(t){let o=this.animation;if(!o)return false;let r=_e((t-o.start)/o.duration,0,1),i=o.fly?r:Vo(r),a=this.transform,l=$(o.from.center),s=$(o.to.center);if(o.fly){let{u:c,w:h}=o.fly.curve(o.fly.S*r),u=o.fly.u1>1e-6?_e(c/o.fly.u1,0,1):r;return a.center={lng:l.lng+(s.lng-l.lng)*u,lat:l.lat+(s.lat-l.lat)*u},a.zoom=o.from.zoom+Math.log2(o.fly.w0/h),a.bearing=o.from.bearing+(o.to.bearing-o.from.bearing)*Vo(r),a.pitch=o.from.pitch+(o.to.pitch-o.from.pitch)*Vo(r),r>=1&&(a.center=s,a.zoom=o.to.zoom),this.emitMove(),r>=1?(this.animation=null,this.emit("moveend",void 0),false):true}return a.center={lng:l.lng+(s.lng-l.lng)*i,lat:l.lat+(s.lat-l.lat)*i},a.zoom=o.from.zoom+(o.to.zoom-o.from.zoom)*i,a.bearing=o.from.bearing+(o.to.bearing-o.from.bearing)*i,a.pitch=o.from.pitch+(o.to.pitch-o.from.pitch)*i,this.emitMove(),r>=1?(this.animation=null,this.emit("moveend",void 0),false):true}afterCameraChange(){return this.emitMove(),this.triggerRepaint(),this}emitMove(){let t=performance.now();t-this.lastMoveEmit<8||(this.lastMoveEmit=t,this.emit("move",void 0));}project(t,o=0){return this.transform.project($(t),o)}unproject(t){return this.transform.unproject(t)}get style(){return this._style}setStyle(t){let o=this._style,r=new Ht(t);Object.assign(r.splitValues,o.splitValues),this._style=r,this.applyLayerOverrides();for(let[i,a]of this.sources.entries()){let l=JSON.stringify(o.workerPlan(i)),s=JSON.stringify(r.workerPlan(i));l!==s&&a.setPlan(this.planFor(i,r));}return this.objects3d?.setModelKey(t.model3dKey??""),this.triggerRepaint(),this}setTheme(t){return this.setStyle(mr(t,this.options.style))}static get themes(){return Object.keys(Xe)}static get themeList(){return Object.entries(Xe).map(([t,o])=>({id:t,name:o.name||t}))}setLayoutProperty(t,o,r){let i=this._style.layers.find(l=>l.id===t);if(!i)return console.warn(`[osmgl] \u0441\u043B\u043E\u0439 \u0441\u0442\u0438\u043B\u044F "${t}" \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D`),this;let a=i.layout??(i.layout={});if(a[o]=r,this.rememberOverride(t,{layout:{[o]:r}}),o==="textField"||o==="iconImage"||o==="splitBy")for(let[l,s]of this.sources)s.setPlan(this.planFor(l));return this.triggerRepaint(),this}setPaintProperty(t,o,r){let i=this._style.layers.find(a=>a.id===t);return i?(i.paint[o]=r,this.rememberOverride(t,{paint:{[o]:r}}),this.triggerRepaint(),this):(console.warn(`[osmgl] \u0441\u043B\u043E\u0439 \u0441\u0442\u0438\u043B\u044F "${t}" \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D`),this)}setShadows(t){let o=typeof t=="boolean"?{enabled:t}:t;return Object.assign(this.renderer.shadows,o),this.triggerRepaint(),this}querySymbol(t,o=2){let r=this.renderer.symbols?.querySymbol(t,o);return r?{layerId:r.layerId,text:r.text,icon:r.icon,lngLat:{lng:Se(r.mercX),lat:Fe(r.mercY)},key:Vt.keyOf(r)}:null}setSymbolHover(t){return this.renderer.symbols?.setHover(t?.key??null)&&this.triggerRepaint(),this}setSymbolHidden(t){return this.renderer.symbols?.setHidden(t?.key??null)&&this.triggerRepaint(),this}queryBuilding(t){let o=null;for(let r of this._style.layers){if(r.type!=="fill-extrusion"||r.overlay||!this._style.layerVisibleAt(r,this.transform.zoom))continue;let i=this.sources.get(r.source??Y);if(!i)continue;let a=Xn(this.transform,i,r.id,t);a&&(!o||a.distance<o.distance)&&(o=a);}return o}setHighlight(t,o={}){return this.renderer.highlight=t?{layerId:t.layerId,featureId:t.featureId,color:o.color??this.options.highlightColor??"#4ec97f",opacity:o.opacity??.45}:null,this.triggerRepaint(),this}queryRoom(t){if(!this.renderer.indoorOpen)return null;let o=[],r=new z,i;for(let l of this._style.layers){if(l.type!=="fill"||!l.id.startsWith("indoor-")||l.id==="indoor-shell"||!this._style.layerVisibleAt(l,this.transform.zoom))continue;let s=this._style.bucketKeyFor(l);s&&(o.push(s),r.set(s,l.id),i??(i=this.sources.get(l.source??Y)));}if(!i||!o.length)return null;let a=jn(this.transform,i,o,t);return a?{...a,layerId:r.get(a.layerId)??a.layerId,bucketKey:a.layerId}:null}setRoomHighlight(t,o={}){return this.renderer.highlightFill=t?{layerId:t.layerId,bucketKey:t.bucketKey??t.layerId,featureId:t.featureId,color:o.color??this.options.highlightColor??"#4ec97f",opacity:o.opacity??.5}:null,this.triggerRepaint(),this}getHighlight(){let t=this.renderer.highlight;return t?{featureId:t.featureId,layerId:t.layerId}:null}initHash(){this.options.hash&&(this.on("move",()=>this.scheduleHash()),this.on("moveend",()=>this.scheduleHash(true)),this.onHashChange=()=>{this.writingHash||this.applyHash(true);},window.addEventListener("hashchange",this.onHashChange),this.scheduleHash(true));}scheduleHash(t=false){if(!(!this.options.hash||this.destroyed)){if(this.hashTimer){if(!t)return;clearTimeout(this.hashTimer);}this.hashTimer=setTimeout(()=>{this.hashTimer=0,this.writeHash();},t?0:300);}}writeHash(){if(!this.options.hash||this.destroyed)return;let t=this.transform,o=Mi({center:t.center,zoom:t.zoom,bearing:t.bearing,pitch:t.pitch},this.hashName);this.writingHash=true,Qs("#"+o),setTimeout(()=>this.writingHash=false,0);}applyHash(t){if(typeof window>"u")return;let o=Fi(window.location.hash,this.hashName);if(!o)return;let r=this.transform;o.center&&(r.center=o.center),o.zoom!==void 0&&(r.zoom=o.zoom),o.bearing!==void 0&&(r.bearing=o.bearing),o.pitch!==void 0&&(r.pitch=o.pitch),t&&(this.emitMove(),this.triggerRepaint());}setQuality(t){this.qualityAuto=t==="auto";let o=t==="auto"?Pr(Rr()):t;return this.qualityCeiling=o,this.resetFrameWindow(),this.applyQuality(Ut(o)),this}getQuality(){return {auto:this.qualityAuto,profile:{...this.quality},pixelRatio:this.transform.width>0?this.canvas.width/this.transform.width:1}}applyQuality(t,o=false){let r=this.quality.simpleGeometry,i=o?r:t.simpleGeometry;if(this.quality={...t,simpleGeometry:i},this.resetFrameWindow(),this.objects3d&&(this.objects3d.budgetScale=t.modelBudget),r!==i)for(let[a,l]of this.sources.entries())l.setPlan(this.planFor(a));o||(this.densityQuality=t,this.options.maxPixelRatio===void 0&&(this.maxPixelRatio=t.maxPixelRatio)),this.renderer.detailScale=t.detail,this.renderer.allowShadows=t.allowShadows,this.renderer.shadows.resolution!==t.shadowMapSize&&this.setShadows({resolution:t.shadowMapSize});for(let a of this.sources.values())a.setCoverOptions({detailBias:t.detailBias,maxTiles:t.maxTiles});this.resize();}resetFrameWindow(){this.frameRing.fill(0),this.ringAt=0,this.ringSum=0,this.ringFilled=0,this.steadyFrames=0;}checkFrameBudget(t){if(!this.qualityAuto||this.sum(a=>a.pendingCount)>0)return;let o=t>Ud?3:t>Kd?1:0;if(this.ringSum+=o-this.frameRing[this.ringAt],this.frameRing[this.ringAt]=o,this.ringAt=(this.ringAt+1)%Ri,this.ringFilled<Ri&&this.ringFilled++,this.steadyFrames++,this.ringFilled<Jd)return;let r=this.ringSum/this.ringFilled;if(r>=Xd){let a=Ii(this.quality.name);if(!a)return;console.info(`[osmgl] \u0442\u044F\u0436\u0451\u043B\u044B\u0445 \u043A\u0430\u0434\u0440\u043E\u0432 ${(r*100).toFixed(0)}% \u2014 \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u043E \u043F\u043E\u043D\u0438\u0436\u0435\u043D\u043E \u0434\u043E \xAB${a}\xBB (\u043F\u043B\u043E\u0442\u043D\u043E\u0441\u0442\u044C \u0431\u0443\u0444\u0435\u0440\u0430 \u043F\u0440\u0435\u0436\u043D\u044F\u044F)`),this.applyQuality(Ut(a),true);return}if(r>jd||this.steadyFrames<Yd)return;let i=$s(this.quality.name);!i||Si(i)>Si(this.qualityCeiling)||(console.info(`[osmgl] \u043A\u0430\u0434\u0440\u044B \u0443\u043A\u043B\u0430\u0434\u044B\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0431\u044E\u0434\u0436\u0435\u0442 \u2014 \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u043E \u043F\u043E\u0434\u043D\u044F\u0442\u043E \u0434\u043E \xAB${i}\xBB`),this.applyQuality(Ut(i),true));}getShadows(){return {...this.renderer.shadows}}setSky(t){let o=typeof t=="boolean"?{enabled:t}:t;return Object.assign(this._style.sky,o),this.triggerRepaint(),this}getSky(){return {...this._style.sky}}setLight(t){return Object.assign(this._style.light,t),this.triggerRepaint(),this}setLayerVisible(t,o){let r=this._style.layers.find(i=>i.id===t);return r&&(r.visible=o,this.rememberOverride(t,{visible:o}),this.triggerRepaint()),this}setObjects3DEnabled(t){return this.objects3dEnabled===t?this:(this.objects3dEnabled=t,this.triggerRepaint(),this)}get objects3DEnabled(){return this.objects3dEnabled}rasterLayerVisible(t){let o=this.transform.zoom;return this._style.layers.some(r=>r.type==="raster"&&r.source===t&&this._style.layerVisibleAt(r,o))}rememberOverride(t,o){let r=this.layerOverrides.get(t)??{};this.layerOverrides.set(t,{...r,...o,paint:{...r.paint??{},...o.paint??{}},layout:{...r.layout??{},...o.layout??{}}});}applyLayerOverrides(){if(this.layerOverrides.size)for(let t of this._style.layers){let o=this.layerOverrides.get(t.id);if(o&&(o.visible!==void 0&&(t.visible=o.visible),o.paint&&Object.assign(t.paint??(t.paint={}),o.paint),o.layout)){let r=t;Object.assign(r.layout??(r.layout={}),o.layout);}}}setBackground(t){return this.background=he(t),this.triggerRepaint(),this}getIndoorLevels(){let t=[];for(let[o,r]of this.sources.entries())if(this._style.layers.some(i=>(i.source??Y)===o&&"splitBy"in i&&i.splitBy===Jt))for(let i of r.splitValues(Jt)){let a=Number(i);Number.isFinite(a)&&!t.includes(a)&&t.push(a);}return t.sort((o,r)=>o-r)}getIndoorLevel(){let t=this._style.splitValues[Jt];return typeof t=="number"?t:null}setIndoorLevel(t){return t===null?delete this._style.splitValues[Jt]:this._style.splitValues[Jt]=t,this.triggerRepaint(),this}syncIndoor(){let t=this.getIndoorLevels(),o=t.join(",");if(o!==this.lastIndoorKey){if(this.lastIndoorKey=o,this.autoIndoorLevel){let r=this.getIndoorLevel();t.length?(r===null||!t.includes(r))&&this.setIndoorLevel(t.includes(0)?0:t.find(i=>i>=0)??t[0]):r!==null&&this.setIndoorLevel(null);}this.emit("indoor",{levels:t,level:this.getIndoorLevel()});}}addObject(t){return this.objects.add(t),this.triggerRepaint(),this}removeObject(t){return this.objects.remove(t),this.triggerRepaint(),this}getObjects(){return this.objects.all}updateObject(){return this.triggerRepaint(),this}addModel(t){return this.renderer.models.add(t),this.triggerRepaint(),this}removeModel(t){return this.renderer.models.remove(t,this.ctx?.gl),this.triggerRepaint(),this}getObjects3DStats(){return this.objects3d?.stats??null}getModels(){return this.renderer.models.all}addMarker(t){return this.objects.addMarker(t),t.update(this.transform),this}removeMarker(t){return this.objects.removeMarker(t),this}getMarkers(){return this.objects.allMarkers}addPopup(t){return t.onCloseRequest(()=>this.removePopup(t)),this.objects.addMarker(t),t.update(this.transform),this}removePopup(t){return this.objects.removeMarker(t),this}getPopups(){return this.objects.allMarkers.filter(t=>t instanceof ko)}objectAt(t,o=4){return this.objects.hitTest(this.transform,t,o)}setProjection(t){let o=this.transform;if(o.projection===t)return this;o.projection=t;let r=o.effectiveMinZoom(),i=t==="globe"?Math.min(o.maxPitch,jt):o.maxPitch,a=o.zoom<r,l=o.pitch>i;return a||l?this.easeTo({zoom:a?r:o.zoom,pitch:l?i:o.pitch,duration:600}):(this.emit("move",void 0),this.triggerRepaint()),this}getProjection(){return this.transform.projection}refreshSource(t){return this.sources.get(t)?.reload(),this.rasterSources.get(t)?.reload(),this.triggerRepaint(),this}refresh(){for(let t of this.sources.values())t.reload();for(let t of this.rasterSources.values())t.reload();return this.renderer.refreshHighlight(),this.triggerRepaint(),this}sum(t){let o=0;for(let r of this.sources.values())o+=t(r);return o}getStats(){return {pendingTiles:this.sum(t=>t.pendingCount),visibleTiles:this.sum(t=>t.visibleTiles.length),labels:this.renderer.symbols?.placedCount??0,models:this.renderer.models.readyCount,workers:this.pool.usingWorkers?this.pool.size:0,renderer:this.ctx?.caps.rendererName??"\u043D\u0435\u0442 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430"}}triggerRepaint(){this.destroyed||(this.needsRepaint=true,!this.frameHandle&&(this.frameHandle=requestAnimationFrame(t=>{this.frameHandle=0,this.renderFrame(t);})));}debugFloatPixels(t,o,r,i){let a=this.ctx;if(!a||!a.caps.colorBufferFloat)return null;let l=a.gl,s=this.canvas.width,c=this.canvas.height,h=!!l.getExtension("EXT_float_blend"),u=h?l.RGBA32F:l.RGBA16F,f=h?l.FLOAT:l.HALF_FLOAT;if(this.debugFB&&(this.debugFB.w!==s||this.debugFB.h!==c)&&(l.deleteFramebuffer(this.debugFB.fb),l.deleteTexture(this.debugFB.tex),l.deleteRenderbuffer(this.debugFB.rb),this.debugFB=null),!this.debugFB){let d=l.createTexture(),p=l.createFramebuffer(),b=l.createRenderbuffer();if(!d||!p||!b)return null;l.bindTexture(l.TEXTURE_2D,d),l.texImage2D(l.TEXTURE_2D,0,u,s,c,0,l.RGBA,f,null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.bindTexture(l.TEXTURE_2D,null),l.bindRenderbuffer(l.RENDERBUFFER,b),l.renderbufferStorage(l.RENDERBUFFER,l.DEPTH24_STENCIL8,s,c),l.bindRenderbuffer(l.RENDERBUFFER,null),l.bindFramebuffer(l.FRAMEBUFFER,p),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,d,0),l.framebufferRenderbuffer(l.FRAMEBUFFER,l.DEPTH_STENCIL_ATTACHMENT,l.RENDERBUFFER,b);let m=l.checkFramebufferStatus(l.FRAMEBUFFER);if(l.bindFramebuffer(l.FRAMEBUFFER,null),a.invalidateState(),m!==l.FRAMEBUFFER_COMPLETE)return null;this.debugFB={fb:p,tex:d,rb:b,w:s,h:c};}a.screen=this.debugFB.fb;try{this.renderFrame(performance.now()),a.bindFramebuffer(this.debugFB.fb);let d=new Float32Array(r*i*4);return l.readPixels(t,o,r,i,l.RGBA,l.FLOAT,d),{data:d,format:h?"rgba32f":"rgba16f"}}finally{a.screen=null,this.triggerRepaint();}}renderFrame(t){if(this.destroyed||!this.ctx)return;let o=performance.now();this.needsRepaint=false;let r=this.stepAnimation(t),i=this.ctx;i.bindFramebuffer(null),i.viewport(0,0,this.canvas.width,this.canvas.height),i.setDepthMask(true),i.clear(this.background??this._style.background,true,true);for(let d of this.sources.values())d.update(this.transform);this.updateObjects3D();for(let[d,p]of this.rasterSources)this.rasterLayerVisible(d)&&p.update(this.transform);this.syncIndoor(),this.objects.updateMarkers(this.transform);let a=(this.sources.size>0||this.rasterSources.size>0)&&this.renderer.render(i,this.transform,this.sources,this._style,t,this.rasterSources),l=performance.now()-o,s=r||a||this.needsRepaint,c=this.lastFrameAt>0?t-this.lastFrameAt:0,h=c>0&&c<Zd,u=h?c:0;this.continuousFrames=h?this.continuousFrames+1:0;let f=this.continuousFrames>1?c:l;this.lastFrameAt=t,this.checkFrameBudget(f),this.emit("render",{frameMs:l,intervalMs:u}),s&&this.triggerRepaint();}stopFrameLoop(){this.frameHandle&&cancelAnimationFrame(this.frameHandle),this.frameHandle=0;}get isLoaded(){return this.loaded}destroy(){if(this.onHashChange&&(window.removeEventListener("hashchange",this.onHashChange),this.onHashChange=null),this.hashTimer&&clearTimeout(this.hashTimer),!this.destroyed){this.destroyed=true,this.stopFrameLoop(),this.resizeObserver?.disconnect(),this.gestures?.destroy();for(let t of this.sources.values())t.destroy();this.sources.clear();for(let t of this.rasterSources.values())t.destroy();this.rasterSources.clear(),this.objects.destroy(),this.markerHost?.remove(),this.pool.destroy(),this.ctx&&this.renderer.destroy(this.ctx),this.removeAllListeners(),this.canvas.remove();}}},m2=Gi;
|
|
2325
|
+
`;var gr=n=>n.kind==="symbol",as=n=>n.kind==="placement";function Qe(n,e,t,o){for(let r of n)for(let i=0;i+5<r.length;i+=6){let a=r[i],l=r[i+1],s=r[i+2],c=r[i+3],h=r[i+4],u=r[i+5];if(Zu(e,t,a,l,s,c,h,u)||o>0&&(Vn(e,t,a,l,s,c)<=o||Vn(e,t,s,c,h,u)<=o||Vn(e,t,h,u,a,l)<=o))return true}return false}function Zu(n,e,t,o,r,i,a,l){let s=(n-r)*(o-i)-(t-r)*(e-i),c=(n-a)*(i-l)-(r-a)*(e-l),h=(n-t)*(l-o)-(a-t)*(e-o),u=s<0||c<0||h<0,f=s>0||c>0||h>0;return !(u&&f)}function Vn(n,e,t,o,r,i){let a=r-t,l=i-o,s=a*a+l*l,c=s>0?Math.max(0,Math.min(1,((n-t)*a+(e-o)*l)/s)):0;return Math.hypot(n-(t+a*c),e-(o+l*c))}function Wn(n,e){let t=new DataView(n.vertices),o=new Uint32Array(n.indices),r=e.bounds(),i=(r.maxX-r.minX)/n.extent,a=new Float64Array(o.length*2);for(let l=0;l<o.length;l++){let s=o[l]*tt;a[l*2]=r.minX+t.getInt16(s,true)*i,a[l*2+1]=r.minY+t.getInt16(s+2,true)*i;}return a}function Nn(n,e,t){let o=new DataView(n.vertices),r=t.bounds(),i=(r.maxX-r.minX)/e,a=r.minX,l=r.minY,s=new Float64Array(n.indices.length*2);for(let c=0;c<n.indices.length;c++){let h=n.indices[c]*Ie;s[c*2]=a+o.getInt16(h,true)*i,s[c*2+1]=l+o.getInt16(h+2,true)*i;}return s}var Qu={stride:8,attribs:[{name:"a_pos",size:2,type:5126,offset:0}]},qu=40,$u=10.5,ls=2.5,eh=16,th=4,oh=7,mo=class{constructor(){this.vbo=null;this.ibo=null;this.vao=null;this.capacity=0;this.perArrow=0;this.indicesPerArrow=0;this.highlightFootprint=null;this.count=0;}render(e,t,o,r,i,a,l,s=false){this.count=0;let c=t.zoom,h=r.layers.filter(B=>B.type==="symbol"&&B.layout?.placement==="map"&&r.layerVisibleAt(B,c));if(!h.length)return;let u=t.center,f=ne(u.lng),d=ie(u.lat),p=t.worldSize>0?t.pixelsPerMeter/t.worldSize:0;if(!(p>0))return;let b=[];for(let B of h){let x=o.get(B.source??Y);if(!x)continue;let w=r.bucketKeyFor(B);if(w===null)continue;let _=B.layout?.showFor==="highlight";if(_&&!this.highlightFootprint)continue;let C=p*1.5,E=B.layout?.arrowUnits==="meters"?p:1/t.worldSize,D=V(B.layout?.arrowLength,c,qu)*E,F=V(B.layout?.arrowWidth,c,$u)*E,H=V(B.layout?.arrowOutline,c,ls)*E,S=V(B.layout?.arrowGap,c,eh)*E,L=V(B.layout?.arrowDotRadius,c,th)*E,M=V(B.layout?.arrowDotGap,c,oh)*E,T=Un(D,F,L,S-M),P=H>0?Un(D,F,L,S-M,H).outline:null,k={layer:B,verts:[],shape:T};for(let O of x.visibleTiles){let G=x.getTile(O)?.data?.buckets?.[w];if(!G||!gr(G))continue;let R=new Int16Array(G.anchors),W=G.rotations?new Int16Array(G.rotations):null,j=O.bounds(),Z=(j.maxX-j.minX)/G.extent,ee=j.minX,ge=j.minY;for(let te=0;te<R.length/2;te++){let X=ee+R[te*2]*Z,re=ge+R[te*2+1]*Z;if(_&&!Qe(this.highlightFootprint,X,re,C))continue;let le=(W?W[te]:0)*Math.PI/180,q=Math.sin(le),U=-Math.cos(le),J=X-f-q*S,fe=re-d-U*S;P&&Jn(k,P,J,fe,q,U),Jn(k,T.outline,J,fe,q,U),this.count++;}}k.verts.length&&b.push(k);}if(!b.length)return;let m=b[0].shape,g=m.outline.length/2,y=[],A=[];for(let B of b){let x=y.length/2/g;for(let w of B.verts)y.push(w);A.push({layer:B.layer,first:x,count:B.verts.length/2/g});}if(this.ensureBuffers(e,y.length/2/g,m,a),!(!this.vao||!this.vbo)){this.vbo.update(new Uint8Array(new Float32Array(y).buffer)),i.use(),l?.(i),s&&i.setMat4("u_shadow_matrix",t.shadowObjectMatrix(f,d,0)),i.setMat4("u_matrix",t.objectMatrix(f,d,0)),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.vao.bind();for(let B of A){let x=B.layer.paint,w=V(x.opacity,c,1),_=He(x.color,c,[.18,.45,.76,1]),C=He(x.haloColor,c,[1,1,1,1]),v=V(B.layer.layout?.arrowOutline,c,ls)>0;rh(e,i,B,C,_,w,v,this.indicesPerArrow);}e.bindVAO(null),e.setDepthTest(true);}}ensureBuffers(e,t,o,r){let i=o.outline.length/2;if(this.vao&&t<=this.capacity&&i===this.perArrow)return;this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.capacity=Math.max(256,Math.ceil(t*1.5)),this.perArrow=i,this.indicesPerArrow=o.indices.length,this.vbo=new ve(e,new Uint8Array(this.capacity*i*8),Qu,true);let a=new Uint32Array(this.capacity*o.indices.length);for(let l=0;l<this.capacity;l++){let s=l*i;for(let c=0;c<o.indices.length;c++)a[l*o.indices.length+c]=s+o.indices[c];}this.ibo=new ye(e,a),this.vao=new pe(e,[{buffer:this.vbo,locations:r}],this.ibo);}destroy(){this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.vao=null,this.vbo=null,this.ibo=null,this.capacity=0;}};function rh(n,e,t,o,r,i,a,l){let s=a?2:1;if(a){e.setVec4v("u_color",Me([o[0],o[1],o[2],o[3]*i]));for(let c=0;c<t.count;c+=s)ss(n,t.first+c,l);}e.setVec4v("u_color",Me([r[0],r[1],r[2],r[3]*i]));for(let c=a?1:0;c<t.count;c+=s)ss(n,t.first+c,l);}function ss(n,e,t){n.gl.drawElements(n.gl.TRIANGLES,t,n.gl.UNSIGNED_INT,e*t*4);}var cs=4,Kn=12;function Un(n,e,t,o,r=0){let i=n*.38,a=e*1.35,l=i*.3,s=e*.32,c=e/2,h=-n+s,u=[],f=(g,y)=>u.push(g,y);f(0,0),f(-i,a),f(-i+l,c),f(h,s);for(let g=1;g<cs;g++){let y=g/cs*Math.PI;f(h-Math.sin(y)*s,Math.cos(y)*s);}f(h,-s),f(-i+l,-c),f(-i,-a);let d=r>0?nh(u,r):u,p=Pe(u,void 0,2);if(t<=0)return {outline:d,indices:p};let b=d.length/2,m=t+r;for(let g=0;g<Kn;g++){let y=g/Kn*Math.PI*2;d.push(o+Math.cos(y)*m,Math.sin(y)*m);}for(let g=1;g<Kn-1;g++)p.push(b,b+g,b+g+1);return {outline:d,indices:p}}function nh(n,e){let t=n.length/2,o=0;for(let a=0;a<t;a++){let l=(a+1)%t;o+=n[a*2]*n[l*2+1]-n[l*2]*n[a*2+1];}let r=o<0?-1:1,i=[];for(let a=0;a<t;a++){let l=n[(a+t-1)%t*2],s=n[(a+t-1)%t*2+1],c=n[a*2],h=n[a*2+1],u=n[(a+1)%t*2],f=n[(a+1)%t*2+1],d=Math.hypot(c-l,h-s)||1,p=Math.hypot(u-c,f-h)||1,b=r*(h-s)/d,m=-r*(c-l)/d,g=r*(f-h)/p,y=-r*(u-c)/p,A=b+g,B=m+y,x=Math.hypot(A,B);if(x<1e-9){i.push(c,h);continue}A/=x,B/=x;let w=Math.min(1/Math.max(A*b+B*m,.35),3);i.push(c+A*e*w,h+B*e*w);}return i}function Jn(n,e,t,o,r,i){let a=-i,l=r;for(let s=0;s<e.length;s+=2){let c=e[s],h=e[s+1];n.verts.push(t+r*c+a*h,o+i*c+l*h);}}function ih(n,e,t,o,r,i=0,a=0){let l=t*Math.PI/180,s={verts:[]};return Jn(s,Un(o,r,i,a).outline,n,e,Math.sin(l),-Math.cos(l)),s.verts}var ah=5;function fs(n,e){let t=1/(1<<e),o=(1<<e)-1;return [(n.x&o)*t,(n.y&o)*t,t]}var yr=class{constructor(){this.anisotropy=0;this.anisotropyPname=0;this.anisotropyChecked=false;}render(e,t,o,r,i,a,l,s=false){if(!a.size)return;let c=i.layers.filter(h=>h.type==="raster"&&!!h.overlay===s&&i.layerVisibleAt(h,l));if(c.length){r.use(),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),r.setInt("u_image",0);for(let h of c){let u=a.get(h.source);if(!u)continue;let f=V(h.paint?.opacity,l,1);if(!(f<=.001)){r.setFloat("u_opacity",f),o.bind();for(let d of u.visibleTiles){let p=this.patchFor(e,u,d);p&&(e.bindTexture(0,p.texture),r.setVec3("u_uv_transform",p.uv[0],p.uv[1],p.uv[2]),r.setMat4("u_matrix",t.tileMatrix(d,1)),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0));}}}e.bindVAO(null);}}patchFor(e,t,o){let r=t.getTile(o),i=r&&r.state==="loaded"?this.textureFor(e,r):null;if(i)return {texture:i,uv:[0,0,1]};for(let a=1;a<=ah&&a<=o.z;a++){let l=o.scaledTo(o.z-a),s=t.getTile(l);if(!s||s.state!=="loaded")continue;let c=this.textureFor(e,s);if(c)return {texture:c,uv:fs(o,a)}}return null}textureFor(e,t){let o=t.texture;if(o)return o.handle;if(!t.image)return null;let r=e.gl,i=r.createTexture();if(!i)return null;e.bindTexture(0,i),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t.image),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),this.applyAnisotropy(r);let a={handle:i,destroy:()=>r.deleteTexture(i)};return t.texture=a,t.image.close(),t.image=null,i}applyAnisotropy(e){if(!this.anisotropyChecked){this.anisotropyChecked=true;let t=e.getExtension("EXT_texture_filter_anisotropic");t&&(this.anisotropyPname=t.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropy=Math.min(4,e.getParameter(t.MAX_TEXTURE_MAX_ANISOTROPY_EXT)));}this.anisotropy>0&&e.texParameterf(e.TEXTURE_2D,this.anisotropyPname,this.anisotropy);}};var lh="indoor-",bo=class{constructor(){this.parts=null;this.stamp="";this.cache=new z;this.box=null;this.hidden=new oe;this.collected=new oe;}get active(){return this.parts!==null}footprint(){return this.parts}get hiddenCount(){return this.hidden.size}sync(e,t,o){let r=[],i;for(let f of t.layers){if(!f.id.startsWith(lh)||f.type!=="fill"||!t.layerVisibleAt(f,o))continue;let d=t.bucketKeyFor(f);d&&(r.push(d),i??(i=e.get(f.source??Y)));}if(!r.length||!i){this.parts&&this.destroy();return}let a=r.join(",")+"|"+i.visibleTiles.map(f=>f.dataKey+(i.getTile(f)?.data?"+":"-")).join(",");if(a===this.stamp)return;this.stamp=a,this.free();let l=[],s=1/0,c=1/0,h=-1/0,u=-1/0;for(let f of i.visibleTiles){let d=i.getTile(f)?.data?.buckets;if(d)for(let p of r){let b=d[p];if(!b||b.kind!=="fill")continue;let m=Wn(b,f);l.push(m);for(let g=0;g<m.length;g+=2)m[g]<s&&(s=m[g]),m[g]>h&&(h=m[g]),m[g+1]<c&&(c=m[g+1]),m[g+1]>u&&(u=m[g+1]);}}this.parts=l.length?l:null,this.box=l.length?[s,c,h,u]:null,this.hidden.clear(),this.collected.clear();}collectHidden(e,t){let o=this.parts;if(!o||!e.featureIds)return;let r=new Uint32Array(e.indices),i=new Float64Array(e.featureIds),a=new DataView(e.vertices),l=t.bounds(),s=(l.maxX-l.minX)/e.extent,c=this.box,h=new z;for(let u=0;u*3<r.length;u++){let f=i[u];if(this.hidden.has(f))continue;let d=h.get(f);d||h.set(f,d=[1/0,1/0,-1/0,-1/0]);for(let p=0;p<3;p++){let b=r[u*3+p]*Ie,m=a.getInt16(b,true),g=a.getInt16(b+2,true);m<d[0]&&(d[0]=m),g<d[1]&&(d[1]=g),m>d[2]&&(d[2]=m),g>d[3]&&(d[3]=g);}}for(let[u,f]of h){let d=l.minX+(f[0]+f[2])/2*s,p=l.minY+(f[1]+f[3])/2*s;c&&(d<c[0]||d>c[2]||p<c[1]||p>c[3])||Qe(o,d,p,0)&&this.hidden.add(u);}}destroy(){this.parts=null,this.hidden.clear(),this.collected.clear(),this.box=null,this.stamp="",this.free();}free(){this.cache.forEach(e=>{e?.vao.destroy(),e?.ibo.destroy();}),this.cache.clear();}prepare(e,t){if(!this.parts)return;let o=this.hidden.size;for(let r of e.visibleTiles){if(this.collected.has(r.dataKey))continue;let i=e.getTile(r)?.data?.buckets?.[t];!i||i.kind!=="fill-extrusion"||(this.collected.add(r.dataKey),this.collectHidden(i,r));}this.hidden.size!==o&&this.free();}indicesFor(e,t,o,r,i,a){if(!this.parts)return null;let l=this.cache.get(r.dataKey);if(l!==void 0)return l;let s=t.data?.buckets?.[o];if(!s)return null;let c=null;if(s.kind==="fill-extrusion"&&s.featureIds&&this.hidden.size){let h=new Uint32Array(s.indices),u=new Float64Array(s.featureIds),f=[];for(let d=0;d*3<h.length;d++)this.hidden.has(u[d])||f.push(h[d*3],h[d*3+1],h[d*3+2]);if(f.length<h.length){let d=new ye(e,new Uint32Array(f));c={vao:new pe(e,[{buffer:i,locations:a}],d),ibo:d,count:f.length};}}return this.cache.set(r.dataKey,c),c}};var us=35,sh=70,ch=.35,fh=.5,uh=1.1;function kt(n,e){let t=e.sky;if(!t.enabled||t.fogIntensity<=0)return {near:0,far:1/0,intensity:0,cutoff:1/0};let o=n.cameraToCenterDistance,r=_e((n.pitch-us)/(sh-us),0,1),i=t.fogRange[0]*(1-ch*r)*o,a=t.fogRange[1]*(1-fh*r)*o,l=Math.min(1,t.fogIntensity+(1-t.fogIntensity)*Math.min(1,r*2)),s=l>=.995?a*uh:1/0;return {near:i,far:a,intensity:l,cutoff:s}}function Xn(n,e,t,o){let r=o.x/Math.max(n.width,1)*2-1,i=1-o.y/Math.max(n.height,1)*2,a=null,l=new Float64Array(16),s=[0,0,0,0],c=[0,0,0,0];for(let h of e.visibleTiles){let u=e.getTile(h),f=u&&hs(u,t);if(!f||!Ne(l,n.tileMatrix64(h,f.extent))||(de(s,l,[r,i,-1,1]),de(c,l,[r,i,1,1]),s[3]===0||c[3]===0))continue;let d=s[0]/s[3],p=s[1]/s[3],b=s[2]/s[3],m=c[0]/c[3]-d,g=c[1]/c[3]-p,y=c[2]/c[3]-b,A=dh(f,d,p,b,m,g,y);A&&(!a||A.t<a.distance)&&(a={featureId:A.featureId,tile:h,layerId:t,distance:A.t});}return a}function jn(n,e,t,o){let r=o.x/Math.max(n.width,1)*2-1,i=1-o.y/Math.max(n.height,1)*2,a=null,l=new Float64Array(16),s=[0,0,0,0],c=[0,0,0,0];for(let h of e.visibleTiles){let u=e.getTile(h);if(u)for(let f of t){let d=u.data?.buckets?.[f];if(!d||d.kind!=="fill"||!d.featureIds||!Ne(l,n.tileMatrix64(h,d.extent))||(de(s,l,[r,i,-1,1]),de(c,l,[r,i,1,1]),s[3]===0||c[3]===0))continue;let p=s[0]/s[3],b=s[1]/s[3],m=s[2]/s[3],g=c[2]/c[3]-m;if(Math.abs(g)<1e-9)continue;let y=-m/g;if(y<0||y>1)continue;let A=p+(c[0]/c[3]-p)*y,B=b+(c[1]/c[3]-b)*y,x=hh(d,A,B);x!==null&&(!a||y<a.distance)&&(a={featureId:x,tile:h,layerId:f,distance:y});}}return a}function hh(n,e,t){let o=new DataView(n.vertices),r=new Uint32Array(n.indices),i=new Float64Array(n.featureIds),a=s=>o.getInt16(s*tt,true),l=s=>o.getInt16(s*tt+2,true);for(let s=0;s*3<r.length;s++){let c=r[s*3],h=r[s*3+1],u=r[s*3+2],f=a(c),d=l(c),p=a(h),b=l(h),m=a(u),g=l(u),y=(e-p)*(d-b)-(f-p)*(t-b),A=(e-m)*(b-g)-(p-m)*(t-g),B=(e-f)*(g-d)-(m-f)*(t-d),x=y<0||A<0||B<0,w=y>0||A>0||B>0;if(!(x&&w))return i[s]}return null}function hs(n,e){let t=n.data?.buckets?.[e];return !t||t.kind!=="fill-extrusion"||!t.featureIds?null:t}function dh(n,e,t,o,r,i,a){let l=new DataView(n.vertices),s=new Uint32Array(n.indices),c=new Float64Array(n.featureIds),h=b=>l.getInt16(b*Ie,true)/Et,u=b=>l.getInt16(b*Ie+2,true)/Et,f=b=>l.getUint16(b*Ie+4,true)/Mt,d=1/0,p=-1;for(let b=0;b+2<s.length;b+=3){let m=s[b],g=s[b+1],y=s[b+2],A=h(m),B=u(m),x=f(m),w=h(g)-A,_=u(g)-B,C=f(g)-x,v=h(y)-A,E=u(y)-B,D=f(y)-x,F=i*D-a*E,H=a*v-r*D,S=r*E-i*v,L=w*F+_*H+C*S;if(L>-1e-9&&L<1e-9)continue;let M=1/L,T=e-A,P=t-B,k=o-x,O=(T*F+P*H+k*S)*M;if(O<0||O>1)continue;let N=P*C-k*_,G=k*w-T*C,R=T*_-P*w,W=(r*N+i*G+a*R)*M;if(W<0||O+W>1)continue;let j=(v*N+E*G+D*R)*M;j<0||j>1||j>=d||(d=j,p=c[b/3]??0);}return p>=0?{featureId:p,t:d}:null}function Ar(n,e,t){let o=hs(n,e);if(!o)return null;let r=new Uint32Array(o.indices),i=new Float64Array(o.featureIds),a=[];for(let l=0;l+2<r.length;l+=3)i[l/3]===t&&a.push(r[l],r[l+1],r[l+2]);return a.length?{vertices:o.vertices,indices:new Uint32Array(a)}:null}var Pt=24,Yn=8,ph=2,mh=12,Br=8,Cr=8;function go(n){let e=0;for(let d of n)e+=d.length/2;if(e<2)return null;let t=(Br+2)*2,o=e*t+n.length*(Cr+2)*2+8,r=e*(Br+2)*6+n.length*Cr*6+24,i=new ArrayBuffer(o*Pt),a=new DataView(i),l=new Uint32Array(r),s=0,c=0,h=(d,p,b,m,g,y)=>{let A=s*Pt;return a.setFloat32(A,d,true),a.setFloat32(A+4,p,true),a.setFloat32(A+8,b,true),a.setFloat32(A+12,m,true),a.setFloat32(A+16,g,true),a.setFloat32(A+20,y,true),s++},u=(d,p,b,m)=>{l[c++]=d,l[c++]=p,l[c++]=m,l[c++]=d,l[c++]=m,l[c++]=b;},f=(d,p,b,m,g,y,A)=>{let B=h(d,p,0,0,0,A),x=h(d,p,b,m,1,A);for(let w=1;w<=Cr;w++){let _=Math.PI*w/Cr,C=b*Math.cos(_)+g*Math.sin(_),v=m*Math.cos(_)+y*Math.sin(_),E=h(d,p,C,v,1,A);l[c++]=B,l[c++]=x,l[c++]=E,x=E;}};for(let d of n){let p=bh(d),b=p.length/2;if(b<2)continue;let m=new Float64Array(b-1),g=new Float64Array(b-1);for(let w=0;w<b-1;w++){let _=p[w*2+2]-p[w*2],C=p[w*2+3]-p[w*2+1],v=Math.hypot(_,C)||1;m[w]=_/v,g[w]=C/v;}let y=0,A=-1,B=-1;for(let w=0;w<b;w++){let _=p[w*2],C=p[w*2+1];w>0&&(y+=Math.hypot(_-p[w*2-2],C-p[w*2-1]));let v=w>0?w-1:0,E=w<b-1?w:b-2,D=-g[v],F=m[v],H=-g[E],S=m[E],L=D+H,M=F+S,T=Math.hypot(L,M);T>1e-9?(L/=T,M/=T):(L=D,M=F);let P=L*H+M*S,k=P>1e-6?1/P:1/0,O=Math.acos(Math.min(1,Math.max(-1,m[v]*m[E]+g[v]*g[E])));if(!(O>mh*Math.PI/180)&&k<=ph){let G=h(_,C,L*k,M*k,1,y),R=h(_,C,-L*k,-M*k,-1,y);A>=0&&u(A,B,G,R),A=G,B=R;}else {let G=Math.max(1,Math.min(Br,Math.ceil(O/(Math.PI/Br)))),W=m[v]*g[E]-g[v]*m[E]>=0?1:-1,j=h(_,C,D,F,1,y),Z=h(_,C,-D,-F,-1,y);A>=0&&u(A,B,j,Z);for(let ee=1;ee<=G;ee++){let ge=W*O*(ee/G),te=Math.cos(ge),X=Math.sin(ge),re=D*te-F*X,le=D*X+F*te,q=h(_,C,re,le,1,y),U=h(_,C,-re,-le,-1,y);u(j,Z,q,U),j=q,Z=U;}A=j,B=Z;}}let x=b-2;f(p[0],p[1],-g[0],m[0],-m[0],-g[0],0),f(p[(b-1)*2],p[(b-1)*2+1],-g[x],m[x],m[x],g[x],y);}return c?{vertices:i.slice(0,s*Pt),indices:l.slice(0,c),vertexCount:s}:null}function Zn(n){if(!n.length||n[0].length<6)return null;let e=[],t=[];for(let i=0;i<n[0].length;i++)e.push(n[0][i]);for(let i=1;i<n.length;i++)if(!(n[i].length<6)){t.push(e.length/2);for(let a=0;a<n[i].length;a++)e.push(n[i][a]);}let o=Pe(e,t.length?t:void 0,2);if(!o.length)return null;let r=new Uint32Array(o.length);for(let i=0;i<o.length;i+=3)r[i]=o[i],r[i+1]=o[i+2],r[i+2]=o[i+1];return {vertices:new Float32Array(e).buffer,indices:r,vertexCount:e.length/2}}function bh(n){let e=[];for(let t=0;t<n.length;t+=2){let o=n[t],r=n[t+1],i=e.length;i>=2&&e[i-2]===o&&e[i-1]===r||e.push(o,r);}return e}var yo=5126,gh={stride:Yn,attribs:[{name:"a_pos",size:2,type:yo,offset:0}]},qn={stride:Pt,attribs:[{name:"a_pos",size:2,type:yo,offset:0},{name:"a_extrude",size:2,type:yo,offset:8},{name:"a_side",size:1,type:yo,offset:16},{name:"a_dist",size:1,type:yo,offset:20}]},Qn=class{constructor(e,t){this.revision=e;this.parts=t;}destroy(){for(let e of this.parts)e.vao.destroy(),e.vbo.destroy(),e.ibo.destroy();}},yh=(n,e)=>[n[0],n[1],n[2],n[3]*e],Ao=class{constructor(){this.objects=[];this.markers=[];this.gpu=new z;this.markerHost=null;}setMarkerHost(e){this.markerHost=e;for(let t of this.markers)t.attach(e);}add(e){this.objects.includes(e)||this.objects.push(e);}remove(e){let t=this.objects.indexOf(e);t<0||(this.objects.splice(t,1),this.gpu.get(e.id)?.destroy(),this.gpu.delete(e.id));}addMarker(e){this.markers.includes(e)||(this.markers.push(e),this.markerHost&&e.attach(this.markerHost));}removeMarker(e){let t=this.markers.indexOf(e);t<0||(this.markers.splice(t,1),e.detach());}get all(){return this.objects}get allMarkers(){return this.markers}get isEmpty(){return this.objects.length===0}updateMarkers(e){for(let t of this.markers)t.update(e);}render(e,t,o,r,i,a,l,s=false,c=false){if(!this.objects.length||c&&!this.objects.some(p=>p.ghostOpacity>0))return;this.objects.length>1&&this.objects.sort((p,b)=>p.zIndex-b.zIndex);let h=e.gl.drawingBufferWidth,u=t.width>0?h/t.width:1,f=t.worldSize*u,d=null;for(let p of this.objects){if(!p.visible)continue;let b=p.ghostOpacity;if(c&&b<=0)continue;let m=this.gpuFor(e,p,r,a);if(!m)continue;let g=s?t.shadowObjectMatrix(p.originX,p.originY,p.altitude):null,y=t.objectMatrix(p.originX,p.originY,p.altitude);for(let{part:A,vao:B,ibo:x}of m.parts){if(c&&(A.kind!=="line"||A.arrow))continue;let w=c?yh(A.color,b):A.color;if(A.kind==="fill")d!==o&&(o.use(),l?.(o),d=o),o.setVec4v("u_color",Me(w)),g&&o.setMat4("u_shadow_matrix",g),o.setMat4("u_matrix",y);else {d!==i&&(i.use(),l?.(i),d=i);let _=A.width/2*u,C=f>1e-9?1/f:1;if(i.setVec4v("u_color",Me(w)),i.setFloat("u_half_width",_),i.setFloat("u_offset",(A.offset??0)*u),i.setFloat("u_aa",1),i.setFloat("u_units_per_px",C),i.setFloat("u_units_to_px",f),i.setInt("u_pattern",c?0:A.dashArray?1:A.arrow?2:0),A.dashArray){let[v,E]=A.dashArray;i.setVec2("u_dash",v*u,(v+E)*u);}if(A.arrow){i.setVec4v("u_arrow_color",Me(A.arrowColor??[1,1,1,1]));let v=(A.arrowSize??5)*u;i.setVec3("u_arrow",(A.arrowPeriod??46)*u,Math.max(v*.4,1),Math.min(v,_*.72));}g&&i.setMat4("u_shadow_matrix",g),i.setMat4("u_matrix",y);}B.bind(),e.gl.drawElements(e.gl.TRIANGLES,x.count,x.type,0);}}e.bindVAO(null);}hitTest(e,t,o=4){let r=e.worldSize,i=(a,l,s)=>e.worldPxToPoint(ne(a)*r,ie(l)*r,s);for(let a=this.objects.length-1;a>=0;a--){let l=this.objects[a];if(l.visible&&l.hitTest(t,i,o))return l}return null}boundsOf(e){let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let a of e.rings())for(let l of a){let s=$(l);s.lng<t&&(t=s.lng),s.lng>r&&(r=s.lng),s.lat<o&&(o=s.lat),s.lat>i&&(i=s.lat);}return isFinite(t)?{west:t,south:o,east:r,north:i}:null}gpuFor(e,t,o,r){let i=this.gpu.get(t.id);if(i&&i.revision===t.revision)return i;i?.destroy();let a=[];for(let s of t.build()){let c=s.kind==="fill"?gh:qn,h=s.kind==="fill"?o:r,u=new ve(e,new Uint8Array(s.mesh.vertices),c),f=new ye(e,s.mesh.indices),d=new pe(e,[{buffer:u,locations:h}],f);a.push({part:s,vao:d,vbo:u,ibo:f});}let l=new Qn(t.revision,a);return this.gpu.set(t.id,l),a.length?l:null}destroy(){for(let e of this.gpu.values())e.destroy();this.gpu.clear();for(let e of this.markers)e.detach();this.markers=[],this.objects=[];}};var vr=32,vh=1179937895,xh=1313821514,wh=5130562,_h={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Eh={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16};async function $n(n){let{json:e,bin:t}=ys(n),o=await Fh(e,t);return Bs(e,t,o)}function Mh(n){let{json:e,bin:t}=ys(n);for(let o of e.bufferViews??[])if(o.extensions?.EXT_meshopt_compression)throw new Error("[osmgl] GLB \u0441\u0436\u0430\u0442 meshopt \u2014 \u043D\u0443\u0436\u0435\u043D parseGlbAsync");return Bs(e,t,null)}function ys(n){let e=new DataView(n);if(e.getUint32(0,true)!==vh)throw new Error("[osmgl] \u044D\u0442\u043E \u043D\u0435 GLB: \u043D\u0435\u0432\u0435\u0440\u043D\u0430\u044F \u0441\u0438\u0433\u043D\u0430\u0442\u0443\u0440\u0430");if(e.getUint32(4,true)!==2)throw new Error("[osmgl] \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F \u0442\u043E\u043B\u044C\u043A\u043E glTF 2.0");let t=null,o=null,r=12;for(;r+8<=n.byteLength;){let i=e.getUint32(r,true),a=e.getUint32(r+4,true),l=r+8;a===xh?t=JSON.parse(new TextDecoder().decode(new Uint8Array(n,l,i))):a===wh&&(o=new Uint8Array(n,l,i)),r=l+i+(4-i%4)%4;}if(!t)throw new Error("[osmgl] \u0432 GLB \u043D\u0435\u0442 JSON-\u043A\u0443\u0441\u043A\u0430");return {json:t,bin:o??new Uint8Array(0)}}async function Fh(n,e){let t=n.bufferViews??[],o=[];for(let a=0;a<t.length;a++)t[a].extensions?.EXT_meshopt_compression&&o.push(a);if(!o.length)return null;let{MeshoptDecoder:r}=await Promise.resolve().then(()=>(gs(),bs));await r.ready;let i=new Map;for(let a of o){let l=t[a].extensions.EXT_meshopt_compression,s=l.byteOffset??0,c=e.subarray(s,s+l.byteLength),h=new Uint8Array(l.count*l.byteStride);r.decodeGltfBuffer(h,l.count,l.byteStride,c,l.mode,l.filter??"NONE"),i.set(a,h);}return i}function As(n){let e=K();if(n.matrix){for(let C=0;C<16;C++)e[C]=n.matrix[C];return e}je(e);let[t,o,r]=n.translation??[0,0,0],[i,a,l,s]=n.rotation??[0,0,0,1],[c,h,u]=n.scale??[1,1,1],f=i+i,d=a+a,p=l+l,b=i*f,m=i*d,g=i*p,y=a*d,A=a*p,B=l*p,x=s*f,w=s*d,_=s*p;return e[0]=(1-(y+B))*c,e[1]=(m+_)*c,e[2]=(g-w)*c,e[4]=(m-_)*h,e[5]=(1-(b+B))*h,e[6]=(A+x)*h,e[8]=(g+w)*u,e[9]=(A-x)*u,e[10]=(1-(b+y))*u,e[12]=t,e[13]=o,e[14]=r,e}var Dh={5120:127,5121:255,5122:32767,5123:65535};function Sh(n){let e=n[0],t=n[1],o=n[2],r=n[4],i=n[5],a=n[6],l=n[8],s=n[9],c=n[10],h=e*(i*c-a*s)-r*(t*c-o*s)+l*(t*a-o*i);if(Math.abs(h)<1e-20)return [1,0,0,0,1,0,0,0,1];let u=1/h;return [(i*c-a*s)*u,(a*l-r*c)*u,(r*s-i*l)*u,(o*s-t*c)*u,(e*c-o*l)*u,(t*l-e*s)*u,(t*a-o*i)*u,(o*r-e*a)*u,(e*i-t*r)*u]}function Bs(n,e,t){let o=C=>{let v=t?.get(C);if(v)return v;let E=n.bufferViews?.[C];if(!E)return null;let D=E.byteOffset??0;return e.subarray(D,D+E.byteLength)},r=[],i=[],a=[],l=[],s=[],c=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0],u=C=>{if(C===void 0)return null;let v=n.accessors?.[C];if(!v)return null;let E=Eh[v.type]??1,D=new Float64Array(v.count*E),F=v.bufferView!==void 0?n.bufferViews?.[v.bufferView]:void 0;if(!F||v.bufferView===void 0)return {data:D,components:E};let H=o(v.bufferView);if(!H)return {data:D,components:E};let S=_h[v.componentType]??4,L=F.extensions?.EXT_meshopt_compression,M=L?L.byteStride:F.byteStride,T=M&&M>0?M:S*E,P=v.byteOffset??0,k=new DataView(H.buffer,H.byteOffset,H.byteLength),O=v.normalized?Dh[v.componentType]??1:1;for(let N=0;N<v.count;N++)for(let G=0;G<E;G++){let R=P+N*T+G*S,W;switch(v.componentType){case 5120:W=k.getInt8(R);break;case 5121:W=k.getUint8(R);break;case 5122:W=k.getInt16(R,true);break;case 5123:W=k.getUint16(R,true);break;case 5125:W=k.getUint32(R,true);break;default:W=k.getFloat32(R,true);}D[N*E+G]=O===1?W:Math.max(W/O,-1);}return {data:D,components:E}},f=(C,v,E=-1)=>{if(C.mode!==void 0&&C.mode!==4)return;let D=u(C.attributes.POSITION);if(!D)return;let F=u(C.attributes.NORMAL),H=u(C.attributes.TEXCOORD_0),S=u(C.indices),L=r.length/3,M=D.data.length/3,T=Sh(v),k=(C.material!==void 0?n.materials?.[C.material]:void 0)?.pbrMetallicRoughness?.baseColorTexture?.extensions?.KHR_texture_transform,O=k?{ox:k.offset?.[0]??0,oy:k.offset?.[1]??0,sx:k.scale?.[0]??1,sy:k.scale?.[1]??1,rot:k.rotation??0}:null;for(let X=0;X<M;X++){let re=D.data[X*3],le=D.data[X*3+1],q=D.data[X*3+2],U=v[0]*re+v[4]*le+v[8]*q+v[12],J=v[1]*re+v[5]*le+v[9]*q+v[13],fe=v[2]*re+v[6]*le+v[10]*q+v[14];if(r.push(U,J,fe),U<c[0]&&(c[0]=U),J<c[1]&&(c[1]=J),fe<c[2]&&(c[2]=fe),U>h[0]&&(h[0]=U),J>h[1]&&(h[1]=J),fe>h[2]&&(h[2]=fe),F){let ae=F.data[X*3],xe=F.data[X*3+1],Te=F.data[X*3+2],we=T[0]*ae+T[3]*xe+T[6]*Te,Ro=T[1]*ae+T[4]*xe+T[7]*Te,Go=T[2]*ae+T[5]*xe+T[8]*Te,Oo=Math.hypot(we,Ro,Go);Oo>1e-12?(we/=Oo,Ro/=Oo,Go/=Oo):(we=0,Ro=1,Go=0),i.push(we,Ro,Go);}else i.push(0,1,0);let se=H?H.data[X*2]:0,ue=H?H.data[X*2+1]:0;if(O){if(O.rot!==0){let ae=Math.cos(O.rot),xe=Math.sin(O.rot),Te=ae*se+xe*ue,we=-xe*se+ae*ue;se=Te,ue=we;}se=se*O.sx+O.ox,ue=ue*O.sy+O.oy;}a.push(se,ue);}let N=l.length;if(S)for(let X=0;X<S.data.length;X++)l.push(L+S.data[X]);else for(let X=0;X<M;X++)l.push(L+X);let G=C.material!==void 0?n.materials?.[C.material]:void 0,R=G?.pbrMetallicRoughness,W=R?.metallicFactor!==void 0||R?.roughnessFactor!==void 0,j=R?.baseColorFactor??[1,1,1,1],Z=R?.baseColorTexture?.index,ee=Z!==void 0?n.textures?.[Z]?.source:void 0,ge=G?.emissiveFactor??[0,0,0],te=G?.extensions?.KHR_materials_emissive_strength?.emissiveStrength??1;s.push({indexOffset:N,indexCount:l.length-N,baseColor:[j[0],j[1],j[2],j[3]??1],metallic:W?R?.metallicFactor??1:0,roughness:W?R?.roughnessFactor??1:1,emissive:[ge[0]*te,ge[1]*te,ge[2]*te],texture:ee??-1,doubleSided:G?.doubleSided===true,blend:G?.alphaMode==="BLEND",alphaCutoff:G?.alphaMode==="MASK"?G.alphaCutoff??.5:.02,node:E});},d=n.skins?.length?null:Ih(n,u),p=d?d.nodes:null,b=(C,v,E,D)=>{let F=n.nodes?.[C];if(!F)return;let H=As(F),S=K();Ee(S,v,H);let L=K(),M=D,T=p?.get(C);if(T?(T.parentNode=D,T.parent=E.slice(),je(L),M=C):Ee(L,E,H),F.mesh!==void 0)for(let k of n.meshes?.[F.mesh]?.primitives??[])f(k,L,M);let P=F.extensions?.KHR_lights_punctual?.light;if(P!==void 0){let k=n.extensions?.KHR_lights_punctual?.lights?.[P],O=k?.type;if(k&&(O==="point"||O==="spot"||O==="directional")){let N=-S[8],G=-S[9],R=-S[10],W=Math.hypot(N,G,R)||1,j=k.spot?.innerConeAngle??0,Z=k.spot?.outerConeAngle??Math.PI/4;m.push({type:O,color:[k.color?.[0]??1,k.color?.[1]??1,k.color?.[2]??1],intensity:k.intensity??1,range:k.range??0,position:[S[12],S[13],S[14]],direction:[N/W,G/W,R/W],cosInner:Math.cos(j),cosOuter:Math.cos(Z)});}}for(let k of F.children??[])b(k,S,L,M);},m=[],g=K();je(g);let y=K();je(y);let A=n.scenes?.[n.scene??0]?.nodes??n.nodes?.map((C,v)=>v)??[];for(let C of A)b(C,g,y,-1);let B=[];for(let C of n.images??[]){if(C.bufferView===void 0){B.push(new Uint8Array(0));continue}let v=o(C.bufferView);B.push(v?v.slice():new Uint8Array(0));}let x=r.length/3,w=new ArrayBuffer(x*vr),_=new Float32Array(w);for(let C=0;C<x;C++){let v=C*8;_[v]=r[C*3],_[v+1]=r[C*3+1],_[v+2]=r[C*3+2],_[v+3]=i[C*3],_[v+4]=i[C*3+1],_[v+5]=i[C*3+2],_[v+6]=a[C*2],_[v+7]=a[C*2+1];}return isFinite(c[0])||(c[0]=c[1]=c[2]=0,h[0]=h[1]=h[2]=0),{vertices:w,indices:new Uint32Array(l),primitives:s,images:B,min:c,max:h,animation:d,lights:m}}function Ih(n,e){let t=n.animations?.[0];if(!t||!t.channels.length)return null;let o=new Map,r=0;for(let i of t.channels){let a=i.target.node,l=i.target.path;if(a===void 0||l!=="translation"&&l!=="rotation"&&l!=="scale")continue;let s=t.samplers[i.sampler];if(!s)continue;let c=e(s.input),h=e(s.output);if(!c||!h||!c.data.length)continue;let u=l==="rotation"?4:3,f=s.interpolation==="CUBICSPLINE",d=c.data.length,p=new Float32Array(d*u);for(let m=0;m<d;m++){let g=f?(m*3+1)*u:m*u;for(let y=0;y<u;y++)p[m*u+y]=h.data[g+y];}let b=o.get(a)??{parentNode:-1,parent:je(K()),base:Lh(n.nodes?.[a]),channels:[]};b.channels.push({path:l,times:Float32Array.from(c.data),values:p,step:s.interpolation==="STEP"}),o.set(a,b),r=Math.max(r,c.data[d-1]);}return o.size?{duration:r||1,nodes:o}:null}function Lh(n){let e=n?.translation,t=n?.rotation,o=n?.scale;return {t:[e?.[0]??0,e?.[1]??0,e?.[2]??0],r:[t?.[0]??0,t?.[1]??0,t?.[2]??0,t?.[3]??1],s:[o?.[0]??1,o?.[1]??1,o?.[2]??1]}}function ei(n,e,t,o){let r=n.nodes.get(e);if(!r)return je(o);let i=K();Th(r,t,i);let a=K();if(Ee(a,r.parent,i),r.parentNode<0)return Cs(o,a);let l=K();return ei(n,r.parentNode,t,l),Ee(o,l,a)}var Cs=(n,e)=>{for(let t=0;t<16;t++)n[t]=e[t];return n};function Th(n,e,t){let o=[...n.base.t],r=[...n.base.r],i=[...n.base.s];for(let a of n.channels){let l=a.times.length,s=a.path==="rotation"?4:3,c=0;for(;c<l-1&&a.times[c+1]<e;)c++;let h=Math.min(c+1,l-1),u=a.times[h]-a.times[c],f=a.step||u<=0?0:Math.min(Math.max((e-a.times[c])/u,0),1),d=c*s,p=h*s;if(a.path==="rotation"){let b=0;for(let y=0;y<4;y++)b+=a.values[d+y]*a.values[p+y];let m=b<0?-1:1,g=0;for(let y=0;y<4;y++)r[y]=a.values[d+y]*(1-f)+a.values[p+y]*m*f,g+=r[y]*r[y];g=Math.sqrt(g)||1;for(let y=0;y<4;y++)r[y]/=g;}else {let b=a.path==="translation"?o:i;for(let m=0;m<3;m++)b[m]=a.values[d+m]*(1-f)+a.values[p+m]*f;}}return Cs(t,As({translation:o,rotation:r,scale:i}))}var Le=5126,Hh=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),vs={stride:vr,attribs:[{name:"a_pos",size:3,type:Le,offset:0},{name:"a_normal",size:3,type:Le,offset:12},{name:"a_tex",size:2,type:Le,offset:24}]},oi=class{constructor(e,t,o,r){this.vao=e;this.vbo=t;this.ibo=o;this.textures=r;this.users=0;this.instVao=null;}destroy(e){this.vao.destroy(),this.instVao?.destroy(),this.vbo.destroy(),this.ibo.destroy();for(let t of this.textures)t&&e.deleteTexture(t);}},ti=256,xr=41,xs={stride:xr*4,attribs:[{name:"a_i_m0",size:4,type:Le,offset:0,divisor:1},{name:"a_i_m1",size:4,type:Le,offset:16,divisor:1},{name:"a_i_m2",size:4,type:Le,offset:32,divisor:1},{name:"a_i_m3",size:4,type:Le,offset:48,divisor:1},{name:"a_i_s0",size:4,type:Le,offset:64,divisor:1},{name:"a_i_s1",size:4,type:Le,offset:80,divisor:1},{name:"a_i_s2",size:4,type:Le,offset:96,divisor:1},{name:"a_i_s3",size:4,type:Le,offset:112,divisor:1},{name:"a_i_n0",size:3,type:Le,offset:128,divisor:1},{name:"a_i_n1",size:3,type:Le,offset:140,divisor:1},{name:"a_i_n2",size:3,type:Le,offset:152,divisor:1}]},Bo=2,Rt=16,at=class{constructor(){this.models=[];this.gpu=new z;this.counted=new Set;this.instBuffer=null;this.instScratch=new Float32Array(ti*xr);this.drawnInstanced=new Set;this.onLoaded=null;this.growDurationSec=.45;this.fadeDurationSec=.6;this.transitioning=false;this.depthTimeSec=0;this.lightPacks=new WeakMap;this.shadow32=new Float32Array(16);this.shadowNode32=new Float32Array(16);this.shadowNodeColor32=new Float32Array(16);}add(e){this.models.includes(e)||(this.models.push(e),e.isLoaded||e.load(()=>this.onLoaded?.()));}remove(e,t){let o=this.models.indexOf(e);if(o<0)return;this.models.splice(o,1);let r=this.gpu.get(e.url);r&&(this.counted.delete(e)&&r.users--,!(r.users>0)&&(t&&r.destroy(t),this.gpu.delete(e.url)));}get all(){return this.models}get hasTransitions(){return this.transitioning}get hasAnimated(){return this.models.some(e=>e.isAnimated)}get isEmpty(){return this.models.length===0}get readyCount(){return this.models.filter(e=>e.visible&&e.isLoaded).length}render(e,t,o,r,i,a,l=0,s){if(this.models.length){this.drawnInstanced.clear(),s&&this.renderInstanced(e,t,s.shader,s.locations,i,a),o.use(),i(o),o.setInt("u_base_texture",Bo);for(let c of this.models){if(this.drawnInstanced.has(c)||!this.inView(t,c))continue;let h=c.visible&&c.fade>0?this.gpuFor(e,c,r):null;if(!h||!c.mesh)continue;let u=c.fade<1;o.setFloat("u_opacity",c.fade);let f=c.matrixFor(t);o.setMat4("u_matrix",f),o.setMat3("u_normal_matrix",c.normalMatrix());let d=a?this.shadowMatrix(t,c):null;this.uploadLights(o,c.mesh);let p=c.cameraInModelSpace(t);o.setVec3("u_camera_model",p[0],p[1],p[2]),o.setFloat("u_reflect",1),h.vao.bind();for(let b of [false,true])if(!(u&&!b))for(let m of c.mesh.primitives){if(!u&&m.blend!==b)continue;o.setMat4("u_matrix",m.node>=0?c.matrixForNode(t,m.node,l):f),d&&o.setMat4("u_shadow_matrix",m.node>=0?this.shadowMatrixForNodeAt(t,c,m.node,l):d);let g=m.texture>=0?h.textures[m.texture]:null;o.setFloat("u_has_texture",g?1:0),o.setFloat("u_alpha_cutoff",m.alphaCutoff),g&&e.bindTexture(Bo,g),o.setVec4v("u_base_color",m.baseColor),o.setVec3("u_emissive",m.emissive[0],m.emissive[1],m.emissive[2]),o.setFloat("u_metallic",m.metallic),o.setFloat("u_roughness",m.roughness),e.setCull(m.doubleSided?"none":"back"),e.setBlend(b?"premultiplied":"none"),e.setDepthMask(!b),e.gl.drawElements(e.gl.TRIANGLES,m.indexCount,e.gl.UNSIGNED_INT,m.indexOffset*4);}}e.bindVAO(null),e.setCull("back"),e.setBlend("premultiplied"),e.setDepthMask(true);}}renderInstanced(e,t,o,r,i,a){let l=new z;for(let c of this.models){if(!c.visible||c.fade<1||!c.mesh||!c.isLoaded||!this.inView(t,c)||c.mesh.primitives.some(u=>u.blend||u.node>=0))continue;let h=l.get(c.url);h?h.push(c):l.set(c.url,[c]);}let s=false;o.setFloat("u_reflect",0);for(let[,c]of l){if(c.length<2)continue;let h=this.gpuFor(e,c[0],r);if(!h||!c[0].mesh)continue;this.instBuffer||(this.instBuffer=new ve(e,this.instScratch,xs,true)),h.instVao||(h.instVao=new pe(e,[{buffer:h.vbo,locations:r},{buffer:this.instBuffer,locations:r}],h.ibo)),s||(o.use(),i(o),o.setInt("u_base_texture",Bo),o.setFloat("u_opacity",1),s=true);let u=c[0].mesh;for(let f=0;f<c.length;f+=ti){let d=Math.min(ti,c.length-f);for(let p=0;p<d;p++){let b=c[f+p],m=p*xr;this.instScratch.set(b.matrixFor(t),m);let g=a?this.shadowMatrix(t,b):Hh;this.instScratch.set(g,m+16),this.instScratch.set(b.normalMatrix(),m+32),this.drawnInstanced.add(b);}this.instBuffer.update(this.instScratch.subarray(0,d*xr)),e.bindVAO(h.instVao.vao);for(let p of u.primitives){let b=p.texture>=0?h.textures[p.texture]:null;o.setFloat("u_has_texture",b?1:0),o.setFloat("u_alpha_cutoff",p.alphaCutoff),b&&e.bindTexture(Bo,b),o.setVec4v("u_base_color",p.baseColor),o.setVec3("u_emissive",p.emissive[0],p.emissive[1],p.emissive[2]),o.setFloat("u_metallic",p.metallic),o.setFloat("u_roughness",p.roughness),e.setCull(p.doubleSided?"none":"back"),e.setBlend("none"),e.setDepthMask(true),e.gl.drawElementsInstanced(e.gl.TRIANGLES,p.indexCount,e.gl.UNSIGNED_INT,p.indexOffset*4,d);}}}s&&e.bindVAO(null);}uploadLights(e,t){let o=this.lightPacks.get(t);if(!o){let r=t.lights.filter(h=>h.type!=="directional"),i=r.length<=Rt?r:[...r].sort((h,u)=>u.intensity-h.intensity).slice(0,Rt),a=new Float32Array(Rt*4),l=new Float32Array(Rt*4),s=new Float32Array(Rt*4),c=new Float32Array(Rt*4);i.forEach((h,u)=>{let f=u*4;a[f]=h.position[0],a[f+1]=h.position[1],a[f+2]=h.position[2],a[f+3]=h.range,l[f]=h.color[0]*h.intensity,l[f+1]=h.color[1]*h.intensity,l[f+2]=h.color[2]*h.intensity,l[f+3]=h.type==="spot"?1:0,s[f]=h.direction[0],s[f+1]=h.direction[1],s[f+2]=h.direction[2],c[f]=h.cosInner,c[f+1]=h.cosOuter;}),o={count:i.length,pos:a,color:l,dir:s,cone:c},this.lightPacks.set(t,o);}e.setInt("u_light_count",o.count),o.count!==0&&(e.setVec4Array("u_light_pos",o.pos),e.setVec4Array("u_light_color",o.color),e.setVec4Array("u_light_dir",o.dir),e.setVec4Array("u_light_cone",o.cone));}inView(e,t){if(!t.mesh)return false;let r=t.origin(),i=t.boundingRadiusM();return e.isSphereVisible(r.x,r.y,t.altitude+i*.5,i)}advanceTransitions(){this.transitioning=false;for(let e of this.models)e.advanceGrow(this.growDurationSec)&&(this.transitioning=true),e.advanceFade(this.fadeDurationSec)&&(this.transitioning=true);}renderDepth(e,t,o,r){if(this.models.length){o.use();for(let i of this.models){let a=i.visible&&i.fade>.5?this.gpuFor(e,i,r):null;if(!a||!i.mesh)continue;let l=this.shadowMatrix(t,i);o.setMat4("u_matrix",l),a.vao.bind();for(let s of i.mesh.primitives)s.blend||(o.setMat4("u_matrix",s.node>=0?this.shadowMatrixForNode(t,i,s.node):l),e.gl.drawElements(e.gl.TRIANGLES,s.indexCount,e.gl.UNSIGNED_INT,s.indexOffset*4));}e.bindVAO(null);}}shadowMatrix(e,t){let o=t.origin();return t.matrixInSpace(e.shadowObjectMatrix(o.x,o.y,t.altitude),this.shadow32)}shadowMatrixForNode(e,t,o){return this.shadowMatrixForNodeInto(e,t,o,this.depthTimeSec,this.shadowNode32)}shadowMatrixForNodeAt(e,t,o,r){return this.shadowMatrixForNodeInto(e,t,o,r,this.shadowNodeColor32)}shadowMatrixForNodeInto(e,t,o,r,i){let a=t.origin();return t.matrixInSpaceForNode(e.shadowObjectMatrix(a.x,a.y,t.altitude),o,r,i)}gpuFor(e,t,o){let r=this.gpu.get(t.url);if(r)return this.counted.has(t)||(this.counted.add(t),r.users++),r;if(!t.mesh)return null;let i=e.gl,a=new ve(e,new Uint8Array(t.mesh.vertices),vs),l=new ye(e,t.mesh.indices),s=new pe(e,[{buffer:a,locations:o}],l),c=t.bitmaps.map(u=>{if(!u)return null;let f=i.createTexture();return f?(e.bindTexture(Bo,f),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,u),i.generateMipmap(i.TEXTURE_2D),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR_MIPMAP_LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.REPEAT),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.REPEAT),f):null}),h=new oi(s,a,l,c);return h.users=1,this.counted.add(t),this.gpu.set(t.url,h),h}static get layout(){return vs}static get instanceLayout(){return xs}destroy(e){for(let t of this.gpu.values())t.destroy(e);this.gpu.clear(),this.models=[];}};var ri=4,ws=new oe;function kh(n){ws.has(n)||(ws.add(n),console.warn(`[osmgl] ${n}`));}var Ph=.5,Rh=.01,Gh=300,ni=127,ii=128,Co=5120,_r=5121,vo=5122,_s=5123,xo=5126,Oh={stride:8,attribs:[{name:"a_pos",size:2,type:xo,offset:0}]},ai={stride:tt,attribs:[{name:"a_pos",size:2,type:vo,offset:0}]},Es={stride:nt,attribs:[{name:"a_p0",size:2,type:vo,offset:0},{name:"a_p1",size:2,type:vo,offset:4},{name:"a_corner",size:2,type:Co,offset:8},{name:"a_ground",size:2,type:Co,offset:10},{name:"a_dist",size:1,type:xo,offset:12},{name:"a_width",size:1,type:xo,offset:16}]},wr={stride:Ie,attribs:[{name:"a_pos",size:2,type:vo,offset:0},{name:"a_height",size:1,type:_s,offset:4},{name:"a_tint",size:1,type:_r,normalized:true,offset:6},{name:"a_ao",size:1,type:_r,normalized:true,offset:7},{name:"a_normal",size:3,type:Co,normalized:true,offset:8},{name:"a_kind",size:1,type:_r,offset:11},{name:"a_wall",size:3,type:_s,offset:12}]},zh={flat:0,water:1,foliage:2,sand:3,asphalt:4},Vh=[1,9,14,26,3],Ms={stride:It,attribs:[{name:"a_pos",size:2,type:xo,offset:0},{name:"a_level",size:1,type:vo,offset:8},{name:"a_normal",size:3,type:Co,normalized:true,offset:10},{name:"a_kind",size:1,type:_r,offset:13},{name:"a_bleed",size:2,type:Co,offset:14}]},li=class{constructor(e,t,o,r,i,a,l=r){this.vao=e;this.buffer=t;this.ibo=o;this.indexCount=r;this.indexType=i;this.extent=a;this.capIndexOffset=l;this.firstDrawTime=0;}destroy(){this.vao.destroy(),this.buffer.destroy(),this.ibo.destroy();}},Fs={enabled:false,resolution:1024,strength:.75,color:"#5a6b86",bias:.25},wo=class{constructor(){this.fill=null;this.surface=null;this.surfaceLocs=new z;this.line=null;this.building=null;this.depth=null;this.groundShadow=null;this.sky=null;this.raster=null;this.rasterLayer=new yr;this.globeBody=null;this.globeClip=null;this.globeMesh=null;this.quad=null;this.fillLocs=new z;this.lineLocs=new z;this.objectLine=null;this.objectLineLocs=new z;this.buildingLocs=new z;this.shadows={...Fs};this.shadowTarget=null;this.shadowPlaceholder=null;this.fog=null;this.shadowActive=false;this.materialTime=0;this.materialAnimating=false;this.stencilIds=new z;this.patternScale=1;this.cameraMeters=[0,0,0];this.dpr=1;this.detailScale=1;this.reliefScale=1;this.allowShadows=true;this.highlight=null;this.highlightGpu=new z;this.highlightKey="";this.groundArrows=new mo;this.highlightTris=new z;this.fillHighlightGpu=new z;this.fillHighlightKey="";this.footprintKey="";this.highlightFill=null;this.indoorMask=new bo;this.hiddenBuildings=new Set;this.hiddenVenues=new Set;this.hiddenVenueLayer=null;this.hiddenCut=new z;this.hiddenStamp="";this.shadowDepthPerMeter=1;this.shadowTexelMeters=0;this.growDurationMs=350;this.symbols=null;this.objects=null;this.models=new at;this.model=null;this.modelInstanced=null;this.modelDepth=null;this.modelLocs=new z;this.modelInstLocs=new z;}get indoorOpen(){return this.indoorMask.active}syncHiddenStamp(){let e=o=>[...o].sort((r,i)=>r-i).join(","),t=e(this.hiddenBuildings)+"#"+e(this.hiddenVenues);if(t!==this.hiddenStamp){this.hiddenStamp=t;for(let o of this.hiddenCut.values())o?.vao.destroy(),o?.ibo.destroy();this.hiddenCut.clear();}}hiddenFor(e,t){return t?this.hiddenBuildings:e===this.hiddenVenueLayer?this.hiddenVenues:null}cutHidden(e,t,o,r,i,a){if(!a||!a.size)return null;let l=r+"|"+o,s=this.hiddenCut.get(l);if(s!==void 0&&(s===null||s.vbo===i))return s;s&&(s.vao.destroy(),s.ibo.destroy());let c=t.data?.buckets?.[o];if(!c||c.kind!=="fill-extrusion"||!c.featureIds)return null;let h=new Uint32Array(c.indices),u=new Float64Array(c.featureIds),f=[];for(let p=0;p*3<h.length;p++)a.has(u[p])||f.push(h[p*3],h[p*3+1],h[p*3+2]);let d=null;if(f.length<h.length){let p=new ye(e,new Uint32Array(f));d={vao:new pe(e,[{buffer:i,locations:this.buildingLocs}],p),ibo:p,count:f.length,vbo:i};}return this.hiddenCut.set(l,d),d}init(e){this.symbols?.init(e),this.fill=new Ae(e,"fill",jl,Yl),this.surface=new Ae(e,"surface",os,rs),this.line=new Ae(e,"line",Zl,Ql),this.objectLine=new Ae(e,"objectLine",ql,$l),this.building=new Ae(e,"buildings",es,ts),this.depth=new Ae(e,"depth",Rl,On),this.groundShadow=new Ae(e,"groundShadow",Jl,Xl),this.sky=new Ae(e,"sky",Wl,Nl),this.raster=new Ae(e,"raster",Kl,Ul),this.globeBody=new Ae(e,"globeBody",Tl,Hl),this.globeClip=new Ae(e,"globeClip",kl,Pl),this.globeMesh=Wh(e,this.globeBody),this.model=new Ae(e,"model",Ol,zn),this.modelInstanced=new Ae(e,"model-instanced",zl,zn),this.modelDepth=new Ae(e,"modelDepth",Vl,On);for(let i of at.layout.attribs)this.modelLocs.set(i.name,this.model.attribLocation(i.name));for(let i of [...at.layout.attribs,...at.instanceLayout.attribs])this.modelInstLocs.set(i.name,this.modelInstanced.attribLocation(i.name));this.shadowPlaceholder=Il(e);let t=new z([["a_pos",this.groundShadow.attribLocation("a_pos")]]),o=new ve(e,new Float32Array([0,0,1,0,1,1,0,1]),Oh),r=new ye(e,new Uint16Array([0,1,2,0,2,3]));this.quad={vao:new pe(e,[{buffer:o,locations:t}],r),vbo:o,ibo:r};for(let i of ai.attribs)this.fillLocs.set(i.name,this.fill.attribLocation(i.name));for(let i of Ms.attribs)this.surfaceLocs.set(i.name,this.surface.attribLocation(i.name));for(let i of Es.attribs)this.lineLocs.set(i.name,this.line.attribLocation(i.name));for(let i of qn.attribs)this.objectLineLocs.set(i.name,this.objectLine.attribLocation(i.name));for(let i of wr.attribs)this.buildingLocs.set(i.name,this.building.attribLocation(i.name));}render(e,t,o,r,i,a=new z){if(!this.fill||!this.line||!this.building)return false;let l=t.zoom,s=false;this.materialTime=i/1e3,this.materialAnimating=false,this.fog=kt(t,r),this.patternScale=No/Math.max(Oe(t.center.lat),1),this.dpr=t.width>0?e.gl.drawingBufferWidth/t.width:1;let c=Math.max(t.pixelsPerMeter,1e-9),h=t.cameraPositionPx;this.cameraMeters=[h[0]/c,h[1]/c,h[2]/c];let u=m=>o.get(m.source??Y);this.syncHighlightFootprint(o,r),this.indoorMask.sync(o,r,l),this.syncHiddenStamp(),this.models.advanceTransitions(),this.renderShadowMap(e,t,o,r,i),this.drawSky(e,t,r),this.drawGlobeBody(e,t,r),this.raster&&this.quad&&this.rasterLayer.render(e,t,this.quad.vao,this.raster,r,a,l),this.drawTileStencil(e,t,o),e.setDepthTest(t.globeActive),e.setDepthFunc("lequal"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");let f=m=>m.type==="line"&&V(m.paint.elevation,l,0)!==0,d=new Set;for(let m of r.layers){if(m.type==="raster"||m.type==="fill-extrusion"||m.type==="symbol"||m.overlay||f(m)||!r.layerVisibleAt(m,l))continue;let g=u(m);if(g){if(m.type==="line"&&m.network){if(d.has(m.network))continue;d.add(m.network),this.drawNetwork(e,t,r,u,m.network,l,y=>!y.overlay&&!f(y)&&r.layerVisibleAt(y,l));continue}if(m.type==="surface"){if(!this.flattened(g,r,m))continue;this.drawFill(e,t,g,r,m,l);continue}m.type==="fill"?this.drawFill(e,t,g,r,m,l):this.drawLine(e,t,g,r,m,l);}}this.drawFillHighlight(e,t,o,r),this.groundArrows&&(this.groundArrows.highlightFootprint=this.highlightFootprint(),this.groundArrows.render(e,t,o,r,this.fill,this.fillLocs,m=>{this.applyFogUniforms(m,t,r),m.setVec4("u_globe",0,0,0,0),m.setInt("u_material",0),m.setFloat("u_elevation",0),m.setVec2("u_world_origin",0,0);},this.shadowActive)),this.drawGroundShadow(e,t,o,r),this.drawEarthDepth(e,t,o,r),e.setDepthTest(true),e.setDepthMask(true),e.setDepthFunc("lequal"),e.setCull("back");for(let m of r.layers){if(m.type!=="surface"||m.overlay||!r.layerVisibleAt(m,l))continue;let g=u(m);g&&(this.flattened(g,r,m)||this.drawSurface(e,t,g,r,m,l));}e.setStencilTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),e.setDepthTest(false);let p=new Set;for(let m of r.layers){if(m.type==="raster"||!f(m)||m.overlay||!r.layerVisibleAt(m,l))continue;let g=u(m);if(g){if(m.type==="line"&&m.network){if(p.has(m.network))continue;p.add(m.network),this.drawNetwork(e,t,r,u,m.network,l,y=>!y.overlay&&f(y)&&r.layerVisibleAt(y,l));continue}this.drawLine(e,t,g,r,m,l);}}this.drawOverlay(e,t,r,u,l,"roads"),e.setDepthTest(true),e.setDepthMask(true),e.setCull("back");for(let m of r.layers){if(m.type!=="fill-extrusion"||!r.layerVisibleAt(m,l))continue;let g=u(m);g&&(this.drawBuildings(e,t,g,r,m,l,i)&&(s=true),this.drawHighlight(e,t,g,r,m,l));}this.model&&!this.models.isEmpty&&(this.models.render(e,t,this.model,this.modelLocs,m=>{this.applyShadowUniforms(m),this.applyFogUniforms(m,t,r),this.applyLight(m,r);},this.shadowActive,i/1e3,this.modelInstanced?{shader:this.modelInstanced,locations:this.modelInstLocs}:void 0),(this.models.hasAnimated||this.models.hasTransitions)&&(s=true)),this.drawOverlay(e,t,r,u,l,"volume"),this.objects&&!this.objects.isEmpty&&(e.setDepthTest(true),e.setDepthFunc("lequal"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.objects.render(e,t,this.fill,this.fillLocs,this.objectLine,this.objectLineLocs,m=>{this.applyFogUniforms(m,t,r),m.setVec4("u_globe",0,0,0,0),m.setInt("u_material",0),m.setFloat("u_elevation",0),m.setVec2("u_world_origin",0,0);},this.shadowActive),e.setDepthTest(false)),this.raster&&this.quad&&this.rasterLayer.render(e,t,this.quad.vao,this.raster,r,a,l,true);let b=r.layers.filter(m=>m.type==="line"&&V(m.paint.ghostOpacity,l,0)>.001&&r.layerVisibleAt(m,l));if(b.length){e.setDepthTest(true),e.setDepthFunc("greater"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");for(let m of b){let g=u(m);g&&this.drawLine(e,t,g,r,m,l,V(m.paint.ghostOpacity,l,0));}e.setDepthFunc("lequal"),e.setDepthTest(false);}return this.objects&&!this.objects.isEmpty&&(e.setDepthTest(true),e.setDepthFunc("greater"),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.objects.render(e,t,this.fill,this.fillLocs,this.objectLine,this.objectLineLocs,m=>{this.applyFogUniforms(m,t,r),m.setVec4("u_globe",0,0,0,0),m.setInt("u_material",0),m.setFloat("u_elevation",0),m.setVec2("u_world_origin",0,0);},this.shadowActive,true),e.setDepthFunc("lequal"),e.setDepthTest(false)),this.symbols&&(this.symbols.highlightFootprint=this.highlightFootprint()),this.symbols?.render(e,t,o,r),e.bindVAO(null),s||this.materialAnimating}renderShadowMap(e,t,o,r,i){if(this.shadowPlaceholder&&e.bindTexture(ri,this.shadowPlaceholder),this.shadowActive=false,!this.shadows.enabled||!this.allowShadows||!this.depth)return;let a=r.layers.filter(u=>u.type==="fill-extrusion"&&!u.overlay&&r.layerVisibleAt(u,t.zoom));if(!a.length&&this.models.isEmpty)return;this.shadowTarget?this.shadowTarget.resize(this.shadows.resolution):this.shadowTarget=new ho(e,this.shadows.resolution);let l=r.light;if(t.updateShadow(Gt(l.keyAzimuth,l.keyAltitude),Gh),!t.shadowReady)return;let s=this.shadowTarget;s.bind(),e.setDepthFunc("lequal"),e.setBlend("none"),e.setCull("none");let c=e.gl;c.enable(c.POLYGON_OFFSET_FILL),c.polygonOffset(2,4);let h=this.depth;h.use();for(let u of a){let f=o.get(u.source??Y);if(!f)continue;let d=r.bucketKeyFor(u);if(d===null)continue;let p=V(u.paint.heightScale,t.zoom,1);(u.source??Y)===Y&&this.indoorMask.prepare(f,d);for(let b of f.visibleTiles){if(!this.drawsTile(t,r,u,b))continue;let m=f.getTile(b),g=m&&this.bucketFor(e,m,d,wr,this.buildingLocs,"fill-extrusion");if(!g)continue;h.setFloat("u_height_scale",this.growScale(g,i,!f.warm)*p),h.setMat4("u_matrix",t.shadowTileMatrix(b,g.extent));let y=(u.source??Y)===Y,A=this.cutHidden(e,m,d,b.dataKey,g.buffer,this.hiddenFor(d,y)),B=y?A??this.indoorMask.indicesFor(e,m,d,b,g.buffer,this.buildingLocs):A;B?(B.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,B.count,e.gl.UNSIGNED_INT,0)):(g.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,g.indexCount,g.indexType,0));}}this.modelDepth&&(this.models.depthTimeSec=i/1e3,e.gl.polygonOffset(6,96),this.models.renderDepth(e,t,this.modelDepth,this.modelLocs),e.gl.polygonOffset(2,4)),c.disable(c.POLYGON_OFFSET_FILL),e.bindFramebuffer(null),e.viewport(0,0,e.gl.drawingBufferWidth,e.gl.drawingBufferHeight),s.bindTexture(ri),this.shadowDepthPerMeter=t.shadowDepthPerMeter(),this.shadowTexelMeters=Math.abs(t.shadowTexelWorldSize(s.size))/(t.pixelsPerMeter||1),this.shadowActive=true;}drawGlobeBody(e,t,o){if(!t.globeActive||!this.globeBody||!this.globeMesh)return;let r=this.globeBody;r.use(),this.applyGlobeUniforms(r,t,o),r.setMat4("u_matrix",t.localMatrix());let i=o.background;r.setVec3("u_body_color",i[0],i[1],i[2]),Ve(r,"u_atmo_color",o.sky.horizonColor),r.setFloat("u_atmo_strength",o.sky.enabled?1-t.globeFlatMix:0),e.setBlend("none"),e.setDepthTest(true),e.setDepthMask(true),e.setDepthFunc("less"),e.setCull("none"),this.globeMesh.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,this.globeMesh.count,e.gl.UNSIGNED_SHORT,0),e.bindVAO(null),this.drawGlobeClip(e,t),e.setBlend("premultiplied"),e.setDepthTest(false),e.setDepthMask(false);}drawGlobeClip(e,t){if(!this.globeClip||!this.quad)return;let o=e.gl,r=[0,0,-t.globeRadiusPx,1],i=[0,0,0,0];if(de(i,t.localProjMatrix,r),i[3]<=1e-6)return;let a=this.globeClip;a.use(),a.setFloat("u_center_depth",i[2]/i[3]),o.colorMask(false,false,false,false),e.setDepthTest(true),e.setDepthMask(true),e.setDepthFunc("always"),this.quad.vao.bind(),o.drawElements(o.TRIANGLES,6,o.UNSIGNED_SHORT,0),o.colorMask(true,true,true,true),e.bindVAO(null);}applyAtmosphere(e,t,o){let r=t.cameraRay();e.setVec3("u_cam_ray",r.axisElev,r.focal*this.dpr,t.height*this.dpr/2),e.setFloat("u_haze_exp",1/Math.max(o.sky.horizonBlend,.01));}skyBand(e,t){let o=e.horizonScreenY(),r=e.height*this.dpr/Math.max(Ge(e.fov),.001);return [(e.height-o)*this.dpr,Math.max(o,1)*this.dpr,Math.max(t.sky.horizonBlend*r,1)]}drawSky(e,t,o){if(!this.sky||!this.quad||!o.sky.enabled)return;let r=this.sky;r.use(),Ve(r,"u_sky_color",o.sky.skyColor),Ve(r,"u_horizon_color",o.sky.horizonColor),Nh(r,o.sky);let[i,a]=this.skyBand(t,o),l=Math.min(a*.5,t.height*this.dpr*.1);r.setVec3("u_sky_params",i,a,l),this.applyAtmosphere(r,t,o);let s=t.cameraRay();r.setVec3("u_cam_right",s.right[0],s.right[1],s.right[2]),r.setVec3("u_cam_up",s.up[0],s.up[1],s.up[2]),r.setVec3("u_cam_fwd",s.fwd[0],s.fwd[1],s.fwd[2]),r.setVec2("u_cam_center",t.width*this.dpr/2,t.height*this.dpr/2);let c=Gt(o.light.keyAzimuth,o.light.keyAltitude);r.setVec3("u_sun_dir",-c[0],-c[1],-c[2]),Ve(r,"u_sun_color",o.light.keyColor),r.setFloat("u_sun_glow",o.light.keyIntensity);let h=t.globeActive?1-t.globeFlatMix:0;if(r.setVec2("u_space",h,o.sky.starIntensity),h>.001){Ve(r,"u_space_color",o.sky.spaceColor),Ve(r,"u_atmo_color",o.sky.atmosphereColor);let u=t.globeDisc();r.setVec4("u_globe_disc",u.dir[0],u.dir[1],u.dir[2],u.angle);let[f,d,p,b]=t.localRayCorners();r.setVec3("u_ray_tl",f[0],f[1],f[2]),r.setVec3("u_ray_tr",d[0],d[1],d[2]),r.setVec3("u_ray_bl",p[0],p[1],p[2]),r.setVec3("u_ray_br",b[0],b[1],b[2]);}e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),this.quad.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0),e.bindVAO(null);}applyGlobeUniforms(e,t,o){if(!t.globeActive){e.setVec4("u_globe",0,0,0,0);return}let r=t.globeBasis,i=t.worldSize;e.setVec4("u_globe",1,t.globeFlatMix,t.globeRadiusPx,i),e.setVec2("u_globe_center",t.centerPointPx.x/i,t.centerPointPx.y/i);let a=t.globeCamera();e.setVec4("u_globe_cam",a.dir[0],a.dir[1],a.dir[2],a.horizonCos);let l=Gt(o.light.keyAzimuth,o.light.keyAltitude);e.setVec3("u_globe_sun",-l[0],-l[1],-l[2]),e.setVec2("u_globe_light",.16,.14),e.setMat3("u_globe_basis",[r.east[0],r.south[0],r.up[0],r.east[1],r.south[1],r.up[1],r.east[2],r.south[2],r.up[2]]);}applyTileMatrix(e,t,o,r){if(t.globeActive){let i=o.bounds();e.setVec3("u_tile_merc",i.minX,i.minY,(i.maxX-i.minX)/r),e.setMat4("u_matrix",t.localMatrix());return}e.setMat4("u_matrix",t.tileMatrix(o,r));}applyFogUniforms(e,t,o){let r=this.fog??kt(t,o);if(r.intensity<=0){e.setVec3("u_fog_range",0,1,0),e.setVec2("u_fog_vertical",0,0),this.applyAtmosphere(e,t,o);return}Ve(e,"u_fog_color",o.sky.horizonColor),e.setVec3("u_fog_range",r.near,r.far,r.intensity);let[i,a]=o.sky.fogVerticalRange;e.setVec2("u_fog_vertical",i,a),this.applyAtmosphere(e,t,o);}drawsTile(e,t,o,r){let i=this.fog;if(!i)return true;let a=e.distanceToTile(r);return a>i.cutoff?false:t.layerVisibleAt(o,e.detailZoom(a))}earthDepthLevel(e,t){let o=0;for(let i of e.layers)i.type==="surface"?o=Math.min(o,(i.elevation-(i.bevelDrop??0))*this.reliefScale):i.type==="line"&&(o=Math.min(o,V(i.paint.elevation,t.zoom,0)*this.reliefScale));let r=Math.max(Ph/Math.max(t.pixelsPerMeter,1e-9),Rh);return o-r}clipToTile(e,t){let o=this.stencilIds.get(t.dataKey);e.setStencilTest(o!==void 0),o!==void 0&&e.gl.stencilFunc(e.gl.EQUAL,o,ni);}drawTileStencil(e,t,o){if(this.stencilIds.clear(),t.globeActive){e.gl.stencilMask(255),e.clear(null,false,true),e.setStencilTest(false);return}let r=o.get(Y);if(!r||!this.fill||!this.quad)return;let i=r.visibleTiles;if(!i.length||i.length>ni)return;let a=e.gl;a.stencilMask(255),e.clear(null,false,true),e.setStencilTest(true),a.stencilOp(a.KEEP,a.KEEP,a.REPLACE),e.setColorMask(false),e.setDepthTest(false),e.setDepthMask(false),e.setCull("none");let l=this.fill;l.use(),l.setVec4("u_globe",0,0,0,0),l.setInt("u_material",0),l.setVec2("u_world_origin",0,0),l.setVec4("u_color",0,0,0,1),l.setFloat("u_elevation",0),this.quad.vao.bind();let s=0;for(let c of i)s++,this.stencilIds.set(c.dataKey,s),a.stencilFunc(a.ALWAYS,s,ni),l.setMat4("u_matrix",t.tileMatrix(c,1)),a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0);e.bindVAO(null),e.setColorMask(true),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),e.setStencilTest(false);}drawEarthDepth(e,t,o,r){if(!this.fill||!this.quad||t.globeActive)return;let i=o.get(Y);if(!i)return;let a=this.fill;a.use(),this.applyFogUniforms(a,t,r),a.setVec4("u_globe",0,0,0,0),a.setInt("u_material",0),a.setVec2("u_world_origin",0,0),a.setVec4("u_color",0,0,0,1),a.setFloat("u_elevation",0);let l=this.earthDepthLevel(r,t);e.gl.colorMask(false,false,false,false),e.setDepthTest(true),e.setDepthFunc("lequal"),e.setDepthMask(true),e.setCull("none"),e.gl.enable(e.gl.POLYGON_OFFSET_FILL),e.gl.polygonOffset(1,8),this.quad.vao.bind();let s=new Float32Array(16);for(let c of i.visibleTiles){let h=t.tileMatrix(c,1);s.set(h);for(let u=0;u<4;u++)s[12+u]+=l*h[8+u];a.setMat4("u_matrix",s),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0);}e.bindVAO(null),e.gl.disable(e.gl.POLYGON_OFFSET_FILL),e.gl.colorMask(true,true,true,true);}drawGroundShadow(e,t,o,r){if(!this.shadowActive||!this.groundShadow||!this.quad)return;let i=o.get(Y);if(!i)return;let a=this.groundShadow;a.use(),this.applyShadowUniforms(a),this.applyFogUniforms(a,t,r);let l=r.light,[,,s]=Gt(l.keyAzimuth,l.keyAltitude),c=Math.max(-s,0),h=he(l.ambientColor),u=he(l.keyColor),f=[0,0,0];for(let d=0;d<3;d++){let p=h[d]*l.ambientIntensity,b=u[d]*l.keyIntensity*c;f[d]=p>0?p/(p+b):1;}a.setVec3("u_shadow_ground",f[0],f[1],f[2]),a.setFloat("u_ground_ndotl",c),e.setBlend("multiply"),e.setDepthTest(false),e.setDepthMask(false),e.setCull("none"),this.quad.vao.bind();for(let d of i.visibleTiles)a.setMat4("u_shadow_matrix",t.shadowTileMatrix(d,1)),a.setMat4("u_matrix",t.tileMatrix(d,1)),e.gl.drawElements(e.gl.TRIANGLES,6,e.gl.UNSIGNED_SHORT,0);e.setBlend("premultiplied");}applyShadowUniforms(e){if(e.setInt("u_shadow_map",ri),!this.shadowActive){e.setVec4("u_shadow_params",0,0,0,0);return}let t=this.shadowTarget?.size??1,r=Math.max(this.shadows.bias,1.5*this.shadowTexelMeters)*(this.shadowDepthPerMeter||1);e.setVec4("u_shadow_params",this.shadows.strength,1/t,r,1),e.setFloat("u_shadow_normal_offset",1.5*2/t);let i=he(this.shadows.color);e.setVec3("u_shadow_color",i[0],i[1],i[2]);}get shadowsActive(){return this.shadowActive}drawOverlay(e,t,o,r,i,a){let l=()=>{e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");};l();for(let s of o.layers){if(s.type==="raster"||s.type==="symbol"||s.type==="fill-extrusion"||!s.overlay||(s.overlay===true?"volume":s.overlay)!==a||!o.layerVisibleAt(s,i))continue;let c=r(s);if(c){if(s.type==="surface"){this.flattened(c,o,s)?this.drawFill(e,t,c,o,s,i):this.drawSurface(e,t,c,o,s,i),l();continue}s.type==="fill"?this.drawFill(e,t,c,o,s,i):this.drawLine(e,t,c,o,s,i);}}}applyTileScale(e,t,o){let r=zr(t.z)/this.patternScale;e.setFloat("u_meters_per_unit",r/o);let[i,a]=Wi(t.z,t.x,t.y);e.setVec2("u_world_origin",i/this.patternScale,a/this.patternScale);let l=this.cameraMeters;e.setVec3("u_camera_local",l[0]-t.x*r,l[1]-t.y*r,l[2]);}applyMaterial(e,t,o){let r=t.paint&&"material"in t.paint?t.paint.material:void 0,i=this.detailScale<=0?0:zh[r??"flat"]??0;if(e.setInt("u_material",i),i===0)return;let a=t.paint,l=V(a.materialStrength,o,1)*this.detailScale,s=V(a.materialScale,o,Vh[i]),c=V(a.materialSpeed,o,i===1?1:0);e.setVec4("u_material_params",l,s,c,this.materialTime),c>0&&l>.004&&(this.materialAnimating=true);}drawFill(e,t,o,r,i,a){let l=this.fill,s=r.colorAt(i,a),c=V(i.paint?.opacity,a,1);if(c<=.001)return;l.use(),this.applyFogUniforms(l,t,r),this.applyGlobeUniforms(l,t,r),this.applyLight(l,r),this.applyMaterial(l,i,a),l.setVec4v("u_color",Me([s[0],s[1],s[2],s[3]*c]));let h=r.bucketKeyFor(i);if(h!==null){for(let u of o.visibleTiles){if(!this.drawsTile(t,r,i,u))continue;let f=o.getTile(u),d=f&&this.bucketFor(e,f,h,ai,this.fillLocs,"fill");d&&(this.clipToTile(e,u),this.shadowActive&&l.setMat4("u_shadow_matrix",t.shadowTileMatrix(u,d.extent)),this.applyTileScale(l,u,d.extent),this.applyTileMatrix(l,t,u,d.extent),d.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,d.indexCount,d.indexType,0));}e.setStencilTest(false);}}drawLine(e,t,o,r,i,a,l=0,s){let c=this.line,h=r.colorAt(i,a),u=V(i.paint.opacity,a,1)*(l||1),f=V(i.paint.width,a,1);if(u<=.001||f<=.01)return;let d=e.gl.drawingBufferWidth,p=e.gl.drawingBufferHeight,b=t.width>0?d/t.width:1,m=f/2*b;c.use(),this.applyFogUniforms(c,t,r),this.applyGlobeUniforms(c,t,r),this.applyLight(c,r),this.applyMaterial(c,i,a),c.setVec4v("u_color",Me([h[0],h[1],h[2],h[3]*u])),c.setFloat("u_center_w",t.cameraToCenterDistance);let g=V(i.paint.offset,a,0)*b,y=Math.max(V(i.paint.blur,a,0),0)*b;c.setFloat("u_elevation",V(i.paint.elevation,a,0)*this.reliefScale),c.setFloat("u_relief",this.reliefScale),c.setVec2("u_viewport",d,p);let A=i.paint.dashArray,B=i.paint.arrow===true,x=i.paint.arrowStyle,w=B&&(x==="head"||x==="headOnly"),_=B&&x==="dash";if(c.setInt("u_pattern",_?5:A?1:x==="headOnly"&&B?4:w?3:B?2:0),A){let[v,E]=A;c.setVec2("u_dash",v*b,(v+E)*b);}if(B){let v=He(i.paint.arrowColor,a,[1,1,1,1]);c.setVec4v("u_arrow_color",Me(v));let E=V(i.paint.arrowPeriod,a,46)*b,D=V(i.paint.arrowSize,a,5)*b;if(_){let F=V(i.paint.arrowGap,a,24)*b,H=Math.max(E-F,1),S=Math.min(D,H),L=V(i.paint.arrowShaft,a,2)*b,M=V(i.paint.arrowHead,a,4)*b,T=V(i.paint.arrowOutline,a,0)*b;c.setVec4("u_arrow",L,S,M,H),c.setVec2("u_dash",T,E);}else w?c.setVec4("u_arrow",E,D,m,0):c.setVec4("u_arrow",E,Math.max(D*.4,1),Math.min(D,m*.72),0);}let C=r.bucketKeyFor(i);if(C!==null)for(let v of o.visibleTiles){if(!this.drawsTile(t,r,i,v))continue;let E=o.getTile(v);if(!E)continue;let D=i.network?s!==void 0?[Je(i.id,s)]:(E.data?.levels??[]).map(F=>Je(i.id,F)):[C];for(let F of D){let H=this.bucketFor(e,E,F,Es,this.lineLocs,"line");if(!H)continue;let S=v.bounds(),L=(S.maxX-S.minX)*t.worldSize/H.extent*b;c.setFloat("u_tile_to_px",L);let M=L>1e-6?1/L:1;c.setFloat("u_half_width",m*M),c.setFloat("u_blur",y*M),c.setFloat("u_meters_to_units",t.pixelsPerMeter*M),c.setFloat("u_width_from_data",i.paint.widthFromData===true?1:0),c.setFloat("u_width_extra",V(i.paint.widthExtra,a,0)*M),c.setFloat("u_offset",g*M),c.setFloat("u_tile_per_px",M),this.applyTileScale(c,v,H.extent),this.shadowActive&&c.setMat4("u_shadow_matrix",t.shadowTileMatrix(v,H.extent)),this.applyTileMatrix(c,t,v,H.extent),H.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,H.indexCount,H.indexType,0);}}}drawNetwork(e,t,o,r,i,a,l){let s=o.layers.filter(h=>h.type==="line"&&h.network===i&&l(h));if(!s.length)return;let c=new Set;for(let h of s){let u=r(h);if(u)for(let f of u.visibleTiles){let d=u.getTile(f);for(let p of d?.data?.levels??[])c.add(p);}}if(c.size)for(let h of [...c].sort((u,f)=>u-f))for(let u of s){let f=r(u);f&&this.drawLine(e,t,f,o,u,a,0,h);}}drawHighlight(e,t,o,r,i,a){let l=this.highlight;if(!l||!this.building||l.layerId!==i.id)return;let s=`${i.id}/${l.featureId}`;this.highlightKey!==s&&(this.disposeHighlight(),this.highlightKey=s);let c=he(l.color)??[.31,.79,.5,1],h=this.building;h.use(),this.applyShadowUniforms(h),this.applyFogUniforms(h,t,r),this.applyLight(h,r),h.setVec4v("u_wall_color",[c[0],c[1],c[2],1]),h.setVec4v("u_roof_color",[c[0],c[1],c[2],1]),h.setFloat("u_opacity",l.opacity),h.setFloat("u_ao_strength",V(i.paint.aoStrength,a,.4)),h.setFloat("u_tint_variation",0),h.setFloat("u_facade_detail",0),h.setFloat("u_window_glow",0),h.setFloat("u_roof_variation",0),h.setFloat("u_height_scale",V(i.paint.heightScale,a,1)),e.setDepthFunc("lequal"),e.setDepthMask(false),e.setBlend("alpha");for(let u of o.visibleTiles){let f=o.getTile(u);if(!f)continue;let d=f.data?.buckets?.[i.id];if(!d)continue;let p=u.dataKey,b=this.highlightGpu.get(p);if(b===void 0){let m=Ar(f,i.id,l.featureId);if(m){let g=new ve(e,new Uint8Array(m.vertices),wr),y=new ye(e,m.indices);b={vao:new pe(e,[{buffer:g,locations:this.buildingLocs}],y),vbo:g,ibo:y,count:m.indices.length};}else b=null;this.highlightGpu.set(p,b);}b&&(this.applyTileScale(h,u,d.extent),this.shadowActive&&h.setMat4("u_shadow_matrix",t.shadowTileMatrix(u,d.extent)),h.setMat4("u_matrix",t.tileMatrix(u,d.extent)),b.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,b.count,e.gl.UNSIGNED_INT,0));}e.setBlend("none"),e.setDepthMask(true);}refreshHighlight(){this.disposeHighlight();}disposeHighlight(){for(let e of this.highlightGpu.values())e&&(e.vao.destroy(),e.vbo.destroy(),e.ibo.destroy());this.highlightGpu.clear(),this.highlightTris.clear(),this.highlightKey="";}syncHighlightFootprint(e,t){let o=this.highlight;if(!o){this.highlightTris.size&&this.highlightTris.clear();return}let r=`${o.layerId}/${o.featureId}`;this.footprintKey!==r&&(this.highlightTris.clear(),this.footprintKey=r);let i=t.layers.find(s=>s.id===o.layerId),a=e.get(i?.source??Y);if(!a)return;let l=new oe;for(let s of a.visibleTiles){if(l.add(s.dataKey),this.highlightTris.has(s.dataKey))continue;let c=a.getTile(s),h=c?.data?.buckets?.[o.layerId];if(!c||!h)continue;let u=Ar(c,o.layerId,o.featureId);u&&this.highlightTris.set(s.dataKey,Nn(u,h.extent,s));}for(let s of [...this.highlightTris.keys()])l.has(s)||this.highlightTris.delete(s);}drawFillHighlight(e,t,o,r){let i=this.highlightFill,a=this.fill;if(!i||!a)return;let l=r.layers.find(f=>f.id===i.layerId),s=l?o.get(l.source??Y):void 0;if(!l||!s)return;let c=i.bucketKey,h=he(i.color)??[.31,.79,.5,1];a.use(),this.applyFogUniforms(a,t,r),a.setVec4("u_globe",0,0,0,0),a.setInt("u_material",0),a.setFloat("u_elevation",0),a.setVec2("u_world_origin",0,0),a.setVec4v("u_color",Me([h[0],h[1],h[2],i.opacity])),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none");let u=e.gl;e.setStencilTest(true),u.stencilFunc(u.NOTEQUAL,ii,ii),u.stencilOp(u.KEEP,u.KEEP,u.REPLACE),u.stencilMask(ii);for(let f of s.visibleTiles){let d=s.getTile(f),p=d?.data?.buckets?.[c];if(!d||!p||p.kind!=="fill"||!p.featureIds)continue;let b=this.fillHighlightFor(e,p,f,i.featureId,c);b&&(a.setMat4("u_matrix",t.tileMatrix(f,p.extent)),b.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,b.count,e.gl.UNSIGNED_INT,0));}e.setStencilTest(false),u.stencilOp(u.KEEP,u.KEEP,u.KEEP),u.stencilMask(255),e.bindVAO(null);}fillHighlightFor(e,t,o,r,i){let a=`${i}/${r}/${o.dataKey}`;this.fillHighlightKey!==`${i}/${r}`&&(this.fillHighlightGpu.forEach(f=>{f?.vao.destroy(),f?.ibo.destroy(),f?.vbo.destroy();}),this.fillHighlightGpu.clear(),this.fillHighlightKey=`${i}/${r}`);let l=this.fillHighlightGpu.get(a);if(l!==void 0)return l;let s=new Uint32Array(t.indices),c=new Float64Array(t.featureIds),h=[];for(let f=0;f*3<s.length;f++)c[f]===r&&h.push(s[f*3],s[f*3+1],s[f*3+2]);let u=null;if(h.length){let f=new ve(e,new Uint8Array(t.vertices),ai),d=new ye(e,new Uint32Array(h));u={vao:new pe(e,[{buffer:f,locations:this.fillLocs}],d),vbo:f,ibo:d,count:h.length};}return this.fillHighlightGpu.set(a,u),u}highlightFootprint(){return this.highlight&&this.highlightTris.size?[...this.highlightTris.values()]:this.indoorMask.footprint()}drawSurface(e,t,o,r,i,a){let l=this.surface,s=r.colorAt(i,a,[.7,.8,.7,1]),c=V(i.paint.opacity,a,1);if(c<=.001)return;l.use(),this.applyShadowUniforms(l),this.applyFogUniforms(l,t,r),this.applyGlobeUniforms(l,t,r),this.applyLight(l,r),this.applyMaterial(l,i,a),l.setVec4v("u_color",s),l.setFloat("u_opacity",c),l.setFloat("u_side_shade",V(i.paint.sideShade,a,.12));let h=i.elevation<(i.base??0),u=i.paint.sideColor?He(i.paint.sideColor,a,s):s;l.setVec3("u_side_color",u[0],u[1],u[2]),l.setFloat("u_side_light",V(i.paint.sideLight,a,h?1:0)),l.setFloat("u_relief",this.reliefScale);let f=r.bucketKeyFor(i);if(f===null)return;let d=c>=1&&!i.overlay;e.setDepthMask(d),e.setBlend(d?"none":"premultiplied"),e.setCull("none");let p=[];for(let g of o.visibleTiles){if(!this.drawsTile(t,r,i,g))continue;let y=o.getTile(g),A=y&&this.bucketFor(e,y,f,Ms,this.surfaceLocs,"surface");A&&p.push({id:g,bucket:A});}let b=(g,y)=>{this.clipToTile(e,g),this.applyTileScale(l,g,y.extent),this.shadowActive&&l.setMat4("u_shadow_matrix",t.shadowTileMatrix(g,y.extent)),this.applyTileMatrix(l,t,g,y.extent),y.vao.bind();},m=p.filter(({bucket:g})=>g.capIndexOffset<g.indexCount);if(m.length){e.setColorMask(false),e.setDepthMask(true);for(let{id:g,bucket:y}of m){b(g,y);let A=y.indexType===e.gl.UNSIGNED_INT?4:2;e.gl.drawElements(e.gl.TRIANGLES,y.indexCount-y.capIndexOffset,y.indexType,y.capIndexOffset*A);}e.setColorMask(true),e.setDepthMask(d);}for(let{id:g,bucket:y}of p)b(g,y),e.gl.drawElements(e.gl.TRIANGLES,y.capIndexOffset,y.indexType,0);e.setCull("back"),e.setDepthMask(true),e.setBlend("none");}drawBuildings(e,t,o,r,i,a,l){let s=this.building,c=r.colorAt(i,a,[.86,.84,.8,1]),h=i.paint.roofColor?r.colorAt({...i,paint:{...i.paint,color:i.paint.roofColor}},a,c):c,u=V(i.paint.opacity,a,1);if(u<=.001)return false;s.use(),this.applyShadowUniforms(s),this.applyFogUniforms(s,t,r),s.setVec4v("u_wall_color",c),s.setVec4v("u_roof_color",h),s.setFloat("u_opacity",u),s.setFloat("u_ao_strength",V(i.paint.aoStrength,a,.4)),s.setFloat("u_tint_variation",V(i.paint.tintVariation,a,.07));let f=(B,x)=>i.paint[B]?r.colorAt({...i,paint:{...i.paint,color:i.paint[B]}},a,x):x,d=f("windowColor",[.62,.71,.8,1]),p=f("windowFrameColor",[c[0]*1.1,c[1]*1.1,c[2]*1.1,1]);s.setVec3("u_window_color",d[0],d[1],d[2]),s.setVec3("u_window_frame",p[0],p[1],p[2]),s.setFloat("u_facade_detail",V(i.paint.facadeDetail,a,1)*this.detailScale),s.setFloat("u_window_glow",V(i.paint.windowGlow,a,0)),s.setFloat("u_floor_height",V(i.paint.floorHeight,a,3.2)),s.setFloat("u_window_variation",V(i.paint.windowVariation,a,1)),s.setFloat("u_seam_strength",V(i.paint.seamStrength,a,1)),s.setFloat("u_window_recess",V(i.paint.windowRecess,a,.18)),s.setFloat("u_window_recess_shade",V(i.paint.windowRecessShade,a,.16)),s.setFloat("u_plinth_height",V(i.paint.plinthHeight,a,4)),s.setFloat("u_plinth_shade",V(i.paint.plinthShade,a,.14)),s.setFloat("u_roof_variation",V(i.paint.roofVariation,a,.3)),this.applyLight(s,r);let b=u>=1;e.setDepthMask(b),e.setBlend(b?"none":"premultiplied");let m=V(i.paint.heightScale,a,1),g=false,y=r.bucketKeyFor(i);if(y===null)return g;let A=(i.source??Y)===Y;A&&this.indoorMask.prepare(o,y);for(let B of o.visibleTiles){if(!this.drawsTile(t,r,i,B))continue;let x=o.getTile(B),w=x&&this.bucketFor(e,x,y,wr,this.buildingLocs,"fill-extrusion");if(!w)continue;let _=this.growScale(w,l,!o.warm);_<1&&(g=true),s.setFloat("u_height_scale",_*m),this.applyTileScale(s,B,w.extent),this.shadowActive&&s.setMat4("u_shadow_matrix",t.shadowTileMatrix(B,w.extent)),s.setMat4("u_matrix",t.tileMatrix(B,w.extent));let v=this.cutHidden(e,x,y,B.dataKey,w.buffer,this.hiddenFor(y,A))??(x&&A?this.indoorMask.indicesFor(e,x,y,B,w.buffer,this.buildingLocs):null);v?(v.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,v.count,e.gl.UNSIGNED_INT,0)):(w.vao.bind(),e.gl.drawElements(e.gl.TRIANGLES,w.indexCount,w.indexType,0));}return g}growScale(e,t,o=true){if(e.firstDrawTime===0&&(e.firstDrawTime=t),!o||this.growDurationMs<=0)return 1;let r=(t-e.firstDrawTime)/this.growDurationMs;return r<1?Kh(Math.max(r,0)):1}applyLight(e,t){let o=t.light;Ve(e,"u_ambient_color",o.ambientColor),e.setFloat("u_ambient_intensity",o.ambientIntensity);let[r,i,a]=Gt(o.keyAzimuth,o.keyAltitude);e.setVec3("u_key_dir",r,i,a),Ve(e,"u_key_color",o.keyColor),e.setFloat("u_key_intensity",o.keyIntensity);let[l,s,c]=Gt(o.fillAzimuth,o.fillAltitude);e.setVec3("u_fill_dir",l,s,c),Ve(e,"u_fill_color",o.fillColor),e.setFloat("u_fill_intensity",o.fillIntensity);}flattened(e,t,o){let r=t.bucketKeyFor(o);if(r===null)return false;for(let i of e.visibleTiles){let a=e.getTile(i)?.data?.buckets?.[r];if(a)return a.kind==="fill"}return false}bucketFor(e,t,o,r,i,a){let l=t.buckets.get(o);if(l)return l;let s=t.data?.buckets?.[o];if(!s||s.kind==="symbol"||s.kind==="placement")return null;if(s.kind!==a)return kh(`\u0441\u043B\u043E\u0439 ${o}: \u0432 \u0442\u0430\u0439\u043B\u0435 \u043C\u0435\u0448 \xAB${s.kind}\xBB, \u0430 \u0440\u0438\u0441\u0443\u044E\u0442 \u043A\u0430\u043A \xAB${a}\xBB \u2014 \u043F\u0440\u043E\u043F\u0443\u0449\u0435\u043D`),null;let c=new ve(e,new Uint8Array(s.vertices),r),h=new ye(e,new Uint32Array(s.indices)),u=new pe(e,[{buffer:c,locations:i}],h),f=new li(u,c,h,h.count,h.type,s.extent,s.capIndexOffset??h.count);return t.buckets.set(o,f),f}destroy(e){this.disposeHighlight(),this.fill?.destroy(),this.surface?.destroy(),this.line?.destroy(),this.objectLine?.destroy(),this.building?.destroy(),this.symbols?.destroy(e),this.models.destroy(e.gl),this.shadowTarget?.destroy(),this.shadowTarget=null,this.shadowPlaceholder&&e.gl.deleteTexture(this.shadowPlaceholder),this.shadowPlaceholder=null,this.quad&&(this.quad.vao.destroy(),this.quad.vbo.destroy(),this.quad.ibo.destroy(),this.quad=null),this.globeMesh&&(this.globeMesh.vao.destroy(),this.globeMesh.vbo.destroy(),this.globeMesh.ibo.destroy(),this.globeMesh=null),this.fill=this.line=this.building=null,this.objectLine=null;}},Er=new z;function Wh(n,e){let r=new Float32Array(66306),i=0;for(let f=0;f<=128;f++){let d=(f/128-.5)*Math.PI;for(let p=0;p<=256;p++)r[i++]=p/256*2*Math.PI-Math.PI,r[i++]=d;}let a=new Uint16Array(256*128*6),l=0;for(let f=0;f<128;f++)for(let d=0;d<256;d++){let p=f*257+d,b=p+256+1;a[l++]=p,a[l++]=p+1,a[l++]=b,a[l++]=p+1,a[l++]=b+1,a[l++]=b;}let s={stride:8,attribs:[{name:"a_lnglat",size:2,type:xo,offset:0}]},c=new z([["a_lnglat",e.attribLocation("a_lnglat")]]),h=new ve(n,r,s),u=new ye(n,a);return {vao:new pe(n,[{buffer:h,locations:c}],u),vbo:h,ibo:u,count:a.length}}function Nh(n,e){if(e.highColor){Ve(n,"u_high_color",e.highColor);return}let t=Er.get(e.skyColor);t||(t=he(e.skyColor),Er.set(e.skyColor,t)),n.setVec3("u_high_color",t[0]*.6,t[1]*.74,Math.min(1,t[2]*.99+.02));}function Ve(n,e,t){let o=Er.get(t);o||(o=he(t),Er.set(t,o)),n.setVec3(e,o[0],o[1],o[2]);}function Gt(n,e){let t=n*Math.PI/180,o=e*Math.PI/180,r=Math.cos(o);return [-Math.sin(t)*r,Math.cos(t)*r,-Math.sin(o)]}function Kh(n){let o=n-1;return 1+2.20158*o*o*o+1.20158*o*o}var Mr=1,_o=class{constructor(e=1024){this.entries=new z;this.shelfY=0;this.shelfX=0;this.shelfHeight=0;this.texture=null;this.dirty=true;this.full=false;this.size=e,this.data=new Uint8Array(e*e);}get(e){return this.entries.get(e)}add(e,t,o,r){let i=this.entries.get(e);if(i)return i;if(this.full||o>this.size)return null;if(this.shelfX+o+Mr>this.size&&(this.shelfY+=this.shelfHeight+Mr,this.shelfX=0,this.shelfHeight=0),this.shelfY+r+Mr>this.size)return this.full||console.warn("[osmgl] \u0430\u0442\u043B\u0430\u0441 SDF \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D, \u043D\u043E\u0432\u044B\u0435 \u0441\u0438\u043C\u0432\u043E\u043B\u044B \u043D\u0435 \u0434\u043E\u0431\u0430\u0432\u043B\u044F\u044E\u0442\u0441\u044F"),this.full=true,null;let a={x:this.shelfX,y:this.shelfY,width:o,height:r};for(let l=0;l<r;l++){let s=l*o,c=(a.y+l)*this.size+a.x;this.data.set(t.subarray(s,s+o),c);}return this.shelfX+=o+Mr,r>this.shelfHeight&&(this.shelfHeight=r),this.entries.set(e,a),this.dirty=true,a}bind(e,t){let o=e.gl;this.texture?e.bindTexture(t,this.texture):(this.texture=o.createTexture(),e.bindTexture(t,this.texture),o.texStorage2D(o.TEXTURE_2D,1,o.R8,this.size,this.size),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),this.dirty=true),this.dirty&&(o.pixelStorei(o.UNPACK_ALIGNMENT,1),o.texSubImage2D(o.TEXTURE_2D,0,0,0,this.size,this.size,o.RED,o.UNSIGNED_BYTE,this.data),this.dirty=false);}destroy(e){this.texture&&e.gl.deleteTexture(this.texture),this.texture=null,this.entries.clear(),this.data=new Uint8Array(0);}};var si=.75,Mo=8,Ce=3,qe=24,Ot=256,Ds=255,Eo=class{constructor(e,t="Noto Sans Regular"){this.urlTemplate=e;this.fontstack=t;this.glyphs=new z;this.loaded=new oe;this.inflight=new z;}get(e){return this.glyphs.get(e)}hasRange(e){return this.loaded.has(Math.floor(e/Ot))}needsLoad(e){for(let t of e){let o=t.codePointAt(0);if(o===void 0)continue;let r=Math.floor(o/Ot);if(r<=Ds&&!this.loaded.has(r))return true}return false}async ensure(e){let t=new oe;for(let o of e){let r=o.codePointAt(0);if(r===void 0)continue;let i=Math.floor(r/Ot);i>Ds||this.loaded.has(i)||t.add(i);}return t.size?(await Promise.all([...t].map(o=>this.loadRange(o))),true):false}loadRange(e){let t=this.inflight.get(e);if(t)return t;let o=this.urlTemplate.replace("{fontstack}",encodeURIComponent(this.fontstack)).replace("{range}",`${e*Ot}-${e*Ot+Ot-1}`),r=fetch(o,{credentials:"same-origin"}).then(i=>{if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.arrayBuffer()}).then(i=>{for(let a of Ss(i))this.glyphs.set(a.id,a);this.loaded.add(e);}).catch(i=>{this.loaded.add(e),console.warn(`[osmgl] \u0433\u043B\u0438\u0444\u044B ${o} \u043D\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043B\u0438\u0441\u044C:`,i instanceof Error?i.message:i);}).finally(()=>{this.inflight.delete(e);});return this.inflight.set(e,r),r}};function Ss(n){let e=new dt(n instanceof Uint8Array?n:new Uint8Array(n)),t=[];return e.readFields((o,r,i)=>{if(o!==1||!i)return;let a=i.readVarint()+i.pos;i.readFields((l,s,c)=>{if(l!==3||!c)return;let h=c.readVarint()+c.pos,u={id:0,bitmap:null,width:0,height:0,left:0,top:0,advance:0};c.readFields((f,d,p)=>{p&&(f===1?u.id=p.readVarint():f===2?u.bitmap=p.readBytes():f===3?u.width=p.readVarint():f===4?u.height=p.readVarint():f===5?u.left=p.readSVarint():f===6?u.top=p.readSVarint():f===7&&(u.advance=p.readVarint()));},null,h),t.push(u);},null,a);},null),t}var Uh=.25,zt=1e20;function ci(n,e,t){let o=e+Ce*2,r=t+Ce*2,i=o*r,a=new Float64Array(i),l=new Float64Array(i);a.fill(zt),l.fill(0);for(let c=0;c<t;c++)for(let h=0;h<e;h++){let u=n[c*e+h]/255,f=(c+Ce)*o+(h+Ce);if(u>=1)a[f]=0,l[f]=zt;else if(u>0){let d=.5-u;a[f]=d>0?d*d:0,l[f]=d<0?d*d:0;}else a[f]=zt,l[f]=0;}Is(a,o,r),Is(l,o,r);let s=new Uint8Array(i);for(let c=0;c<i;c++){let h=Math.sqrt(a[c])-Math.sqrt(l[c]);s[c]=Jh(Math.round(255-255*(h/Mo+Uh)));}return {data:s,width:o,height:r}}function Is(n,e,t){let o=Math.max(e,t),r=new Float64Array(o),i=new Float64Array(o),a=new Int32Array(o),l=new Float64Array(o+1);for(let s=0;s<e;s++){for(let c=0;c<t;c++)r[c]=n[c*e+s];Ls(r,i,a,l,t);for(let c=0;c<t;c++)n[c*e+s]=i[c];}for(let s=0;s<t;s++){for(let c=0;c<e;c++)r[c]=n[s*e+c];Ls(r,i,a,l,e);for(let c=0;c<e;c++)n[s*e+c]=i[c];}}function Ls(n,e,t,o,r){t[0]=0,o[0]=-zt,o[1]=zt;for(let i=1,a=0;i<r;i++){let l=0;do{let s=t[a];l=(n[i]-n[s]+i*i-s*s)/(i-s)/2;}while(l<=o[a]&&--a>-1);a++,t[a]=i,o[a]=l,o[a+1]=zt;}for(let i=0,a=0;i<r;i++){for(;o[a+1]<i;)a++;let l=t[a];e[i]=(i-l)*(i-l)+n[l];}}var Jh=n=>n<0?0:n>255?255:n;var Ts=48,Fo=class{constructor(e={}){this.defs=e;this.sdfs=new z;this.pending=new oe;this.failed=new oe;}setIcons(e){this.defs=e,this.sdfs.clear(),this.failed.clear();}has(e){return this.sdfs.has(e)}get(e){return this.sdfs.get(e)}isDefined(e){return this.defs[e]!==void 0}async ensure(e){if(this.sdfs.has(e)||this.pending.has(e)||this.failed.has(e))return false;let t=this.defs[e];if(t===void 0)return this.failed.add(e),false;this.pending.add(e);try{let o=typeof t=="string"?t:t.svg,r=/viewBox="0 0 ([\d.]+) ([\d.]+)"/.exec(o),i=r?Number(r[1])/Number(r[2]):1,a=Math.max(8,Math.round(Ts*(i>1?i:1))),l=Math.max(8,Math.round(Ts/(i<1?i:1))),s=await Xh(o,a,l);return this.sdfs.set(e,ci(s,a,l)),!0}catch(o){return this.failed.add(e),console.warn(`[osmgl] \u0438\u043A\u043E\u043D\u043A\u0430 \xAB${e}\xBB \u043D\u0435 \u0440\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043E\u0432\u0430\u043B\u0430\u0441\u044C:`,o instanceof Error?o.message:o),false}finally{this.pending.delete(e);}}};async function Xh(n,e,t){let o=n.includes("width=")?n:n.replace("<svg",`<svg width="${e}" height="${t}"`),r=new Blob([o],{type:"image/svg+xml;charset=utf-8"}),i=URL.createObjectURL(r);try{let a=new Image;a.width=e,a.height=t,await new Promise((u,f)=>{a.onload=()=>u(),a.onerror=()=>f(new Error("\u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0434\u0435\u043A\u043E\u0434\u0438\u0440\u043E\u0432\u0430\u0442\u044C SVG")),a.src=i;});let l=document.createElement("canvas");l.width=e,l.height=t;let s=l.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("\u043D\u0435\u0442 2D-\u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430");s.clearRect(0,0,e,t),s.drawImage(a,0,0,e,t);let c=s.getImageData(0,0,e,t).data,h=new Uint8ClampedArray(e*t);for(let u=0;u<h.length;u++)h[u]=c[u*4+3];return h}finally{URL.revokeObjectURL(i);}}var At={dot:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="5"/></svg>',entrance:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2.5 19.5 10l-2.1 2.1-3.9-3.9V21h-3V8.2l-3.9 3.9L4.5 10 12 2.5z"/></svg>',door:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 2h11a3 3 0 0 1 3 3v17H5V2zm9 9.2a1.2 1.2 0 1 0 0 2.4 1.2 1.2 0 0 0 0-2.4z"/></svg>',elevator:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 3h14v18H5V3zm7 2.2L9.2 9h5.6L12 5.2zM9.2 15h5.6L12 18.8 9.2 15z"/></svg>',"frame-circle":'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="11"/></svg>',cafe:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 6h12v6a6 6 0 0 1-12 0V6zm12 1h2.5a2.5 2.5 0 0 1 0 5H16V7zM3 20h14v2H3z"/></svg>',restaurant:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 2h2v8a2 2 0 0 1-4 0V2h2zM5 2v6h2V2zm7 0h2v20h-2V13a4 4 0 0 1 0-8V2zM6 12h2v10H6z"/></svg>',shop:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 8h16l-1.5 12h-13L4 8zm4-3a4 4 0 0 1 8 0v2h-2V5a2 2 0 0 0-4 0v2H8V5z"/></svg>',grocery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 4h3l3 11h9l2-8H8m1 15a2 2 0 1 0 4 0 2 2 0 0 0-4 0zm8 0a2 2 0 1 0 4 0 2 2 0 0 0-4 0z"/></svg>',fuel:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 3h9v18H4V3zm2 2v5h5V5H6zm10 2 3 3v8a2 2 0 0 1-4 0V9h1V7z"/></svg>',parking:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 3h6a5 5 0 0 1 0 10H9v8H6V3zm3 3v4h3a2 2 0 0 0 0-4H9z"/></svg>',hospital:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 3h4v7h7v4h-7v7h-4v-7H3v-4h7V3z"/></svg>',pharmacy:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11 4h2v5h5v2h-5v5h-2v-5H6V9h5V4zM5 18h14v3H5z"/></svg>',school:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 3 2 8l10 5 10-5-10-5zM5 12v5c0 2 3 4 7 4s7-2 7-4v-5l-7 3.5L5 12z"/></svg>',bank:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2 2 8h20L12 2zM4 10h3v8H4v-8zm6.5 0h3v8h-3v-8zM17 10h3v8h-3v-8zM2 20h20v2H2z"/></svg>',bus:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 5a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v10a2 2 0 0 1-2 2v2h-3v-2H9v2H6v-2a2 2 0 0 1-2-2V5zm2 2v5h12V7H6zm1 8a1.5 1.5 0 1 0 3 0 1.5 1.5 0 0 0-3 0zm7 0a1.5 1.5 0 1 0 3 0 1.5 1.5 0 0 0-3 0z"/></svg>',railway:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 3h12v11a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3V3zm2 3v4h8V6H8zm-2 15 3-3h6l3 3H6z"/></svg>',park:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a6 6 0 0 1 5.2 9 4.5 4.5 0 0 1-2.4 8.3H13V22h-2v-2.7H9.2A4.5 4.5 0 0 1 6.8 11 6 6 0 0 1 12 2z"/></svg>',hotel:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 6h3v7h10a4 4 0 0 1 4 4v3h-3v-3H5v3H2V6zm5 2a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z"/></svg>',place_of_worship:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c3 3 5 5 5 8v12h-4v-5a1 1 0 0 0-2 0v5H7V10c0-3 2-5 5-8z"/></svg>',police:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l8 3v7c0 5-3.5 8.5-8 10-4.5-1.5-8-5-8-10V5l8-3z"/></svg>',stadium:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 4c5.5 0 10 1.8 10 4v4c0 2.2-4.5 4-10 4S2 14.2 2 12V8c0-2.2 4.5-4 10-4zm0 2C7.6 6 4 7.1 4 8s3.6 2 8 2 8-1.1 8-2-3.6-2-8-2z"/></svg>',fast_food:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 9a9 9 0 0 1 18 0H3zm-1 3h20v2H2v-2zm2 4h16a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3z"/></svg>',bakery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 9c0-2 1.5-3 3-3h10c1.5 0 3 1 3 3l-1 9H5L4 9zm4-1v9h2V8H8zm4 0v9h2V8h-2z"/></svg>',ice_cream:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a5 5 0 0 1 5 5H7a5 5 0 0 1 5-5zM7 9h10l-5 13L7 9z"/></svg>',bar:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 4h18l-8 9v6h4v2H7v-2h4v-6L3 4zm3.5 2 2 2h7l2-2h-11z"/></svg>',butcher:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 3h6l2 5-3 3-5-3V3zm8 7 6 6-2 2-6-6 2-2zM3 17h8v4H3v-4z"/></svg>',alcohol_shop:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 2h4v4l3 5v11H7V11l3-5V2zm-1 11h6v7H9v-7z"/></svg>',clothing_store:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 3h6l5 3-2 4-2-1v12H8V9L6 10 4 6l5-3zm1 1.5L12 6l2-1.5h-4z"/></svg>',hairdresser:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 3l9 9-2 2-2-2-2 2 2 2-1 1a3 3 0 1 1-2-2l1-1-1-1a3 3 0 1 1 2-2L5 3zm14 0l-6 6 2 2 5-6V3zM6 17a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm0-11a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"/></svg>',laundry:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 2h14v20H5V2zm2 2v2h10V4H7zm5 4a6 6 0 1 0 0 12 6 6 0 0 0 0-12zm0 3a3 3 0 1 1 0 6 3 3 0 0 1 0-6z"/></svg>',music:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 4l11-2v13a3.5 3.5 0 1 1-2-3.2V6L11 7.4v10.1A3.5 3.5 0 1 1 9 14.3V4z"/></svg>',car:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M5 11l2-5a2 2 0 0 1 2-1h6a2 2 0 0 1 2 1l2 5v7h-3v-2H8v2H5v-7zm2.5-1h9l-1.2-3H8.7L7.5 10zM7 13a1.3 1.3 0 1 0 0 2.6A1.3 1.3 0 0 0 7 13zm10 0a1.3 1.3 0 1 0 0 2.6 1.3 1.3 0 0 0 0-2.6z"/></svg>',bicycle:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 12a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm12 0a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM6 15a2 2 0 1 1 0 4 2 2 0 0 1 0-4zm12 0a2 2 0 1 1 0 4 2 2 0 0 1 0-4zM9 4h4l4 8-2 1-3-6H9V4z"/></svg>',atm:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 5h20v14H2V5zm2 2v3h16V7H4zm0 5v5h16v-5H4zm2 2h5v2H6v-2z"/></svg>',post:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 5h20v14H2V5zm2.5 2 7.5 6 7.5-6h-15z"/></svg>',telephone:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 2c1 0 2 3 2 4s-2 2-2 3 4 6 5 6 2-2 3-2 4 1 4 2-1 4-3 4C9 19 5 15 3 5c0-2 3-3 4-3z"/></svg>',office:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 2h11v20H4V2zm2 3v3h3V5H6zm5 0v3h3V5h-3zM6 10v3h3v-3H6zm5 0v3h3v-3h-3zM6 15v3h3v-3H6zm5 0v7h3v-7h-3zM17 8h4v14h-4V8z"/></svg>',town_hall:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l9 5v2H3V7l9-5zM5 11h3v7H5v-7zm5.5 0h3v7h-3v-7zM16 11h3v7h-3v-7zM3 20h18v2H3v-2z"/></svg>',doctors:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 2v6a5 5 0 0 0 4 4.9V16a3 3 0 1 0 6 0v-1.2a2.5 2.5 0 1 0-2 0V16a1 1 0 1 1-2 0v-3.1A5 5 0 0 0 17 8V2h-3v6a2 2 0 0 1-4 0V2H7z"/></svg>',dentist:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c3 0 4-1 6 0 2 1 2 4 1 8l-1 5c-1 4-3 4-3.5 1L14 12c-.4-2-1.6-2-2 0l-.5 4c-.5 3-2.5 3-3.5-1l-1-5C6 6 6 3 8 2c2-1 3 0 4 0z"/></svg>',veterinary:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 11c3 0 6 3 6 6a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3c0-3 3-6 6-6zM6 5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zm12 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zM10 2a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zm4 0a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z"/></svg>',library:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 3h5c1.5 0 2.5.5 3 1.2.5-.7 1.5-1.2 3-1.2h5v16h-5c-1.5 0-2.5.6-3 1.5-.5-.9-1.5-1.5-3-1.5H4V3zm2 2v12h3c1 0 2 .2 2.5.5V5.8C11 5.3 10 5 9 5H6z"/></svg>',college:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 3 2 8l10 5 10-5-10-5zM5 12v5c0 2 3 4 7 4s7-2 7-4v-5l-7 3.5L5 12zm15-2v7h2v-7h-2z"/></svg>',museum:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l10 5v2H2V7l10-5zM5 11h2.5v7H5v-7zm5 0h2.5v7H10v-7zm5 0h2.5v7H15v-7zM3 20h18v2H3v-2z"/></svg>',art_gallery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a10 10 0 0 0 0 20c1.7 0 2-1 1.4-2-.7-1.2 0-2.5 1.6-2.5H18a4 4 0 0 0 4-4c0-6-4.5-11.5-10-11.5zM7 9a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 7 9zm3-4a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 10 5zm5 0a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 15 5zm3 4a1.7 1.7 0 1 1 0 3.4A1.7 1.7 0 0 1 18 9z"/></svg>',theatre:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 5h8v9a4 4 0 0 1-8 0V5zm2.5 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm3 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2zM13 5h8v9a4 4 0 0 1-8 0V5zm2.5 3a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm3 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/></svg>',cinema:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 4h20v16H2V4zm3 2v2h2V6H5zm0 5v2h2v-2H5zm0 5v2h2v-2H5zm12-10v2h2V6h-2zm0 5v2h2v-2h-2zm0 5v2h2v-2h-2zM9 6v12h6V6H9z"/></svg>',monument:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10 2h4l1 13H9l1-13zM7 17h10v2H7v-2zm-2 3h14v2H5v-2z"/></svg>',castle:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 6h3V3h2v3h3V3h2v3h3V3h2v3h3v16H2V6zm7 8h6v8H9v-8z"/></svg>',attraction:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l2.9 6.3 6.9.8-5.1 4.7 1.4 6.8L12 17.2 5.9 20.6l1.4-6.8L2.2 9.1l6.9-.8L12 2z"/></svg>',zoo:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 12c3.3 0 6 2.7 6 5.5S15.3 21 12 21s-6-.7-6-3.5S8.7 12 12 12zM5 6a2.7 2.7 0 1 1 0 5.4A2.7 2.7 0 0 1 5 6zm14 0a2.7 2.7 0 1 1 0 5.4A2.7 2.7 0 0 1 19 6zM9.5 2a2.7 2.7 0 1 1 0 5.4 2.7 2.7 0 0 1 0-5.4zm5 0a2.7 2.7 0 1 1 0 5.4 2.7 2.7 0 0 1 0-5.4z"/></svg>',theme_park:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11 2h2v6h-2V2zM4 20a8 8 0 0 1 16 0v2H4v-2zm3.5-2h9A6 6 0 0 0 12 14a6 6 0 0 0-4.5 4zM3 9l3-2 3 2-3 2-3-2zm12 0l3-2 3 2-3 2-3-2z"/></svg>',information:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm-1.5 4h3v3h-3V6zm0 5h3v8h-3v-8z"/></svg>',garden:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c2 2 3 4 3 6a3 3 0 0 1-6 0c0-2 1-4 3-6zM4 9c2.5 0 5 1.5 6 4H8c-2.5 0-4-1.5-4-4zm16 0c0 2.5-1.5 4-4 4h-2c1-2.5 3.5-4 6-4zm-9 5h2v8h-2v-8z"/></svg>',pitch:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 5h20v14H2V5zm2 2v10h7V7H4zm9 0v10h7V7h-7zm-1 3a2 2 0 1 1 0 4 2 2 0 0 1 0-4z"/></svg>',playground:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 4h2v16H3V4zm16 0h2v16h-2V4zM5 6h14v2H5V6zm2 3 3 11H8L5 9h2zm10 0-3 11h2l3-11h-2z"/></svg>',swimming_pool:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 3a3 3 0 0 1 6 0v3h4a3 3 0 0 1 3 3h-3a1 1 0 0 0-1 1v3H12V6a1 1 0 0 0-2 0v8H6V3zm-4 14c2 0 2 2 5 2s3-2 5-2 3 2 5 2 3-2 5-2v3c-2 0-2 2-5 2s-3-2-5-2-3 2-5 2-3-2-5-2v-3z"/></svg>',sports_centre:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 8h3v8H4V8zM2 10h2v4H2v-4zm15-2h3v8h-3V8zm3 2h2v4h-2v-4zM8 11h8v2H8v-2z"/></svg>',bicycle_parking:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 2h5a4 4 0 0 1 0 8H7v5H4V2zm3 3v2h2a1 1 0 0 0 0-2H7zm-2 13a4 4 0 1 1 8 0 4 4 0 0 1-8 0zm10 0a4 4 0 1 1 8 0 4 4 0 0 1-8 0z"/></svg>',aerialway:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 4l20-2v2L13 5v2h1l4 3v6a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-6l4-3h1V5.3L2 6V4zm7 8v3h6v-3H9z"/></svg>',ferry_terminal:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11 2h2v3h4v4h-4v5l7 2-2 6c-2 0-2-1-4-1s-2 1-4 1-2-1-4-1-2 1-4 1l-2-6 7-2V9H3V5h4V2h4zM9 7v2h6V7H9z"/></svg>',traffic_signals:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-3v3h4v2H7v-2h4v-3H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2zm4 1.6a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2zm0 4.3a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2zm0 4.3a1.4 1.4 0 1 0 0 2.8 1.4 1.4 0 0 0 0-2.8z"/></svg>',road_closed:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M4 10.1h16v3.8H4z"/></svg>',gate:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 4h3v16H2V4zm17 0h3v16h-3V4zM6 8h12v2H6V8zm0 5h12v2H6v-2z"/></svg>',toilets:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4zM4 7h4l2 7H8v8H4v-8H2l2-7zm12-5a2 2 0 1 1 0 4 2 2 0 0 1 0-4zm-3 5h6l1 8h-2v7h-4v-7h-2l1-8z"/></svg>',drinking_water:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c4 5 6 8 6 11a6 6 0 0 1-12 0c0-3 2-6 6-11zm0 5c-2 3-3 4.6-3 6a3 3 0 0 0 6 0c0-1.4-1-3-3-6z"/></svg>',waste_basket:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M9 2h6l1 2h4v3H4V4h4l1-2zM5 8h14l-1 14H6L5 8zm4 3v8h2v-8H9zm4 0v8h2v-8h-2z"/></svg>',recycling:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l4 7h-3v4h-2V9H8l4-7zM3 18l3-6 2 1-1.4 2.5H10v2H6.6L8 20l-2 1-3-3zm18 0-3 3-2-1 1.4-2.5H14v-2h3.4L16 13l2-1 3 6z"/></svg>',campsite:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l9 18h-4l-5-10-5 10H3L12 2zm0 9 5 9H7l5-9z"/></svg>',shelter:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2l10 8-1.5 2L19 11v9H5v-9l-1.5 1L2 10l10-8zm0 3.5L7 9.5V18h10V9.5l-5-4z"/></svg>',fire_station:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M13 2c0 3-4 4-4 8 0 1 .4 2 1 2.6C9.4 11 10 9.5 11 9c0 2 3 3 3 6a3.5 3.5 0 0 1-1 2.5c2.5-.6 4-2.8 4-5.5 0-5-4-7-4-10zM7 15c0 4 2.5 7 5 7s5-3 5-7c0 2-1 3-2 3.5.3-.6.5-1.2.5-2 0-2.5-2-3.5-2.5-5.5-1 1-2 2.5-2 4 0 .8.2 1.5.6 2C10.2 17.5 9 16.5 9 15H7z"/></svg>',prison:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 3h2v18H3V3zm4 0h2v18H7V3zm4 0h2v18h-2V3zm4 0h2v18h-2V3zm4 0h2v18h-2V3zM2 10h20v2H2v-2z"/></svg>',cemetery:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c3 0 5 2 5 5v13H7V7c0-3 2-5 5-5zm-1 3v2H9v2h2v7h2v-7h2V7h-2V5h-2zM5 21h14v2H5v-2z"/></svg>',basin:'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M2 8c2 0 2 2 5 2s3-2 5-2 3 2 5 2 3-2 5-2v3c-2 0-2 2-5 2s-3-2-5-2-3 2-5 2-3-2-5-2V8zm0 7c2 0 2 2 5 2s3-2 5-2 3 2 5 2 3-2 5-2v3c-2 0-2 2-5 2s-3-2-5-2-3 2-5 2-3-2-5-2v-3z"/></svg>',"shield-2":'<svg viewBox="0 0 32 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="30" height="18" rx="4"/></svg>',"shield-3":'<svg viewBox="0 0 41 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="39" height="18" rx="4"/></svg>',"shield-4":'<svg viewBox="0 0 50 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="48" height="18" rx="4"/></svg>',"shield-5":'<svg viewBox="0 0 59 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="57" height="18" rx="4"/></svg>',"shield-6":'<svg viewBox="0 0 68 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="66" height="18" rx="4"/></svg>',"shield-7":'<svg viewBox="0 0 77 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="75" height="18" rx="4"/></svg>',"shield-8":'<svg viewBox="0 0 86 24" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="3" width="84" height="18" rx="4"/></svg>'},jh={lodging:"hotel",beer:"bar",pub:"bar",kindergarten:"school",university:"college",lift_gate:"gate",toll_booth:"gate",border_control:"gate",bollard:"gate",picnic_site:"campsite",motorcycle_parking:"parking",bicycle_rental:"bicycle",harbor:"ferry_terminal",reservoir:"basin",water_park:"swimming_pool",volleyball:"pitch",basketball:"pitch",tennis:"pitch",horse_racing:"pitch",athletics:"sports_centre",running:"sports_centre",cycling:"bicycle",climbing:"sports_centre",climbing_adventure:"sports_centre",winter_sports:"sports_centre",ice_rink:"sports_centre",karting:"car",motor:"car",escape_game:"attraction"};for(let[n,e]of Object.entries(jh)){let t=At[e];t?At[n]=t:console.warn(`[osmgl] \u043F\u0441\u0435\u0432\u0434\u043E\u043D\u0438\u043C \u0438\u043A\u043E\u043D\u043A\u0438 \xAB${n}\xBB \u0441\u0441\u044B\u043B\u0430\u0435\u0442\u0441\u044F \u043D\u0430 \u043D\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0443\u044E \xAB${e}\xBB`);}var Yh=1.2;function fi(n,e,t=16,o=0){let r=Zh(n,t),i=[],a=[],l=0;for(let h of r){let u=0,f=0;for(let d of h){let p=d.codePointAt(0);if(p===void 0)continue;let b=e.get(p);b&&(u+=b.advance,f++);}f>1&&(u+=o*(f-1)),a.push(u),u>l&&(l=u);}if(l===0)return null;let s=qe*Yh,c=r.length*s;for(let h=0;h<r.length;h++){let u=-a[h]/2,f=-c/2+h*s+s/2;for(let d of r[h]){let p=d.codePointAt(0);if(p===void 0)continue;let b=e.get(p);b&&(b.width>0&&b.height>0&&b.bitmap&&i.push({glyph:b,x:u,y:f}),u+=b.advance+o);}}return i.length?{glyphs:i,width:l,height:c}:null}function Zh(n,e){let t=n.replace(/\s+/g," ").trim();if(t.length<=e)return [t];let o=t.split(" "),r=[],i="";for(let a of o)i?i.length+1+a.length<=e?i+=" "+a:(r.push(i),i=a):i=a;return i&&r.push(i),r.slice(0,3)}function ui(n,e,t,o){if(n.length<2)return [];let r=-o,i=-o,a=e+o,l=t+o,s=f=>f.x>=r&&f.x<=a&&f.y>=i&&f.y<=l,c=[],h=[],u=()=>{h.length>=2&&c.push(h),h=[];};for(let f=0;f+1<n.length;f++){let d=n[f],p=n[f+1],b=s(d),m=s(p);if(b&&m){h.length||h.push(d),h.push(p);continue}let g=Qh(d,p,r,i,a,l);if(!g){u();continue}h.length||h.push(g[0]),h.push(g[1]),m||u();}return u(),c}function Qh(n,e,t,o,r,i){let a=e.x-n.x,l=e.y-n.y,s=0,c=1,h=[[-a,n.x-t],[a,r-n.x],[-l,n.y-o],[l,i-n.y]];for(let[u,f]of h){if(u===0){if(f<0)return null;continue}let d=f/u;if(u<0){if(d>c)return null;d>s&&(s=d);}else {if(d<s)return null;d<c&&(c=d);}}return [{x:n.x+a*s,y:n.y+l*s},{x:n.x+a*c,y:n.y+l*c}]}var qh=[0,.25,-0.25,.5,-0.5,.75,-0.75,1,-1];function di(n,e,t,o={}){if(n.length<2||!e.length||t<=0)return [];let r=od(n),i=r[r.length-1];if(i<t)return [];let a=o.maxAngle??25,l=o.stableScale&&o.stableScale>0?o.stableScale:1,s=i*l,c=o.fontSize?o.fontSize*.6:t/e.length,h=(o.fontSize??0)*.85,u=[],f=o.spacing??250,d=f>0&&f-t<f*.25?t+f*.25:f;if(o.accept)return $h(n,r,e,t,d,c,a,h,o.accept);if(d>0&&s>=t+d){let b=Math.min(Math.floor((s-t)/d)+1,24),m=t+d*(b-1),g=(s-m)/2;for(let y=0;y<b;y++,g+=d){let A=g/l,B=hi(n,r,e,t,A,c,a,h);B&&u.push({glyphs:B,path:B.map(x=>({x:x.x,y:x.y})),at:A});}if(u.length)return u}let p=(i-t)/2;for(let b of qh){let m=p+p*b,g=hi(n,r,e,t,m,c,a,h);if(g)return [{glyphs:g,path:g.map(y=>({x:y.x,y:y.y})),at:m}];if(p===0)break}return []}function $h(n,e,t,o,r,i,a,l,s){let c=e[e.length-1],h=Math.max(o/3,r/8,12),u=[],f=-1/0;for(let d=0;d+o<=c;d+=h){if(d-f<r)continue;let p=hi(n,e,t,o,d,i,a,l);if(!p)continue;let b={glyphs:p,path:p.map(m=>({x:m.x,y:m.y})),at:d};if(s(b)&&(u.push(b),f=d,u.length>=24))break}return u}function hi(n,e,t,o,r,i,a,l){if(r<0||r+o>e[e.length-1]||!ed(n,e,r,r+o,i,a))return null;let s=Do(n,e,r),c=Do(n,e,r+o);if(!s||!c)return null;if(c.x>=s.x)return Hs(n,e,t,r,l);let h=e[e.length-1];return Hs([...n].reverse(),rd(e),t,h-(r+o),l)}function ed(n,e,t,o,r,i){if(r<=0)return true;let a=[],l=0;for(let s=1;s+1<n.length;s++){let c=e[s];if(c<=t)continue;if(c>=o)break;let h=Math.atan2(n[s].y-n[s-1].y,n[s].x-n[s-1].x),u=Math.atan2(n[s+1].y-n[s].y,n[s+1].x-n[s].x),f=Math.abs((u-h)*180/Math.PI+540)%360-180,d=Math.abs(f);for(a.push({at:c,delta:d}),l+=d;a.length&&c-a[0].at>r;)l-=a.shift().delta;if(l>i)return false}return true}function Hs(n,e,t,o,r){let i=[];for(let c of t){let h=ks(n,e,o+c.offset,c.width);if(!h)return null;i.push(h);}if(!i.length)return null;if(r<=0)return i;let a=[],l=o,s=0;for(let c=0;c<t.length;c++){if(c>0){let u=Math.abs(td(i[c].angle,i[c-1].angle))*(Math.PI/180);s+=r*2*Math.tan(Math.min(u,Math.PI/3)/2);}l=o+t[c].offset+s;let h=ks(n,e,l,t[c].width);if(!h)return null;a.push(h);}return a}function ks(n,e,t,o){let r=Do(n,e,t+o/2);if(!r)return null;let i=Do(n,e,t),a=Do(n,e,t+o);if(!i||!a)return r;let l=a.x-i.x,s=a.y-i.y;return l===0&&s===0?r:{x:r.x,y:r.y,angle:Math.atan2(s,l)*180/Math.PI}}function td(n,e){let t=n-e;for(;t>180;)t-=360;for(;t<=-180;)t+=360;return t}function od(n){let e=new Array(n.length);e[0]=0;for(let t=1;t<n.length;t++)e[t]=e[t-1]+Math.hypot(n[t].x-n[t-1].x,n[t].y-n[t-1].y);return e}function rd(n){let e=n[n.length-1];return n.map(t=>e-t).reverse()}function Do(n,e,t){if(t<0||t>e[e.length-1])return null;let o=1;for(;o<e.length-1&&e[o]<t;)o++;let r=e[o]-e[o-1];if(r<=0)return null;let i=(t-e[o-1])/r,a=n[o-1],l=n[o],s=l.x-a.x,c=l.y-a.y;return {x:a.x+s*i,y:a.y+c*i,angle:Math.atan2(c,s)*180/Math.PI}}var mi=20,Ps={stride:mi,attribs:[{name:"a_pos",size:2,type:5126,offset:0},{name:"a_tex",size:2,type:5123,offset:8},{name:"a_scale",size:1,type:5126,offset:12},{name:"a_fade",size:1,type:5126,offset:16}]},nd=220,lt=64,Rs=2,id=1.22,ad=128,ld=.7;function sd(n,e,t){let o=n.layout?.letterSpacing;if(o!==void 0)return V(o,e,0)*qe;let r=V(n.paint?.haloWidth,e,0);return r<=0||t<=0?0:r*ld/(t/qe)}var cd=256,fd=200,pi="frame-circle",Vt=class n{constructor(e,t){this.shader=null;this.locations=new z;this.atlas=new _o(1024);this.vbo=null;this.ibo=null;this.vao=null;this.capacityQuads=0;this.onAssetsReady=null;this.pendingText=new Set;this.pendingIcons=new Set;this.highlightFootprint=null;this.placedCount=0;this.placed=[];this.hoverKey=null;this.hiddenKey=null;this.padding={top:0,right:0,bottom:0,left:0};this.viewport={width:0,height:0};this.stickyKeys=new Set;this.now=0;this.shownAt=new z;this.fading=false;this.styleOrder=new z;this.glyphs=new Eo(e,t),this.icons=new Fo(At);}init(e){this.shader=new Ae(e,"symbol",ns,is);for(let t of Ps.attribs)this.locations.set(t.name,this.shader.attribLocation(t.name));}static keyOf(e){return `${e.layerId}|${e.mercX.toFixed(9)}|${e.mercY.toFixed(9)}`}setHover(e){return this.hoverKey===e?false:(this.hoverKey=e,true)}setHidden(e){return this.hiddenKey===e?false:(this.hiddenKey=e,true)}querySymbol(e,t=2){let o=null;for(let r of this.placed)e.x<r.box.x1-t||e.x>r.box.x2+t||e.y<r.box.y1-t||e.y>r.box.y2+t||(!o||r.order>=o.order)&&(o=r);return o}fadeOf(e,t){let o=this.shownAt.get(e);if(o===void 0)return this.shownAt.set(e,t),this.fading=true,0;let r=(t-o)/nd;return r<1?(this.fading=true,r):1}order(e){let t=o=>o.priority+(this.stickyKeys.has(n.keyOf({layerId:o.layer.id,mercX:o.mercX,mercY:o.mercY}))?fd:0);e.sort((o,r)=>t(r)-t(o));}rememberPlaced(){this.stickyKeys=new Set(this.placed.map(e=>n.keyOf(e)));for(let e of [...this.shownAt.keys()])this.stickyKeys.has(e)||this.shownAt.delete(e);}render(e,t,o,r){let i=this.shader;if(this.placedCount=0,this.placed=[],this.viewport={width:t.width,height:t.height},!i)return;let a=t.zoom,l=r.layers.filter(d=>d.type==="symbol"&&r.layerVisibleAt(d,a));if(!l.length)return;let s=this.collect(t,o,r,l);if(!s.length)return;this.now=performance.now(),this.fading=false,this.order(s);let c=new z,h=new z,u=new z;l.forEach((d,p)=>u.set(d.id,p));let f=0;for(let d of s){let p=this.place(d,a,c);if(!p)continue;this.placed.push({layerId:d.layer.id,text:d.text,icon:d.icon,mercX:d.mercX,mercY:d.mercY,box:p.box,order:u.get(d.layer.id)??0});let b=h.get(d.layer.id);b||h.set(d.layer.id,b={layer:d.layer,verts:[],texs:[],iconVerts:[],iconTexs:[],frameVerts:[],frameTexs:[]}),b.verts.push(...p.verts),b.texs.push(...p.texs),b.iconVerts.push(...p.iconVerts),b.iconTexs.push(...p.iconTexs),b.frameVerts.push(...p.frameVerts),b.frameTexs.push(...p.frameTexs),f+=p.quads,this.placedCount++;}this.rememberPlaced(),this.fading&&this.onAssetsReady?.(),this.requestMissing(),f&&(this.styleOrder=u,this.draw(e,t,h,f,a));}collect(e,t,o,r){let i=[],l=this.padding,s=kt(e,o).far,[c,h,u]=e.cameraPositionPx;for(let f of r){let d=(f.layout?.priority??0)*cd,p=t.get(f.source??Y);if(!p)continue;let b=f.layout?.showFor==="highlight",m=f.layout?.placement==="map",{shift:g,drop:y}=m?Vs(f,e.zoom,e.pixelsPerMeter):{shift:0,drop:0};if(b&&!this.highlightFootprint)continue;let A=e.worldSize>0?e.pixelsPerMeter/e.worldSize*1.5:0,B=o.bucketKeyFor(f);if(B!==null)for(let x of p.visibleTiles){if(!o.layerVisibleAt(f,e.detailZoom(e.distanceToTile(x))))continue;let _=p.getTile(x)?.data?.buckets?.[B];if(!_||!gr(_))continue;let C=new Int16Array(_.anchors),v=new Uint8Array(_.priorities),E=_.rotations?new Int16Array(_.rotations):null,D=_.lines?new Int16Array(_.lines):null,F=_.lineStarts?new Uint32Array(_.lineStarts):null,H=x.bounds(),S=e.worldSize,L=(H.maxX-H.minX)*S/_.extent,M=H.minX*S,T=H.minY*S;for(let P=0;P<v.length;P++){let k=M+C[P*2]*L,O=T+C[P*2+1]*L;if(s!==1/0&&Math.hypot(k-c,O-h,u)>s||b&&!Qe(this.highlightFootprint,k/S,O/S,A))continue;let N=k,G=O;if(m&&E){let Z=E[P]*Math.PI/180,ee=g;N-=Math.sin(Z)*ee,G+=Math.cos(Z)*ee;}let R=e.worldPxToPoint(N,G),W=D&&F?ud(e,D,F,P,M,T,L):void 0;if(f.layout?.textPlacement==="line"){if(!W)continue}else if(!R||R.x<l.left-64||R.y<l.top-64||R.x>e.width-l.right+64||R.y>e.height-l.bottom+64)continue;i.push({layer:f,screenX:R?R.x:W[0].x,screenY:(R?R.y:W[0].y)+y,text:_.texts[P]??"",icon:_.icons[P]??"",priority:v[P]+d,rotate:Ws(f,E,P,e.bearing),mercX:k/S,mercY:O/S,line:W});}}}return i}place(e,t,o){let r=e.layer.layout??{},i=n.keyOf({layerId:e.layer.id,mercX:e.mercX,mercY:e.mercY});if(this.hiddenKey!==null&&this.hiddenKey===i)return null;let a=this.fadeOf(i,this.now),l=this.hoverKey!==null&&this.hoverKey===i,s=V(r.textSize,t,13),c=V(r.iconSize,t,16),h=r.iconTextGap??5,[u,f]=r.offset??[0,0],d=r.placement==="map",p=null;if(e.icon&&!d){this.icons.isDefined(e.icon)||(e.icon="dot");let q=`icon:${e.icon}`,U=this.atlas.get(q);if(!U){let J=this.icons.get(e.icon);J?U=this.atlas.add(q,J.data,J.width,J.height)??void 0:this.pendingIcons.add(e.icon);}U&&(p=U);}let b=null;if(p&&r.iconFrame==="circle"){let q=`icon:${pi}`,U=this.atlas.get(q);if(!U){let J=this.icons.get(pi);J?U=this.atlas.add(q,J.data,J.width,J.height)??void 0:this.pendingIcons.add(pi);}U&&(b=U);}let m=b?Math.max(r.iconFrameScale??1.6,1):1,g=null;if(e.text&&(this.glyphs.needsLoad(e.text)&&this.pendingText.add(e.text),g=fi(e.text,this.glyphs,r.textPlacement==="line"?Number.MAX_SAFE_INTEGER:r.maxLineChars??15,sd(e.layer,t,s)),!g&&!p)||!g&&!p)return null;let y=s/qe,A=g?g.width*y:0,B=g?g.height*y:0;if(e.layer.layout?.textPlacement==="line")return g&&e.line?this.placeOnLine(e,g,y,B,o,t,a):null;let x=r.iconPlacement??"top",w=x==="behind"&&!!p&&!!g,_=x==="top"&&!!p&&!!g,C=p?p.width/Math.max(p.height,1):1,v=w?B+h*2:c,E=p?v*C:0,D=Math.max(E,p?c*m:0),F=Math.max(v,p?c*m:0),H=w?Math.max(E,A+h*2):_?Math.max(D,A):D+(p&&g?h:0)+A,S=w?Math.max(v,B):_?F+h+B:Math.max(p?F:0,B),L=e.screenX+u,M=e.screenY+f,T=Rs+(r.collisionPadding??0),P={x1:L-H/2-T,y1:M-S/2-T,x2:L+H/2+T,y2:M+S/2+T},k=this.padding;if(P.x1<k.left||P.y1<k.top||P.x2>this.viewport.width-k.right||P.y2>this.viewport.height-k.bottom)return null;if(!r.allowOverlap){if(Gs(o,P))return null;Os(o,P);}let O=[],N=[],G=[],R=[],W=[],j=[],Z=0,ee=L-H/2,ge=_?(F+h)/2:0,te=1/0,X=1/0,re=-1/0,le=-1/0;if(g){let q=_||w?L:ee+(p?D+h:0)+A/2;for(let U of g.glyphs){let J=U.glyph,fe=`g:${J.id}`,se=this.atlas.get(fe);if(!se&&(!J.bitmap||(se=this.atlas.add(fe,J.bitmap,J.width+Ce*2,J.height+Ce*2)??void 0,!se)))continue;let ue=q+(U.x+J.left-Ce)*y,ae=M+ge+(U.y-J.top-Ce)*y,xe=se.width*y,Te=se.height*y;Fr(O,N,ue,ae,xe,Te,se,0,a),Z++;let we=Ce*y;te=Math.min(te,ue+we),X=Math.min(X,ae+we),re=Math.max(re,ue+xe-we),le=Math.max(le,ae+Te-we);}if(_&&p&&X<1/0){let U=M-S/2+F+h-X;if(U!==0){for(let J=1;J<O.length;J+=4)O[J]+=U;X+=U,le+=U;}}}if(p){let q=l?id:1,U=E*q,J=v*q,fe=(_?L-E/2:ee+(D-E)/2)-(U-E)/2,se=(_?M-S/2+(F-v)/2:M-v/2)-(J-v)/2;if(b){let ae=c*m*q,xe=fe+U/2-ae/2,Te=se+J/2-ae/2,we=Ce/Math.max(b.height-Ce*2,1)*ae;Fr(W,j,xe-we,Te-we,ae+we*2,ae+we*2,b,0,a),Z++;}if(w&&re>te){let ae=h*1.6,xe=h;U=(re-te+ae*2)*q,J=(le-X+xe*2)*q,fe=te-ae,se=X-xe;}let ue=Ce/Math.max(p.height-Ce*2,1)*J;Fr(G,R,fe-ue,se-ue,U+ue*2,J+ue*2,p,e.rotate,a),Z++;}return Z?{verts:O,texs:N,iconVerts:G,iconTexs:R,frameVerts:W,frameTexs:j,quads:Z,box:P}:null}placeOnLine(e,t,o,r,i,a,l){let s=e.line,c=t.glyphs.map(E=>({offset:(E.x+t.width/2)*o,width:Math.max(E.glyph.advance,1)*o})),h=c.length?c[c.length-1].offset+c[c.length-1].width:0,u=e.layer.layout??{},f=[],d=[],p=[],b=0,m=r/2+Rs,g=this.padding,y=E=>{let D=E.path.map(F=>({x1:F.x-m,y1:F.y-m,x2:F.x+m,y2:F.y+m}));for(let F of D)if(F.x1<g.left||F.y1<g.top||F.x2>this.viewport.width-g.right||F.y2>this.viewport.height-g.bottom||!u.allowOverlap&&Gs(i,F))return false;if(!u.allowOverlap)for(let F of D)Os(i,F);return p.push(...D),true},A=-1/0,B=1/0;for(let E of t.glyphs)E.glyph.height<=0||(A=Math.max(A,E.glyph.top),B=Math.min(B,E.glyph.top-E.glyph.height));let x=Number.isFinite(A)?(A+B)/2*o:0,_=ui(s,this.viewport.width,this.viewport.height,ad).flatMap(E=>di(E,c,h,{spacing:u.symbolSpacing,fontSize:qe*o,stableScale:Math.pow(2,Math.round(a)-a),accept:y}));if(!_.length)return null;for(let E of _)for(let D=0;D<t.glyphs.length;D++){let F=t.glyphs[D].glyph,H=E.glyphs[D],S=`g:${F.id}`,L=this.atlas.get(S);if(!L&&(!F.bitmap||(L=this.atlas.add(S,F.bitmap,F.width+Ce*2,F.height+Ce*2)??void 0,!L)))continue;let M=L.width*o,T=L.height*o,P=(F.height/2-F.top)*o+x,k=H.angle*Math.PI/180;Fr(f,d,H.x-M/2-Math.sin(k)*P,H.y-T/2+Math.cos(k)*P,M,T,L,H.angle,l),b++;}if(!b)return null;let C=p.map(E=>(E.x1+E.x2)/2),v=p.map(E=>(E.y1+E.y2)/2);return {verts:f,texs:d,iconVerts:[],iconTexs:[],frameVerts:[],frameTexs:[],quads:b,box:{x1:Math.min(...C)-m,y1:Math.min(...v)-m,x2:Math.max(...C)+m,y2:Math.max(...v)+m}}}inStyleOrder(e){return [...e.values()].sort((t,o)=>(this.styleOrder.get(t.layer.id)??0)-(this.styleOrder.get(o.layer.id)??0))}draw(e,t,o,r,i){let a=this.shader,l=e.gl;this.ensureBuffers(e,r);let s=this.vbo,c=this.vao;if(!s||!c||!this.ibo)return;let h=new ArrayBuffer(r*4*mi),u=new Float32Array(h),f=new Uint16Array(h),d=[],p=0,b=(m,g,y,A)=>{let B=m.length/16;if(B){d.push({layer:y,role:A,first:p/4*6,count:B*6});for(let x=0;x<B*4;x++){let w=p*5;u[w]=m[x*4],u[w+1]=m[x*4+1],f[w*2+4]=g[x*2],f[w*2+5]=g[x*2+1],u[w+3]=m[x*4+2],u[w+4]=m[x*4+3],p++;}}};for(let m of this.inStyleOrder(o))b(m.frameVerts,m.frameTexs,m.layer,"frame"),b(m.iconVerts,m.iconTexs,m.layer,"icon"),b(m.verts,m.texs,m.layer,"text");s.update(new Uint8Array(h)),a.use(),this.atlas.bind(e,0),a.setInt("u_atlas",0),a.setVec2("u_viewport",t.width,t.height),a.setFloat("u_atlas_size",this.atlas.size),a.setFloat("u_edge",si),a.setFloat("u_dpr",t.width>0?l.drawingBufferWidth/t.width:1),e.setDepthTest(false),e.setDepthMask(false),e.setBlend("premultiplied"),e.setCull("none"),c.bind();for(let m of d){let g=m.layer.paint,y=V(g.opacity,i,1),A=m.role==="icon",B=m.role==="frame",x=(D,F,H)=>B?F??D??H:A?D??H:H,w=He(B?g.frameColor??g.haloColor??g.color:x(g.iconColor,void 0,g.color),i,[.15,.15,.15,1]),_=B?g.frameHaloColor:x(g.iconHaloColor,void 0,g.haloColor),C=He(_??(B?g.iconColor??g.color:g.haloColor),i,[1,1,1,1]);B&&g.frameHaloColor===void 0&&(C[3]*=.35),B&&(w[3]*=V(g.frameOpacity,i,1));let v=V(B?g.frameHaloWidth??1.1:x(g.iconHaloWidth,void 0,g.haloWidth),i,1.2),E=V(m.layer.layout?.textSize,i,13);a.setVec4v("u_color",Me([w[0],w[1],w[2],w[3]*y])),a.setVec4v("u_halo_color",Me([C[0],C[1],C[2],C[3]*y])),a.setFloat("u_halo",v/(Mo*(E/qe))),l.drawElements(l.TRIANGLES,m.count,l.UNSIGNED_INT,m.first*4);}e.bindVAO(null);}ensureBuffers(e,t){if(this.vao&&t<=this.capacityQuads)return;this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.capacityQuads=Math.max(1024,Math.ceil(t*1.5)),this.vbo=new ve(e,new Uint8Array(this.capacityQuads*4*mi),Ps,true);let o=new Uint32Array(this.capacityQuads*6);for(let r=0;r<this.capacityQuads;r++){let i=r*4;o.set([i,i+1,i+2,i,i+2,i+3],r*6);}this.ibo=new ye(e,o),this.vao=new pe(e,[{buffer:this.vbo,locations:this.locations}],this.ibo);}requestMissing(){if(this.pendingText.size){let e=[...this.pendingText].join("");this.pendingText.clear(),this.glyphs.ensure(e).then(t=>{t&&this.onAssetsReady?.();});}if(this.pendingIcons.size){let e=[...this.pendingIcons];this.pendingIcons.clear(),Promise.all(e.map(t=>this.icons.ensure(t))).then(t=>{t.some(Boolean)&&this.onAssetsReady?.();});}}destroy(e){this.shader?.destroy(),this.vao?.destroy(),this.vbo?.destroy(),this.ibo?.destroy(),this.atlas.destroy(e),this.shader=null,this.vao=null;}};function Fr(n,e,t,o,r,i,a,l=0,s=1){let c=i/Math.max(a.height,1);if(l){let h=l*Math.PI/180,u=Math.cos(h),f=Math.sin(h),d=t+r/2,p=o+i/2;for(let[b,m]of [[t,o],[t+r,o],[t+r,o+i],[t,o+i]]){let g=b-d,y=m-p;n.push(d+g*u-y*f,p+g*f+y*u,c,s);}}else n.push(t,o,c,s,t+r,o,c,s,t+r,o+i,c,s,t,o+i,c,s);e.push(a.x,a.y,a.x+a.width,a.y,a.x+a.width,a.y+a.height,a.x,a.y+a.height);}function ud(n,e,t,o,r,i,a){if(o+1>=t.length)return;let l=t[o],s=t[o+1],c=[];for(let h=l;h<s;h++){let u=n.worldPxToPoint(r+e[h*2]*a,i+e[h*2+1]*a);if(!u)break;c.push(u);}return c.length>=2?c:void 0}var zs=(n,e)=>n*4096+e;function Gs(n,e){let t=Math.floor(e.x1/lt),o=Math.floor(e.y1/lt),r=Math.floor(e.x2/lt),i=Math.floor(e.y2/lt);for(let a=t;a<=r;a++)for(let l=o;l<=i;l++){let s=n.get(zs(a,l));if(s){for(let c of s)if(e.x1<c.x2&&e.x2>c.x1&&e.y1<c.y2&&e.y2>c.y1)return true}}return false}function Os(n,e){let t=Math.floor(e.x1/lt),o=Math.floor(e.y1/lt),r=Math.floor(e.x2/lt),i=Math.floor(e.y2/lt);for(let a=t;a<=r;a++)for(let l=o;l<=i;l++){let s=zs(a,l),c=n.get(s);c||n.set(s,c=[]),c.push(e);}}function Vs(n,e,t){let r=n.layout?.arrowUnits!=="meters"?1:t,i=V(n.layout?.arrowLength,e,50)*r;return {shift:V(n.layout?.arrowGap,e,20)*r+i/2,drop:i/2+(n.layout?.iconTextGap??4)}}function Ws(n,e,t,o){return !n.layout?.iconRotate||!e?0:e[t]-o}var Wt=class{constructor(e,t){this.capacity=e;this.onEvict=t;this.map=new z;}get size(){return this.map.size}has(e){return this.map.has(e)}get(e){let t=this.map.get(e);if(t!==void 0)return this.map.delete(e),this.map.set(e,t),t}peek(e){return this.map.get(e)}set(e,t){let o=this.map.get(e);o!==void 0&&(this.map.delete(e),o!==t&&this.onEvict?.(e,o)),this.map.set(e,t),this.trim();}delete(e){let t=this.map.get(e);return t===void 0?false:(this.map.delete(e),this.onEvict?.(e,t),true)}setCapacity(e){this.capacity=e,this.trim();}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}clear(){for(let[e,t]of this.map)this.onEvict?.(e,t);this.map.clear();}trim(){for(;this.map.size>this.capacity;){let e=this.map.keys().next();if(e.done)break;let t=e.value,o=this.map.get(t);this.map.delete(t),this.onEvict?.(t,o);}}};var Nt=class n{constructor(e,t,o,r=0){this.z=e;this.x=t;this.y=o;this.wrap=r;this.dataKey=`${e}/${t}/${o}`,this.key=r===0?this.dataKey:`${this.dataKey}@${r}`;}parent(){return this.z===0?null:new n(this.z-1,this.x>>1,this.y>>1,this.wrap)}children(){let e=this.z+1,t=this.x*2,o=this.y*2;return [new n(e,t,o,this.wrap),new n(e,t+1,o,this.wrap),new n(e,t,o+1,this.wrap),new n(e,t+1,o+1,this.wrap)]}scaledTo(e){if(e>=this.z)return this;let t=this.z-e;return new n(e,this.x>>t,this.y>>t,this.wrap)}isAncestorOf(e){if(e.z<=this.z||e.wrap!==this.wrap)return false;let t=e.z-this.z;return e.x>>t===this.x&&e.y>>t===this.y}bounds(){let t=1/Math.pow(2,this.z);return {minX:this.x*t+this.wrap,minY:this.y*t,maxX:(this.x+1)*t+this.wrap,maxY:(this.y+1)*t}}toString(){return this.key}};function hd(n,e,t){let o=Math.pow(2,t),r=e.maxTiles??512,i=[],a=128;for(let l=0;l<o;l++)for(let s=0;s<o;s++){let c=new Nt(t,s,l),h=c.bounds(),u=(h.minX+h.maxX)/2,f=(h.minY+h.maxY)/2,d=[[u,f],[h.minX,h.minY],[h.maxX,h.minY],[h.minX,h.maxY],[h.maxX,h.maxY]],p=false;for(let[m,g]of d)if(n.isOnGlobeFront(Se(m),Fe(g))){p=true;break}if(!p)continue;let b=false;for(let[m,g]of d){let y=n.localToPoint(n.globeLocal(m,g));if(y&&y.x>-a&&y.y>-a&&y.x<n.width+a&&y.y<n.height+a){b=true;break}}if(b&&(i.push(c),i.length>=r))return i}return i}function So(n,e){let t=Math.min(e.maxzoom,24),o=Math.max(0,Math.min(e.minzoom,t)),r=e.detailBias??1,i=e.maxTiles??512,a=512*r,l=Math.min(Math.round(n.zoom),t);if(l<o)return [];if(n.globeActive)return hd(n,e,l);let{min:s,max:c}=n.visibleWrapRange(),h=[],u=[];for(let d=s;d<=c;d++)u.push(new Nt(0,0,0,d));let f=0;for(;u.length&&!(++f>2e4||h.length>=i);){let d=u.pop();if(!n.isTileVisible(d))continue;if(d.z>=l){d.z>=o&&h.push(d);continue}if(n.tileScreenSize(d.z,n.distanceToTile(d))<=a&&d.z>=o){h.push(d);continue}for(let b of d.children())u.push(b);}return h.sort((d,p)=>n.distanceToTile(d)-n.distanceToTile(p)),h}var bi=class{constructor(e){this.id=e;this.state="loading";this.data=null;this.error=null;this.requestId=0;this.buckets=new z;}get hasGeometry(){return this.state==="loaded"&&!!this.data&&Object.keys(this.data.buckets).length>0}destroy(){for(let e of this.buckets.values())e.destroy();this.buckets.clear(),this.data=null;}},dd=1500,Dr=class extends $e{constructor(t,o){super();this.pool=t;this.visible=[];this.holdSince=0;this.warmed=false;this.version=0;this.opts={cacheSize:160,detailBias:1,maxTiles:512,...o},this.cache=new Wt(this.opts.cacheSize,(r,i)=>{i.state==="loading"&&this.pool.abort(i.requestId),i.destroy();});}get visibleTiles(){return this.visible}get dataVersion(){return this.version+this.visible.length*1e6}get warm(){return this.warmed}getTile(t){return this.cache.peek(t.dataKey)}splitValues(t){let o=[];for(let r of this.visible){let i=this.getTile(r)?.data?.splits?.[t];if(i)for(let a of i)o.includes(a)||o.push(a);}return o.sort((r,i)=>typeof r=="number"&&typeof i=="number"?r-i:String(r).localeCompare(String(i))),o}get pendingCount(){let t=0;for(let o of this.cache.values())o.state==="loading"&&t++;return t}update(t){let o=So(t,this.opts),r=new oe;for(let u of o)r.add(u.dataKey);for(let[u,f]of this.cache.entries())f.state==="loading"&&!r.has(u)&&(this.pool.abort(f.requestId),this.cache.delete(u));let i=Math.max(this.opts.cacheSize,r.size*2);this.cache.setCapacity(i);for(let u of o)this.cache.get(u.dataKey)||this.loadTile(u);let a=this.visible.length>0&&this.covers(o),l=performance.now(),s=this.readyFor(o),c=this.holdSince>0&&l-this.holdSince>dd,h=this.anyReady(o);s||h&&(!a||c)?(this.visible=o,this.holdSince=0,s&&o.length&&(this.warmed=true)):this.holdSince||(this.holdSince=l);}anyReady(t){for(let o of t){let r=this.cache.peek(o.dataKey);if(r&&r.state!=="loading")return true}return t.length===0}readyFor(t){for(let o of t){let r=this.cache.peek(o.dataKey);if(!r||r.state==="loading")return false}return true}covers(t){let o=new oe;for(let r of this.visible)o.add(r.dataKey);for(let r of t){if(o.has(r.dataKey))continue;let i=r.parent(),a=false;for(let l=0;i&&l<4;l++){if(o.has(i.dataKey)){a=true;break}i=i.parent();}if(!a)for(let l of this.visible){let s=l.parent();for(let c=0;s&&c<4;c++){if(s.dataKey===r.dataKey){a=true;break}s=s.parent();}if(a)break}if(!a)return false}return true}loadTile(t){let o=new bi(t);this.cache.set(t.dataKey,o);let r=pd(this.opts.url.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y)));o.requestId=this.pool.load({url:r,zoom:t.z,metersPerTile:Vi(t.z,t.y),sourceMaxZoom:this.opts.maxzoom,plan:this.opts.plan},i=>{if(this.cache.peek(t.dataKey)===o){if(i.type==="error"){if(i.aborted)return;o.state="error",o.error=i.message,this.emit("error",{tile:t,message:i.message});}else o.data=i,o.state=Object.keys(i.buckets).length?"loaded":"empty",this.version++,i.diag?.failed?.length&&console.warn(`[osmgl] \u0442\u0430\u0439\u043B ${t.z}/${t.x}/${t.y}: \u0441\u043B\u043E\u0438 \u043D\u0435 \u0441\u043E\u0431\u0440\u0430\u043B\u0438\u0441\u044C \u2014 ${i.diag.failed.join("; ")}`),this.emit("data",{tile:o});this.pendingCount===0&&this.emit("idle",void 0);}});}findReadyAncestor(t,o=5){let r=t.parent();for(let i=0;r&&i<o;i++){let a=this.cache.peek(r.dataKey);if(a&&a.hasGeometry)return a;r=r.parent();}return null}setCoverOptions(t){t.detailBias!==void 0&&(this.opts.detailBias=t.detailBias),t.maxTiles!==void 0&&(this.opts.maxTiles=t.maxTiles);}setPlan(t){this.opts.plan=t,this.cache.clear();}reload(){this.cache.clear();}destroy(){this.cache.clear(),this.removeAllListeners();}};function pd(n){if(typeof location>"u")return n;try{return new URL(n,location.href).href}catch{return n}}var Sr=class{constructor(e){this.id=e;this.state="loading";this.image=null;this.error=null;this.texture=null;}destroy(){this.texture?.destroy(),this.texture=null,this.image?.close(),this.image=null;}},Io=class extends $e{constructor(t){super();this.visible=[];this.aborts=new Map;this.opts={cacheSize:128,detailBias:1,maxTiles:256,...t},this.cache=new Wt(this.opts.cacheSize,(o,r)=>{this.aborts.get(o)?.abort(),this.aborts.delete(o),r.destroy();});}get visibleTiles(){return this.visible}getTile(t){return this.cache.peek(t.dataKey)}update(t){this.visible=So(t,this.opts);let o=new oe;for(let r of this.visible)o.add(r.dataKey);for(let[r,i]of this.cache.entries())i.state==="loading"&&!o.has(r)&&(this.aborts.get(r)?.abort(),this.aborts.delete(r),this.cache.delete(r));this.cache.setCapacity(Math.max(this.opts.cacheSize,o.size*2));for(let r of this.visible)this.cache.get(r.dataKey)||this.loadTile(r);}reload(){for(let t of this.aborts.values())t.abort();this.aborts.clear(),this.cache.clear();}destroy(){this.reload(),this.removeAllListeners();}loadTile(t){let o=new Sr(t);this.cache.set(t.dataKey,o);let r=new AbortController;this.aborts.set(t.dataKey,r),this.fetchImage(Ns(this.opts.url,t),r.signal).then(i=>{if(this.aborts.delete(t.dataKey),this.cache.peek(t.dataKey)!==o){i.close();return}o.image=i,o.state="loaded",this.emit("data",{tile:o});}).catch(i=>{this.aborts.delete(t.dataKey),!r.signal.aborted&&this.cache.peek(t.dataKey)===o&&(o.state="error",o.error=i instanceof Error?i.message:String(i),this.emit("error",{tile:t,message:o.error}));});}async fetchImage(t,o){let r=await fetch(t,{signal:o});if(!r.ok)throw new Error(`\u0442\u0430\u0439\u043B \u043F\u043E\u0434\u043B\u043E\u0436\u043A\u0438 ${r.status} ${r.statusText}`);return createImageBitmap(await r.blob())}};function Ns(n,e){let t=n.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));if(typeof location>"u")return t;try{return new URL(t,location.href).href}catch{return t}}var md="osmgl-assets",Kt="assets";var Ir=null;function Us(){return Ir||(Ir=new Promise(n=>{if(typeof indexedDB>"u")return n(null);try{let e=indexedDB.open(md,1);e.onupgradeneeded=()=>{let t=e.result;t.objectStoreNames.contains(Kt)||t.createObjectStore(Kt,{keyPath:"key"});},e.onsuccess=()=>n(e.result),e.onerror=()=>n(null);}catch{n(null);}}),Ir)}function bd(n){return Us().then(e=>new Promise(t=>{if(!e)return t(null);try{let o=e.transaction(Kt,"readonly").objectStore(Kt).get(n);o.onsuccess=()=>t(o.result??null),o.onerror=()=>t(null);}catch{t(null);}}))}function gd(n){Us().then(e=>{if(e)try{e.transaction(Kt,"readwrite").objectStore(Kt).put(n);}catch{}});}var Ks=n=>{let e=atob(n),t=new Uint8Array(e.length);for(let o=0;o<e.length;o++)t[o]=e.charCodeAt(o);return t};async function yd(n,e,t){let o=await crypto.subtle.importKey("raw",Ks(e),"AES-GCM",false,["decrypt"]);return crypto.subtle.decrypt({name:"AES-GCM",iv:Ks(t),tagLength:128},o,n)}var Lo=class{constructor(e){this.keys=new Map;this.variants=null;this.inflight=new Map;this.endpoint=e.endpoint.replace(/\/+$/,""),this.apiKey=e.apiKey??null;}withKey(e){return this.apiKey?e+(e.includes("?")?"&":"?")+"key="+encodeURIComponent(this.apiKey):e}loadVariants(){return this.variants??(this.variants=fetch(this.withKey(`${this.endpoint}/variants`),{credentials:"same-origin"}).then(e=>e.ok?e.json():{}).catch(()=>({}))),this.variants}async resolve(e,t){return t?(await this.loadVariants())[String(e)]?.[t]??e:e}async load(e,t,o="",r){let i=await this.resolve(e,o),a=`${i}:${t}`,l=this.inflight.get(a);if(l)return l;let s=this.fetchAsset(a,i,t,r).finally(()=>this.inflight.delete(a));return this.inflight.set(a,s),s}async fetchAsset(e,t,o,r){let i,a,l=await bd(e);if(l)i=l.bytes,a=l.encrypted;else {let c=await fetch(this.withKey(`${this.endpoint}/files/${t}/data?lod=${o}`),{signal:r,credentials:"same-origin"});if(!c.ok)throw new Error(`data ${c.status}`);a=(c.headers.get("X-Enc")??"none")!=="none",i=await c.arrayBuffer(),gd({key:e,bytes:i,encrypted:a,savedAt:Date.now()});}if(!a)return i;let s=await this.getKey(t,r);if(!s)throw new Error("\u043D\u0435\u0442 \u043A\u043B\u044E\u0447\u0430 \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043E\u0432\u043A\u0438");return yd(i,s.key,s.iv)}getKey(e,t){let o=this.keys.get(e);if(o)return o;let r=(async()=>{let i=await fetch(this.withKey(`${this.endpoint}/files/${e}/key`),{signal:t,credentials:"same-origin"});if(!i.ok)return null;let a=await i.json();return a.encrypted&&a.key&&a.iv?{key:a.key,iv:a.iv}:null})();return r.catch(()=>this.keys.delete(e)),this.keys.set(e,r),r}};var Ad=1,To=class{constructor(e){this.mesh=null;this.bitmaps=[];this.error=null;this.loading=null;this.matrix=K();this.grow=1;this.growTarget=1;this.animateIn=false;this.shrinkFrom=1;this.growStart=-1;this.fade=1;this.fadeTarget=1;this.fadeFrom=1;this.fadeStart=-1;this.matrix32=new Float32Array(16);this.nodeMatrix32=new Float32Array(16);this.normal32=new Float32Array(9);this.id=e.id??`model-${Ad++}`,this.url=e.url,this.fetchBytes=e.fetchBytes,this.coordinates=e.coordinates,this.altitude=e.altitude??0,this.rotation=e.rotation??0,this.rotationTiltX=e.rotationTiltX??0,this.rotationTiltZ=e.rotationTiltZ??0,e.growIn&&(this.animateIn=true,this.grow=0),this.scale=e.scale??1,this.fitHeight=e.fitHeight,this.visible=e.visible!==false,this.userData=e.userData??{};}get isLoaded(){return this.mesh!==null}load(e){return this.loading?(e&&this.loading.then(e),this.loading):(this.loading=(async()=>{try{let t=this.fetchBytes?await this.fetchBytes():await(async()=>{let r=await fetch(this.url);if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.arrayBuffer()})(),o=await $n(t);this.bitmaps=await Promise.all(o.images.map(async r=>{if(!r.length)return null;try{return await createImageBitmap(new Blob([r]))}catch{return null}})),this.mesh=o;}catch(t){this.error=t instanceof Error?t.message:String(t),console.warn(`[osmgl] \u043C\u043E\u0434\u0435\u043B\u044C ${this.url} \u043D\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043B\u0430\u0441\u044C: ${this.error}`);}e?.();})(),this.loading)}advanceGrow(e){if(!this.mesh)return false;if(!this.animateIn&&this.growTarget===1)return this.grow=1,false;if(e<=0)return this.grow=1,false;let t=performance.now()/1e3;this.growStart<0&&(this.growStart=t);let o=(t-this.growStart)/e;if(this.growTarget===0){if(o>=1)return this.grow=0,false;let i=Math.max(o,0);return this.grow=this.shrinkFrom*(1-i*i*(3-2*i)),true}if(o>=1)return this.grow=1,false;let r=Math.max(o,0)-1;return this.grow=1+r*r*(2.70158*r+1.70158),true}retire(){this.growTarget!==0&&(this.growTarget=0,this.shrinkFrom=this.grow,this.growStart=performance.now()/1e3);}setHidden(e){let t=e?0:1;this.fadeTarget!==t&&(this.fadeTarget=t,this.fadeFrom=this.fade,this.fadeStart=performance.now()/1e3);}advanceFade(e){if(this.fadeStart<0)return false;if(e<=0)return this.fade=this.fadeTarget,this.fadeStart=-1,false;let t=(performance.now()/1e3-this.fadeStart)/e;if(t>=1)return this.fade=this.fadeTarget,this.fadeStart=-1,false;let o=Math.max(t,0),r=o*o*(3-2*o);return this.fade=this.fadeFrom+(this.fadeTarget-this.fadeFrom)*r,true}markGrown(){this.grow=1,this.growTarget=1,this.growStart=-1/0;}revive(){this.growTarget!==1&&(this.growTarget=1,this.growStart=performance.now()/1e3-(this.animateIn?0:1e9));}effectiveScale(){if(!this.mesh||this.fitHeight===void 0)return this.scale;let e=this.mesh.max[1]-this.mesh.min[1];return e>1e-6?this.fitHeight/e:this.scale}boundingRadiusM(){let e=this.mesh;if(!e)return 0;let t=this.effectiveScale(),o=Math.max(Math.abs(e.min[0]),Math.abs(e.max[0])),r=Math.max(Math.abs(e.min[1]),Math.abs(e.max[1])),i=Math.max(Math.abs(e.min[2]),Math.abs(e.max[2]));return Math.hypot(o,r,i)*t}origin(){let e=$(this.coordinates);return {x:ne(e.lng),y:ie(e.lat)}}localMatrix(e){let t=this.effectiveScale(),o=t/Oe(e),r=[o,0,0,0,0,t*this.grow,0,o,0],i=c=>c*Math.PI/180,a=yi(i(-this.rotation));this.rotationTiltX&&(a=st(gi(i(this.rotationTiltX)),a)),this.rotationTiltZ&&(a=st(Ai(i(this.rotationTiltZ)),a));let l=st(r,a),s=this.matrix;return je(s),s[0]=l[0],s[1]=l[1],s[2]=l[2],s[4]=l[3],s[5]=l[4],s[6]=l[5],s[8]=l[6],s[9]=l[7],s[10]=l[8],s[15]=1,s}matrixInSpace(e,t){let o=$(this.coordinates),r=K();for(let a=0;a<16;a++)r[a]=e[a];let i=K();return Ee(i,r,this.localMatrix(o.lat)),Ye(t??this.matrix32,i)}cameraInModelSpace(e){let t=this.effectiveScale();if(!(t>0))return [0,0,0];let o=this.origin(),r=$(this.coordinates),i=Oe(r.lat),a=e.worldSize,l=e.cameraPositionPx,s=(l[0]/a-o.x)*i,c=(l[1]/a-o.y)*i,h=l[2]/e.pixelsPerMeter-this.altitude,u=s,f=h,d=c,p=m=>m*Math.PI/180,b=yi(p(-this.rotation));return this.rotationTiltX&&(b=st(gi(p(this.rotationTiltX)),b)),this.rotationTiltZ&&(b=st(Ai(p(this.rotationTiltZ)),b)),[(b[0]*u+b[1]*f+b[2]*d)/t,(b[3]*u+b[4]*f+b[5]*d)/t,(b[6]*u+b[7]*f+b[8]*d)/t]}matrixFor(e){let t=this.origin();return this.matrixInSpace(e.objectMatrix(t.x,t.y,this.altitude))}coversPoint(e,t){let o=this.mesh;if(!o)return false;let r=this.origin(),i=e-r.x,a=t-r.y,l=$(this.coordinates),s=this.localMatrix(l.lat),c=s[0],h=s[1],u=s[8],f=s[9],d=c*f-h*u;if(Math.abs(d)<1e-30)return false;let p=(i*f-a*u)/d,b=(c*a-h*i)/d,m=1.05,g=(o.min[0]+o.max[0])/2,y=(o.min[2]+o.max[2])/2,A=(o.max[0]-o.min[0])/2*m,B=(o.max[2]-o.min[2])/2*m;return Math.abs(p-g)<=A&&Math.abs(b-y)<=B}get isAnimated(){return this.mesh?.animation!=null}matrixForNode(e,t,o){let r=this.origin();return this.matrixInSpaceForNode(e.objectMatrix(r.x,r.y,this.altitude),t,o,this.nodeMatrix32)}matrixInSpaceForNode(e,t,o,r){let i=this.mesh?.animation;if(!i||!i.nodes.has(t))return this.matrixInSpace(e,r);let a=K();for(let u=0;u<16;u++)a[u]=e[u];let l=$(this.coordinates),s=K();Ee(s,a,this.localMatrix(l.lat));let c=K();ei(i,t,i.duration>0?o%i.duration:0,c);let h=K();return Ee(h,s,c),Ye(r,h)}normalMatrix(){let e=i=>i*Math.PI/180,t=yi(e(-this.rotation));this.rotationTiltX&&(t=st(gi(e(this.rotationTiltX)),t)),this.rotationTiltZ&&(t=st(Ai(e(this.rotationTiltZ)),t));let o=st([1,0,0,0,0,1,0,1,0],t),r=this.normal32;for(let i=0;i<9;i++)r[i]=o[i];return r}};function st(n,e){let t=new Array(9);for(let o=0;o<3;o++)for(let r=0;r<3;r++)t[o*3+r]=n[r]*e[o*3]+n[3+r]*e[o*3+1]+n[6+r]*e[o*3+2];return t}var gi=n=>{let e=Math.cos(n),t=Math.sin(n);return [1,0,0,0,e,t,0,-t,e]},yi=n=>{let e=Math.cos(n),t=Math.sin(n);return [e,0,-t,0,1,0,t,0,e]},Ai=n=>{let e=Math.cos(n),t=Math.sin(n);return [e,t,0,-t,e,0,0,0,1]};var Tr=class{constructor(){this.hit=new z;this.miss=new oe;this.stamp="";}find(e,t){if(!t)return null;let o=this.hit.get(e.id);if(o!==void 0)return o;let r=t.source.visibleTiles.map(i=>i.dataKey).join(",");if(r!==this.stamp&&(this.stamp=r,this.miss.clear()),this.miss.has(e.id))return null;for(let i of t.source.visibleTiles){let a=t.source.getTile(i)?.data?.buckets?.[t.key];if(!a||a.kind!=="fill-extrusion"||!a.featureIds)continue;let l=i.bounds();if(e.mercX<l.minX||e.mercX>l.maxX||e.mercY<l.minY||e.mercY>l.maxY)continue;let s=(e.mercX-l.minX)/(l.maxX-l.minX)*a.extent,c=(e.mercY-l.minY)/(l.maxY-l.minY)*a.extent,h=new Int16Array(a.vertices),u=new Uint32Array(a.indices),f=new Float64Array(a.featureIds),d=h.length/a.vertexCount;for(let p=0;p*3+2<u.length;p++){let b=u[p*3]*d,m=u[p*3+1]*d,g=u[p*3+2]*d;if(!Ed(s,c,h[b],h[b+1],h[m],h[m+1],h[g],h[g+1]))continue;let y=f[p];return this.hit.set(e.id,y),y}}return this.miss.add(e.id),null}clear(){this.hit.clear(),this.miss.clear(),this.stamp="";}},Bd=14,Cd=2e3,vd=4e3,Js=160,xd=50,wd=4e3,Bi=6,Hr=class{constructor(e){this.wantKey="";this.modelKey="";this.entries=new z;this.loading=0;this.pending=[];this.known=new z;this.underBuilding=new Tr;this.underVenue=new Tr;this.tilesStamp="";this.rulesInScan=0;this.found=[];this.foundStamp="";this.sortedAt=null;this.budgetScale=1;this.addModel=null;this.lod=0;this.budget=Js;this.replacedBuildings=new oe;this.replacedVenues=new oe;this.onReady=null;this.stats={found:0,kept:0,live:0,tooFar:0,overBudget:0,queued:0,rules:0,loadingNow:0,pendingNow:0,replaced:0};this.loader=new Lo(e);}get models(){let e=[];for(let t of this.entries.values())e.push(t.model);return e}update(e,t,o,r,i,a,l){this.wantKey!==this.modelKey&&(this.modelKey=this.wantKey,this.clear(i));let s=e.layout??{},c=s.minZoom??Bd,h=s.loadRadius??Cd,u=Math.max(s.keepRadius??vd,h),f=Math.min(1,Math.max(.25,(o.zoom-c)/3)),d=Math.max(8,Math.round((s.budget??Js)*this.budgetScale*f));this.budget=d,this.addModel=r;let p=s.maskReplaced!==false,b=performance.now();if(o.zoom<c){for(let M of [...this.entries.values()])M.model.retire(),M.model.grow<=0&&this.release(M,i);this.replacedBuildings.clear(),this.replacedVenues.clear();return}let m=o.center,g=this.lodFor(o.zoom,c);this.lod=g;let y="";for(let M of t.visibleTiles)y+=M.dataKey+(t.getTile(M)?.data?"+":"-");let A=this.rulesInScan;if(y!==this.tilesStamp){this.tilesStamp=y;let M=new oe;A=0;for(let T of t.visibleTiles){let P=t.getTile(T)?.data?.buckets?.[e.id];if(!P||!as(P))continue;let k=new Int16Array(P.anchors),O=T.bounds(),N=O.maxX-O.minX,G=O.maxY-O.minY;for(let R=0;R<P.props.length;R++){let W=P.props[R],j=Bt(W.file,NaN);if(!Number.isFinite(j))continue;let Z=String(W.kind??"model"),ee=Z==="rule"?`t-${W.rid}-${W.oid}`:`m-${W.mid}`;if(M.has(ee))continue;M.add(ee),Z==="rule"&&A++;let ge=O.minX+k[R*2]/P.extent*N,te=O.minY+k[R*2+1]/P.extent*G,X=_d(ge,te);this.known.set(ee,{id:ee,fileId:j,lng:X.lng,lat:X.lat,mercX:ge,mercY:te,altitude:Bt(W.alt,0),scale:Bt(W.scale,1),rotation:Bt(W.rx,0),tiltX:Bt(W.rz,0),tiltZ:Bt(W.ry,0),kind:Z==="rule"?"rule":"model",target:Lr(Z==="rule"?W.oid:W.replaces),replaces:p?Z==="rule"?Lr(W.oid):String(W.anchor??"replace")==="replace"?Lr(W.replaces):null:null});}}this.rulesInScan=A;}y!==this.foundStamp&&(this.foundStamp=y,this.found=[...this.known.values()],this.sortedAt=null);let B=this.found,x=new oe;for(let M of B)M.kind==="model"&&M.target!==null&&x.add(M.target);let w=111320,_=Math.cos(m.lat*Math.PI/180),C=M=>Math.hypot((M.lng-m.lng)*w*_,(M.lat-m.lat)*w);this.replacedBuildings.clear(),this.replacedVenues.clear();let v=new oe,E=[],D=0,F=0;(this.sortedAt===null||Math.hypot((m.lng-this.sortedAt.lng)*w*_,(m.lat-this.sortedAt.lat)*w)>xd)&&(B.sort((M,T)=>C(M)-C(T)),this.sortedAt={lng:m.lng,lat:m.lat});let S=0;for(let M of B){let T=C(M);if(T>u){D++;continue}if(M.kind==="rule"&&M.target!==null&&x.has(M.target)){let N=this.entries.get(M.id);N&&N.model.retire();continue}let P=this.entries.get(M.id);if(S>=d){F++,P&&P.model.retire();continue}S++,v.add(M.id);let k=()=>{if(M.replaces===null)return;this.replacedBuildings.add(M.replaces);let N=this.underBuilding.find(M,a);N!==null&&this.replacedBuildings.add(N);let G=this.underVenue.find(M,l);G!==null&&this.replacedVenues.add(G);},O=P;if(O){k(),O.distance=T,O.leftAt=0,O.model.revive(),g<O.lod&&!O.upgrading&&this.loading<Bi&&this.upgrade(O,g,r,i);continue}if(T>h){D++;continue}if(this.loading>=Bi){E.push(M),k();continue}k(),this.spawn(M,T,g,r);}for(let M of [...this.entries.values()])if(!v.has(M.placement.id)){if(M.leftAt===0){M.leftAt=b;continue}b-M.leftAt>wd&&M.model.retire();}for(let M of [...this.entries.values()])M.model.growTarget===0&&M.model.grow<=0&&this.release(M,i);if(this.known.size>4e3)for(let[M,T]of [...this.known.entries()])C(T)>u*3&&this.known.delete(M);let L=this.stats;L.found=B.length,L.kept=v.size,L.live=this.entries.size,L.tooFar=D,L.overBudget=F,L.queued=E.length,L.rules=A,L.loadingNow=this.loading,L.pendingNow=E.length,L.replaced=this.replacedBuildings.size,this.pending=E;}pump(){let e=this.addModel;if(this.stats.loadingNow=this.loading,this.stats.pendingNow=this.pending.length,!!e)for(;this.pending.length&&this.loading<Bi&&this.entries.size<this.budget;){let t=this.pending.shift();this.entries.has(t.id)||this.spawn(t,0,this.lod,e);}}lodFor(e,t){return e>=t+2?0:1}upgrade(e,t,o,r){let i=this.makeModel(e.placement,t,true);e.upgrading=i,this.loading++,i.load(()=>{this.loading--,this.pump(),this.entries.get(e.placement.id)===e&&(e.upgrading=null,i.isLoaded&&(r(e.model),e.model=i,e.lod=t,o(i),this.onReady?.()));});}makeModel(e,t,o){let r=new To({id:`objects3d-${e.id}`,url:`objects3d:${e.fileId}/${this.modelKey}/lod${t}`,fetchBytes:()=>this.loader.load(e.fileId,t,this.modelKey),coordinates:[e.lng,e.lat],altitude:e.altitude,scale:e.scale,rotation:e.rotation,rotationTiltX:e.tiltX,rotationTiltZ:e.tiltZ,growIn:!o});return o&&r.markGrown(),r}spawn(e,t,o,r,i=false){let a=this.makeModel(e,o,i);this.entries.set(e.id,{placement:e,model:a,distance:t,leftAt:0,lod:o,upgrading:null}),this.loading++,r(a),a.load(()=>{this.loading--,this.pump(),this.onReady?.();});}release(e,t){this.entries.delete(e.placement.id),e.upgrading=null,t(e.model);}setModelKey(e){this.wantKey=e??"";}clear(e){for(let t of [...this.entries.values()])this.release(t,e);this.replacedBuildings.clear(),this.replacedVenues.clear(),this.underBuilding.clear(),this.underVenue.clear();for(let t of Object.keys(this.stats))this.stats[t]=0;}},Bt=(n,e)=>{let t=typeof n=="number"?n:Number(n);return Number.isFinite(t)?t:e},Lr=n=>{let e=Bt(n,NaN);return Number.isFinite(e)?e:null};function _d(n,e){let t=n*360-180,o=Math.PI*(1-2*e),r=Math.atan(Math.sinh(o))*180/Math.PI;return {lng:t,lat:r}}function Ed(n,e,t,o,r,i,a,l){let s=(n-r)*(o-i)-(t-r)*(e-i),c=(n-a)*(i-l)-(r-a)*(e-l),h=(n-t)*(l-o)-(a-t)*(e-o),u=s<0||c<0||h<0,f=s>0||c>0||h>0;return !(u&&f)}var Md=200,Fd={center:"translate(-50%, -50%)",top:"translate(-50%, 0)",bottom:"translate(-50%, -100%)",left:"translate(0, -50%)",right:"translate(-100%, -50%)"},Ho=class{constructor(e){this.attachedTo=null;this.culled=false;this._visible=true;this._coordinates=e.coordinates,this.altitude=e.altitude??0,this.offset=e.offset??[0,0],this.anchorTransform=Fd[e.anchor??"bottom"],this.userData=e.userData??{};let t=e.element??document.createElement("div");e.element||(t.className="osmgl-marker-default",t.innerHTML=e.html??Dd),t.classList.add("osmgl-marker"),e.className&&t.classList.add(e.className),t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.willChange="transform",e.zIndex!==void 0&&(t.style.zIndex=String(e.zIndex)),this.element=t;}get coordinates(){return this._coordinates}setCoordinates(e){return this._coordinates=e,this}setVisible(e){return this._visible=e,this.applyVisibility(),this}get visible(){return this._visible}attach(e){this.attachedTo!==e&&(e.appendChild(this.element),this.attachedTo=e);}detach(){this.element.remove(),this.attachedTo=null;}update(e){let t=$(this._coordinates),o=e.worldSize,r=e.worldPxToPoint(ne(t.lng)*o,ie(t.lat)*o,this.altitude);if(!r){this.culled=true,this.applyVisibility();return}let i=Md;if(r.x<-i||r.y<-i||r.x>e.width+i||r.y>e.height+i){this.culled=true,this.applyVisibility();return}this.culled=false,this.applyVisibility(),this.element.style.transform=`translate(${Math.round(r.x+this.offset[0])}px, ${Math.round(r.y+this.offset[1])}px) ${this.anchorTransform}`;}applyVisibility(){this.element.style.display=this._visible&&!this.culled?"":"none";}},Dd='<svg width="24" height="32" viewBox="0 0 24 32" xmlns="http://www.w3.org/2000/svg"><path d="M12 0C5.4 0 0 5.4 0 12c0 9 12 20 12 20s12-11 12-20c0-6.6-5.4-12-12-12z" fill="#2f6df6"/><circle cx="12" cy="12" r="4.5" fill="#fff"/></svg>';var ko=class extends Ho{constructor(t){let o=document.createElement("div");o.className="osmgl-popup",o.style.pointerEvents="auto";let r=document.createElement("div");if(r.className="osmgl-popup-content",t.element?r.appendChild(t.element):r.innerHTML=t.html??"",o.appendChild(r),t.closeButton!==false){let a=document.createElement("button");a.className="osmgl-popup-close",a.type="button",a.setAttribute("aria-label","\u0417\u0430\u043A\u0440\u044B\u0442\u044C"),a.textContent="\xD7",o.appendChild(a);}let i=document.createElement("div");i.className="osmgl-popup-tip",o.appendChild(i);super({coordinates:t.coordinates,element:o,anchor:t.anchor??"bottom",offset:t.offset??[0,-12],altitude:t.altitude,zIndex:t.zIndex??10,className:t.className,userData:t.userData});this.onClose=null;this.content=r,this.closeOnClick=t.closeOnClick!==false,o.querySelector(".osmgl-popup-close")?.addEventListener("click",()=>this.onClose?.());}onCloseRequest(t){return this.onClose=t,this}setHtml(t){return this.content.innerHTML=t,this}setContent(t){return this.content.replaceChildren(t),this}};var Sd=[["\u0443\u043B\u0438\u0446\u0430","\u0443\u043B."],["\u0443\u043B\u0438\u0446\u044B","\u0443\u043B."],["\u0443\u043B\u0438\u0446\u0435","\u0443\u043B."],["\u043F\u0440\u043E\u0441\u043F\u0435\u043A\u0442","\u043F\u0440\u043E\u0441\u043F."],["\u043F\u0440\u043E\u0441\u043F\u0435\u043A\u0442\u0430","\u043F\u0440\u043E\u0441\u043F."],["\u043F\u0435\u0440\u0435\u0443\u043B\u043E\u043A","\u043F\u0435\u0440."],["\u043F\u0435\u0440\u0435\u0443\u043B\u043A\u0430","\u043F\u0435\u0440."],["\u043F\u0440\u043E\u0435\u0437\u0434","\u043F\u0440-\u0434"],["\u043F\u0440\u043E\u0435\u0437\u0434\u0430","\u043F\u0440-\u0434"],["\u043F\u043B\u043E\u0449\u0430\u0434\u044C","\u043F\u043B."],["\u043F\u043B\u043E\u0449\u0430\u0434\u0438","\u043F\u043B."],["\u0431\u0443\u043B\u044C\u0432\u0430\u0440","\u0431\u0443\u043B."],["\u0431\u0443\u043B\u044C\u0432\u0430\u0440\u0430","\u0431\u0443\u043B."],["\u043D\u0430\u0431\u0435\u0440\u0435\u0436\u043D\u0430\u044F","\u043D\u0430\u0431."],["\u043D\u0430\u0431\u0435\u0440\u0435\u0436\u043D\u043E\u0439","\u043D\u0430\u0431."],["\u0448\u043E\u0441\u0441\u0435","\u0448."],["\u0442\u0443\u043F\u0438\u043A","\u0442\u0443\u043F."],["\u0442\u0443\u043F\u0438\u043A\u0430","\u0442\u0443\u043F."],["\u043C\u0438\u043A\u0440\u043E\u0440\u0430\u0439\u043E\u043D","\u043C\u043A\u0440."],["\u043C\u0438\u043A\u0440\u043E\u0440\u0430\u0439\u043E\u043D\u0430","\u043C\u043A\u0440."],["\u043A\u04EF\u0447\u0430\u0438","\u043A."],["\u043A\u0443\u0447\u0430\u0438","\u043A."],["\u0445\u0438\u0451\u0431\u043E\u043D\u0438","\u0445\u0438\u0451\u0431."],["\u0448\u043E\u04B3\u0440\u043E\u04B3\u0438","\u0448\u043E\u04B3."],["\u0433\u0443\u0437\u0430\u0440\u0433\u043E\u04B3\u0438","\u0433\u0443\u0437."],["\u043C\u0430\u0439\u0434\u043E\u043D\u0438","\u043C\u0430\u0439\u0434."]],Xs=new Map(Sd);function Ci(n){let e=n.split(" ");if(e.length<2)return n;let t=false,o=e.map(i=>{let a=Xs.get(i.toLowerCase());return a?(t=true,i[0]===i[0].toUpperCase()?a[0].toUpperCase()+a.slice(1):a):i});return !t||!e.filter(i=>Xs.get(i.toLowerCase())===void 0).length?n:o.join(" ")}function xi(n,e){let t=[],o=[],r=[],i=[],a=[],l=e.textPlacement==="line",s=[],c=[],h=[];for(let u of n.features()){if(!Be(e.filter,u.properties))continue;let f=u.loadGeometry(),d=Td(u.type,f);if(!d)continue;let p=e.textField?vi(e.textField,u.properties):"",b=p&&e.abbreviate?Ci(p):p,m=e.iconImage?vi(e.iconImage,u.properties):"";if(!(!b&&!m)){if(l){let g=Ld(u.type,f);if(!g)continue;h.push({text:b,line:g});continue}t.push(d[0],d[1]),o.push(b),r.push(m),i.push(Hd(u.properties)),a.push(e.iconRotate&&Math.round(Number(u.properties[e.iconRotate]??0))||0);}}if(l){for(let{text:u,line:f}of Id(h)){c.push(s.length/2);for(let d of f)s.push(d);t.push(Math.round(f[0]),Math.round(f[1])),o.push(u),r.push(""),i.push(128),a.push(0);}c.push(s.length/2);}return o.length?{anchors:new Int16Array(t).buffer,texts:o,icons:r,priorities:new Uint8Array(i).buffer,rotations:new Int16Array(a).buffer,...l?{lines:new Int16Array(s).buffer,lineStarts:new Uint32Array(c).buffer}:{}}:null}function Id(n){let e=[],t=new Map,o=new Map,r=(i,a,l)=>`${i}\u241F${a}\u241F${l}`;for(let{text:i,line:a}of n){let l=r(i,a[0],a[1]),s=r(i,a[a.length-2],a[a.length-1]),c=t.get(s),h=o.get(l);if(h!==void 0){let u=e[h];if(u.line.push(...a.slice(2)),o.delete(l),o.set(r(i,u.line[u.line.length-2],u.line[u.line.length-1]),h),c!==void 0&&c!==h){let f=e[c];u.line.push(...f.line.slice(2)),f.line=[],t.delete(s),o.set(r(i,u.line[u.line.length-2],u.line[u.line.length-1]),h);}continue}if(c!==void 0){let u=e[c];u.line.unshift(...a.slice(0,a.length-2)),t.delete(s),t.set(r(i,u.line[0],u.line[1]),c);continue}t.set(l,e.length),o.set(s,e.length),e.push({text:i,line:a});}return e.filter(i=>i.line.length>=4)}function Ld(n,e){if(n!==2)return null;let t=null,o=0;for(let r of e){if(r.length<4)continue;let i=0;for(let a=0;a+3<r.length;a+=2)i+=Math.hypot(r[a+2]-r[a],r[a+3]-r[a+1]);i>o&&(o=i,t=r);}return t}function Td(n,e){if(!e.length)return null;if(n===1){let a=e[0];return a.length>=2?[a[0],a[1]]:null}if(n===2){let a=-1,l=0,s=0;for(let c of e)for(let h=0;h+3<c.length;h+=2){let u=c[h+2]-c[h],f=c[h+3]-c[h+1],d=u*u+f*f;d>a&&(a=d,l=c[h]+u/2,s=c[h+1]+f/2);}return a>0?[Math.round(l),Math.round(s)]:null}let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let a of e)for(let l=0;l<a.length;l+=2)a[l]<t&&(t=a[l]),a[l]>r&&(r=a[l]),a[l+1]<o&&(o=a[l+1]),a[l+1]>i&&(i=a[l+1]);return isFinite(t)?[Math.round((t+r)/2),Math.round((o+i)/2)]:null}function Hd(n){let e=n.rank;return typeof e=="number"&&isFinite(e)?Math.max(0,255-Math.min(e,255)):128}function vi(n,e){let t=Array.isArray(n)?n:[n];for(let o of t){let r=true,a=o.replace(/\{([^}]+)\}/g,(l,s)=>{let c=e[s];return c==null||c===""?(r=false,""):String(c)}).trim();if(r&&a)return a}return ""}function js(n,e){let t=[],o=[];for(let r=0;r<n.length;r++){let i=n.feature(r);if(i.type===1&&Be(e,i.properties))for(let a of i.loadGeometry())for(let l=0;l+1<a.length;l+=2)t.push(a[l],a[l+1]),o.push(i.properties);}return o.length?{anchors:Int16Array.from(t).buffer,props:o}:null}function kd(){let n=typeof self<"u"?self.origin:void 0;return n&&n!=="null"&&!n.startsWith("blob:")?n+"/":void 0}async function Ys(n,e){let t=performance.now(),o=kd(),r=await fetch(n.url,{signal:e,credentials:"same-origin",...o?{referrer:o}:{}}),i=(g,y,A,B,x=0)=>({type:"loaded",id:n.id,buckets:{},timing:{fetchMs:B,parseMs:x},diag:{status:g,bytes:y,layers:A,built:0}});if(!r.ok){if(r.status===404||r.status===204)return i(r.status,0,[],performance.now()-t);throw new Error(`HTTP ${r.status} \u0434\u043B\u044F ${n.url}`)}let a=await r.arrayBuffer(),l=performance.now()-t;if(a.byteLength===0)return i(r.status,0,[],l);let s=performance.now(),c=new no(a),h=Object.keys(c.layers),u={},f={},d=new Set,p=[],m=n.plan.some(g=>g.type==="surface"&&(g.elevation??0)>0)&&n.plan.some(g=>g.type==="line"&&g.ground)?Sn(n.metersPerTile):void 0;for(let g of n.plan){if(!Rd(g,n.zoom,n.sourceMaxZoom))continue;let y=c.layers[g.sourceLayer];if(!y)continue;let A=Gd(n.zoom,y.extent);try{if(g.splitBy){let x=Od(y,g.splitBy,g.filter);if(!x.length)continue;let w=f[g.splitBy]??(f[g.splitBy]=[]);for(let _ of x){w.includes(_)||w.push(_);let C={...g,splitBy:void 0,filter:Vd(g.filter,g.splitBy,_)},v=wi(C,y,A,n.metersPerTile,m);v&&(u[Je(g.id,_)]=v);}continue}if(g.network&&g.type==="line"){for(let x of zd(y,g.filter)){let w=wi(g,y,A,n.metersPerTile,m,x);w&&(u[Je(g.id,x)]=w,d.add(x));}continue}let B=wi(g,y,A,n.metersPerTile,m);B&&(u[g.id]=B);}catch(B){p.push(`${g.id}: ${B instanceof Error?B.message:String(B)}`);}}return {type:"loaded",id:n.id,buckets:u,...Object.keys(f).length?{splits:f}:{},...d.size?{levels:[...d].sort((g,y)=>g-y)}:{},timing:{fetchMs:l,parseMs:performance.now()-s},diag:{status:r.status,bytes:a.byteLength,layers:h,built:Object.keys(u).length,...p.length?{failed:p}:{}}}}function Pd(n){return e=>{let t=e.on;if(typeof t!="string"||!t)return 0;let o=0;for(let r of t.split(",")){let i=n[r];typeof i=="number"&&i>o&&(o=i);}return o}}function Rd(n,e,t){let o=e-1,r=e<t?e+1:24;return !(n.maxzoom<o||n.minzoom>r)}function Gd(n,e){return n<=6?Math.max(64,e/24):0}function wi(n,e,t,o,r,i){{if(n.type==="fill"){let l=o>0?o/e.extent:0,s=n.cornerRadius&&l>0?{radius:n.cornerRadius/l,segments:n.cornerSegments,extent:e.extent,minCutRatio:0,maxChord:ya/l}:void 0,c=fn(e,n.filter,t,s,n.clipToTile===true,e.extent);return c?{kind:"fill",...c,extent:e.extent}:null}if(n.type==="surface"){let l=Dn(e,e.extent,n.filter,{metersPerUnit:o>0?o/e.extent:0,maxSegment:t,elevation:n.elevation??0,base:n.base,bevel:n.bevel,weld:n.weld,bevelDrop:n.bevelDrop,cornerRadius:n.cornerRadius,cornerSegments:n.cornerSegments,...r?{onShapes:s=>In(r,s,n.elevation??0,e.extent)}:{},...n.groundBy?{liftBy:Pd(n.groundBy)}:{}});return l?{kind:"surface",...l}:null}if(n.type==="line"){let l=Tn(e,n.filter,t,n.ground?r:void 0,o>0?o/e.extent:0,{level:i});return l?{kind:"line",...l,extent:e.extent}:null}if(n.type==="model"){let l=js(e,n.filter);return l?{kind:"placement",...l,extent:e.extent}:null}if(n.type==="symbol"){let l=xi(e,{filter:n.filter,textField:n.textField,iconImage:n.iconImage,iconRotate:n.iconRotate,textPlacement:n.textPlacement,abbreviate:n.abbreviate});return l?{kind:"symbol",...l,extent:e.extent}:null}let a=ln(e,e.extent,n.filter,{metersPerUnit:o>0?o/e.extent:0,cornerRadius:n.cornerRadius,cornerSegments:n.cornerSegments});return a?{kind:"fill-extrusion",vertices:a.vertices,indices:a.indices,featureIds:a.featureIds,vertexCount:a.vertexCount,indexCount:a.indexCount,extent:a.extent}:null}}function Od(n,e,t){let o=[];for(let r of n.features()){if(!Be(t,r.properties))continue;let i=r.properties[e];typeof i!="string"&&typeof i!="number"||o.includes(i)||o.push(i);}return o.sort((r,i)=>typeof r=="number"&&typeof i=="number"?r-i:String(r).localeCompare(String(i))),o}function zd(n,e){let t=[];for(let o of n.features()){if(!Be(e,o.properties))continue;let r=yt(o.properties);t.includes(r)||t.push(r);}return t.sort((o,r)=>o-r)}function Vd(n,e,t){let o=["==",e,t];return n?["all",n,o]:o}var _i='"use strict";(()=>{var ur=Object.create;var Kt=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var cr=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,ar=Object.prototype.hasOwnProperty;var hr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var pr=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of cr(e))!ar.call(t,i)&&i!==n&&Kt(t,i,{get:()=>e[i],enumerable:!(r=lr(e,i))||r.enumerable});return t};var mr=(t,e,n)=>(n=t!=null?ur(fr(t)):{},pr(e||!t||!t.__esModule?Kt(n,"default",{value:t,enumerable:!0}):n,t));var An=hr((Gt,Nt)=>{(function(t,e){typeof Gt=="object"&&typeof Nt<"u"?Nt.exports=e():typeof define=="function"&&define.amd?define(e):(t=typeof globalThis<"u"?globalThis:t||self,t.polygonClipping=e())})(Gt,function(){"use strict";function t(y,o){var u={label:0,sent:function(){if(h[0]&1)throw h[1];return h[1]},trys:[],ops:[]},f,p,h,S;return S={next:v(0),throw:v(1),return:v(2)},typeof Symbol=="function"&&(S[Symbol.iterator]=function(){return this}),S;function v(M){return function(V){return F([M,V])}}function F(M){if(f)throw new TypeError("Generator is already executing.");for(;u;)try{if(f=1,p&&(h=M[0]&2?p.return:M[0]?p.throw||((h=p.return)&&h.call(p),0):p.next)&&!(h=h.call(p,M[1])).done)return h;switch(p=0,h&&(M=[M[0]&2,h.value]),M[0]){case 0:case 1:h=M;break;case 4:return u.label++,{value:M[1],done:!1};case 5:u.label++,p=M[1],M=[0];continue;case 7:M=u.ops.pop(),u.trys.pop();continue;default:if(h=u.trys,!(h=h.length>0&&h[h.length-1])&&(M[0]===6||M[0]===2)){u=0;continue}if(M[0]===3&&(!h||M[1]>h[0]&&M[1]<h[3])){u.label=M[1];break}if(M[0]===6&&u.label<h[1]){u.label=h[1],h=M;break}if(h&&u.label<h[2]){u.label=h[2],u.ops.push(M);break}h[2]&&u.ops.pop(),u.trys.pop();continue}M=o.call(y,u)}catch(V){M=[6,V],p=0}finally{f=h=0}if(M[0]&5)throw M[1];return{value:M[0]?M[1]:void 0,done:!0}}}var e=function(){function y(o,u){this.next=null,this.key=o,this.data=u,this.left=null,this.right=null}return y}();function n(y,o){return y>o?1:y<o?-1:0}function r(y,o,u){for(var f=new e(null,null),p=f,h=f;;){var S=u(y,o.key);if(S<0){if(o.left===null)break;if(u(y,o.left.key)<0){var v=o.left;if(o.left=v.right,v.right=o,o=v,o.left===null)break}h.left=o,h=o,o=o.left}else if(S>0){if(o.right===null)break;if(u(y,o.right.key)>0){var v=o.right;if(o.right=v.left,v.left=o,o=v,o.right===null)break}p.right=o,p=o,o=o.right}else break}return p.right=o.left,h.left=o.right,o.left=f.right,o.right=f.left,o}function i(y,o,u,f){var p=new e(y,o);if(u===null)return p.left=p.right=null,p;u=r(y,u,f);var h=f(y,u.key);return h<0?(p.left=u.left,p.right=u,u.left=null):h>=0&&(p.right=u.right,p.left=u,u.right=null),p}function s(y,o,u){var f=null,p=null;if(o){o=r(y,o,u);var h=u(o.key,y);h===0?(f=o.left,p=o.right):h<0?(p=o.right,o.right=null,f=o):(f=o.left,o.left=null,p=o)}return{left:f,right:p}}function l(y,o,u){return o===null?y:(y===null||(o=r(y.key,o,u),o.left=y),o)}function c(y,o,u,f,p){if(y){f(""+o+(u?"\\u2514\\u2500\\u2500 ":"\\u251C\\u2500\\u2500 ")+p(y)+`\n`);var h=o+(u?" ":"\\u2502 ");y.left&&c(y.left,h,!1,f,p),y.right&&c(y.right,h,!0,f,p)}}var a=function(){function y(o){o===void 0&&(o=n),this._root=null,this._size=0,this._comparator=o}return y.prototype.insert=function(o,u){return this._size++,this._root=i(o,u,this._root,this._comparator)},y.prototype.add=function(o,u){var f=new e(o,u);this._root===null&&(f.left=f.right=null,this._size++,this._root=f);var p=this._comparator,h=r(o,this._root,p),S=p(o,h.key);return S===0?this._root=h:(S<0?(f.left=h.left,f.right=h,h.left=null):S>0&&(f.right=h.right,f.left=h,h.right=null),this._size++,this._root=f),this._root},y.prototype.remove=function(o){this._root=this._remove(o,this._root,this._comparator)},y.prototype._remove=function(o,u,f){var p;if(u===null)return null;u=r(o,u,f);var h=f(o,u.key);return h===0?(u.left===null?p=u.right:(p=r(o,u.left,f),p.right=u.right),this._size--,p):u},y.prototype.pop=function(){var o=this._root;if(o){for(;o.left;)o=o.left;return this._root=r(o.key,this._root,this._comparator),this._root=this._remove(o.key,this._root,this._comparator),{key:o.key,data:o.data}}return null},y.prototype.findStatic=function(o){for(var u=this._root,f=this._comparator;u;){var p=f(o,u.key);if(p===0)return u;p<0?u=u.left:u=u.right}return null},y.prototype.find=function(o){return this._root&&(this._root=r(o,this._root,this._comparator),this._comparator(o,this._root.key)!==0)?null:this._root},y.prototype.contains=function(o){for(var u=this._root,f=this._comparator;u;){var p=f(o,u.key);if(p===0)return!0;p<0?u=u.left:u=u.right}return!1},y.prototype.forEach=function(o,u){for(var f=this._root,p=[],h=!1;!h;)f!==null?(p.push(f),f=f.left):p.length!==0?(f=p.pop(),o.call(u,f),f=f.right):h=!0;return this},y.prototype.range=function(o,u,f,p){for(var h=[],S=this._comparator,v=this._root,F;h.length!==0||v;)if(v)h.push(v),v=v.left;else{if(v=h.pop(),F=S(v.key,u),F>0)break;if(S(v.key,o)>=0&&f.call(p,v))return this;v=v.right}return this},y.prototype.keys=function(){var o=[];return this.forEach(function(u){var f=u.key;return o.push(f)}),o},y.prototype.values=function(){var o=[];return this.forEach(function(u){var f=u.data;return o.push(f)}),o},y.prototype.min=function(){return this._root?this.minNode(this._root).key:null},y.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},y.prototype.minNode=function(o){if(o===void 0&&(o=this._root),o)for(;o.left;)o=o.left;return o},y.prototype.maxNode=function(o){if(o===void 0&&(o=this._root),o)for(;o.right;)o=o.right;return o},y.prototype.at=function(o){for(var u=this._root,f=!1,p=0,h=[];!f;)if(u)h.push(u),u=u.left;else if(h.length>0){if(u=h.pop(),p===o)return u;p++,u=u.right}else f=!0;return null},y.prototype.next=function(o){var u=this._root,f=null;if(o.right){for(f=o.right;f.left;)f=f.left;return f}for(var p=this._comparator;u;){var h=p(o.key,u.key);if(h===0)break;h<0?(f=u,u=u.left):u=u.right}return f},y.prototype.prev=function(o){var u=this._root,f=null;if(o.left!==null){for(f=o.left;f.right;)f=f.right;return f}for(var p=this._comparator;u;){var h=p(o.key,u.key);if(h===0)break;h<0?u=u.left:(f=u,u=u.right)}return f},y.prototype.clear=function(){return this._root=null,this._size=0,this},y.prototype.toList=function(){return g(this._root)},y.prototype.load=function(o,u,f){u===void 0&&(u=[]),f===void 0&&(f=!1);var p=o.length,h=this._comparator;if(f&&E(o,u,0,p-1,h),this._root===null)this._root=m(o,u,0,p),this._size=p;else{var S=b(this.toList(),x(o,u),h);p=this._size+p,this._root=d({head:S},0,p)}return this},y.prototype.isEmpty=function(){return this._root===null},Object.defineProperty(y.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(y.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),y.prototype.toString=function(o){o===void 0&&(o=function(f){return String(f.key)});var u=[];return c(this._root,"",!0,function(f){return u.push(f)},o),u.join("")},y.prototype.update=function(o,u,f){var p=this._comparator,h=s(o,this._root,p),S=h.left,v=h.right;p(o,u)<0?v=i(u,f,v,p):S=i(u,f,S,p),this._root=l(S,v,p)},y.prototype.split=function(o){return s(o,this._root,this._comparator)},y.prototype[Symbol.iterator]=function(){var o,u,f;return t(this,function(p){switch(p.label){case 0:o=this._root,u=[],f=!1,p.label=1;case 1:return f?[3,6]:o===null?[3,2]:(u.push(o),o=o.left,[3,5]);case 2:return u.length===0?[3,4]:(o=u.pop(),[4,o]);case 3:return p.sent(),o=o.right,[3,5];case 4:f=!0,p.label=5;case 5:return[3,1];case 6:return[2]}})},y}();function m(y,o,u,f){var p=f-u;if(p>0){var h=u+Math.floor(p/2),S=y[h],v=o[h],F=new e(S,v);return F.left=m(y,o,u,h),F.right=m(y,o,h+1,f),F}return null}function x(y,o){for(var u=new e(null,null),f=u,p=0;p<y.length;p++)f=f.next=new e(y[p],o[p]);return f.next=null,u.next}function g(y){for(var o=y,u=[],f=!1,p=new e(null,null),h=p;!f;)o?(u.push(o),o=o.left):u.length>0?(o=h=h.next=u.pop(),o=o.right):f=!0;return h.next=null,p.next}function d(y,o,u){var f=u-o;if(f>0){var p=o+Math.floor(f/2),h=d(y,o,p),S=y.head;return S.left=h,y.head=y.head.next,S.right=d(y,p+1,u),S}return null}function b(y,o,u){for(var f=new e(null,null),p=f,h=y,S=o;h!==null&&S!==null;)u(h.key,S.key)<0?(p.next=h,h=h.next):(p.next=S,S=S.next),p=p.next;return h!==null?p.next=h:S!==null&&(p.next=S),f.next}function E(y,o,u,f,p){if(!(u>=f)){for(var h=y[u+f>>1],S=u-1,v=f+1;;){do S++;while(p(y[S],h)<0);do v--;while(p(y[v],h)>0);if(S>=v)break;var F=y[S];y[S]=y[v],y[v]=F,F=o[S],o[S]=o[v],o[v]=F}E(y,o,u,v,p),E(y,o,v+1,f,p)}}let A=(y,o)=>y.ll.x<=o.x&&o.x<=y.ur.x&&y.ll.y<=o.y&&o.y<=y.ur.y,_=(y,o)=>{if(o.ur.x<y.ll.x||y.ur.x<o.ll.x||o.ur.y<y.ll.y||y.ur.y<o.ll.y)return null;let u=y.ll.x<o.ll.x?o.ll.x:y.ll.x,f=y.ur.x<o.ur.x?y.ur.x:o.ur.x,p=y.ll.y<o.ll.y?o.ll.y:y.ll.y,h=y.ur.y<o.ur.y?y.ur.y:o.ur.y;return{ll:{x:u,y:p},ur:{x:f,y:h}}},R=Number.EPSILON;R===void 0&&(R=Math.pow(2,-52));let L=R*R,k=(y,o)=>{if(-R<y&&y<R&&-R<o&&o<R)return 0;let u=y-o;return u*u<L*y*o?0:y<o?-1:1};class T{constructor(){this.reset()}reset(){this.xRounder=new O,this.yRounder=new O}round(o,u){return{x:this.xRounder.round(o),y:this.yRounder.round(u)}}}class O{constructor(){this.tree=new a,this.round(0)}round(o){let u=this.tree.add(o),f=this.tree.prev(u);if(f!==null&&k(u.key,f.key)===0)return this.tree.remove(o),f.key;let p=this.tree.next(u);return p!==null&&k(u.key,p.key)===0?(this.tree.remove(o),p.key):o}}let D=new T,U=11102230246251565e-32,P=134217729,C=(3+8*U)*U;function Y(y,o,u,f,p){let h,S,v,F,M=o[0],V=f[0],w=0,I=0;V>M==V>-M?(h=M,M=o[++w]):(h=V,V=f[++I]);let B=0;if(w<y&&I<u)for(V>M==V>-M?(S=M+h,v=h-(S-M),M=o[++w]):(S=V+h,v=h-(S-V),V=f[++I]),h=S,v!==0&&(p[B++]=v);w<y&&I<u;)V>M==V>-M?(S=h+M,F=S-h,v=h-(S-F)+(M-F),M=o[++w]):(S=h+V,F=S-h,v=h-(S-F)+(V-F),V=f[++I]),h=S,v!==0&&(p[B++]=v);for(;w<y;)S=h+M,F=S-h,v=h-(S-F)+(M-F),M=o[++w],h=S,v!==0&&(p[B++]=v);for(;I<u;)S=h+V,F=S-h,v=h-(S-F)+(V-F),V=f[++I],h=S,v!==0&&(p[B++]=v);return(h!==0||B===0)&&(p[B++]=h),B}function Q(y,o){let u=o[0];for(let f=1;f<y;f++)u+=o[f];return u}function Z(y){return new Float64Array(y)}let re=(3+16*U)*U,X=(2+12*U)*U,$=(9+64*U)*U*U,z=Z(4),N=Z(8),q=Z(12),te=Z(16),K=Z(4);function oe(y,o,u,f,p,h,S){let v,F,M,V,w,I,B,H,G,W,j,ne,ae,ue,he,pe,ge,me,Se=y-p,Ee=u-p,Me=o-h,Re=f-h;ue=Se*Re,I=P*Se,B=I-(I-Se),H=Se-B,I=P*Re,G=I-(I-Re),W=Re-G,he=H*W-(ue-B*G-H*G-B*W),pe=Me*Ee,I=P*Me,B=I-(I-Me),H=Me-B,I=P*Ee,G=I-(I-Ee),W=Ee-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,z[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,z[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,z[2]=ne-(me-w)+(j-w),z[3]=me;let ke=Q(4,z),Je=X*S;if(ke>=Je||-ke>=Je||(w=y-Se,v=y-(Se+w)+(w-p),w=u-Ee,M=u-(Ee+w)+(w-p),w=o-Me,F=o-(Me+w)+(w-h),w=f-Re,V=f-(Re+w)+(w-h),v===0&&F===0&&M===0&&V===0)||(Je=$*S+C*Math.abs(ke),ke+=Se*V+Re*v-(Me*M+Ee*F),ke>=Je||-ke>=Je))return ke;ue=v*Re,I=P*v,B=I-(I-v),H=v-B,I=P*Re,G=I-(I-Re),W=Re-G,he=H*W-(ue-B*G-H*G-B*W),pe=F*Ee,I=P*F,B=I-(I-F),H=F-B,I=P*Ee,G=I-(I-Ee),W=Ee-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,K[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,K[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,K[2]=ne-(me-w)+(j-w),K[3]=me;let ir=Y(4,z,4,K,N);ue=Se*V,I=P*Se,B=I-(I-Se),H=Se-B,I=P*V,G=I-(I-V),W=V-G,he=H*W-(ue-B*G-H*G-B*W),pe=Me*M,I=P*Me,B=I-(I-Me),H=Me-B,I=P*M,G=I-(I-M),W=M-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,K[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,K[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,K[2]=ne-(me-w)+(j-w),K[3]=me;let or=Y(ir,N,4,K,q);ue=v*V,I=P*v,B=I-(I-v),H=v-B,I=P*V,G=I-(I-V),W=V-G,he=H*W-(ue-B*G-H*G-B*W),pe=F*M,I=P*F,B=I-(I-F),H=F-B,I=P*M,G=I-(I-M),W=M-G,ge=H*W-(pe-B*G-H*G-B*W),j=he-ge,w=he-j,K[0]=he-(j+w)+(w-ge),ne=ue+j,w=ne-ue,ae=ue-(ne-w)+(j-w),j=ae-pe,w=ae-j,K[1]=ae-(j+w)+(w-pe),me=ne+j,w=me-ne,K[2]=ne-(me-w)+(j-w),K[3]=me;let sr=Y(or,q,4,K,te);return te[sr-1]}function ee(y,o,u,f,p,h){let S=(o-h)*(u-p),v=(y-p)*(f-h),F=S-v,M=Math.abs(S+v);return Math.abs(F)>=re*M?F:-oe(y,o,u,f,p,h,M)}let J=(y,o)=>y.x*o.y-y.y*o.x,fe=(y,o)=>y.x*o.x+y.y*o.y,be=(y,o,u)=>{let f=ee(y.x,y.y,o.x,o.y,u.x,u.y);return f>0?-1:f<0?1:0},de=y=>Math.sqrt(fe(y,y)),Fe=(y,o,u)=>{let f={x:o.x-y.x,y:o.y-y.y},p={x:u.x-y.x,y:u.y-y.y};return J(p,f)/de(p)/de(f)},Ce=(y,o,u)=>{let f={x:o.x-y.x,y:o.y-y.y},p={x:u.x-y.x,y:u.y-y.y};return fe(p,f)/de(p)/de(f)},Le=(y,o,u)=>o.y===0?null:{x:y.x+o.x/o.y*(u-y.y),y:u},Ve=(y,o,u)=>o.x===0?null:{x:u,y:y.y+o.y/o.x*(u-y.x)},we=(y,o,u,f)=>{if(o.x===0)return Ve(u,f,y.x);if(f.x===0)return Ve(y,o,u.x);if(o.y===0)return Le(u,f,y.y);if(f.y===0)return Le(y,o,u.y);let p=J(o,f);if(p==0)return null;let h={x:u.x-y.x,y:u.y-y.y},S=J(h,o)/p,v=J(h,f)/p,F=y.x+v*o.x,M=u.x+S*f.x,V=y.y+v*o.y,w=u.y+S*f.y,I=(F+M)/2,B=(V+w)/2;return{x:I,y:B}};class se{static compare(o,u){let f=se.comparePoints(o.point,u.point);return f!==0?f:(o.point!==u.point&&o.link(u),o.isLeft!==u.isLeft?o.isLeft?1:-1:xe.compare(o.segment,u.segment))}static comparePoints(o,u){return o.x<u.x?-1:o.x>u.x?1:o.y<u.y?-1:o.y>u.y?1:0}constructor(o,u){o.events===void 0?o.events=[this]:o.events.push(this),this.point=o,this.isLeft=u}link(o){if(o.point===this.point)throw new Error("Tried to link already linked events");let u=o.point.events;for(let f=0,p=u.length;f<p;f++){let h=u[f];this.point.events.push(h),h.point=this.point}this.checkForConsuming()}checkForConsuming(){let o=this.point.events.length;for(let u=0;u<o;u++){let f=this.point.events[u];if(f.segment.consumedBy===void 0)for(let p=u+1;p<o;p++){let h=this.point.events[p];h.consumedBy===void 0&&f.otherSE.point.events===h.otherSE.point.events&&f.segment.consume(h.segment)}}}getAvailableLinkedEvents(){let o=[];for(let u=0,f=this.point.events.length;u<f;u++){let p=this.point.events[u];p!==this&&!p.segment.ringOut&&p.segment.isInResult()&&o.push(p)}return o}getLeftmostComparator(o){let u=new Map,f=p=>{let h=p.otherSE;u.set(p,{sine:Fe(this.point,o.point,h.point),cosine:Ce(this.point,o.point,h.point)})};return(p,h)=>{u.has(p)||f(p),u.has(h)||f(h);let{sine:S,cosine:v}=u.get(p),{sine:F,cosine:M}=u.get(h);return S>=0&&F>=0?v<M?1:v>M?-1:0:S<0&&F<0?v<M?-1:v>M?1:0:F<S?-1:F>S?1:0}}}let Pe=0;class xe{static compare(o,u){let f=o.leftSE.point.x,p=u.leftSE.point.x,h=o.rightSE.point.x,S=u.rightSE.point.x;if(S<f)return 1;if(h<p)return-1;let v=o.leftSE.point.y,F=u.leftSE.point.y,M=o.rightSE.point.y,V=u.rightSE.point.y;if(f<p){if(F<v&&F<M)return 1;if(F>v&&F>M)return-1;let w=o.comparePoint(u.leftSE.point);if(w<0)return 1;if(w>0)return-1;let I=u.comparePoint(o.rightSE.point);return I!==0?I:-1}if(f>p){if(v<F&&v<V)return-1;if(v>F&&v>V)return 1;let w=u.comparePoint(o.leftSE.point);if(w!==0)return w;let I=o.comparePoint(u.rightSE.point);return I<0?1:I>0?-1:1}if(v<F)return-1;if(v>F)return 1;if(h<S){let w=u.comparePoint(o.rightSE.point);if(w!==0)return w}if(h>S){let w=o.comparePoint(u.rightSE.point);if(w<0)return 1;if(w>0)return-1}if(h!==S){let w=M-v,I=h-f,B=V-F,H=S-p;if(w>I&&B<H)return 1;if(w<I&&B>H)return-1}return h>S?1:h<S||M<V?-1:M>V?1:o.id<u.id?-1:o.id>u.id?1:0}constructor(o,u,f,p){this.id=++Pe,this.leftSE=o,o.segment=this,o.otherSE=u,this.rightSE=u,u.segment=this,u.otherSE=o,this.rings=f,this.windings=p}static fromRing(o,u,f){let p,h,S,v=se.comparePoints(o,u);if(v<0)p=o,h=u,S=1;else if(v>0)p=u,h=o,S=-1;else throw new Error(`Tried to create degenerate segment at [${o.x}, ${o.y}]`);let F=new se(p,!0),M=new se(h,!1);return new xe(F,M,[f],[S])}replaceRightSE(o){this.rightSE=o,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){let o=this.leftSE.point.y,u=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:o<u?o:u},ur:{x:this.rightSE.point.x,y:o>u?o:u}}}vector(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}isAnEndpoint(o){return o.x===this.leftSE.point.x&&o.y===this.leftSE.point.y||o.x===this.rightSE.point.x&&o.y===this.rightSE.point.y}comparePoint(o){if(this.isAnEndpoint(o))return 0;let u=this.leftSE.point,f=this.rightSE.point,p=this.vector();if(u.x===f.x)return o.x===u.x?0:o.x<u.x?1:-1;let h=(o.y-u.y)/p.y,S=u.x+h*p.x;if(o.x===S)return 0;let v=(o.x-u.x)/p.x,F=u.y+v*p.y;return o.y===F?0:o.y<F?-1:1}getIntersection(o){let u=this.bbox(),f=o.bbox(),p=_(u,f);if(p===null)return null;let h=this.leftSE.point,S=this.rightSE.point,v=o.leftSE.point,F=o.rightSE.point,M=A(u,v)&&this.comparePoint(v)===0,V=A(f,h)&&o.comparePoint(h)===0,w=A(u,F)&&this.comparePoint(F)===0,I=A(f,S)&&o.comparePoint(S)===0;if(V&&M)return I&&!w?S:!I&&w?F:null;if(V)return w&&h.x===F.x&&h.y===F.y?null:h;if(M)return I&&S.x===v.x&&S.y===v.y?null:v;if(I&&w)return null;if(I)return S;if(w)return F;let B=we(h,this.vector(),v,o.vector());return B===null||!A(p,B)?null:D.round(B.x,B.y)}split(o){let u=[],f=o.events!==void 0,p=new se(o,!0),h=new se(o,!1),S=this.rightSE;this.replaceRightSE(h),u.push(h),u.push(p);let v=new xe(p,S,this.rings.slice(),this.windings.slice());return se.comparePoints(v.leftSE.point,v.rightSE.point)>0&&v.swapEvents(),se.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),f&&(p.checkForConsuming(),h.checkForConsuming()),u}swapEvents(){let o=this.rightSE;this.rightSE=this.leftSE,this.leftSE=o,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let u=0,f=this.windings.length;u<f;u++)this.windings[u]*=-1}consume(o){let u=this,f=o;for(;u.consumedBy;)u=u.consumedBy;for(;f.consumedBy;)f=f.consumedBy;let p=xe.compare(u,f);if(p!==0){if(p>0){let h=u;u=f,f=h}if(u.prev===f){let h=u;u=f,f=h}for(let h=0,S=f.rings.length;h<S;h++){let v=f.rings[h],F=f.windings[h],M=u.rings.indexOf(v);M===-1?(u.rings.push(v),u.windings.push(F)):u.windings[M]+=F}f.rings=null,f.windings=null,f.consumedBy=u,f.leftSE.consumedBy=u.leftSE,f.rightSE.consumedBy=u.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{let o=this.prev.consumedBy||this.prev;this._beforeState=o.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;let o=this.beforeState();this._afterState={rings:o.rings.slice(0),windings:o.windings.slice(0),multiPolys:[]};let u=this._afterState.rings,f=this._afterState.windings,p=this._afterState.multiPolys;for(let v=0,F=this.rings.length;v<F;v++){let M=this.rings[v],V=this.windings[v],w=u.indexOf(M);w===-1?(u.push(M),f.push(V)):f[w]+=V}let h=[],S=[];for(let v=0,F=u.length;v<F;v++){if(f[v]===0)continue;let M=u[v],V=M.poly;if(S.indexOf(V)===-1)if(M.isExterior)h.push(V);else{S.indexOf(V)===-1&&S.push(V);let w=h.indexOf(M.poly);w!==-1&&h.splice(w,1)}}for(let v=0,F=h.length;v<F;v++){let M=h[v].multiPoly;p.indexOf(M)===-1&&p.push(M)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;let o=this.beforeState().multiPolys,u=this.afterState().multiPolys;switch(ve.type){case"union":{let f=o.length===0,p=u.length===0;this._isInResult=f!==p;break}case"intersection":{let f,p;o.length<u.length?(f=o.length,p=u.length):(f=u.length,p=o.length),this._isInResult=p===ve.numMultiPolys&&f<p;break}case"xor":{let f=Math.abs(o.length-u.length);this._isInResult=f%2===1;break}case"difference":{let f=p=>p.length===1&&p[0].isSubject;this._isInResult=f(o)!==f(u);break}default:throw new Error(`Unrecognized operation type found ${ve.type}`)}return this._isInResult}}class Be{constructor(o,u,f){if(!Array.isArray(o)||o.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=u,this.isExterior=f,this.segments=[],typeof o[0][0]!="number"||typeof o[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let p=D.round(o[0][0],o[0][1]);this.bbox={ll:{x:p.x,y:p.y},ur:{x:p.x,y:p.y}};let h=p;for(let S=1,v=o.length;S<v;S++){if(typeof o[S][0]!="number"||typeof o[S][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let F=D.round(o[S][0],o[S][1]);F.x===h.x&&F.y===h.y||(this.segments.push(xe.fromRing(h,F,this)),F.x<this.bbox.ll.x&&(this.bbox.ll.x=F.x),F.y<this.bbox.ll.y&&(this.bbox.ll.y=F.y),F.x>this.bbox.ur.x&&(this.bbox.ur.x=F.x),F.y>this.bbox.ur.y&&(this.bbox.ur.y=F.y),h=F)}(p.x!==h.x||p.y!==h.y)&&this.segments.push(xe.fromRing(h,p,this))}getSweepEvents(){let o=[];for(let u=0,f=this.segments.length;u<f;u++){let p=this.segments[u];o.push(p.leftSE),o.push(p.rightSE)}return o}}class Oe{constructor(o,u){if(!Array.isArray(o))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new Be(o[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let f=1,p=o.length;f<p;f++){let h=new Be(o[f],this,!1);h.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=h.bbox.ll.x),h.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=h.bbox.ll.y),h.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=h.bbox.ur.x),h.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=h.bbox.ur.y),this.interiorRings.push(h)}this.multiPoly=u}getSweepEvents(){let o=this.exteriorRing.getSweepEvents();for(let u=0,f=this.interiorRings.length;u<f;u++){let p=this.interiorRings[u].getSweepEvents();for(let h=0,S=p.length;h<S;h++)o.push(p[h])}return o}}class De{constructor(o,u){if(!Array.isArray(o))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof o[0][0][0]=="number"&&(o=[o])}catch{}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(let f=0,p=o.length;f<p;f++){let h=new Oe(o[f],this);h.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=h.bbox.ll.x),h.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=h.bbox.ll.y),h.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=h.bbox.ur.x),h.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=h.bbox.ur.y),this.polys.push(h)}this.isSubject=u}getSweepEvents(){let o=[];for(let u=0,f=this.polys.length;u<f;u++){let p=this.polys[u].getSweepEvents();for(let h=0,S=p.length;h<S;h++)o.push(p[h])}return o}}class Ie{static factory(o){let u=[];for(let f=0,p=o.length;f<p;f++){let h=o[f];if(!h.isInResult()||h.ringOut)continue;let S=null,v=h.leftSE,F=h.rightSE,M=[v],V=v.point,w=[];for(;S=v,v=F,M.push(v),v.point!==V;)for(;;){let I=v.getAvailableLinkedEvents();if(I.length===0){let G=M[0].point,W=M[M.length-1].point;throw new Error(`Unable to complete output ring starting at [${G.x}, ${G.y}]. Last matching segment found ends at [${W.x}, ${W.y}].`)}if(I.length===1){F=I[0].otherSE;break}let B=null;for(let G=0,W=w.length;G<W;G++)if(w[G].point===v.point){B=G;break}if(B!==null){let G=w.splice(B)[0],W=M.splice(G.index);W.unshift(W[0].otherSE),u.push(new Ie(W.reverse()));continue}w.push({index:M.length,point:v.point});let H=v.getLeftmostComparator(S);F=I.sort(H)[0].otherSE;break}u.push(new Ie(M))}return u}constructor(o){this.events=o;for(let u=0,f=o.length;u<f;u++)o[u].segment.ringOut=this;this.poly=null}getGeom(){let o=this.events[0].point,u=[o];for(let M=1,V=this.events.length-1;M<V;M++){let w=this.events[M].point,I=this.events[M+1].point;be(w,o,I)!==0&&(u.push(w),o=w)}if(u.length===1)return null;let f=u[0],p=u[1];be(f,o,p)===0&&u.shift(),u.push(u[0]);let h=this.isExteriorRing()?1:-1,S=this.isExteriorRing()?0:u.length-1,v=this.isExteriorRing()?u.length:-1,F=[];for(let M=S;M!=v;M+=h)F.push([u[M].x,u[M].y]);return F}isExteriorRing(){if(this._isExteriorRing===void 0){let o=this.enclosingRing();this._isExteriorRing=o?!o.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let o=this.events[0];for(let p=1,h=this.events.length;p<h;p++){let S=this.events[p];se.compare(o,S)>0&&(o=S)}let u=o.segment.prevInResult(),f=u?u.prevInResult():null;for(;;){if(!u)return null;if(!f)return u.ringOut;if(f.ringOut!==u.ringOut)return f.ringOut.enclosingRing()!==u.ringOut?u.ringOut:u.ringOut.enclosingRing();u=f.prevInResult(),f=u?u.prevInResult():null}}}class ze{constructor(o){this.exteriorRing=o,o.poly=this,this.interiorRings=[]}addInterior(o){this.interiorRings.push(o),o.poly=this}getGeom(){let o=[this.exteriorRing.getGeom()];if(o[0]===null)return null;for(let u=0,f=this.interiorRings.length;u<f;u++){let p=this.interiorRings[u].getGeom();p!==null&&o.push(p)}return o}}class vt{constructor(o){this.rings=o,this.polys=this._composePolys(o)}getGeom(){let o=[];for(let u=0,f=this.polys.length;u<f;u++){let p=this.polys[u].getGeom();p!==null&&o.push(p)}return o}_composePolys(o){let u=[];for(let f=0,p=o.length;f<p;f++){let h=o[f];if(!h.poly)if(h.isExteriorRing())u.push(new ze(h));else{let S=h.enclosingRing();S.poly||u.push(new ze(S)),S.poly.addInterior(h)}}return u}}class ft{constructor(o){let u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:xe.compare;this.queue=o,this.tree=new a(u),this.segments=[]}process(o){let u=o.segment,f=[];if(o.consumedBy)return o.isLeft?this.queue.remove(o.otherSE):this.tree.remove(u),f;let p=o.isLeft?this.tree.add(u):this.tree.find(u);if(!p)throw new Error(`Unable to find segment #${u.id} [${u.leftSE.point.x}, ${u.leftSE.point.y}] -> [${u.rightSE.point.x}, ${u.rightSE.point.y}] in SweepLine tree.`);let h=p,S=p,v,F;for(;v===void 0;)h=this.tree.prev(h),h===null?v=null:h.key.consumedBy===void 0&&(v=h.key);for(;F===void 0;)S=this.tree.next(S),S===null?F=null:S.key.consumedBy===void 0&&(F=S.key);if(o.isLeft){let M=null;if(v){let w=v.getIntersection(u);if(w!==null&&(u.isAnEndpoint(w)||(M=w),!v.isAnEndpoint(w))){let I=this._splitSafely(v,w);for(let B=0,H=I.length;B<H;B++)f.push(I[B])}}let V=null;if(F){let w=F.getIntersection(u);if(w!==null&&(u.isAnEndpoint(w)||(V=w),!F.isAnEndpoint(w))){let I=this._splitSafely(F,w);for(let B=0,H=I.length;B<H;B++)f.push(I[B])}}if(M!==null||V!==null){let w=null;M===null?w=V:V===null?w=M:w=se.comparePoints(M,V)<=0?M:V,this.queue.remove(u.rightSE),f.push(u.rightSE);let I=u.split(w);for(let B=0,H=I.length;B<H;B++)f.push(I[B])}f.length>0?(this.tree.remove(u),f.push(o)):(this.segments.push(u),u.prev=v)}else{if(v&&F){let M=v.getIntersection(F);if(M!==null){if(!v.isAnEndpoint(M)){let V=this._splitSafely(v,M);for(let w=0,I=V.length;w<I;w++)f.push(V[w])}if(!F.isAnEndpoint(M)){let V=this._splitSafely(F,M);for(let w=0,I=V.length;w<I;w++)f.push(V[w])}}}this.tree.remove(u)}return f}_splitSafely(o,u){this.tree.remove(o);let f=o.rightSE;this.queue.remove(f);let p=o.split(u);return p.push(f),o.consumedBy===void 0&&this.tree.add(o),p}}let Qt=typeof process<"u"&&process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,tr=typeof process<"u"&&process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6;class nr{run(o,u,f){ve.type=o,D.reset();let p=[new De(u,!0)];for(let w=0,I=f.length;w<I;w++)p.push(new De(f[w],!1));if(ve.numMultiPolys=p.length,ve.type==="difference"){let w=p[0],I=1;for(;I<p.length;)_(p[I].bbox,w.bbox)!==null?I++:p.splice(I,1)}if(ve.type==="intersection")for(let w=0,I=p.length;w<I;w++){let B=p[w];for(let H=w+1,G=p.length;H<G;H++)if(_(B.bbox,p[H].bbox)===null)return[]}let h=new a(se.compare);for(let w=0,I=p.length;w<I;w++){let B=p[w].getSweepEvents();for(let H=0,G=B.length;H<G;H++)if(h.insert(B[H]),h.size>Qt)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).")}let S=new ft(h),v=h.size,F=h.pop();for(;F;){let w=F.key;if(h.size===v){let B=w.segment;throw new Error(`Unable to pop() ${w.isLeft?"left":"right"} SweepEvent [${w.point.x}, ${w.point.y}] from segment #${B.id} [${B.leftSE.point.x}, ${B.leftSE.point.y}] -> [${B.rightSE.point.x}, ${B.rightSE.point.y}] from queue.`)}if(h.size>Qt)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");if(S.segments.length>tr)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");let I=S.process(w);for(let B=0,H=I.length;B<H;B++){let G=I[B];G.consumedBy===void 0&&h.insert(G)}v=h.size,F=h.pop()}D.reset();let M=Ie.factory(S.segments);return new vt(M).getGeom()}}let ve=new nr;var rr={union:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("union",y,u)},intersection:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("intersection",y,u)},xor:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("xor",y,u)},difference:function(y){for(var o=arguments.length,u=new Array(o>1?o-1:0),f=1;f<o;f++)u[f-1]=arguments[f];return ve.run("difference",y,u)}};return rr})});var nt=new Set,St=!1;function Te(t,e,n=2){let r=e&&e.length,i=r?e[0]*n:t.length;nt.size&&nt.clear();let s=tn(t,0,i,n,!0),l=[];if(!s||s.next===s.prev)return l;let c=0,a=0,m=0;if(r&&(s=br(t,e,s,n)),t.length>80*n){c=t[0],a=t[1];let x=c,g=a;for(let d=n;d<i;d+=n){let b=t[d],E=t[d+1];b<c&&(c=b),E<a&&(a=E),b>x&&(x=b),E>g&&(g=E)}m=Math.max(x-c,g-a),m=m!==0?32767/m:0}return Et(s,l,c,a,m),l}function tn(t,e,n,r,i){let s=null;if(i===Lr(t,e,n,r)>0)for(let l=e;l<n;l+=r)s=en(l/r|0,t[l],t[l+1],s);else for(let l=n-r;l>=e;l-=r)s=en(l/r|0,t[l],t[l+1],s);return s&&rt(s,s.next)&&(ot(s),s=s.next),s}function Ge(t,e=t){let n=e===t,r=t,i;do i=!1,r!==r.next&&(nt.size===0||!nt.has(r))&&(rt(r,r.next)||le(r.prev,r,r.next)===0)?((n||r===e)&&(e=r.prev),St=!0,ot(r),r=r.prev,i=!0):(n||r!==e)&&(r=r.next,i=!n);while(i||r!==e);return e}function Et(t,e,n,r,i){i&&Fr(t,n,r,i);let s=t,l=!1;for(;t.prev!==t.next;){let c=t.prev,a=t.next;if(le(c,t,a)<0&&(i?dr(t,n,r,i):xr(t))){e.push(c.i,t.i,a.i),ot(t),t=a,s=a;continue}if(t=a,t===s){if(St=!1,t=Ge(t),St){s=t;continue}if(!l){t=gr(t,e),s=t,l=!0;continue}yr(t,e,n,r,i);break}}}function xr(t){let e=t.prev,n=t,r=t.next,i=e.x,s=n.x,l=r.x,c=e.y,a=n.y,m=r.y,x=Math.min(i,s,l),g=Math.min(c,a,m),d=Math.max(i,s,l),b=Math.max(c,a,m),E=r.next;for(;E!==e;){if(E.x>=x&&E.x<=d&&E.y>=g&&E.y<=b&&!(i===E.x&&c===E.y)&&mt(i,c,s,a,l,m,E.x,E.y)&&le(E.prev,E,E.next)>=0)return!1;E=E.next}return!0}function dr(t,e,n,r){let i=t.prev,s=t,l=t.next,c=i.x,a=s.x,m=l.x,x=i.y,g=s.y,d=l.y,b=Math.min(c,a,m),E=Math.min(x,g,d),A=Math.max(c,a,m),_=Math.max(x,g,d),R=It(b,E,e,n,r),L=It(A,_,e,n,r),k=t.prevZ;for(;k&&k.z>=R;){if(k.x>=b&&k.x<=A&&k.y>=E&&k.y<=_&&k!==l&&!(c===k.x&&x===k.y)&&mt(c,x,a,g,m,d,k.x,k.y)&&le(k.prev,k,k.next)>=0)return!1;k=k.prevZ}let T=t.nextZ;for(;T&&T.z<=L;){if(T.x>=b&&T.x<=A&&T.y>=E&&T.y<=_&&T!==l&&!(c===T.x&&x===T.y)&&mt(c,x,a,g,m,d,T.x,T.y)&&le(T.prev,T,T.next)>=0)return!1;T=T.nextZ}return!0}function gr(t,e){let n=t,r=!1;do{let i=n.prev,s=n.next.next;on(i,n,n.next,s,!1)&&it(i,s)&&it(s,i)&&(e.push(i.i,n.i,s.i),ot(n),ot(n.next),n=t=s,r=!0),n=n.next}while(n!==t);return r?Ge(n):n}function yr(t,e,n,r,i){let s=t;do{let l=s.next.next;for(;l!==s.prev;){if(s.i!==l.i&&kr(s,l)){let c=sn(s,l);s=Ge(s,s.next),c=Ge(c,c.next),Et(s,e,n,r,i),Et(c,e,n,r,i);return}l=l.next}s=s.next}while(s!==t)}var Mt=!1;function br(t,e,n,r){let i=[];for(let s=0,l=e.length;s<l;s++){let c=e[s]*r,a=s<l-1?e[s+1]*r:t.length,m=tn(t,c,a,r,!1);m===m.next&&nt.add(m),i.push(Pr(m))}i.sort(wr),Sr(t.length/r,e.length),rn(n,n),Mt=!0;for(let s=0;s<i.length;s++)n=vr(i[s],n);return Mt=!1,Ge(n)}function wr(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function vr(t,e){let n=Mr(t,e);if(!n)return e;let r=sn(n,t),i=r.next;return rn(n,i.next),Ge(r,r.next),Ge(n,n.next)}var nn=16,ie=new Float64Array(0),pt=0,Rt=[],Ft=[];function Sr(t,e){let n=Math.ceil((t+2*e)/nn)+e+2;ie.length<n*4&&(ie=new Float64Array(n*4)),pt=0}function rn(t,e){let n=t;do{let r=pt++;Rt[r]=n;let i=1/0,s=1/0,l=-1/0,c=-1/0,a=0;do{let x=n.next;n.z=r,n.x<i&&(i=n.x),n.x>l&&(l=n.x),n.y<s&&(s=n.y),n.y>c&&(c=n.y),x.x<i&&(i=x.x),x.x>l&&(l=x.x),x.y<s&&(s=x.y),x.y>c&&(c=x.y),n=x}while(++a<nn&&n!==e);Ft[r]=n;let m=r*4;ie[m]=i,ie[m+1]=s,ie[m+2]=l,ie[m+3]=c}while(n!==e)}function Er(t,e){let n=t.z*4;e.x<ie[n]&&(ie[n]=e.x),e.y<ie[n+1]&&(ie[n+1]=e.y),e.x>ie[n+2]&&(ie[n+2]=e.x),e.y>ie[n+3]&&(ie[n+3]=e.y)}function Jt(t){let e=Ft[t];for(;e.prev.next!==e;)e=e.next;return Ft[t]=e,e}function qt(t){let e=Rt[t];for(;e.prev.next!==e;)e=e.next;return Rt[t]=e,e}function Mr(t,e){let n=e,r=t.x,i=t.y,s=-1/0,l;if(rt(t,n))return n;for(let d=0,b=0;d<pt;d++,b+=4){if(i<ie[b+1]||i>ie[b+3]||ie[b]>r||ie[b+2]<=s)continue;let E=Jt(d);n=qt(d);do{if(n.prev.next===n){if(rt(t,n.next))return n.next;if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){let A=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(A<=r&&A>s&&(s=A,l=n.x<n.next.x?n:n.next,A===r))return l}}n=n.next}while(n!==E)}if(!l)return null;let c=l.x,a=l.y,m=Math.min(i,a),x=Math.max(i,a),g=1/0;for(let d=0,b=0;d<pt;d++,b+=4){if(ie[b+2]<c||ie[b]>r||ie[b+3]<m||ie[b+1]>x)continue;let E=Jt(d);n=qt(d);do{if(n.prev.next===n&&r>=n.x&&n.x>=c&&r!==n.x&&mt(i<a?r:s,i,c,a,i<a?s:r,i,n.x,n.y)){let A=Math.abs(i-n.y)/(r-n.x);(it(n,t)||n.y===i&&n.next.y===i&&n.next.x>r)&&(A<g||A===g&&(n.x>l.x||n.x===l.x&&Rr(l,n)))&&(l=n,g=A)}n=n.next}while(n!==E)}return l}function Rr(t,e){return le(t.prev,t,e.prev)<0&&le(e.next,t,t.next)<0}var ye=[],qe=[],Ue=new Uint32Array(0),et=new Uint32Array(0),tt=new Uint32Array(256);function Fr(t,e,n,r){let i=t,s=0;do i.z=It(i.x,i.y,e,n,r),ye[s++]=i,i=i.next;while(i!==t);Ir(s);let l=null;for(let c=0;c<s;c++){let a=ye[c];a.prevZ=l,l&&(l.nextZ=a),l=a}l.nextZ=null}function Ir(t){if(t<=32){for(let e=1;e<t;e++){let n=ye[e],r=n.z,i=e-1;for(;i>=0&&ye[i].z>r;)ye[i+1]=ye[i],i--;ye[i+1]=n}return}Ue.length<t&&(Ue=new Uint32Array(t),et=new Uint32Array(t),qe=new Array(t));for(let e=0;e<t;e++)Ue[e]=ye[e].z;at(t,ye,Ue,qe,et,0),at(t,qe,et,ye,Ue,8),at(t,ye,Ue,qe,et,16),at(t,qe,et,ye,Ue,24)}function at(t,e,n,r,i,s){tt.fill(0);for(let c=0;c<t;c++)tt[n[c]>>>s&255]++;let l=0;for(let c=0;c<256;c++){let a=tt[c];tt[c]=l,l+=a}for(let c=0;c<t;c++){let a=n[c],m=tt[a>>>s&255]++;r[m]=e[c],i[m]=a}}function It(t,e,n,r,i){return t=(t-n)*i|0,e=(e-r)*i|0,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t|e<<1}function Pr(t){let e=t,n=t;do(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next;while(e!==t);return n}function mt(t,e,n,r,i,s,l,c){return(i-l)*(e-c)>=(t-l)*(s-c)&&(t-l)*(r-c)>=(n-l)*(e-c)&&(n-l)*(s-c)>=(i-l)*(r-c)}function kr(t,e){let n=rt(t,e)&&le(t.prev,t,t.next)>0&&le(e.prev,e,e.next)>0;return t.next.i!==e.i&&(n||it(t,e)&&it(e,t)&&(le(t.prev,t,e.prev)!==0||le(t,e.prev,e)!==0))&&!_r(t,e)&&(n||Ar(t,e))}function le(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function rt(t,e){return t.x===e.x&&t.y===e.y}function on(t,e,n,r,i=!0){let s=le(t,e,n),l=le(t,e,r),c=le(n,r,t),a=le(n,r,e);return(s>0&&l<0||s<0&&l>0)&&(c>0&&a<0||c<0&&a>0)?!0:i?!!(s===0&&ht(t,n,e)||l===0&&ht(t,r,e)||c===0&&ht(n,t,r)||a===0&&ht(n,e,r)):!1}function ht(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function _r(t,e){let n=Math.min(t.x,e.x),r=Math.max(t.x,e.x),i=Math.min(t.y,e.y),s=Math.max(t.y,e.y),l=t;do{let c=l.next;if(l.x>r&&c.x>r||l.x<n&&c.x<n||l.y>s&&c.y>s||l.y<i&&c.y<i){l=c;continue}if(l.i!==t.i&&c.i!==t.i&&l.i!==e.i&&c.i!==e.i&&on(l,c,t,e))return!0;l=c}while(l!==t);return!1}function it(t,e){return le(t.prev,t,t.next)<0?le(t,e,t.next)>=0&&le(t,t.prev,e)>=0:le(t,e,t.prev)<0||le(t,t.next,e)<0}function Ar(t,e){let n=t,r=!1,i=(t.x+e.x)/2,s=(t.y+e.y)/2;do{let l=n.next;n.y>s!=l.y>s&&i<(l.x-n.x)*(s-n.y)/(l.y-n.y)+n.x&&(r=!r),n=l}while(n!==t);return r}function sn(t,e){let n=Pt(t.i,t.x,t.y),r=Pt(e.i,e.x,e.y),i=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=i,i.prev=n,r.next=n,n.prev=r,s.next=r,r.prev=s,r}function en(t,e,n,r){let i=Pt(t,e,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function ot(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),Mt&&Er(t.prev,t.next)}function Pt(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function Lr(t,e,n,r){let i=0;for(let s=e,l=n-r;s<n;s+=r)i+=(t[l]-t[s])*(t[s+1]+t[l+1]),l=s;return i}var un=23283064365386963e-26,Br=12,ln=typeof TextDecoder>"u"?null:new TextDecoder("utf-8"),kt=0,xt=1,st=2,dt=5,ut=class{constructor(e=new Uint8Array(16)){this.buf=ArrayBuffer.isView(e)?e:new Uint8Array(e),this.dataView=new DataView(this.buf.buffer),this.pos=0,this.type=0,this.length=this.buf.length}readFields(e,n,r=this.length){for(;this.pos<r;){let i=this.readVarint(),s=i>>3,l=this.pos;this.type=i&7,e(s,n,this),this.pos===l&&this.skip(i)}return n}readMessage(e,n){return this.readFields(e,n,this.readVarint()+this.pos)}readFixed32(){let e=this.dataView.getUint32(this.pos,!0);return this.pos+=4,e}readSFixed32(){let e=this.dataView.getInt32(this.pos,!0);return this.pos+=4,e}readFixed64(){let e=this.dataView.getUint32(this.pos,!0)+this.dataView.getUint32(this.pos+4,!0)*4294967296;return this.pos+=8,e}readSFixed64(){let e=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*4294967296;return this.pos+=8,e}readFloat(){let e=this.dataView.getFloat32(this.pos,!0);return this.pos+=4,e}readDouble(){let e=this.dataView.getFloat64(this.pos,!0);return this.pos+=8,e}readVarint(e){let n=this.buf,r,i;return i=n[this.pos++],r=i&127,i<128||(i=n[this.pos++],r|=(i&127)<<7,i<128)||(i=n[this.pos++],r|=(i&127)<<14,i<128)||(i=n[this.pos++],r|=(i&127)<<21,i<128)?r:(i=n[this.pos],r|=(i&15)<<28,Tr(r,e,this))}readVarint64(){return this.readVarint(!0)}readSVarint(){let e=this.readVarint();return e%2===1?(e+1)/-2:e/2}readBoolean(){return!!this.readVarint()}readString(){let e=this.readVarint()+this.pos,n=this.pos;return this.pos=e,e-n>=Br&&ln?ln.decode(this.buf.subarray(n,e)):Yr(this.buf,n,e)}readBytes(){let e=this.readVarint()+this.pos,n=this.buf.subarray(this.pos,e);return this.pos=e,n}readPackedVarint(e=[],n){let r=this.readPackedEnd();for(;this.pos<r;)e.push(this.readVarint(n));return e}readPackedSVarint(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readSVarint());return e}readPackedBoolean(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readBoolean());return e}readPackedFloat(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readFloat());return e}readPackedDouble(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readDouble());return e}readPackedFixed32(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readFixed32());return e}readPackedSFixed32(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readSFixed32());return e}readPackedFixed64(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readFixed64());return e}readPackedSFixed64(e=[]){let n=this.readPackedEnd();for(;this.pos<n;)e.push(this.readSFixed64());return e}readPackedEnd(){return this.type===st?this.readVarint()+this.pos:this.pos+1}skip(e){let n=e&7;if(n===kt)for(;this.buf[this.pos++]>127;);else if(n===st)this.pos=this.readVarint()+this.pos;else if(n===dt)this.pos+=4;else if(n===xt)this.pos+=8;else throw new Error(`Unimplemented type: ${n}`)}writeTag(e,n){this.writeVarint(e<<3|n)}realloc(e){let n=this.length||16;for(;n<this.pos+e;)n*=2;if(n!==this.length){let r=new Uint8Array(n);r.set(this.buf),this.buf=r,this.dataView=new DataView(r.buffer),this.length=n}}finish(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)}writeFixed32(e){this.realloc(4),this.dataView.setInt32(this.pos,e,!0),this.pos+=4}writeSFixed32(e){this.realloc(4),this.dataView.setInt32(this.pos,e,!0),this.pos+=4}writeFixed64(e){this.realloc(8),this.dataView.setInt32(this.pos,e&-1,!0),this.dataView.setInt32(this.pos+4,Math.floor(e*un),!0),this.pos+=8}writeSFixed64(e){this.realloc(8),this.dataView.setInt32(this.pos,e&-1,!0),this.dataView.setInt32(this.pos+4,Math.floor(e*un),!0),this.pos+=8}writeVarint(e){if(e=+e||0,e>268435455||e<0){Cr(e,this);return}this.realloc(4),this.buf[this.pos++]=e&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=e>>>7&127)))}writeSVarint(e){this.writeVarint(e<0?-e*2-1:e*2)}writeBoolean(e){this.writeVarint(+e)}writeString(e){e=String(e),this.realloc(e.length*4),this.pos++;let n=this.pos;this.pos=Zr(this.buf,e,this.pos);let r=this.pos-n;r>=128&&cn(n,r,this),this.pos=n-1,this.writeVarint(r),this.pos+=r}writeFloat(e){this.realloc(4),this.dataView.setFloat32(this.pos,e,!0),this.pos+=4}writeDouble(e){this.realloc(8),this.dataView.setFloat64(this.pos,e,!0),this.pos+=8}writeBytes(e){let n=e.length;this.writeVarint(n),this.realloc(n);for(let r=0;r<n;r++)this.buf[this.pos++]=e[r]}writeRawMessage(e,n){this.pos++;let r=this.pos;e(n,this);let i=this.pos-r;i>=128&&cn(r,i,this),this.pos=r-1,this.writeVarint(i),this.pos+=i}writeMessage(e,n,r){this.writeTag(e,st),this.writeRawMessage(n,r)}writePackedVarint(e,n){n.length&&this.writeMessage(e,Dr,n)}writePackedSVarint(e,n){n.length&&this.writeMessage(e,Ur,n)}writePackedBoolean(e,n){n.length&&this.writeMessage(e,zr,n)}writePackedFloat(e,n){n.length&&this.writeMessage(e,Gr,n)}writePackedDouble(e,n){n.length&&this.writeMessage(e,Nr,n)}writePackedFixed32(e,n){n.length&&this.writeMessage(e,Hr,n)}writePackedSFixed32(e,n){n.length&&this.writeMessage(e,$r,n)}writePackedFixed64(e,n){n.length&&this.writeMessage(e,jr,n)}writePackedSFixed64(e,n){n.length&&this.writeMessage(e,Xr,n)}writeBytesField(e,n){this.writeTag(e,st),this.writeBytes(n)}writeFixed32Field(e,n){this.writeTag(e,dt),this.writeFixed32(n)}writeSFixed32Field(e,n){this.writeTag(e,dt),this.writeSFixed32(n)}writeFixed64Field(e,n){this.writeTag(e,xt),this.writeFixed64(n)}writeSFixed64Field(e,n){this.writeTag(e,xt),this.writeSFixed64(n)}writeVarintField(e,n){this.writeTag(e,kt),this.writeVarint(n)}writeSVarintField(e,n){this.writeTag(e,kt),this.writeSVarint(n)}writeStringField(e,n){this.writeTag(e,st),this.writeString(n)}writeFloatField(e,n){this.writeTag(e,dt),this.writeFloat(n)}writeDoubleField(e,n){this.writeTag(e,xt),this.writeDouble(n)}writeBooleanField(e,n){this.writeVarintField(e,+n)}};function Tr(t,e,n){let r=n.buf,i,s;if(s=r[n.pos++],i=(s&112)>>4,s<128||(s=r[n.pos++],i|=(s&127)<<3,s<128)||(s=r[n.pos++],i|=(s&127)<<10,s<128)||(s=r[n.pos++],i|=(s&127)<<17,s<128)||(s=r[n.pos++],i|=(s&127)<<24,s<128)||(s=r[n.pos++],i|=(s&1)<<31,s<128))return He(t,i,e);throw new Error("Expected varint not more than 10 bytes")}function He(t,e,n){return n?e*4294967296+(t>>>0):(e>>>0)*4294967296+(t>>>0)}function Cr(t,e){let n,r;if(t>=0?(n=t%4294967296|0,r=t/4294967296|0):(n=~(-t%4294967296),r=~(-t/4294967296),n^4294967295?n=n+1|0:(n=0,r=r+1|0)),t>=18446744073709552e3||t<-18446744073709552e3)throw new Error("Given varint doesn\'t fit into 10 bytes");e.realloc(10),Vr(n,r,e),Or(r,e)}function Vr(t,e,n){n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos++]=t&127|128,t>>>=7,n.buf[n.pos]=t&127}function Or(t,e){let n=(t&7)<<4;e.buf[e.pos++]|=n|((t>>>=3)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=t&127)))))}function cn(t,e,n){let r=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(Math.LN2*7));n.realloc(r);for(let i=n.pos-1;i>=t;i--)n.buf[i+r]=n.buf[i]}function Dr(t,e){for(let n=0;n<t.length;n++)e.writeVarint(t[n])}function Ur(t,e){for(let n=0;n<t.length;n++)e.writeSVarint(t[n])}function Gr(t,e){for(let n=0;n<t.length;n++)e.writeFloat(t[n])}function Nr(t,e){for(let n=0;n<t.length;n++)e.writeDouble(t[n])}function zr(t,e){for(let n=0;n<t.length;n++)e.writeBoolean(t[n])}function Hr(t,e){for(let n=0;n<t.length;n++)e.writeFixed32(t[n])}function $r(t,e){for(let n=0;n<t.length;n++)e.writeSFixed32(t[n])}function jr(t,e){for(let n=0;n<t.length;n++)e.writeFixed64(t[n])}function Xr(t,e){for(let n=0;n<t.length;n++)e.writeSFixed64(t[n])}function Yr(t,e,n){let r="",i=e;for(;i<n;){let s=t[i],l=null,c=s>239?4:s>223?3:s>191?2:1;if(i+c>n)break;let a,m,x;c===1?s<128&&(l=s):c===2?(a=t[i+1],(a&192)===128&&(l=(s&31)<<6|a&63,l<=127&&(l=null))):c===3?(a=t[i+1],m=t[i+2],(a&192)===128&&(m&192)===128&&(l=(s&15)<<12|(a&63)<<6|m&63,(l<=2047||l>=55296&&l<=57343)&&(l=null))):c===4&&(a=t[i+1],m=t[i+2],x=t[i+3],(a&192)===128&&(m&192)===128&&(x&192)===128&&(l=(s&15)<<18|(a&63)<<12|(m&63)<<6|x&63,(l<=65535||l>=1114112)&&(l=null))),l===null?(l=65533,c=1):l>65535&&(l-=65536,r+=String.fromCharCode(l>>>10&1023|55296),l=56320|l&1023),r+=String.fromCharCode(l),i+=c}return r}function Zr(t,e,n){for(let r=0,i,s;r<e.length;r++){if(i=e.charCodeAt(r),i>55295&&i<57344)if(s)if(i<56320){t[n++]=239,t[n++]=191,t[n++]=189,s=i;continue}else i=s-55296<<10|i-56320|65536,s=null;else{i>56319||r+1===e.length?(t[n++]=239,t[n++]=191,t[n++]=189):s=i;continue}else s&&(t[n++]=239,t[n++]=191,t[n++]=189,s=null);i<128?t[n++]=i:(i<2048?t[n++]=i>>6|192:(i<65536?t[n++]=i>>12|224:(t[n++]=i>>18|240,t[n++]=i>>12&63|128),t[n++]=i>>6&63|128),t[n++]=i&63|128)}return n}var _t=class t{constructor(e,n,r,i){this.pbf=e;this.keys=n;this.values=r;this.extent=i;this.type=0;this.properties={};this.geomOffset=-1}static read(e,n,r,i,s){let l=new t(e,r,i,s);return e.readFields(Wr,l,n),l}loadGeometry(){if(this.geomOffset<0)return[];let e=this.pbf,n=e.pos;e.pos=this.geomOffset;let r=e.readVarint()+e.pos,i=1,s=0,l=0,c=0,a=[],m=[];for(;e.pos<r;){if(s<=0){let x=e.readVarint();i=x&7,s=x>>3}if(s--,i===1||i===2)l+=e.readSVarint(),c+=e.readSVarint(),i===1&&(m.length&&a.push(m),m=[]),m.push(l,c);else if(i===7)m.length>=2&&m.push(m[0],m[1]);else throw new Error(`[osmgl] \\u043D\\u0435\\u0438\\u0437\\u0432\\u0435\\u0441\\u0442\\u043D\\u0430\\u044F \\u043A\\u043E\\u043C\\u0430\\u043D\\u0434\\u0430 \\u0433\\u0435\\u043E\\u043C\\u0435\\u0442\\u0440\\u0438\\u0438 MVT: ${i}`)}return m.length&&a.push(m),e.pos=n,a}bbox(){let e=this.loadGeometry(),n=1/0,r=1/0,i=-1/0,s=-1/0;for(let l of e)for(let c=0;c<l.length;c+=2)l[c]<n&&(n=l[c]),l[c]>i&&(i=l[c]),l[c+1]<r&&(r=l[c+1]),l[c+1]>s&&(s=l[c+1]);return[n,r,i,s]}};function Wr(t,e,n){n&&(t===1?e.id=n.readVarint():t===2?Qr(n,e):t===3?e.type=n.readVarint():t===4&&(e.geomOffset=n.pos,n.skip(2)))}function Qr(t,e){let n=t.readVarint()+t.pos;for(;t.pos<n;){let r=e.keys[t.readVarint()],i=e.values[t.readVarint()];r!==void 0&&(e.properties[r]=i)}}var At=class t{constructor(e){this.pbf=e;this.version=1;this.name="";this.extent=4096;this.featureOffsets=[];this.keys=[];this.values=[]}static read(e,n){let r=new t(e);return e.readFields(Kr,r,n),r}get length(){return this.featureOffsets.length}feature(e){let n=this.pbf;n.pos=this.featureOffsets[e];let r=n.readVarint()+n.pos;return _t.read(n,r,this.keys,this.values,this.extent)}*features(){for(let e=0;e<this.featureOffsets.length;e++)yield this.feature(e)}};function Kr(t,e,n){n&&(t===15?e.version=n.readVarint():t===1?e.name=n.readString():t===5?e.extent=n.readVarint():t===2?e.featureOffsets.push(n.pos):t===3?e.keys.push(n.readString()):t===4&&e.values.push(Jr(n)))}function Jr(t){let e=t.readVarint()+t.pos,n=null;for(;t.pos<e;){let r=t.readVarint()>>3;r===1?n=t.readString():r===2?n=t.readFloat():r===3?n=t.readDouble():r===4?n=t.readVarint64():r===5?n=t.readVarint():r===6?n=t.readSVarint():r===7?n=t.readBoolean():t.skip(r)}return n}var gt=class{constructor(e){this.layers={};new ut(e instanceof Uint8Array?e:new Uint8Array(e)).readFields((r,i,s)=>{if(r===3&&s){let l=At.read(s,s.readVarint()+s.pos);l.length&&(this.layers[l.name]=l)}},null)}};function $e(t){let e=[],n=null;for(let r of t){if(r.length<6)continue;let i=qr(r);i!==0&&(i>0?(n&&e.push(n),n={outer:r,holes:[]}):n&&n.holes.push(r))}return n&&e.push(n),e}function qr(t){let e=0;for(let n=0,r=t.length-2;n<t.length;r=n,n+=2)e+=(t[r]-t[n])*(t[n+1]+t[r+1]);return e/2}function ce(t,e){if(!t)return!0;let n=t[0];switch(n){case"all":return t.slice(1).every(r=>ce(r,e));case"any":return t.slice(1).some(r=>ce(r,e));case"!":return!ce(t[1],e);case"has":return e[t[1]]!=null;case"!has":return e[t[1]]==null;case"in":{let r=e[t[1]];return r==null?!1:t.slice(2).includes(r)}case"!in":{let r=e[t[1]];return r==null?!0:!t.slice(2).includes(r)}default:{let r=e[t[1]],i=t[2];if(r==null)return n==="!=";switch(n){case"==":return r===i;case"!=":return r!==i;case">":return r>i;case">=":return r>=i;case"<":return r<i;case"<=":return r<=i;default:return!0}}}}var ei=Math.PI/8,ti=.35,ni=32,fn=.25,an=.5,hn=.07;function _e(t,e){let n=e.radius;if(!(n>0))return t;let r=t.length/2-1;if(r<3)return t;let i=Math.max(2,Math.round(e.segments??4)),s=Math.max(e.minCutRatio??ti,0),l=e.extent,c=e.margin??0,a=[];for(let m=0;m<r;m++){let x=t[m*2],g=t[m*2+1],d=t[(m+r-1)%r*2],b=t[(m+r-1)%r*2+1],E=t[(m+1)%r*2],A=t[(m+1)%r*2+1],_=x-d,R=g-b,L=E-x,k=A-g,T=Math.hypot(_,R),O=Math.hypot(L,k);if(T<1e-6||O<1e-6){a.push(x,g);continue}let D=_/T,U=R/T,P=L/O,C=k/O;if(e.keep?.[m]){a.push(x,g);continue}let Y=D*P+U*C;if(Y>.985){a.push(x,g);continue}if(l!==void 0&&(Lt(x,g,l,c)||Lt(d,b,l,c)||Lt(E,A,l,c))){a.push(x,g);continue}let Q=Math.min(n,T*.4,O*.4);if(Q<n*s){a.push(x,g);continue}let Z=x-D*Q,re=g-U*Q,X=x+P*Q,$=g+C*Q,z=Math.acos(Math.max(-1,Math.min(1,Y))),N=Math.min(ei,Math.PI/2/i),q=Math.ceil(z/N-1e-6),te=e.maxChord&&e.maxChord>0?Math.ceil(Q/Math.tan(z/2)*z/e.maxChord):0,K=Math.max(1,Math.min(ni,Math.max(Math.min(i,q),te)));a.push(Z,re);for(let oe=1;oe<K;oe++){let ee=oe/K,J=1-ee;a.push(J*J*Z+2*J*ee*x+ee*ee*X,J*J*re+2*J*ee*g+ee*ee*$)}a.push(X,$)}return a.length<6?t:(a.push(a[0],a[1]),a)}var Lt=(t,e,n,r)=>t<=-r||e<=-r||t>=n+r||e>=n+r;var Ae=t=>t/64;function je(t,e,n=0){let r=pn(t.outer,e,n);if(!r)return null;let i=[];for(let s of t.holes){let l=pn(s,e,n);l&&i.push(l)}return{outer:r,holes:i}}function pn(t,e,n){let r=[];for(let i=0;i<t.length-2;i+=2)r.push(t[i],t[i+1]);if(r.length<6)return null;for(let i=0;i<4;i++){let s=r;r=[];let l=s.length/2;if(l===0)return null;for(let c=0;c<l;c++){let a=s[c*2],m=s[c*2+1],x=s[(c+l-1)%l*2],g=s[(c+l-1)%l*2+1],d=mn(a,m,i,e,n),b=mn(x,g,i,e,n);if(d!==b){let E=ri(x,g,a,m,i,e,n);r.push(x+(a-x)*E,g+(m-g)*E)}d&&r.push(a,m)}}return r.length<6?null:(r.push(r[0],r[1]),r)}function mn(t,e,n,r,i){return n===0?t>=-i:n===1?t<=r+i:n===2?e>=-i:e<=r+i}function ri(t,e,n,r,i,s,l){return i===0?(-l-t)/(n-t):i===1?(s+l-t)/(n-t):i===2?(-l-e)/(r-e):(s+l-e)/(r-e)}function yt(t,e,n,r,i,s=0){let l=-s,c=i+s;return t===l&&n===l||t===c&&n===c||e===l&&r===l||e===c&&r===c}function xn(t,e){for(let n=0;n<t.length;n+=2)if(t[n]<=0||t[n]>=e||t[n+1]<=0||t[n+1]>=e)return!0;return!1}var Ct=18,Vt=32,dn=8,Sn=65535/Vt,ii=9,oi=1,si=0,ui=1,li=2;var gn=0,ci=1,yn=2,fi=3,ai=.47;function En(t,e,n,r={}){let i=r.metersPerUnit&&r.metersPerUnit>0?r.metersPerUnit:ai,s=Math.max(1024,t.length*48),l=new ArrayBuffer(s*Ct),c={verts:new DataView(l),vertsU8:new Uint8Array(l),vertOffset:0,vertexCount:0,indices:[],featureIds:[],ensure:()=>{}};c.ensure=d=>a(d);let a=d=>{if(c.vertexCount+d<=s)return;s=Math.max(s*2,c.vertexCount+d);let b=new ArrayBuffer(s*Ct);new Uint8Array(b).set(c.vertsU8.subarray(0,c.vertOffset)),l=b,c.verts=new DataView(b),c.vertsU8=new Uint8Array(b)};for(let d of t.features()){if(d.type!==3||!ce(n,d.properties))continue;let b=Li(d.properties),E=Bi(d.properties,b);if(b<=E)continue;let A=Ci(d.properties)??Number(d.id??0),_=Ai(A>>>0),R=_i(_,d.properties),L=ki(d.properties,b),k=$e(d.loadGeometry());for(let T of k){let O=je(T,e);if(!O)continue;let D=xn(O.outer,e),U=(r.cornerRadius??0)/i,P={radius:U,segments:r.cornerSegments,extent:e,minCutRatio:0,maxChord:i>0?an/i:0},C=U>0?{outer:_e(O.outer,P),holes:O.holes.map($=>_e($,P))}:O,Y=C.outer.length/2+C.holes.reduce(($,z)=>$+z.length/2,0);a(Y*5+32);let Q=C.holes.length||D?null:xi(C.outer),Z=Q?vi(d.properties,Q,b,_,i):null,re=null,X=[];if(Z&&Q){let $=Mn(Mi(C.outer,i),Q,Z.shape);X=Ri($,C.outer);let z=Fi($,X);if(z>1e-6){let N=Math.min(Math.max(z*i*yi,wi),bi);re=Ii($,N/z,b)}}wn(c,C.outer,E,b,A,R,L,i,e,re);for(let $ of C.holes)wn(c,$,E,b,A,R,L,i,e,null);re?Pi(c,X,re,b,A,R,L,i):mi(c,C.outer,C.holes,b,A,R,L)}}if(!c.indices.length)return null;let m=new Uint32Array(c.indices),x=new Float64Array(c.featureIds);return{vertices:l.slice(0,c.vertOffset),indices:m.buffer,featureIds:x.buffer,vertexCount:c.vertexCount,indexCount:m.length,extent:e}}var Ot=(t,e)=>t|e<<2,bn=t=>Math.max(-32768,Math.min(32767,t)),Bt=t=>Math.max(0,Math.min(65535,Math.round(Math.min(t,Sn)*Vt)));function Xe(t,e,n,r,i,s,l,c,a,m,x=0,g=0,d=0){let b=t.vertOffset;return t.verts.setInt16(b,bn(Math.round(e*dn)),!0),t.verts.setInt16(b+2,bn(Math.round(n*dn)),!0),t.verts.setUint16(b+4,Math.round(Math.min(r,Sn)*Vt),!0),t.vertsU8[b+6]=a,t.vertsU8[b+7]=c,t.verts.setInt8(b+8,Tt(Math.round(i*127))),t.verts.setInt8(b+9,Tt(Math.round(s*127))),t.verts.setInt8(b+10,Tt(Math.round(l*127))),t.vertsU8[b+11]=m,t.verts.setUint16(b+12,Bt(x),!0),t.verts.setUint16(b+14,Bt(g),!0),t.verts.setUint16(b+16,Bt(d),!0),t.vertOffset+=Ct,t.vertexCount++}function wn(t,e,n,r,i,s,l,c,a,m=null){let x=e.length/2;if(x<3)return;let g=Ot(si,l),d=pi(e,c),b=r-n,E=new Float64Array(x*2),A=new Uint8Array(x);{let _=new Float64Array(x*2);for(let R=0;R<x-1;R++){let L=e[R*2+2]-e[R*2],k=e[R*2+3]-e[R*2+1],T=Math.hypot(L,k)||1;_[R*2]=k/T,_[R*2+1]=-L/T}for(let R=0;R<x-1;R++){let L=(R+x-2)%(x-1),k=_[L*2]*_[R*2]+_[L*2+1]*_[R*2+1],T=_[L*2]+_[R*2],O=_[L*2+1]+_[R*2+1],D=Math.hypot(T,O);k>.5&&D>1e-6&&(E[R*2]=T/D,E[R*2+1]=O/D,A[R]=1)}}for(let _=0;_<x-1;_++){let R=e[_*2],L=e[_*2+1],k=e[_*2+2],T=e[_*2+3];if(R===k&&L===T||yt(R,L,k,T,a))continue;let O=k-R,D=T-L,U=Math.hypot(O,D)||1,P=D/U,C=-O/U,Y=d.offset[_],Q=d.width[_],Z=[0,1];if(m){for(let X=0;X<m.length;X++)for(let $=X+1;$<m.length;$++){let z=Ne(m[X],R,L)-Ne(m[$],R,L),N=Ne(m[X],k,T)-Ne(m[$],k,T);if(z===N)continue;let q=z/(z-N);q>1e-4&&q<1-1e-4&&Z.push(q)}Z.sort((X,$)=>X-$)}let re=(X,$)=>{if(!m)return r;let z=1/0;for(let N of m)z=Math.min(z,Ne(N,X,$));return Math.max(r,z)};for(let X=0;X+1<Z.length;X++){let $=Z[X],z=Z[X+1];if(z-$<1e-6)continue;let N=R+O*$,q=L+D*$,te=R+O*z,K=L+D*z,oe=Y+U*$*c,ee=Y+U*z*c,J=(_+1)%(x-1),fe=A[_]?E[_*2]:P,be=A[_]?E[_*2+1]:C,de=A[J]?E[J*2]:P,Fe=A[J]?E[J*2+1]:C,Ce=P+(fe-P)*(1-$),Le=C+(be-C)*(1-$),Ve=P+(de-P)*z,we=C+(Fe-C)*z,se=Math.hypot(Ce,Le)||1,Pe=Math.hypot(Ve,we)||1,xe=Ce/se,Be=Le/se,Oe=Ve/Pe,De=we/Pe;t.ensure(4);let Ie=Xe(t,N,q,n,xe,Be,0,0,s,g,oe,Q,b),ze=Xe(t,te,K,n,Oe,De,0,0,s,g,ee,Q,b),vt=Xe(t,N,q,re(N,q),xe,Be,0,255,s,g,oe,Q,b),ft=Xe(t,te,K,re(te,K),Oe,De,0,255,s,g,ee,Q,b);t.indices.push(Ie,ft,ze,Ie,vt,ft),t.featureIds.push(i,i)}}}var hi=.9976;function pi(t,e){let n=t.length/2-1,r=[];for(let a=0;a<n;a++){let m=t[a*2+2]-t[a*2],x=t[a*2+3]-t[a*2+1],g=Math.hypot(m,x);r.push(g>0?{x:m/g,y:x/g,len:g*e}:{x:0,y:0,len:0})}let i=(a,m)=>r[a].len>0&&r[m].len>0&&r[a].x*r[m].x+r[a].y*r[m].y>=hi,s=0;for(;s<n&&i((s-1+n)%n,s);)s++;s>=n&&(s=0);let l=new Array(n).fill(0),c=new Array(n).fill(0);for(let a=0;a<n;){let m=(s+a)%n,x=[m],g=r[m].len,d=a+1;for(;d<n;){let E=(s+d)%n;if(!i((s+d-1)%n,E))break;x.push(E),g+=r[E].len,d++}let b=0;for(let E of x)l[E]=b,c[E]=g,b+=r[E].len;a=d}return{offset:l,width:c}}function mi(t,e,n,r,i,s,l){let c=[],a=[];for(let d=0;d<e.length;d++)c.push(e[d]);for(let d of n){a.push(c.length/2);for(let b=0;b<d.length;b++)c.push(d[b])}let m=Te(c,a.length?a:void 0,2);if(!m.length)return;let x=Ot(ui,l),g=t.vertexCount;for(let d=0;d<c.length;d+=2)Xe(t,c[d],c[d+1],r,0,0,1,255,s,x);for(let d=0;d<m.length;d+=3)t.indices.push(g+m[d],g+m[d+2],g+m[d+1]),t.featureIds.push(i)}function xi(t){let e=di(t);if(e.length<3)return null;let n=Math.abs(gi(t));if(n<=0)return null;let r=null,i=1/0;for(let s=0;s<e.length;s++){let l=(s+1)%e.length,c=e[l].x-e[s].x,a=e[l].y-e[s].y,m=Math.hypot(c,a);if(m<1e-6)continue;c/=m,a/=m;let x=1/0,g=-1/0,d=1/0,b=-1/0;for(let T of e){let O=T.x*c+T.y*a,D=-T.x*a+T.y*c;O<x&&(x=O),O>g&&(g=O),D<d&&(d=D),D>b&&(b=D)}let E=g-x,A=b-d,_=E*A;if(_<=0||_>=i)continue;i=_;let R=(x+g)/2,L=(d+b)/2,k=E>=A;r={cx:R*c-L*a,cy:R*a+L*c,ax:k?c:-a,ay:k?a:c,halfLong:(k?E:A)/2,halfShort:(k?A:E)/2,fill:n/_}}return r}function di(t){let e=[];for(let s=0;s<t.length-2;s+=2)e.push({x:t[s],y:t[s+1]});if(e.length<3)return e;e.sort((s,l)=>s.x===l.x?s.y-l.y:s.x-l.x);let n=(s,l,c)=>(l.x-s.x)*(c.y-s.y)-(l.y-s.y)*(c.x-s.x),r=[];for(let s of e){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=e.length-1;s>=0;s--){let l=e[s];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],l)<=0;)i.pop();i.push(l)}return r.pop(),i.pop(),r.concat(i)}function gi(t){let e=0;for(let n=0;n<t.length-2;n+=2)e+=t[n]*t[n+3]-t[n+2]*t[n+1];return e/2}var yi=Math.tan(30*Math.PI/180),bi=3.5,wi=.9;function vi(t,e,n,r,i){if(e.fill<.86)return null;let s=e.halfShort*2*i,l=e.halfLong*2*i,c=s*l,a=e.halfShort>0?e.halfLong/e.halfShort:99,m=Si(t);if(!m){if(n>15||c>600||s<3)return null;let x=r%1e3/1e3;c<30?m=x<.5?"skillion":"gabled":a<1.25?m=x<.35?"pyramidal":"hipped":m=x<.8?"gabled":"hipped"}return m==="flat"?null:{shape:m}}function Si(t){let e=String(t.roof_shape??t["roof:shape"]??"").toLowerCase();return e?e==="flat"?"flat":e==="skillion"||e==="lean_to"||e==="shed"?"skillion":e==="hipped"||e==="half-hipped"||e==="gambrel"?"hipped":e==="pyramidal"||e==="dome"||e==="conical"||e==="onion"?"pyramidal":e==="gabled"||e==="mansard"||e==="round"?"gabled":null:null}var Ne=(t,e,n)=>t.a*e+t.b*n+t.c;function Ei(t,e,n,r){let i=t.length/2;if(i<3)return[];let s=[],l=c=>[t[c*2],t[c*2+1]];for(let c=0;c<i;c++){let[a,m]=l(c),[x,g]=l((c+i-1)%i),d=e*a+n*m+r,b=e*x+n*g+r;if(d<=0!=b<=0){let E=b/(b-d);s.push(x+(a-x)*E,g+(m-g)*E)}d<=0&&s.push(a,m)}return s}function Mi(t,e){let n=.5/Math.max(e,1e-6),r=t.length/2-1;if(r<5)return t;let i=[],s=0;i.push(t[0],t[1]);for(let l=1;l<r;l++){let c=t[s*2],a=t[s*2+1],m=t[l*2],x=t[l*2+1],g=m-c,d=x-a,b=Math.hypot(g,d),E=b>1e-6;if(E){for(let A=s+1;A<l;A++)if(Math.abs((t[A*2]-c)*d-(t[A*2+1]-a)*g)/b>=n){E=!1;break}}E||(i.push(t[(l-1)*2],t[(l-1)*2+1]),s=l-1)}return i.length/2<3?t:(i.push(i[0],i[1]),i)}function Mn(t,e,n){let{ax:r,ay:i,halfLong:s}=e;if(n==="skillion"){let a=-i,m=r;return[{a,b:m,c:-(a*e.cx+m*e.cy)+e.halfShort}]}let l=[],c=t.length/2-1;for(let a=0;a<c;a++){let m=t[a*2],x=t[a*2+1],g=t[(a+1)%c*2],d=t[(a+1)%c*2+1],b=g-m,E=d-x,A=Math.hypot(b,E);if(A<1e-6||n==="gabled"&&Math.abs((b*r+E*i)/A)<.86)continue;let _=-E/A,R=b/A;l.push({a:_,b:R,c:-(_*m+R*x)})}return!l.length&&s>0?Mn(t,e,"hipped"):l}function Ri(t,e){let n=[];for(let i=0;i<e.length-2;i+=2)n.push(e[i],e[i+1]);if(n.length<6)return[];let r=[];for(let i=0;i<t.length;i++){let s=n;for(let l=0;l<t.length&&s.length>=6;l++)l!==i&&(s=Ei(s,t[i].a-t[l].a,t[i].b-t[l].b,t[i].c-t[l].c));r.push(s.length>=6?s:[])}return r}function Fi(t,e){let n=0;for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<i.length;s+=2){let l=Ne(t[r],i[s],i[s+1]);l>n&&(n=l)}}return n}function Ii(t,e,n){return t.map(r=>({a:r.a*e,b:r.b*e,c:r.c*e+n}))}function Pi(t,e,n,r,i,s,l,c){let a=Ot(li,l);for(let m=0;m<n.length;m++){let x=e[m];if(!x||x.length<6)continue;let g=Te(x,void 0,2);if(!g.length)continue;let d=-n[m].a/c,b=-n[m].b/c,E=Math.hypot(d,b,1),A={x:d/E,y:b/E,z:1/E};t.ensure(x.length/2);let _=t.vertexCount;for(let R=0;R<x.length;R+=2){let L=Math.max(r,Ne(n[m],x[R],x[R+1]));Xe(t,x[R],x[R+1],L,A.x,A.y,A.z,255,s,a)}for(let R=0;R<g.length;R+=3)t.indices.push(_+g[R],_+g[R+2],_+g[R+1]),t.featureIds.push(i)}}function ki(t,e){let n=String(t.class??"").toLowerCase();return n==="industrial"||n==="warehouse"||n==="hangar"||n==="construction"?fi:n==="commercial"||n==="office"||n==="retail"||n==="supermarket"?yn:n==="house"||n==="detached"||n==="garage"||n==="hut"||n==="shed"||e<=7?gn:e>=40?yn:ci}function _i(t,e){let n=String(e.class??""),r=128;return n==="industrial"||n==="warehouse"||n==="construction"?r=96:n==="commercial"||n==="office"||n==="retail"?r=150:(n==="apartments"||n==="residential"||n==="house")&&(r=134),Math.max(0,Math.min(255,r+(t%121-60)))}function Ai(t){let e=t>>>0;return e=(e>>>16^e)*73244475,e=(e>>>16^e)*73244475,e=e>>>16^e,e>>>0}function Li(t){let e=Ye(t.render_height)??Ye(t.height)??Ti(t.levels??t.building_levels??t["building:levels"]);return e&&e>0?Math.max(e,oi):ii}function Bi(t,e){let n=Ye(t.render_min_height)??Ye(t.min_height)??Ye(t.base)??0;return n>0&&n<e?n:0}function Ti(t){let e=Ye(t);return e&&e>0?e*3:null}function Ye(t){if(typeof t=="number"&&isFinite(t))return t;if(typeof t=="string"){let e=parseFloat(t);if(isFinite(e))return e}return null}var Tt=t=>t>127?127:t<-127?-127:t;function Ci(t){let e=t.osm_id;if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let n=Number(e);if(Number.isFinite(n))return n}return null}function Dt(t,e,n,r,i){let s=r*r,l=[],c=x=>t[x*2],a=x=>t[x*2+1],m=(x,g)=>{let d=t.length/2;return t.push((c(x)+c(g))/2,(a(x)+a(g))/2),d};for(let x=0;x<e.length;x+=3){l.push([n+e[x],n+e[x+1],n+e[x+2]]);let g=0;for(;l.length&&!(++g>2e4);){let[d,b,E]=l.pop(),A=(c(d)-c(b))**2+(a(d)-a(b))**2,_=(c(b)-c(E))**2+(a(b)-a(E))**2,R=(c(E)-c(d))**2+(a(E)-a(d))**2,L=Math.max(A,_,R);if(L<=s){i.push(d,b,E);continue}if(L===A){let k=m(d,b);l.push([d,k,E],[k,b,E])}else if(L===_){let k=m(b,E);l.push([b,k,d],[k,E,d])}else{let k=m(E,d);l.push([E,k,b],[k,d,b])}}}}function Rn(t,e,n=0,r,i=!1,s=4096){let l=[],c=[],a=[];for(let b of t.features()){if(b.type!==3||!ce(e,b.properties))continue;let E=b.properties.osm_id,A=typeof E=="number"?E:typeof E=="string"?Number(E):NaN,_=Number.isFinite(A)?A:Number(b.id??0);for(let R of $e(b.loadGeometry())){let L=i?je(R,s):R;if(!L)continue;let k=[],T=[],O=r?_e(L.outer,r):L.outer;for(let P=0;P<O.length;P++)k.push(O[P]);for(let P of L.holes){let C=r?_e(P,r):P;T.push(k.length/2);for(let Y=0;Y<C.length;Y++)k.push(C[Y])}let D=Te(k,T.length?T:void 0,2);if(!D.length)continue;let U=l.length/2;for(let P=0;P<k.length;P++)l.push(k[P]);if(n>0){let P=[];Dt(l,D,U,n,P);for(let C=0;C<P.length;C+=3)c.push(P[C],P[C+2],P[C+1]),a.push(_);continue}for(let P=0;P<D.length;P+=3)c.push(U+D[P],U+D[P+2],U+D[P+1]),a.push(_)}}if(!c.length)return null;let m=l.length/2,x=new Int16Array(l),g=new Uint32Array(c);return{featureIds:new Float64Array(a).buffer,vertices:x.buffer,indices:g.buffer,vertexCount:m,indexCount:g.length}}function In(t){return{shapes:[],cells:[],extent:0,metersPerTile:t}}function Pn(t,e,n,r){if(!(n<=0)){t.extent=r;for(let i of e){let s=i.outer;if(s.length<6)continue;let l=1/0,c=1/0,a=-1/0,m=-1/0;for(let x=0;x<s.length;x+=2)s[x]<l&&(l=s[x]),s[x]>a&&(a=s[x]),s[x+1]<c&&(c=s[x+1]),s[x+1]>m&&(m=s[x+1]);t.shapes.push({outer:s,holes:i.holes,level:n,minX:l,minY:c,maxX:a,maxY:m})}t.cells=[]}}function Vi(t){t.cells=Array.from({length:32*32},()=>[]);let e=t.extent/32;for(let n=0;n<t.shapes.length;n++){let r=t.shapes[n],i=Ze(Math.floor(r.minX/e)),s=Ze(Math.floor(r.maxX/e)),l=Ze(Math.floor(r.minY/e)),c=Ze(Math.floor(r.maxY/e));for(let a=l;a<=c;a++)for(let m=i;m<=s;m++)t.cells[a*32+m].push(n)}}var kn=t=>t.shapes.length===0;function Ut(t,e,n){!t.cells.length&&t.shapes.length&&Vi(t);let r=t.extent/32,i=t.cells[Ze(Math.floor(n/r))*32+Ze(Math.floor(e/r))];if(!i||!i.length)return 0;let s=0;for(let l of i){let c=t.shapes[l];if(c.level<=s||e<c.minX||e>c.maxX||n<c.minY||n>c.maxY||!Fn(c.outer,e,n))continue;let a=!1;for(let m of c.holes)if(Fn(m,e,n)){a=!0;break}a||(s=c.level)}return Math.min(Math.round(s*100),127)}function _n(t,e){let n=[],r=[],i=t.extent>0?t.metersPerTile/t.extent:0,s=i>0?2/i:0,l=Ut(t,e[0],e[1]);n.push(e[0],e[1]),r.push(l);for(let c=0;c+3<e.length;c+=2){let a=e[c],m=e[c+1],x=e[c+2],g=e[c+3],d=Ut(t,x,g);if(d!==l&&s>0){let b=Math.hypot(x-a,g-m),E=Math.min(Math.ceil(b/s),64),A=l;for(let _=1;_<E;_++){let R=_/E,L=a+(x-a)*R,k=m+(g-m)*R,T=Ut(t,L,k);T!==A&&(n.push(L,k),r.push(T),A=T)}}n.push(x,g),r.push(d),l=d}return{pts:n,levels:r}}var Ze=t=>t<0?0:t>31?31:t;function Fn(t,e,n){let r=!1,i=t.length/2;for(let s=0,l=i-1;s<i;l=s++){let c=t[s*2],a=t[s*2+1],m=t[l*2],x=t[l*2+1];a>n!=x>n&&e<(m-c)*(n-a)/(x-a)+c&&(r=!r)}return r}var Tn=mr(An(),1);function Ln(t){let e=[];for(let n=0;n+1<t.length;n+=2)e.push([t[n],t[n+1]]);return e}function Bn(t){let e=[];for(let r of t)e.push(r[0],r[1]);let n=e.length;return n>=4&&(e[0]!==e[n-2]||e[1]!==e[n-1])&&e.push(e[0],e[1]),e}function Cn(t,e,n=0){if(t.length<2)return t;let r=new Map;for(let s of t){let l=s.lift??0,c=r.get(l);c?c.push(s):r.set(l,[s])}let i=[];for(let[s,l]of r){if(l.length<2){i.push(...l);continue}let a=(n>0&&e?l.map(g=>({outer:e(g.outer,-n)??g.outer,holes:g.holes.map(d=>e(d,n)??d)})):l).map(g=>[Ln(g.outer),...g.holes.map(Ln)]),m;try{m=Tn.union(a[0],...a.slice(1))}catch{i.push(...l);continue}let x=m;if(!Array.isArray(x)||x.length===0){i.push(...l);continue}for(let g of x){if(!g.length)continue;let d=Bn(g[0]);if(d.length<8)continue;let b=[];for(let E=1;E<g.length;E++){let A=Bn(g[E]);A.length>=8&&b.push(A)}i.push(s?{outer:d,holes:b,lift:s}:{outer:d,holes:b})}}return i}var Xt=16,Oi=64,Nn=0,Di=1,Vn=2,Ui=3,bt=1,Gi=.6;function zn(t,e,n,r){let i=r.metersPerUnit>0?r.metersPerUnit:.5,s=r.elevation,l=r.base??0,c=Math.max(r.bevel??0,0)/i,a=Math.max(r.bevelDrop??0,0),m=Math.max(r.cornerRadius??0,0)/i,x=Math.max(512,t.length*24),g=new ArrayBuffer(x*Xt),d={view:new DataView(g),bytes:new Uint8Array(g),offset:0,count:0,indices:[],extent:e,ensure(P){if(d.count+P<=x)return;x=Math.max(x*2,d.count+P);let C=new ArrayBuffer(x*Xt);new Uint8Array(C).set(d.bytes.subarray(0,d.offset)),g=C,d.view=new DataView(C),d.bytes=new Uint8Array(C)}},b=[],E=new Map;for(let P of t.features()){if(P.type!==3||!ce(n,P.properties))continue;let C=r.liftBy?.(P.properties)??0;for(let Y of $e(P.loadGeometry())){let Q=je(Y,e,Ae(e));Q&&b.push(C?{...Q,lift:C}:Q)}}let A=new Set,_=Math.max(r.weld??Gi,0),R=Cn(b,(P,C)=>Ht(P,C,e,A),_/i),L=_>0?R.map(P=>({...P,outer:Gn(P.outer,_/i,e),holes:P.holes.map(C=>Gn(C,_/i,e))})):R;for(let P of L){On(P.outer,E);for(let C of P.holes)On(C,E)}r.onShapes?.(L);let k=new Set;for(let[P,C]of E)C>1&&k.add(P);let T=[],O={radius:m,segments:r.cornerSegments,extent:e,margin:Ae(e),minCutRatio:0,maxChord:fn/i};for(let P of L){let C=m>0?{outer:_e(P.outer,{...O,keep:Dn(P.outer,k)}),holes:P.holes.map(N=>_e(N,{...O,keep:Dn(N,k)}))}:P,Y=c>0?Ht(C.outer,c,e,k):C.outer,Q=C.holes.map(N=>c>0?Ht(N,-c,e,k):N),Z=P.lift??0,re=s+Z,X=l+Z;Un(d,Y??C.outer,Q.map((N,q)=>N??C.holes[q]),re,Nn,r.maxSegment??0);let $=re,z=re-a;Y&&c>0&&a>0&&zt(d,Y,C.outer,$,z,Di,e,k),z!==X&&zt(d,C.outer,C.outer,z,X,Vn,e,k);for(let N of C.holes)if(z!==X&&zt(d,N,N,z,X,Vn,e,k),re<X){let q=d.indices.length;Un(d,N,[],X,Ui);for(let te=q;te<d.indices.length;te++)T.push(d.indices[te]);d.indices.length=q}}if(!d.indices.length&&!T.length)return null;let D=d.indices.length,U=new Uint32Array(D+T.length);return U.set(d.indices,0),U.set(T,D),{vertices:g.slice(0,d.offset),indices:U.buffer,vertexCount:d.count,indexCount:U.length,extent:e,capIndexOffset:D}}function We(t,e,n,r){let i=`${Math.round(t*100)},${Math.round(e*100)}`,s=`${Math.round(n*100)},${Math.round(r*100)}`;return i<s?`${i}|${s}`:`${s}|${i}`}function On(t,e){for(let n=0;n+3<t.length;n+=2){let r=We(t[n],t[n+1],t[n+2],t[n+3]);e.set(r,(e.get(r)??0)+1)}}function Dn(t,e){if(!e.size)return;let n=t.length/2-1,r=new Array(n).fill(!1);for(let i=0;i<n;i++){let s=We(t[(i+n-1)%n*2],t[(i+n-1)%n*2+1],t[i*2],t[i*2+1]),l=We(t[i*2],t[i*2+1],t[(i+1)%n*2],t[(i+1)%n*2+1]);(e.has(s)||e.has(l))&&(r[i]=!0)}return r}function lt(t,e,n,r,i,s,l,c){let a=t.offset;return t.view.setFloat32(a,e,!0),t.view.setFloat32(a+4,n,!0),t.view.setInt16(a+8,Ni(Math.round(r*Oi)),!0),t.view.setInt8(a+10,jt(Math.round(i*127))),t.view.setInt8(a+11,jt(Math.round(s*127))),t.view.setInt8(a+12,jt(Math.round(l*127))),t.bytes[a+13]=c,t.view.setInt8(a+14,e<=0?-bt:e>=t.extent?bt:0),t.view.setInt8(a+15,n<=0?-bt:n>=t.extent?bt:0),t.offset+=Xt,t.count++}function Un(t,e,n,r,i=Nn,s=0){let l=[],c=[];for(let g=0;g<e.length;g++)l.push(e[g]);for(let g of n){c.push(l.length/2);for(let d=0;d<g.length;d++)l.push(g[d])}let a=Te(l,c.length?c:void 0,2);if(!a.length)return;let m=a;if(s>0){let g=[];Dt(l,a,0,s,g),m=g}t.ensure(l.length/2);let x=t.count;for(let g=0;g<l.length;g+=2)lt(t,l[g],l[g+1],r,0,0,1,i);for(let g=0;g<m.length;g+=3)t.indices.push(x+m[g],x+m[g+2],x+m[g+1])}function zt(t,e,n,r,i,s,l,c){let a=Math.min(e.length,n.length)/2;if(!(a<3)){t.ensure((a-1)*4);for(let m=0;m<a-1;m++){let x=n[m*2],g=n[m*2+1],d=n[m*2+2],b=n[m*2+3];if(x===d&&g===b||yt(x,g,d,b,l,Ae(l))||c.has(We(x,g,d,b)))continue;let E=d-x,A=b-g,_=Math.hypot(E,A)||1,R=A/_,L=-E/_,k=r-i,T=Math.hypot(e[m*2]-x,e[m*2+1]-g)||0,O=0;if(T>1e-6&&k!==0){let Y=1/Math.hypot(1,k/T);O=T/Math.hypot(T,k)*Math.sign(k),R*=Y,L*=Y}let D=lt(t,e[m*2],e[m*2+1],r,R,L,O,s),U=lt(t,e[m*2+2],e[m*2+3],r,R,L,O,s),P=lt(t,x,g,i,R,L,O,s),C=lt(t,d,b,i,R,L,O,s);t.indices.push(P,U,C,P,D,U)}}}function Ht(t,e,n,r){let i=t.length/2-1;if(i<3)return null;let s=[];for(let x=0;x<i;x++){let g=t[x*2],d=t[x*2+1],b=t[(x+i-1)%i*2],E=t[(x+i-1)%i*2+1],A=t[(x+1)%i*2],_=t[(x+1)%i*2+1],R=Math.hypot(g-b,d-E)||1,L=Math.hypot(A-g,_-d)||1,k=(d-E)/R,T=-(g-b)/R,O=(_-d)/L,D=-(A-g)/L,U=k+O,P=T+D,C=Math.hypot(U,P);if(C<1e-6){s.push(g,d);continue}U/=C,P/=C;let Y=Math.min(1/Math.max(U*k+P*T,.35),3),Q=g-U*e*Y,Z=d-P*e*Y,re=We(b,E,g,d),X=We(g,d,A,_);if(r.has(re)||r.has(X)){s.push(g,d);continue}let $=-Ae(n),z=n+Ae(n),N=(q,te)=>q<=$||q>=z||te<=$||te>=z;(N(g,d)||N(b,E)||N(A,_))&&(Q=g,Z=d),s.push(Q,Z)}s.push(s[0],s[1]);let l=Math.abs($t(t)),c=$t(s);if(Math.sign(c)!==Math.sign($t(t))||Math.abs(c)<l*.25)return null;let a=-Ae(n),m=n+Ae(n);for(let x=0;x<s.length;x+=2)s[x]=Math.max(a,Math.min(m,s[x])),s[x+1]=Math.max(a,Math.min(m,s[x+1]));return s}function $t(t){let e=0;for(let n=0;n<t.length-2;n+=2)e+=t[n]*t[n+3]-t[n+2]*t[n+1];return e/2}var jt=t=>t>127?127:t<-127?-127:t,Ni=t=>t>32767?32767:t<-32768?-32768:t;function Gn(t,e,n){if(!(e>0))return t;let r=Ae(n),i=-r,s=n+r,l=t;for(let c=0;c<3;c++){let a=l.length/2-1;if(a<6)break;let m=new Array(a).fill(!0),x=a;for(let d=0;d<a&&!(x<=5);d++){let b=l[d*2],E=l[d*2+1];if(b<=i||b>=s||E<=i||E>=s)continue;let A=(d+a-1)%a;for(;!m[A]&&A!==d;)A=(A+a-1)%a;let _=(d+1)%a;for(;!m[_]&&_!==d;)_=(_+1)%a;if(A===d||_===d)break;let R=l[A*2],L=l[A*2+1],k=l[_*2]-R,T=l[_*2+1]-L,O=Math.hypot(k,T);O<1e-6||Math.abs((b-R)*T-(E-L)*k)/O<e&&(m[d]=!1,x--)}if(x===a)break;let g=[];for(let d=0;d<a;d++)m[d]&&g.push(l[d*2],l[d*2+1]);g.push(g[0],g[1]),l=g}return l}function Qe(t){let e=t.layer,n=typeof e=="number"?e:typeof e=="string"?Number(e):NaN;if(Number.isFinite(n)&&n!==0)return Math.max(-5,Math.min(5,Math.trunc(n)));let r=t.brunnel;return r==="bridge"?1:r==="tunnel"?-1:0}var ct=20;function jn(t,e,n=0,r,i=0,s={}){let{level:l}=s,c=Math.max(256,t.length*24),a=new ArrayBuffer(c*ct),m=new DataView(a),x=0,g=[],d=L=>{if(x+L<=c)return;c=Math.max(c*2,x+L);let k=new ArrayBuffer(c*ct);new Uint8Array(k).set(new Uint8Array(a,0,x*ct)),a=k,m=new DataView(k)},b=(L,k,T,O,D,U,P,C=0,Y=0,Q=0)=>{let Z=x*ct;return m.setInt16(Z,L,!0),m.setInt16(Z+2,k,!0),m.setInt16(Z+4,T,!0),m.setInt16(Z+6,O,!0),m.setInt8(Z+8,D),m.setInt8(Z+9,U),m.setInt8(Z+10,C),m.setInt8(Z+11,Y),m.setFloat32(Z+12,P,!0),m.setFloat32(Z+16,Q,!0),x++},E=0,A=i>0?12/i:0,_=A>0?Xi(t):null;for(let L of t.features()){if(L.type!==2&&L.type!==3||!ce(e,L.properties)||l!==void 0&&Qe(L.properties)!==l)continue;let k=L.properties.width;E=typeof k=="number"&&k>.5&&k<100?k:0;let T=L.type===3;for(let O of L.loadGeometry()){let D=n>0?Hi(Hn(O),n):Hn(O);if(D.length<4)continue;let U=r&&!kn(r)?_n(r,D):null,P=U?U.pts:D,C=U?.levels,Y=P.length/2;if(Y<2)continue;let Q=Qe(L.properties),Z=wt(Math.round(P[0]),Math.round(P[1])),re=wt(Math.round(P[Y*2-2]),Math.round(P[Y*2-1])),X=null,$=E;if(_&&E>0&&!T){let N=0;for(let ee=0;ee<Y-1;ee++)N+=Math.hypot(P[ee*2+2]-P[ee*2],P[ee*2+3]-P[ee*2+1]);$=Xn(Q,E,Z,re,_);let q=ee=>Math.min(_.width.get(ee)??0,$*2),te=q(Z)-$,K=q(re)-$,oe=Math.min(A,N/2);if(oe>0&&(te>0||K>0)){X=J=>{let fe=0;return te>0&&J<oe&&(fe=te*(1-J/oe)),K>0&&N-J<oe&&(fe=Math.max(fe,K*(1-(N-J)/oe))),$+fe};let ee=[];for(let J of[oe,N-oe])J>.01&&J<N-.01&&ee.push(J);if(ee.length){let J=zi(P,C,ee);P=J.pts,C=J.levels,Y=P.length/2}}}d((Y-1)*4);let z=0;for(let N=0;N<Y-1;N++){let q=P[N*2],te=P[N*2+1],K=P[N*2+2],oe=P[N*2+3],ee=Math.hypot(K-q,oe-te);if(T&&ji(q,te,K,oe,t.extent)){z+=ee;continue}let J=$i(q,te,K,oe,t.extent);if(!J){z+=ee;continue}let[fe,be,de,Fe]=J,Ce=Math.hypot(fe-q,be-te),Le=Math.hypot(de-fe,Fe-be),Ve=Math.hypot(K-de,oe-Fe),we=z+Ce,se=C?C[N]:0,Pe=C?C[N+1]:0,xe=X?X(we):$,Be=X?X(we+Le):$,Oe=b(fe,be,de,Fe,0,-1,we,se,Pe,xe),De=b(fe,be,de,Fe,0,1,we,se,Pe,xe),Ie=b(fe,be,de,Fe,1,1,we,se,Pe,Be),ze=b(fe,be,de,Fe,1,-1,we,se,Pe,Be);z+=Ce+Le+Ve,g.push(Oe,De,Ie,Oe,Ie,ze)}}}if(!g.length)return null;let R=new Uint32Array(g);return{vertices:a.slice(0,x*ct),indices:R.buffer,vertexCount:x,indexCount:R.length}}function zi(t,e,n){let r=[...n].sort((a,m)=>a-m),i=[t[0],t[1]],s=e?[e[0]]:void 0,l=0,c=0;for(let a=0;a+3<t.length;a+=2){let m=t[a],x=t[a+1],g=t[a+2],d=t[a+3],b=Math.hypot(g-m,d-x);for(;c<r.length&&r[c]<=l+.01;)c++;for(;c<r.length&&r[c]<l+b-.01;){let E=(r[c]-l)/b;i.push(m+(g-m)*E,x+(d-x)*E),s&&e&&s.push(Math.round(e[a/2]+(e[a/2+1]-e[a/2])*E)),c++}l+=b,i.push(g,d),s&&e&&s.push(e[a/2+1])}return{pts:i,levels:s}}function Hi(t,e){let n=[];for(let r=0;r+3<t.length;r+=2){let i=t[r],s=t[r+1],l=t[r+2],c=t[r+3];n.push(i,s);let a=Math.min(64,Math.floor(Math.hypot(l-i,c-s)/e));for(let m=1;m<a;m++){let x=m/a;n.push(i+(l-i)*x,s+(c-s)*x)}}return n.push(t[t.length-2],t[t.length-1]),n}function Hn(t){let e=[];for(let n=0;n<t.length;n+=2){let r=t[n],i=t[n+1],s=e.length;s>=2&&e[s-2]===r&&e[s-1]===i||e.push(r,i)}return e}function $i(t,e,n,r,i){let s=n-t,l=r-e,c=0,a=1,m=[[-s,t],[s,i-t],[-l,e],[l,i-e]];for(let[x,g]of m){if(x===0){if(g<0)return null;continue}let d=g/x;if(x<0){if(d>a)return null;d>c&&(c=d)}else{if(d<c)return null;d<a&&(a=d)}}return a-c<1e-6?null:[Math.round(t+s*c),Math.round(e+l*c),Math.round(t+s*a),Math.round(e+l*a)]}function ji(t,e,n,r,i){return t===n&&(t<=0||t>=i)?!0:e===r&&(e<=0||e>=i)}var $n=new WeakMap,wt=(t,e)=>(t+512)*65536+(e+512);function Xn(t,e,n,r,i){if(t===0||e<=0)return e;let s=8*4294967296,l=Math.max(i.raw.get(n+s)??0,i.raw.get(r+s)??0);return l>0&&e>l?l:e}function Xi(t){let e=$n.get(t);if(e)return e;let n={width:new Map,ends:new Map,raw:new Map},r=[];for(let i of t.features()){if(i.type!==2)continue;let s=i.properties.width,l=typeof s=="number"&&s>.5&&s<100?s:0,c=Qe(i.properties);for(let a of i.loadGeometry()){if(a.length<4)continue;let m=wt(Math.round(a[0]),Math.round(a[1])),x=wt(Math.round(a[a.length-2]),Math.round(a[a.length-1]));for(let g of[m,x]){let d=g+(c+8)*4294967296;n.ends.set(d,(n.ends.get(d)??0)+1),l>0&&n.raw.set(d,Math.max(n.raw.get(d)??0,l))}r.push({h:m,t:x,lv:c,w:l})}}for(let i of r){let s=Xn(i.lv,i.w,i.h,i.t,n);if(!(s<=0))for(let l of[i.h,i.t]){let c=n.width.get(l);(c===void 0||s>c)&&n.width.set(l,s)}}return $n.set(t,n),n}var Yi=[["\\u0443\\u043B\\u0438\\u0446\\u0430","\\u0443\\u043B."],["\\u0443\\u043B\\u0438\\u0446\\u044B","\\u0443\\u043B."],["\\u0443\\u043B\\u0438\\u0446\\u0435","\\u0443\\u043B."],["\\u043F\\u0440\\u043E\\u0441\\u043F\\u0435\\u043A\\u0442","\\u043F\\u0440\\u043E\\u0441\\u043F."],["\\u043F\\u0440\\u043E\\u0441\\u043F\\u0435\\u043A\\u0442\\u0430","\\u043F\\u0440\\u043E\\u0441\\u043F."],["\\u043F\\u0435\\u0440\\u0435\\u0443\\u043B\\u043E\\u043A","\\u043F\\u0435\\u0440."],["\\u043F\\u0435\\u0440\\u0435\\u0443\\u043B\\u043A\\u0430","\\u043F\\u0435\\u0440."],["\\u043F\\u0440\\u043E\\u0435\\u0437\\u0434","\\u043F\\u0440-\\u0434"],["\\u043F\\u0440\\u043E\\u0435\\u0437\\u0434\\u0430","\\u043F\\u0440-\\u0434"],["\\u043F\\u043B\\u043E\\u0449\\u0430\\u0434\\u044C","\\u043F\\u043B."],["\\u043F\\u043B\\u043E\\u0449\\u0430\\u0434\\u0438","\\u043F\\u043B."],["\\u0431\\u0443\\u043B\\u044C\\u0432\\u0430\\u0440","\\u0431\\u0443\\u043B."],["\\u0431\\u0443\\u043B\\u044C\\u0432\\u0430\\u0440\\u0430","\\u0431\\u0443\\u043B."],["\\u043D\\u0430\\u0431\\u0435\\u0440\\u0435\\u0436\\u043D\\u0430\\u044F","\\u043D\\u0430\\u0431."],["\\u043D\\u0430\\u0431\\u0435\\u0440\\u0435\\u0436\\u043D\\u043E\\u0439","\\u043D\\u0430\\u0431."],["\\u0448\\u043E\\u0441\\u0441\\u0435","\\u0448."],["\\u0442\\u0443\\u043F\\u0438\\u043A","\\u0442\\u0443\\u043F."],["\\u0442\\u0443\\u043F\\u0438\\u043A\\u0430","\\u0442\\u0443\\u043F."],["\\u043C\\u0438\\u043A\\u0440\\u043E\\u0440\\u0430\\u0439\\u043E\\u043D","\\u043C\\u043A\\u0440."],["\\u043C\\u0438\\u043A\\u0440\\u043E\\u0440\\u0430\\u0439\\u043E\\u043D\\u0430","\\u043C\\u043A\\u0440."],["\\u043A\\u04EF\\u0447\\u0430\\u0438","\\u043A."],["\\u043A\\u0443\\u0447\\u0430\\u0438","\\u043A."],["\\u0445\\u0438\\u0451\\u0431\\u043E\\u043D\\u0438","\\u0445\\u0438\\u0451\\u0431."],["\\u0448\\u043E\\u04B3\\u0440\\u043E\\u04B3\\u0438","\\u0448\\u043E\\u04B3."],["\\u0433\\u0443\\u0437\\u0430\\u0440\\u0433\\u043E\\u04B3\\u0438","\\u0433\\u0443\\u0437."],["\\u043C\\u0430\\u0439\\u0434\\u043E\\u043D\\u0438","\\u043C\\u0430\\u0439\\u0434."]],Yn=new Map(Yi);function Zn(t){let e=t.split(" ");if(e.length<2)return t;let n=!1,r=e.map(s=>{let l=Yn.get(s.toLowerCase());return l?(n=!0,s[0]===s[0].toUpperCase()?l[0].toUpperCase()+l.slice(1):l):s});return!n||!e.filter(s=>Yn.get(s.toLowerCase())===void 0).length?t:r.join(" ")}function Qn(t,e){let n=[],r=[],i=[],s=[],l=[],c=e.textPlacement==="line",a=[],m=[],x=[];for(let g of t.features()){if(!ce(e.filter,g.properties))continue;let d=g.loadGeometry(),b=Qi(g.type,d);if(!b)continue;let E=e.textField?Wn(e.textField,g.properties):"",A=E&&e.abbreviate?Zn(E):E,_=e.iconImage?Wn(e.iconImage,g.properties):"";if(!(!A&&!_)){if(c){let R=Wi(g.type,d);if(!R)continue;x.push({text:A,line:R});continue}n.push(b[0],b[1]),r.push(A),i.push(_),s.push(Ki(g.properties)),l.push(e.iconRotate&&Math.round(Number(g.properties[e.iconRotate]??0))||0)}}if(c){for(let{text:g,line:d}of Zi(x)){m.push(a.length/2);for(let b of d)a.push(b);n.push(Math.round(d[0]),Math.round(d[1])),r.push(g),i.push(""),s.push(128),l.push(0)}m.push(a.length/2)}return r.length?{anchors:new Int16Array(n).buffer,texts:r,icons:i,priorities:new Uint8Array(s).buffer,rotations:new Int16Array(l).buffer,...c?{lines:new Int16Array(a).buffer,lineStarts:new Uint32Array(m).buffer}:{}}:null}function Zi(t){let e=[],n=new Map,r=new Map,i=(s,l,c)=>`${s}\\u241F${l}\\u241F${c}`;for(let{text:s,line:l}of t){let c=i(s,l[0],l[1]),a=i(s,l[l.length-2],l[l.length-1]),m=n.get(a),x=r.get(c);if(x!==void 0){let g=e[x];if(g.line.push(...l.slice(2)),r.delete(c),r.set(i(s,g.line[g.line.length-2],g.line[g.line.length-1]),x),m!==void 0&&m!==x){let d=e[m];g.line.push(...d.line.slice(2)),d.line=[],n.delete(a),r.set(i(s,g.line[g.line.length-2],g.line[g.line.length-1]),x)}continue}if(m!==void 0){let g=e[m];g.line.unshift(...l.slice(0,l.length-2)),n.delete(a),n.set(i(s,g.line[0],g.line[1]),m);continue}n.set(c,e.length),r.set(a,e.length),e.push({text:s,line:l})}return e.filter(s=>s.line.length>=4)}function Wi(t,e){if(t!==2)return null;let n=null,r=0;for(let i of e){if(i.length<4)continue;let s=0;for(let l=0;l+3<i.length;l+=2)s+=Math.hypot(i[l+2]-i[l],i[l+3]-i[l+1]);s>r&&(r=s,n=i)}return n}function Qi(t,e){if(!e.length)return null;if(t===1){let l=e[0];return l.length>=2?[l[0],l[1]]:null}if(t===2){let l=-1,c=0,a=0;for(let m of e)for(let x=0;x+3<m.length;x+=2){let g=m[x+2]-m[x],d=m[x+3]-m[x+1],b=g*g+d*d;b>l&&(l=b,c=m[x]+g/2,a=m[x+1]+d/2)}return l>0?[Math.round(c),Math.round(a)]:null}let n=1/0,r=1/0,i=-1/0,s=-1/0;for(let l of e)for(let c=0;c<l.length;c+=2)l[c]<n&&(n=l[c]),l[c]>i&&(i=l[c]),l[c+1]<r&&(r=l[c+1]),l[c+1]>s&&(s=l[c+1]);return isFinite(n)?[Math.round((n+i)/2),Math.round((r+s)/2)]:null}function Ki(t){let e=t.rank;return typeof e=="number"&&isFinite(e)?Math.max(0,255-Math.min(e,255)):128}function Wn(t,e){let n=Array.isArray(t)?t:[t];for(let r of n){let i=!0,l=r.replace(/\\{([^}]+)\\}/g,(c,a)=>{let m=e[a];return m==null||m===""?(i=!1,""):String(m)}).trim();if(i&&l)return l}return""}function Kn(t,e){let n=[],r=[];for(let i=0;i<t.length;i++){let s=t.feature(i);if(s.type===1&&ce(e,s.properties))for(let l of s.loadGeometry())for(let c=0;c+1<l.length;c+=2)n.push(l[c],l[c+1]),r.push(s.properties)}return r.length?{anchors:Int16Array.from(n).buffer,props:r}:null}var Ji="\\u241F",Yt=(t,e)=>t+Ji+String(e);function qi(){let t=typeof self<"u"?self.origin:void 0;return t&&t!=="null"&&!t.startsWith("blob:")?t+"/":void 0}async function Jn(t,e){let n=performance.now(),r=qi(),i=await fetch(t.url,{signal:e,credentials:"same-origin",...r?{referrer:r}:{}}),s=(R,L,k,T,O=0)=>({type:"loaded",id:t.id,buckets:{},timing:{fetchMs:T,parseMs:O},diag:{status:R,bytes:L,layers:k,built:0}});if(!i.ok){if(i.status===404||i.status===204)return s(i.status,0,[],performance.now()-n);throw new Error(`HTTP ${i.status} \\u0434\\u043B\\u044F ${t.url}`)}let l=await i.arrayBuffer(),c=performance.now()-n;if(l.byteLength===0)return s(i.status,0,[],c);let a=performance.now(),m=new gt(l),x=Object.keys(m.layers),g={},d={},b=new Set,E=[],_=t.plan.some(R=>R.type==="surface"&&(R.elevation??0)>0)&&t.plan.some(R=>R.type==="line"&&R.ground)?In(t.metersPerTile):void 0;for(let R of t.plan){if(!to(R,t.zoom,t.sourceMaxZoom))continue;let L=m.layers[R.sourceLayer];if(!L)continue;let k=no(t.zoom,L.extent);try{if(R.splitBy){let O=ro(L,R.splitBy,R.filter);if(!O.length)continue;let D=d[R.splitBy]??(d[R.splitBy]=[]);for(let U of O){D.includes(U)||D.push(U);let P={...R,splitBy:void 0,filter:oo(R.filter,R.splitBy,U)},C=Zt(P,L,k,t.metersPerTile,_);C&&(g[Yt(R.id,U)]=C)}continue}if(R.network&&R.type==="line"){for(let O of io(L,R.filter)){let D=Zt(R,L,k,t.metersPerTile,_,O);D&&(g[Yt(R.id,O)]=D,b.add(O))}continue}let T=Zt(R,L,k,t.metersPerTile,_);T&&(g[R.id]=T)}catch(T){E.push(`${R.id}: ${T instanceof Error?T.message:String(T)}`)}}return{type:"loaded",id:t.id,buckets:g,...Object.keys(d).length?{splits:d}:{},...b.size?{levels:[...b].sort((R,L)=>R-L)}:{},timing:{fetchMs:c,parseMs:performance.now()-a},diag:{status:i.status,bytes:l.byteLength,layers:x,built:Object.keys(g).length,...E.length?{failed:E}:{}}}}function eo(t){return e=>{let n=e.on;if(typeof n!="string"||!n)return 0;let r=0;for(let i of n.split(",")){let s=t[i];typeof s=="number"&&s>r&&(r=s)}return r}}function to(t,e,n){let r=e-1,i=e<n?e+1:24;return!(t.maxzoom<r||t.minzoom>i)}function no(t,e){return t<=6?Math.max(64,e/24):0}function Zt(t,e,n,r,i,s){{if(t.type==="fill"){let c=r>0?r/e.extent:0,a=t.cornerRadius&&c>0?{radius:t.cornerRadius/c,segments:t.cornerSegments,extent:e.extent,minCutRatio:0,maxChord:hn/c}:void 0,m=Rn(e,t.filter,n,a,t.clipToTile===!0,e.extent);return m?{kind:"fill",...m,extent:e.extent}:null}if(t.type==="surface"){let c=zn(e,e.extent,t.filter,{metersPerUnit:r>0?r/e.extent:0,maxSegment:n,elevation:t.elevation??0,base:t.base,bevel:t.bevel,weld:t.weld,bevelDrop:t.bevelDrop,cornerRadius:t.cornerRadius,cornerSegments:t.cornerSegments,...i?{onShapes:a=>Pn(i,a,t.elevation??0,e.extent)}:{},...t.groundBy?{liftBy:eo(t.groundBy)}:{}});return c?{kind:"surface",...c}:null}if(t.type==="line"){let c=jn(e,t.filter,n,t.ground?i:void 0,r>0?r/e.extent:0,{level:s});return c?{kind:"line",...c,extent:e.extent}:null}if(t.type==="model"){let c=Kn(e,t.filter);return c?{kind:"placement",...c,extent:e.extent}:null}if(t.type==="symbol"){let c=Qn(e,{filter:t.filter,textField:t.textField,iconImage:t.iconImage,iconRotate:t.iconRotate,textPlacement:t.textPlacement,abbreviate:t.abbreviate});return c?{kind:"symbol",...c,extent:e.extent}:null}let l=En(e,e.extent,t.filter,{metersPerUnit:r>0?r/e.extent:0,cornerRadius:t.cornerRadius,cornerSegments:t.cornerSegments});return l?{kind:"fill-extrusion",vertices:l.vertices,indices:l.indices,featureIds:l.featureIds,vertexCount:l.vertexCount,indexCount:l.indexCount,extent:l.extent}:null}}function ro(t,e,n){let r=[];for(let i of t.features()){if(!ce(n,i.properties))continue;let s=i.properties[e];typeof s!="string"&&typeof s!="number"||r.includes(s)||r.push(s)}return r.sort((i,s)=>typeof i=="number"&&typeof s=="number"?i-s:String(i).localeCompare(String(s))),r}function io(t,e){let n=[];for(let r of t.features()){if(!ce(e,r.properties))continue;let i=Qe(r.properties);n.includes(i)||n.push(i)}return n.sort((r,i)=>r-i)}function oo(t,e,n){let r=["==",e,n];return t?["all",t,r]:r}var so=t=>t.kind==="symbol",uo=t=>t.kind==="placement";function qn(t){let e=[];for(let n of Object.values(t.buckets)){if(uo(n)){e.push(n.anchors);continue}if(so(n)){e.push(n.anchors,n.priorities),n.lines&&e.push(n.lines),n.lineStarts&&e.push(n.lineStarts);continue}e.push(n.vertices,n.indices),n.featureIds&&e.push(n.featureIds)}return e}var er=Map;var Ke=new er,Wt=self;Wt.onmessage=t=>{let e=t.data;if(e.type==="abort"){Ke.get(e.id)?.abort(),Ke.delete(e.id);return}let n=new AbortController;Ke.set(e.id,n),Jn(e,n.signal).then(r=>{Ke.has(e.id)&&(Ke.delete(e.id),Wt.postMessage(r,qn(r)))}).catch(r=>{let i=n.signal.aborted;Ke.delete(e.id);let s={type:"error",id:e.id,message:r instanceof Error?r.message:String(r),aborted:i};Wt.postMessage(s)})};})();\n';var kr=class{constructor(e=Ei()){this.workers=[];this.blobUrl=null;this.pending=new z;this.nextId=1;this.cursor=0;this.mainThreadAborts=new z;this.destroyed=false;try{let t=new Blob([_i],{type:"text/javascript"});this.blobUrl=URL.createObjectURL(t);for(let o=0;o<e;o++){let r=new Worker(this.blobUrl);r.onmessage=i=>this.onMessage(i.data),r.onerror=i=>console.error("[osmgl] \u0432\u043E\u0440\u043A\u0435\u0440 \u0443\u043F\u0430\u043B:",i.message),this.workers.push(r);}}catch(t){console.warn("[osmgl] \u0432\u043E\u0440\u043A\u0435\u0440\u044B \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u044B, \u0440\u0430\u0437\u0431\u043E\u0440 \u0442\u0430\u0439\u043B\u043E\u0432 \u043F\u043E\u0439\u0434\u0451\u0442 \u0432 \u0433\u043B\u0430\u0432\u043D\u043E\u043C \u043F\u043E\u0442\u043E\u043A\u0435:",t),this.disposeWorkers();}this.usingWorkers=this.workers.length>0;}get size(){return this.workers.length}load(e,t){let o=this.nextId++,r={type:"load",id:o,...e};if(!this.usingWorkers){let a=new AbortController;return this.mainThreadAborts.set(o,a),Ys(r,a.signal).then(l=>{this.mainThreadAborts.has(o)&&(this.mainThreadAborts.delete(o),t(l));}).catch(l=>{let s=a.signal.aborted;this.mainThreadAborts.delete(o),t({type:"error",id:o,message:l instanceof Error?l.message:String(l),aborted:s});}),o}let i=this.cursor++%this.workers.length;return this.pending.set(o,{resolve:t,workerIndex:i}),this.workers[i].postMessage(r),o}abort(e){if(!this.usingWorkers){this.mainThreadAborts.get(e)?.abort(),this.mainThreadAborts.delete(e);return}let t=this.pending.get(e);if(!t)return;this.pending.delete(e);let o={type:"abort",id:e};this.workers[t.workerIndex].postMessage(o);}onMessage(e){if(this.destroyed)return;let t=this.pending.get(e.id);t&&(this.pending.delete(e.id),t.resolve(e));}disposeWorkers(){for(let e of this.workers)e.terminate();this.workers=[],this.blobUrl&&URL.revokeObjectURL(this.blobUrl),this.blobUrl=null;}destroy(){this.destroyed=true;for(let e of this.mainThreadAborts.values())e.abort();this.mainThreadAborts.clear(),this.pending.clear(),this.disposeWorkers();}};function Ei(){let n=typeof navigator<"u"&&navigator.hardwareConcurrency||4;return Math.max(1,Math.min(n-1,6))}function Zs(n){return Math.max(0,Math.ceil((n*Math.LN2+Math.log(512/360/.5))/Math.LN10))}function Mi(n,e){let t=Zs(n.zoom),o=[Math.round(n.zoom*100)/100,n.center.lat.toFixed(t),n.center.lng.toFixed(t)],r=Math.round(n.bearing*10)/10,i=Math.round(n.pitch*10)/10;(r!==0||i!==0)&&(o.push(r),i!==0&&o.push(i));let a=o.join("/");return e?`${e}=${a}`:a}function Fi(n,e){let t=n.replace(/^#/,"");if(!t)return null;if(e){let s=t.split("&").map(c=>c.split("=")).find(([c])=>c===e);if(!s||s.length<2)return null;t=s[1];}let o=t.split("/");if(o.length<3)return null;let r=Number(o[0]),i=Number(o[1]),a=Number(o[2]);if(!isFinite(r)||!isFinite(i)||!isFinite(a)||Math.abs(i)>90||Math.abs(a)>180)return null;let l={center:{lng:a,lat:i},zoom:r};return o.length>3&&isFinite(Number(o[3]))&&(l.bearing=Number(o[3])),o.length>4&&isFinite(Number(o[4]))&&(l.pitch=Number(o[4])),l}function Qs(n){if(typeof window>"u"||!window.history?.replaceState)return;let e=new URL(window.location.href);e.hash=n,window.history.replaceState(window.history.state,"",e.toString());}var qs={high:{name:"high",maxPixelRatio:2,maxCanvasPixels:16777216,antialias:true,maxWorkers:6,shadowMapSize:1024,detail:1,tileCacheSize:64,allowShadows:true,detailBias:1,maxTiles:512,modelBudget:1,simpleGeometry:false},balanced:{name:"balanced",maxPixelRatio:1.75,maxCanvasPixels:5529600,antialias:true,maxWorkers:4,shadowMapSize:1024,detail:.85,tileCacheSize:40,allowShadows:true,detailBias:1.1,maxTiles:192,modelBudget:.7,simpleGeometry:false},low:{name:"low",maxPixelRatio:1.25,maxCanvasPixels:2592e3,antialias:true,maxWorkers:2,shadowMapSize:512,detail:.5,tileCacheSize:24,allowShadows:false,detailBias:1.25,maxTiles:96,modelBudget:.4,simpleGeometry:true},minimal:{name:"minimal",maxPixelRatio:1,maxCanvasPixels:1152e3,antialias:false,maxWorkers:2,shadowMapSize:512,detail:0,tileCacheSize:16,allowShadows:false,detailBias:1.7,maxTiles:48,modelBudget:.2,simpleGeometry:true}},Ut=n=>qs[n]??qs.high;function Pr(n){let{cores:e,memory:t,mobile:o,devicePixelRatio:r}=n;return e<=2||t!==void 0&&t<=2?"minimal":o?e<=4||t!==void 0&&t<=3?"minimal":e<=6||t!==void 0&&t<=4||r>=3?"low":"balanced":e<=4||t!==void 0&&t<=4?"balanced":"high"}function Rr(){if(typeof navigator>"u")return {cores:4,mobile:false,devicePixelRatio:1};let n=navigator,e=typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches&&typeof screen<"u"&&Math.min(screen.width,screen.height)<=820,t=n.userAgentData?.mobile===true||e;return {cores:n.hardwareConcurrency||4,memory:n.deviceMemory,mobile:t,devicePixelRatio:typeof devicePixelRatio=="number"?devicePixelRatio:1}}function Di(n,e,t,o){let r=Math.min(t||1,o.maxPixelRatio),i=Math.max(n*e,1),a=Math.sqrt(o.maxCanvasPixels/i);return Math.max(Math.min(r,a),1)}function Si(n){return n==="high"?3:n==="balanced"?2:n==="low"?1:0}function $s(n){return n==="minimal"?"low":n==="low"?"balanced":n==="balanced"?"high":null}function Ii(n){return n==="high"?"balanced":n==="balanced"?"low":n==="low"?"minimal":null}var Wd=1,Po=class{constructor(e){this.originX=0;this.originY=0;this._revision=0;this.id=e.id??`obj-${Wd++}`,this.zIndex=e.zIndex??0,this.altitude=e.altitude??0,this.visible=e.visible!==false,this.userData=e.userData??{},this.paint=e;}get ghostOpacity(){return this.paint.ghostOpacity??0}get revision(){return this._revision}invalidate(){this._revision++;}setPaint(e){return Object.assign(this.paint,e),this.invalidate(),this}setOriginFromCoords(e){let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let a of e)for(let l of a){let s=$(l),c=ne(s.lng),h=ie(s.lat);c<t&&(t=c),c>r&&(r=c),h<o&&(o=h),h>i&&(i=h);}if(!isFinite(t)){this.originX=0,this.originY=0;return}this.originX=(t+r)/2,this.originY=(o+i)/2;}toLocal(e){let t=[];for(let o of e){let r=$(o);t.push(ne(r.lng)-this.originX,ie(r.lat)-this.originY);}return t}color(e,t){let o=he(this.paint[e]??t),r=this.paint.opacity??1;return [o[0],o[1],o[2],o[3]*r]}linePaint(e){return e.dashArray=this.paint.dashArray,e.offset=this.paint.offset,this.paint.arrow&&(e.arrow=true,e.arrowColor=this.color("arrowColor","#ffffff"),e.arrowPeriod=this.paint.arrowPeriod??46,e.arrowSize=this.paint.arrowSize??5),e}},Ti=class extends Po{constructor(e){super(e),this.coordinates=e.coordinates,this.segments=e.segments??[],this.setOriginFromCoords([this.coordinates]);}setCoordinates(e){return this.coordinates=e,this.setOriginFromCoords([e]),this.invalidate(),this}setSegments(e){return this.segments=e,this.invalidate(),this}getCoordinates(){return this.coordinates}rings(){return [this.coordinates]}build(){let e=go([this.toLocal(this.coordinates)]);if(!e)return [];let t=this.paint.width??6,o=[],r=this.paint.strokeWidth??0;r>0&&o.push({kind:"line",mesh:e,color:this.color("strokeColor","#ffffff"),width:t+r*2,offset:this.paint.offset});let i=this.colorRuns();if(!i.length)return o.push(this.linePaint({kind:"line",mesh:e,color:this.color("color","#2f6df6"),width:t})),o;let a=this.paint.opacity??1;for(let l of i){let s=go([this.toLocal(this.coordinates.slice(l.from,l.to+1))]);if(!s)continue;let c=he(l.color);o.push(this.linePaint({kind:"line",mesh:s,color:[c[0],c[1],c[2],c[3]*a],width:t}));}return o}colorRuns(){if(this.segments.length===0||this.coordinates.length<2)return [];let e=this.coordinates.length-1,t=this.segments.filter(r=>Number.isInteger(r.at)&&r.at>=0&&r.at<e).sort((r,i)=>r.at-i.at);if(!t.length)return [];let o=[];for(let r=0;r<t.length;r++){let i=r===0?0:t[r].at,a=r+1<t.length?t[r+1].at:e;a>i&&o.push({from:i,to:a,color:t[r].color});}return o}hitTest(e,t,o){let r=(this.paint.width??6)/2+(this.paint.strokeWidth??0)+o,i=ki(this.coordinates,this.altitude,t);for(let a=0;a+1<i.length;a++)if(ec(e,i[a],i[a+1])<=r)return true;return false}},Gr=class extends Po{constructor(e){super(e),this.coordinates=e.coordinates,this.setOriginFromCoords(this.coordinates);}setCoordinates(e){return this.coordinates=e,this.setOriginFromCoords(e),this.invalidate(),this}rings(){return this.coordinates}build(){let e=[],t=Zn(this.coordinates.map(r=>this.toLocal(r)));t&&e.push({kind:"fill",mesh:t,color:this.color("color","#2f6df6"),width:0});let o=this.paint.strokeWidth??this.paint.width??0;if(o>0){let r=this.coordinates.map(a=>this.toLocal(Li(a))),i=go(r);i&&e.push(this.linePaint({kind:"line",mesh:i,color:this.color("strokeColor","#2f6df6"),width:o}));}return e}hitTest(e,t){let o=ki(Li(this.coordinates[0]??[]),this.altitude,t);if(!Pi(e,o))return false;for(let r=1;r<this.coordinates.length;r++)if(Pi(e,ki(Li(this.coordinates[r]),this.altitude,t)))return false;return true}},Hi=class extends Gr{constructor(e){super({...e,coordinates:[Nd(e.center,e.radius,e.segments)]});}};function Nd(n,e,t){let o=$(n),r=e/Oe(o.lat),i=ne(o.lng),a=ie(o.lat),l=Math.max(12,t??Math.min(128,Math.round(24+e/20))),s=[];for(let c=0;c<l;c++){let h=c/l*Math.PI*2;s.push([Se(i+Math.cos(h)*r),Fe(a+Math.sin(h)*r)]);}return s}function ki(n,e,t){let o=[];for(let r of n){let i=$(r),a=t(i.lng,i.lat,e);a&&o.push(a);}return o}function Li(n){if(n.length<2)return n;let e=$(n[0]),t=$(n[n.length-1]);return e.lng===t.lng&&e.lat===t.lat?n:[...n,n[0]]}function ec(n,e,t){let o=t.x-e.x,r=t.y-e.y,i=o*o+r*r;if(i<1e-12)return Math.hypot(n.x-e.x,n.y-e.y);let a=((n.x-e.x)*o+(n.y-e.y)*r)/i;return a=a<0?0:a>1?1:a,Math.hypot(n.x-(e.x+a*o),n.y-(e.y+a*r))}function Pi(n,e){let t=false;for(let o=0,r=e.length-1;o<e.length;r=o++){let i=e[o].x,a=e[o].y,l=e[r].x,s=e[r].y;a>n.y!=s>n.y&&n.x<(l-i)*(n.y-a)/(s-a)+i&&(t=!t);}return t}var tc="objects3d",Jt="level",Kd=32,Ud=100,Ri=120,Jd=40,Xd=.35,jd=.02,Yd=150,Zd=250;function oc(n){return typeof n=="number"?{top:n,right:n,bottom:n,left:n}:{top:n?.top??0,right:n?.right??0,bottom:n?.bottom??0,left:n?.left??0}}function Qd(n){let e={...n};return delete e.cornerRadius,delete e.cornerSegments,e.type==="surface"&&(e.type="fill",delete e.elevation,delete e.base,delete e.bevel,delete e.bevelDrop),e}var Gi=class extends $e{constructor(t){super();this.options=t;this.transform=new Yt;this.ctx=null;this.sources=new z;this.rasterSources=new z;this.renderer=new wo;this.objects=new Ao;this.markerHost=null;this.gestures=null;this.resizeObserver=null;this.frameHandle=0;this.needsRepaint=true;this.padding={top:0,right:0,bottom:0,left:0};this.animation=null;this.loaded=false;this.destroyed=false;this.objects3d=null;this.objects3dEnabled=true;this.frameRing=new Uint8Array(Ri);this.ringAt=0;this.ringSum=0;this.ringFilled=0;this.steadyFrames=0;this.lastFrameAt=0;this.continuousFrames=0;this.onHashChange=null;this.lastMoveEmit=0;this.lastIndoorKey="";this.writingHash=false;this.hashTimer=0;this.layerOverrides=new z;this.autoIndoorLevel=true;this.debugFB=null;let o=typeof t.container=="string"?document.getElementById(t.container):t.container;if(!o)throw new Error(`[osmgl] \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${String(t.container)}`);this.container=o,this.qualityAuto=(t.quality??"auto")==="auto";let r=this.qualityAuto?Pr(Rr()):t.quality;this.qualityCeiling=r,this.quality=Ut(r),this.densityQuality=this.quality,this.maxPixelRatio=t.maxPixelRatio??this.quality.maxPixelRatio,this._style=new Ht(t.theme?mr(t.theme,t.style):t.style),this.background=t.background?he(t.background):null,this.canvas=document.createElement("canvas"),this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.display="block",this.canvas.style.outline="none",getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.container.appendChild(this.canvas);let i=document.createElement("div");i.className="osmgl-markers",i.style.cssText="position:absolute;inset:0;overflow:hidden;pointer-events:none",this.container.appendChild(i),this.markerHost=i,this.objects.setMarkerHost(i);let a=this.transform;a.minZoom=t.minZoom??0,a.maxZoom=t.maxZoom??22,a.maxPitch=t.maxPitch??75,a.projection=t.projection??"mercator",a.center=$(t.center??[0,0]),a.zoom=t.zoom??2,a.bearing=t.bearing??0,a.pitch=t.pitch??0,this.hashName=typeof t.hash=="string"?t.hash:void 0,t.hash&&this.applyHash(false),this.pool=new kr(t.workerCount??Math.min(Ei(),this.quality.maxWorkers)),this.initGL(),this.initSource(),this.initInput(),this.initResize(),queueMicrotask(()=>{this.destroyed||(this.loaded=true,this.emit("load",void 0),this.triggerRepaint());});}initGL(){let t=this.canvas.getContext("webgl2",{alpha:false,antialias:this.quality.antialias,depth:true,stencil:true,preserveDrawingBuffer:false,powerPreference:"high-performance",failIfMajorPerformanceCaveat:false});if(!t)throw new Error("[osmgl] WebGL2 \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0432 \u044D\u0442\u043E\u043C \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435");this.ctx=new Wo(t);let o=new Vt(this.options.fonts??"/tileserver/fonts/{fontstack}/{range}.pbf",this.options.fontstack);this.options.icons&&o.icons.setIcons({...At,...this.options.icons}),o.onAssetsReady=()=>this.triggerRepaint(),this.renderer.symbols=o,this.renderer.objects=this.objects,this.renderer.models.onLoaded=()=>this.triggerRepaint(),this.renderer.init(this.ctx),this.canvas.addEventListener("webglcontextlost",r=>{r.preventDefault(),this.stopFrameLoop(),this.emit("contextlost",void 0),this.emit("error",{message:"\u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442 WebGL \u043F\u043E\u0442\u0435\u0440\u044F\u043D"});});}initSource(){this.options.tiles&&this.addSource(Y,{url:this.options.tiles,minzoom:this.options.sourceMinZoom??0,maxzoom:this.options.sourceMaxZoom??14});for(let[o,r]of Object.entries({...this._style.spec.sources??{},...this.options.sources??{}}))this.addSource(o,r);let t=this.options.objects3d;if(t){this.objects3d=new Hr({endpoint:t.endpoint??"/objects3d",apiKey:t.apiKey??null}),this.objects3d.onReady=()=>this.triggerRepaint(),this.objects3d.setModelKey(this._style.spec.model3dKey??"");let o=t.sourceMaxZoom??14;this.addSource(this.objects3dSource,{url:t.tiles,minzoom:o,maxzoom:o});}}get objects3dSource(){return this.options.objects3d?this.options.objects3d.source??"model3d":null}objects3dPlan(){let t=this.options.objects3d;return {id:tc,type:"model",sourceLayer:t.sourceLayer??"model3d",minzoom:0,maxzoom:24}}planFor(t,o=this._style){let r=o.workerPlan(t),i=t===this.objects3dSource?[...r,this.objects3dPlan()]:r;return this.quality.simpleGeometry?i.map(Qd):i}updateObjects3D(){let t=this.objects3d,o=this.objects3dSource;if(!t||!o)return;let r=this.sources.get(o);if(!r)return;if(!this.objects3dEnabled){t.models.length&&t.clear(l=>this.renderer.models.remove(l,this.ctx?.gl)),this.renderer.hiddenBuildings=t.replacedBuildings,this.renderer.hiddenVenues=t.replacedVenues,this.renderer.hiddenVenueLayer=null;return}let i=this.venuesForMask();t.update({id:tc,"source-layer":this.options.objects3d.sourceLayer??"model3d",layout:this.options.objects3d.layout},r,this.transform,l=>this.renderer.models.add(l),l=>this.renderer.models.remove(l,this.ctx?.gl),this.buildingsForMask(),i),this.renderer.hiddenBuildings=t.replacedBuildings,this.renderer.hiddenVenues=t.replacedVenues,this.renderer.hiddenVenueLayer=i?.key??null;let a=this.renderer.indoorMask.footprint();if(a){let l=this.transform.worldSize>0?this.transform.pixelsPerMeter/this.transform.worldSize*1.5:0;for(let s of t.models){let c=s.origin();s.setHidden(Qe(a,c.x,c.y,l));}}else for(let l of t.models)l.setHidden(false);}buildingsForMask(){let t=this.sources.get(Y);if(!t)return null;for(let o of this._style.layers){if(o.type!=="fill-extrusion"||(o.source??Y)!==Y)continue;let r=this._style.bucketKeyFor(o);if(r!==null)return {source:t,key:r}}return null}venuesForMask(){let t=new Set;for(let o of this._style.layers)"splitBy"in o&&o.splitBy===Jt&&t.add(o.source??Y);for(let o of this._style.layers){if(o.type!=="fill-extrusion"||"splitBy"in o&&o.splitBy)continue;let r=o.source??Y;if(!t.has(r))continue;let i=this.sources.get(r),a=this._style.bucketKeyFor(o);if(i&&a!==null)return {source:i,key:a}}return null}addSource(t,o){if(this.sources.get(t)?.destroy(),this.sources.delete(t),this.rasterSources.get(t)?.destroy(),this.rasterSources.delete(t),o.type==="raster"){let i=new Io({url:o.url,minzoom:o.minzoom??0,maxzoom:o.maxzoom??19,cacheSize:this.quality.tileCacheSize*2});return i.on("data",()=>this.triggerRepaint()),i.on("error",({message:a})=>this.emit("error",{message:a})),this.rasterSources.set(t,i),this.triggerRepaint(),this}let r=new Dr(this.pool,{url:o.url,minzoom:o.minzoom??0,maxzoom:o.maxzoom??14,cacheSize:this.quality.tileCacheSize*2,plan:this.planFor(t)});return r.on("data",()=>this.triggerRepaint()),r.on("error",({message:i})=>this.emit("error",{message:i})),t===Y&&r.on("idle",()=>this.emit("idle",void 0)),this.sources.set(t,r),this.triggerRepaint(),this}initInput(){this.gestures=new Zo(this.canvas,this.transform,t=>{this.animation=null,t==="zoom"&&this.emit("zoom",void 0),this.emitMove(),this.triggerRepaint();},()=>this.emit("moveend",void 0),this.options.gestures),this.initClicks(),this.initHash();}initClicks(){let t=null;this.canvas.addEventListener("pointerdown",r=>{r.button===0&&(t={x:r.clientX,y:r.clientY,t:performance.now()});}),this.canvas.addEventListener("pointerup",r=>{let i=t;if(t=null,r.button!==0||!i||Math.hypot(r.clientX-i.x,r.clientY-i.y)>4||performance.now()-i.t>500)return;let a=this.canvas.getBoundingClientRect(),l={x:r.clientX-a.left,y:r.clientY-a.top},s=this.objects.hitTest(this.transform,l),c=s?null:this.queryRoom(l),h=s||c?null:this.queryBuilding(l);this.options.highlightBuildings!==false&&(this.setHighlight(h),this.setRoomHighlight(c));for(let u of this.getPopups())u.closeOnClick&&this.removePopup(u);this.emit("click",{point:l,lngLat:this.transform.unproject(l),object:s,building:h,symbol:this.querySymbol(l,4)});}),this.canvas.addEventListener("dblclick",r=>{let i=this.pointOf(r);this.emit("dblclick",{point:i,lngLat:this.transform.unproject(i)});}),this.canvas.addEventListener("contextmenu",r=>{r.preventDefault();let i=this.pointOf(r);this.emit("contextmenu",{point:i,lngLat:this.transform.unproject(i)});});let o=0;this.canvas.addEventListener("pointermove",r=>{if(r.pointerType==="touch")return;let i=performance.now();if(i-o<16)return;o=i;let a=this.pointOf(r),l=this.querySymbol(a);this.setSymbolHover(l),this.emit("mousemove",{point:a,lngLat:this.transform.unproject(a),object:this.objects.hitTest(this.transform,a),symbol:l});});}pointOf(t){let o=this.canvas.getBoundingClientRect();return {x:t.clientX-o.left,y:t.clientY-o.top}}initResize(){this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.container),this.resize();}resize(){if(this.destroyed)return;let t=this.container.clientWidth||1,o=this.container.clientHeight||1,r=Di(t,o,Math.min(window.devicePixelRatio||1,this.maxPixelRatio),this.densityQuality);this.canvas.width=Math.round(t*r),this.canvas.height=Math.round(o*r),this.transform.resize(t,o),this.triggerRepaint();}getCenter(){return this.transform.center}getZoom(){return this.transform.zoom}getBearing(){return this.transform.bearing}getPitch(){return this.transform.pitch}setCenter(t){return this.transform.center=$(t),this.afterCameraChange()}setZoom(t){return this.transform.zoom=t,this.emit("zoom",void 0),this.afterCameraChange()}setBearing(t){return this.transform.bearing=t,this.afterCameraChange()}setPitch(t){return this.transform.pitch=t,this.afterCameraChange()}jumpTo(t){let o=this.transform;return t.center!==void 0&&(o.center=$(t.center)),t.zoom!==void 0&&(o.zoom=t.zoom),t.bearing!==void 0&&(o.bearing=t.bearing),t.pitch!==void 0&&(o.pitch=t.pitch),this.animation=null,this.afterCameraChange()}easeTo(t){let o=t.duration??0;if(o<=0)return this.jumpTo(t);let r=this.transform,i={center:r.center,zoom:r.zoom,bearing:r.bearing,pitch:r.pitch},l={center:t.center!==void 0?$(t.center):r.center,zoom:t.zoom??r.zoom,bearing:i.bearing+Ct((t.bearing??r.bearing)-i.bearing),pitch:t.pitch??r.pitch};return this.animation={start:performance.now(),duration:o,from:i,to:l},this.triggerRepaint(),this}flyTo(t){let o=this.transform,r={center:o.center,zoom:o.zoom,bearing:o.bearing,pitch:o.pitch},a={center:t.center!==void 0?$(t.center):o.center,zoom:t.zoom??o.zoom,bearing:r.bearing+Ct((t.bearing??o.bearing)-r.bearing),pitch:t.pitch??o.pitch},l=et(r.zoom),s=(ne(a.center.lng)-ne(r.center.lng))*l,c=(ie(a.center.lat)-ie(r.center.lat))*l,h=Math.hypot(s,c),u=Math.max(o.width,o.height),f=u*Math.pow(2,r.zoom-a.zoom),d=1.42,p=d*d,b,m=null;if(h<1e-6){let y=Math.log(f/u);b=Math.abs(y)/d,m=A=>({u:0,w:u*Math.exp(d*Math.sign(y)*A)});}else {let y=C=>{let v=C===0?u:f,E=C===0?f:u;return (E*E-v*v+(C===0?1:-1)*p*p*h*h)/(2*v*p*h)},A=C=>Math.log(-y(C)+Math.sqrt(y(C)*y(C)+1)),B=A(0);b=(A(1)-B)/d;let w=C=>(Math.exp(C)+Math.exp(-C))/2,_=C=>(Math.exp(2*C)-1)/(Math.exp(2*C)+1);m=C=>{let v=d*C+B;return {u:u*w(B)*_(v)/p-u*Math.sinh(B)/p,w:u*w(B)/w(v)}};}if(!Number.isFinite(b)||b<=0)return this.jumpTo(t);let g=t.duration??Math.min(3e3,b/1.2*1e3);return this.animation={start:performance.now(),duration:g,from:r,to:a,fly:{S:b,u1:h,curve:m,w0:u}},this.triggerRepaint(),this}setPadding(t){return this.padding=oc(t),this.renderer.symbols&&(this.renderer.symbols.padding=this.padding),this.triggerRepaint(),this}getPadding(){return {...this.padding}}getBounds(){let t=this.transform,o=new Xt;for(let[r,i]of [[0,0],[t.width,0],[t.width,t.height],[0,t.height]])o.extend(t.unproject({x:r,y:i}));return o}cameraForBounds(t,o={}){let r=this.transform,i=Vr(t,{width:r.width,height:r.height,bearing:o.bearing??r.bearing,padding:o.padding!==void 0?oc(o.padding):this.padding,maxZoom:Math.min(o.maxZoom??r.maxZoom,r.maxZoom),minZoom:r.minZoom});return i?{...i,pitch:o.pitch??r.pitch}:null}fitBounds(t,o={}){let r=this.cameraForBounds(t,o);if(!r)return this;let i={...r,duration:o.duration??600};return o.fly?this.flyTo(i):this.easeTo(i)}stepAnimation(t){let o=this.animation;if(!o)return false;let r=_e((t-o.start)/o.duration,0,1),i=o.fly?r:Vo(r),a=this.transform,l=$(o.from.center),s=$(o.to.center);if(o.fly){let{u:c,w:h}=o.fly.curve(o.fly.S*r),u=o.fly.u1>1e-6?_e(c/o.fly.u1,0,1):r;return a.center={lng:l.lng+(s.lng-l.lng)*u,lat:l.lat+(s.lat-l.lat)*u},a.zoom=o.from.zoom+Math.log2(o.fly.w0/h),a.bearing=o.from.bearing+(o.to.bearing-o.from.bearing)*Vo(r),a.pitch=o.from.pitch+(o.to.pitch-o.from.pitch)*Vo(r),r>=1&&(a.center=s,a.zoom=o.to.zoom),this.emitMove(),r>=1?(this.animation=null,this.emit("moveend",void 0),false):true}return a.center={lng:l.lng+(s.lng-l.lng)*i,lat:l.lat+(s.lat-l.lat)*i},a.zoom=o.from.zoom+(o.to.zoom-o.from.zoom)*i,a.bearing=o.from.bearing+(o.to.bearing-o.from.bearing)*i,a.pitch=o.from.pitch+(o.to.pitch-o.from.pitch)*i,this.emitMove(),r>=1?(this.animation=null,this.emit("moveend",void 0),false):true}afterCameraChange(){return this.emitMove(),this.triggerRepaint(),this}emitMove(){let t=performance.now();t-this.lastMoveEmit<8||(this.lastMoveEmit=t,this.emit("move",void 0));}project(t,o=0){return this.transform.project($(t),o)}unproject(t){return this.transform.unproject(t)}get style(){return this._style}setStyle(t){let o=this._style,r=new Ht(t);Object.assign(r.splitValues,o.splitValues),this._style=r,this.applyLayerOverrides();for(let[i,a]of this.sources.entries()){let l=JSON.stringify(o.workerPlan(i)),s=JSON.stringify(r.workerPlan(i));l!==s&&a.setPlan(this.planFor(i,r));}return this.objects3d?.setModelKey(t.model3dKey??""),this.triggerRepaint(),this}setTheme(t){return this.setStyle(mr(t,this.options.style))}static get themes(){return Object.keys(Xe)}static get themeList(){return Object.entries(Xe).map(([t,o])=>({id:t,name:o.name||t}))}setLayoutProperty(t,o,r){let i=this._style.layers.find(l=>l.id===t);if(!i)return console.warn(`[osmgl] \u0441\u043B\u043E\u0439 \u0441\u0442\u0438\u043B\u044F "${t}" \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D`),this;let a=i.layout??(i.layout={});if(a[o]=r,this.rememberOverride(t,{layout:{[o]:r}}),o==="textField"||o==="iconImage"||o==="splitBy")for(let[l,s]of this.sources)s.setPlan(this.planFor(l));return this.triggerRepaint(),this}setPaintProperty(t,o,r){let i=this._style.layers.find(a=>a.id===t);return i?(i.paint[o]=r,this.rememberOverride(t,{paint:{[o]:r}}),this.triggerRepaint(),this):(console.warn(`[osmgl] \u0441\u043B\u043E\u0439 \u0441\u0442\u0438\u043B\u044F "${t}" \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D`),this)}setShadows(t){let o=typeof t=="boolean"?{enabled:t}:t;return Object.assign(this.renderer.shadows,o),this.triggerRepaint(),this}querySymbol(t,o=2){let r=this.renderer.symbols?.querySymbol(t,o);return r?{layerId:r.layerId,text:r.text,icon:r.icon,lngLat:{lng:Se(r.mercX),lat:Fe(r.mercY)},key:Vt.keyOf(r)}:null}setSymbolHover(t){return this.renderer.symbols?.setHover(t?.key??null)&&this.triggerRepaint(),this}setSymbolHidden(t){return this.renderer.symbols?.setHidden(t?.key??null)&&this.triggerRepaint(),this}queryBuilding(t){let o=null;for(let r of this._style.layers){if(r.type!=="fill-extrusion"||r.overlay||!this._style.layerVisibleAt(r,this.transform.zoom))continue;let i=this.sources.get(r.source??Y);if(!i)continue;let a=Xn(this.transform,i,r.id,t);a&&(!o||a.distance<o.distance)&&(o=a);}return o}setHighlight(t,o={}){return this.renderer.highlight=t?{layerId:t.layerId,featureId:t.featureId,color:o.color??this.options.highlightColor??"#4ec97f",opacity:o.opacity??.45}:null,this.triggerRepaint(),this}queryRoom(t){if(!this.renderer.indoorOpen)return null;let o=[],r=new z,i;for(let l of this._style.layers){if(l.type!=="fill"||!l.id.startsWith("indoor-")||l.id==="indoor-shell"||!this._style.layerVisibleAt(l,this.transform.zoom))continue;let s=this._style.bucketKeyFor(l);s&&(o.push(s),r.set(s,l.id),i??(i=this.sources.get(l.source??Y)));}if(!i||!o.length)return null;let a=jn(this.transform,i,o,t);return a?{...a,layerId:r.get(a.layerId)??a.layerId,bucketKey:a.layerId}:null}setRoomHighlight(t,o={}){return this.renderer.highlightFill=t?{layerId:t.layerId,bucketKey:t.bucketKey??t.layerId,featureId:t.featureId,color:o.color??this.options.highlightColor??"#4ec97f",opacity:o.opacity??.5}:null,this.triggerRepaint(),this}getHighlight(){let t=this.renderer.highlight;return t?{featureId:t.featureId,layerId:t.layerId}:null}initHash(){this.options.hash&&(this.on("move",()=>this.scheduleHash()),this.on("moveend",()=>this.scheduleHash(true)),this.onHashChange=()=>{this.writingHash||this.applyHash(true);},window.addEventListener("hashchange",this.onHashChange),this.scheduleHash(true));}scheduleHash(t=false){if(!(!this.options.hash||this.destroyed)){if(this.hashTimer){if(!t)return;clearTimeout(this.hashTimer);}this.hashTimer=setTimeout(()=>{this.hashTimer=0,this.writeHash();},t?0:300);}}writeHash(){if(!this.options.hash||this.destroyed)return;let t=this.transform,o=Mi({center:t.center,zoom:t.zoom,bearing:t.bearing,pitch:t.pitch},this.hashName);this.writingHash=true,Qs("#"+o),setTimeout(()=>this.writingHash=false,0);}applyHash(t){if(typeof window>"u")return;let o=Fi(window.location.hash,this.hashName);if(!o)return;let r=this.transform;o.center&&(r.center=o.center),o.zoom!==void 0&&(r.zoom=o.zoom),o.bearing!==void 0&&(r.bearing=o.bearing),o.pitch!==void 0&&(r.pitch=o.pitch),t&&(this.emitMove(),this.triggerRepaint());}setQuality(t){this.qualityAuto=t==="auto";let o=t==="auto"?Pr(Rr()):t;return this.qualityCeiling=o,this.resetFrameWindow(),this.applyQuality(Ut(o)),this}getQuality(){return {auto:this.qualityAuto,profile:{...this.quality},pixelRatio:this.transform.width>0?this.canvas.width/this.transform.width:1}}applyQuality(t,o=false){let r=this.quality.simpleGeometry,i=o?r:t.simpleGeometry;if(this.quality={...t,simpleGeometry:i},this.resetFrameWindow(),this.objects3d&&(this.objects3d.budgetScale=t.modelBudget),r!==i)for(let[a,l]of this.sources.entries())l.setPlan(this.planFor(a));o||(this.densityQuality=t,this.options.maxPixelRatio===void 0&&(this.maxPixelRatio=t.maxPixelRatio)),this.renderer.detailScale=t.detail,this.renderer.allowShadows=t.allowShadows,this.renderer.shadows.resolution!==t.shadowMapSize&&this.setShadows({resolution:t.shadowMapSize});for(let a of this.sources.values())a.setCoverOptions({detailBias:t.detailBias,maxTiles:t.maxTiles});this.resize();}resetFrameWindow(){this.frameRing.fill(0),this.ringAt=0,this.ringSum=0,this.ringFilled=0,this.steadyFrames=0;}checkFrameBudget(t){if(!this.qualityAuto||this.sum(a=>a.pendingCount)>0)return;let o=t>Ud?3:t>Kd?1:0;if(this.ringSum+=o-this.frameRing[this.ringAt],this.frameRing[this.ringAt]=o,this.ringAt=(this.ringAt+1)%Ri,this.ringFilled<Ri&&this.ringFilled++,this.steadyFrames++,this.ringFilled<Jd)return;let r=this.ringSum/this.ringFilled;if(r>=Xd){let a=Ii(this.quality.name);if(!a)return;console.info(`[osmgl] \u0442\u044F\u0436\u0451\u043B\u044B\u0445 \u043A\u0430\u0434\u0440\u043E\u0432 ${(r*100).toFixed(0)}% \u2014 \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u043E \u043F\u043E\u043D\u0438\u0436\u0435\u043D\u043E \u0434\u043E \xAB${a}\xBB (\u043F\u043B\u043E\u0442\u043D\u043E\u0441\u0442\u044C \u0431\u0443\u0444\u0435\u0440\u0430 \u043F\u0440\u0435\u0436\u043D\u044F\u044F)`),this.applyQuality(Ut(a),true);return}if(r>jd||this.steadyFrames<Yd)return;let i=$s(this.quality.name);!i||Si(i)>Si(this.qualityCeiling)||(console.info(`[osmgl] \u043A\u0430\u0434\u0440\u044B \u0443\u043A\u043B\u0430\u0434\u044B\u0432\u0430\u044E\u0442\u0441\u044F \u0432 \u0431\u044E\u0434\u0436\u0435\u0442 \u2014 \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u043E \u043F\u043E\u0434\u043D\u044F\u0442\u043E \u0434\u043E \xAB${i}\xBB`),this.applyQuality(Ut(i),true));}getShadows(){return {...this.renderer.shadows}}setSky(t){let o=typeof t=="boolean"?{enabled:t}:t;return Object.assign(this._style.sky,o),this.triggerRepaint(),this}getSky(){return {...this._style.sky}}setLight(t){return Object.assign(this._style.light,t),this.triggerRepaint(),this}setLayerVisible(t,o){let r=this._style.layers.find(i=>i.id===t);return r&&(r.visible=o,this.rememberOverride(t,{visible:o}),this.triggerRepaint()),this}setObjects3DEnabled(t){return this.objects3dEnabled===t?this:(this.objects3dEnabled=t,this.triggerRepaint(),this)}get objects3DEnabled(){return this.objects3dEnabled}rasterLayerVisible(t){let o=this.transform.zoom;return this._style.layers.some(r=>r.type==="raster"&&r.source===t&&this._style.layerVisibleAt(r,o))}rememberOverride(t,o){let r=this.layerOverrides.get(t)??{};this.layerOverrides.set(t,{...r,...o,paint:{...r.paint??{},...o.paint??{}},layout:{...r.layout??{},...o.layout??{}}});}applyLayerOverrides(){if(this.layerOverrides.size)for(let t of this._style.layers){let o=this.layerOverrides.get(t.id);if(o&&(o.visible!==void 0&&(t.visible=o.visible),o.paint&&Object.assign(t.paint??(t.paint={}),o.paint),o.layout)){let r=t;Object.assign(r.layout??(r.layout={}),o.layout);}}}setBackground(t){return this.background=he(t),this.triggerRepaint(),this}getIndoorLevels(){let t=[];for(let[o,r]of this.sources.entries())if(this._style.layers.some(i=>(i.source??Y)===o&&"splitBy"in i&&i.splitBy===Jt))for(let i of r.splitValues(Jt)){let a=Number(i);Number.isFinite(a)&&!t.includes(a)&&t.push(a);}return t.sort((o,r)=>o-r)}getIndoorLevel(){let t=this._style.splitValues[Jt];return typeof t=="number"?t:null}setIndoorLevel(t){return t===null?delete this._style.splitValues[Jt]:this._style.splitValues[Jt]=t,this.triggerRepaint(),this}syncIndoor(){let t=this.getIndoorLevels(),o=t.join(",");if(o!==this.lastIndoorKey){if(this.lastIndoorKey=o,this.autoIndoorLevel){let r=this.getIndoorLevel();t.length?(r===null||!t.includes(r))&&this.setIndoorLevel(t.includes(0)?0:t.find(i=>i>=0)??t[0]):r!==null&&this.setIndoorLevel(null);}this.emit("indoor",{levels:t,level:this.getIndoorLevel()});}}addObject(t){return this.objects.add(t),this.triggerRepaint(),this}removeObject(t){return this.objects.remove(t),this.triggerRepaint(),this}getObjects(){return this.objects.all}updateObject(){return this.triggerRepaint(),this}addModel(t){return this.renderer.models.add(t),this.triggerRepaint(),this}removeModel(t){return this.renderer.models.remove(t,this.ctx?.gl),this.triggerRepaint(),this}getObjects3DStats(){return this.objects3d?.stats??null}getModels(){return this.renderer.models.all}addMarker(t){return this.objects.addMarker(t),t.update(this.transform),this}removeMarker(t){return this.objects.removeMarker(t),this}getMarkers(){return this.objects.allMarkers}addPopup(t){return t.onCloseRequest(()=>this.removePopup(t)),this.objects.addMarker(t),t.update(this.transform),this}removePopup(t){return this.objects.removeMarker(t),this}getPopups(){return this.objects.allMarkers.filter(t=>t instanceof ko)}objectAt(t,o=4){return this.objects.hitTest(this.transform,t,o)}setProjection(t){let o=this.transform;if(o.projection===t)return this;o.projection=t;let r=o.effectiveMinZoom(),i=t==="globe"?Math.min(o.maxPitch,jt):o.maxPitch,a=o.zoom<r,l=o.pitch>i;return a||l?this.easeTo({zoom:a?r:o.zoom,pitch:l?i:o.pitch,duration:600}):(this.emit("move",void 0),this.triggerRepaint()),this}getProjection(){return this.transform.projection}refreshSource(t){return this.sources.get(t)?.reload(),this.rasterSources.get(t)?.reload(),this.triggerRepaint(),this}refresh(){for(let t of this.sources.values())t.reload();for(let t of this.rasterSources.values())t.reload();return this.renderer.refreshHighlight(),this.triggerRepaint(),this}sum(t){let o=0;for(let r of this.sources.values())o+=t(r);return o}getStats(){return {pendingTiles:this.sum(t=>t.pendingCount),visibleTiles:this.sum(t=>t.visibleTiles.length),labels:this.renderer.symbols?.placedCount??0,models:this.renderer.models.readyCount,workers:this.pool.usingWorkers?this.pool.size:0,renderer:this.ctx?.caps.rendererName??"\u043D\u0435\u0442 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430"}}triggerRepaint(){this.destroyed||(this.needsRepaint=true,!this.frameHandle&&(this.frameHandle=requestAnimationFrame(t=>{this.frameHandle=0,this.renderFrame(t);})));}debugFloatPixels(t,o,r,i){let a=this.ctx;if(!a||!a.caps.colorBufferFloat)return null;let l=a.gl,s=this.canvas.width,c=this.canvas.height,h=!!l.getExtension("EXT_float_blend"),u=h?l.RGBA32F:l.RGBA16F,f=h?l.FLOAT:l.HALF_FLOAT;if(this.debugFB&&(this.debugFB.w!==s||this.debugFB.h!==c)&&(l.deleteFramebuffer(this.debugFB.fb),l.deleteTexture(this.debugFB.tex),l.deleteRenderbuffer(this.debugFB.rb),this.debugFB=null),!this.debugFB){let d=l.createTexture(),p=l.createFramebuffer(),b=l.createRenderbuffer();if(!d||!p||!b)return null;l.bindTexture(l.TEXTURE_2D,d),l.texImage2D(l.TEXTURE_2D,0,u,s,c,0,l.RGBA,f,null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l.NEAREST),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l.NEAREST),l.bindTexture(l.TEXTURE_2D,null),l.bindRenderbuffer(l.RENDERBUFFER,b),l.renderbufferStorage(l.RENDERBUFFER,l.DEPTH24_STENCIL8,s,c),l.bindRenderbuffer(l.RENDERBUFFER,null),l.bindFramebuffer(l.FRAMEBUFFER,p),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,d,0),l.framebufferRenderbuffer(l.FRAMEBUFFER,l.DEPTH_STENCIL_ATTACHMENT,l.RENDERBUFFER,b);let m=l.checkFramebufferStatus(l.FRAMEBUFFER);if(l.bindFramebuffer(l.FRAMEBUFFER,null),a.invalidateState(),m!==l.FRAMEBUFFER_COMPLETE)return null;this.debugFB={fb:p,tex:d,rb:b,w:s,h:c};}a.screen=this.debugFB.fb;try{this.renderFrame(performance.now()),a.bindFramebuffer(this.debugFB.fb);let d=new Float32Array(r*i*4);return l.readPixels(t,o,r,i,l.RGBA,l.FLOAT,d),{data:d,format:h?"rgba32f":"rgba16f"}}finally{a.screen=null,this.triggerRepaint();}}renderFrame(t){if(this.destroyed||!this.ctx)return;let o=performance.now();this.needsRepaint=false;let r=this.stepAnimation(t),i=this.ctx;i.bindFramebuffer(null),i.viewport(0,0,this.canvas.width,this.canvas.height),i.setDepthMask(true),i.clear(this.background??this._style.background,true,true);for(let d of this.sources.values())d.update(this.transform);this.updateObjects3D();for(let[d,p]of this.rasterSources)this.rasterLayerVisible(d)&&p.update(this.transform);this.syncIndoor(),this.objects.updateMarkers(this.transform);let a=(this.sources.size>0||this.rasterSources.size>0)&&this.renderer.render(i,this.transform,this.sources,this._style,t,this.rasterSources),l=performance.now()-o,s=r||a||this.needsRepaint,c=this.lastFrameAt>0?t-this.lastFrameAt:0,h=c>0&&c<Zd,u=h?c:0;this.continuousFrames=h?this.continuousFrames+1:0;let f=this.continuousFrames>1?c:l;this.lastFrameAt=t,this.checkFrameBudget(f),this.emit("render",{frameMs:l,intervalMs:u}),s&&this.triggerRepaint();}stopFrameLoop(){this.frameHandle&&cancelAnimationFrame(this.frameHandle),this.frameHandle=0;}get isLoaded(){return this.loaded}destroy(){if(this.onHashChange&&(window.removeEventListener("hashchange",this.onHashChange),this.onHashChange=null),this.hashTimer&&clearTimeout(this.hashTimer),!this.destroyed){this.destroyed=true,this.stopFrameLoop(),this.resizeObserver?.disconnect(),this.gestures?.destroy();for(let t of this.sources.values())t.destroy();this.sources.clear();for(let t of this.rasterSources.values())t.destroy();this.rasterSources.clear(),this.objects.destroy(),this.markerHost?.remove(),this.pool.destroy(),this.ctx&&this.renderer.destroy(this.ctx),this.removeAllListeners(),this.canvas.remove();}}},m2=Gi;
|
|
2326
2326
|
exports.AssetLoader=Lo;exports.BASE_SOURCE=Y;exports.BUILDING_HEIGHT_SCALE=Mt;exports.BUILDING_POS_SCALE=Et;exports.BUILDING_VERTEX_STRIDE=Ie;exports.CITY_STYLE=Xu;exports.Circle=Hi;exports.DEFAULT_ICONS=At;exports.DEFAULT_LIGHT=kn;exports.DEFAULT_SHADOWS=Fs;exports.DEFAULT_SKY=Hn;exports.DEFAULT_STYLE=Pn;exports.DepthTarget=ho;exports.EARTH_CIRCUMFERENCE=No;exports.FILL_VERTEX_STRIDE=tt;exports.GLOBE_MAX_PITCH=jt;exports.GLOBE_ZOOM_MAX=ft;exports.GLOBE_ZOOM_MIN=Jo;exports.GLYPH_BORDER=Ce;exports.GLYPH_SIZE=qe;exports.GROUND_SCALE=cu;exports.GeomType=io;exports.GlyphSource=Eo;exports.GroundArrows=mo;exports.IconSource=Fo;exports.IndoorMask=bo;exports.LEVEL_LIMIT=uu;exports.LINE_VERTEX_STRIDE=nt;exports.LayerRenderer=wo;exports.LngLatBounds=Xt;exports.MAX_LATITUDE=zi;exports.MODEL_VERTEX_STRIDE=vr;exports.Map=Gi;exports.MapObject=Po;exports.Marker=Ho;exports.Model=To;exports.ModelLayer=at;exports.ObjectManager=Ao;exports.Polygon=Gr;exports.Polyline=Ti;exports.Popup=ko;exports.RELIEF_STYLE=Ju;exports.RUNTIME_FILL_STRIDE=Yn;exports.RUNTIME_LINE_STRIDE=Pt;exports.RasterSource=Io;exports.RasterTile=Sr;exports.SDF_EDGE=si;exports.SDF_PX=Mo;exports.SOFT_STYLE=Uu;exports.SPLIT_SEP=Dl;exports.SURFACE_CUT_BLEED=fo;exports.SURFACE_LEVEL_SCALE=Xa;exports.SURFACE_VERTEX_STRIDE=It;exports.SdfAtlas=_o;exports.Style=Ht;exports.SymbolRenderer=Vt;exports.THEMES=Xe;exports.TILE_SIZE=ct;exports.TileID=Nt;exports.Transform=Yt;exports.VectorTile=no;exports.VectorTileFeature=rr;exports.VectorTileLayer=nr;exports.abbreviateStreet=Ci;exports.addGround=In;exports.altitudeFromMercatorZ=ip;exports.applyTheme=pr;exports.arrowLabelOffset=Vs;exports.arrowVertices=ih;exports.buildRuntimeFill=Zn;exports.buildRuntimeLine=go;exports.cameraForBounds=Vr;exports.circumferenceAtLatitude=Oe;exports.clampLat=Ko;exports.clampPixelRatio=Di;exports.clipLineToRect=ui;exports.coordinateDigits=Zs;exports.coveringTiles=So;exports.createGround=Sn;exports.default=m2;exports.deviceHints=Rr;exports.distToSegment=ec;exports.evaluateColor=He;exports.evaluateNumber=V;exports.extractFeature=Ar;exports.featureLevel=yt;exports.fillFootprint=Wn;exports.fogPlanes=kt;exports.footprintOf=Nn;exports.formatHash=Mi;exports.generateBuildings=ln;exports.generateFill=fn;exports.generateLine=Tn;exports.generateSurface=Dn;exports.generateSymbols=xi;exports.globeBasis=Jr;exports.globeFlatMix=jo;exports.globeRadius=Xo;exports.globeToLocal=ji;exports.groundAt=hr;exports.iconRotation=Ws;exports.insideFootprint=Qe;exports.latFromMercatorY=Fe;exports.lngFromMercatorX=Se;exports.lngLatToUnit=Yo;exports.matchesFilter=Be;exports.mercatorMetersPerTile=zr;exports.mercatorX=ne;exports.mercatorY=ie;exports.mercatorZFromAltitude=Or;exports.metersPerPixel=lp;exports.metersPerTile=Vi;exports.nextQualityDown=Ii;exports.parseGlb=Mh;exports.parseGlbAsync=$n;exports.parseGlyphs=Ss;exports.parseHash=Fi;exports.patchUV=fs;exports.pickBuilding=Xn;exports.pickFill=jn;exports.pitchIntent=ta;exports.pixelsPerMeter=ap;exports.placeAlongLine=di;exports.pointInRing=Pi;exports.qualityFor=Pr;exports.qualityProfile=Ut;exports.raySphere=Xr;exports.resolveTemplate=vi;exports.roundRing=Ke;exports.sdfFromAlpha=ci;exports.shapeText=fi;exports.splitBucketKey=Je;exports.splitByGround=Ln;exports.splitPolygons=pt;exports.styleWithTheme=mr;exports.tileOriginMeters=Wi;exports.tileUrl=Ns;exports.toLngLat=$;exports.unitToLngLat=Ur;exports.worldSize=et;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=osmgl.global.js.map
|
|
2327
2327
|
//# sourceMappingURL=osmgl.global.js.map
|