t.y!=o.y>t.y&&t.x<(o.x-i.x)*(t.y-i.y)/(o.y-i.y)+i.x&&(r=!r),n=Math.min(n,ql(t,i,o));}}return (r?1:-1)*Math.sqrt(n)}(this.p,n),this.max=this.d+this.h*Math.SQRT2;}}const By=Number.POSITIVE_INFINITY,Cy=Math.sqrt(2);function Ry(t,[e,r]){let n=0,i=0;if(r===By){e<0&&(e=0);const r=e/Cy;switch(t){case"top-right":case"top-left":i=r-7;break;case"bottom-right":case"bottom-left":i=7-r;break;case"bottom":i=7-e;break;case"top":i=e-7;}switch(t){case"top-right":case"bottom-right":n=-r;break;case"top-left":case"bottom-left":n=r;break;case"left":n=e;break;case"right":n=-e;}}else {switch(e=Math.abs(e),r=Math.abs(r),t){case"top-right":case"top-left":case"top":i=r-7;break;case"bottom-right":case"bottom-left":case"bottom":i=7-r;}switch(t){case"top-right":case"bottom-right":case"right":n=-e;break;case"top-left":case"bottom-left":case"left":n=e;}}return [n,i]}function Dy(t){switch(t){case"right":case"top-right":case"bottom-right":return "right";case"left":case"top-left":case"bottom-left":return "left"}return "center"}function Vy(t,e,r,n,i,a,s,o,l,u,c,h,p,f,d){let m=a.textMaxSize.evaluate(e,{},h);void 0===m&&(m=s);const y=t.layers[0].layout,g=y.get("icon-offset").evaluate(e,{},h),x=Oy(r.horizontal)||r.vertical,v="globe"===p.name,_=im,w=s/_,M=t.tilePixelRatio*m/_,A=(B=t.overscaling,t.zoom>18&&B>2&&(B>>=1),Math.max(Tr/(512*B),1)*y.get("symbol-spacing")),S=y.get("text-padding")*t.tilePixelRatio,I=y.get("icon-padding")*t.tilePixelRatio,k=b(y.get("text-max-angle")),P="map"===y.get("text-rotation-alignment")&&"point"!==y.get("symbol-placement"),E="map"===y.get("icon-rotation-alignment")&&"point"!==y.get("symbol-placement"),z=y.get("symbol-placement"),T=A/2;var B;const C=y.get("icon-text-fit").evaluate(e,{},h),R=y.get("icon-text-fit-padding").evaluate(e,{},h),D="none"!==C;let V;!1===t.hasAnyIconTextFit&&D&&(t.hasAnyIconTextFit=!0),n&&D&&(t.allowVerticalPlacement&&r.vertical&&(V=ry(n,r.vertical,C,R,g,w)),x&&(n=ry(n,x,C,R,g,w)));const L=(s,o,m)=>{if(o.x<0||o.x>=Tr||o.y<0||o.y>=Tr)return;let y=null;if(v){const{x:t,y:e,z:r}=p.projectTilePoint(o.x,o.y,m);y={anchor:new ny(t,e,r,0,void 0),up:p.upVector(m,o.x,o.y)};}!function(t,e,r,n,i,a,s,o,l,u,c,h,p,f,d,m,y,g,x,v,b,_,w,M,A,S,I){const k=t.addToLineVertexArray(e,n);let P,E,z,T,B,C,R,D=0,V=0,L=0,F=0,N=-1,O=-1;const U={};let q=ho("");const $=r?r.anchor:e,G="none"!==l.layout.get("icon-text-fit").evaluate(b,{},A);let Y=0,X=0;if(void 0===l._unevaluatedLayout.getValue("text-radial-offset")?[Y,X]=l.layout.get("text-offset").evaluate(b,{},A).map((t=>t*im)):(Y=l.layout.get("text-radial-offset").evaluate(b,{},A)*im,X=By),t.allowVerticalPlacement&&i.vertical){const t=i.vertical;if(d)C=jy(t),o&&(R=jy(o));else {const r=l.layout.get("text-rotate").evaluate(b,{},A)+90;z=Uy(u,$,e,c,h,p,t,f,r,m),o&&(T=Uy(u,$,e,c,h,p,o,g,r));}}if(a){const n=l.layout.get("icon-rotate").evaluate(b,{},A),i=My(a,n,w,G),s=o?My(o,n,w,G):void 0;E=Uy(u,$,e,c,h,p,a,g,n),D=4*i.length;const f=t.iconSizeData;let d=null;"source"===f.kind?(d=[am*l.layout.get("icon-size").evaluate(b,{},A)],d[0]>Fy&&j(`${t.layerIds[0]}: Value for "icon-size" is >= ${Ly}. Reduce your "icon-size".`)):"composite"===f.kind&&(d=[am*_.compositeIconSizes[0].evaluate(b,{},A),am*_.compositeIconSizes[1].evaluate(b,{},A)],(d[0]>Fy||d[1]>Fy)&&j(`${t.layerIds[0]}: Value for "icon-size" is >= ${Ly}. Reduce your "icon-size".`)),t.addSymbols(t.icon,i,d,v,x,b,!1,r,e,k.lineStartIndex,k.lineLength,-1,M,A,S,I),N=t.icon.placedSymbolArray.length-1,s&&(V=4*s.length,t.addSymbols(t.icon,s,d,v,x,b,jm.vertical,r,e,k.lineStartIndex,k.lineLength,-1,M,A,S,I),O=t.icon.placedSymbolArray.length-1);}for(const n in i.horizontal){const a=i.horizontal[n];P||(q=ho(a.text),d?B=jy(a):P=Uy(u,$,e,c,h,p,a,f,l.layout.get("text-rotate").evaluate(b,{},A),m));const o=1===a.positionedLines.length;if(L+=Ny(t,r,e,a,s,l,d,b,m,k,i.vertical?jm.horizontal:jm.horizontalOnly,o?Object.keys(i.horizontal):[n],U,N,_,M,A,S),o)break}i.vertical&&(F+=Ny(t,r,e,i.vertical,s,l,d,b,m,k,jm.vertical,["vertical"],U,O,_,M,A,S));let Z=-1;const K=(t,e)=>t?Math.max(t,e):e;Z=K(B,Z),Z=K(C,Z),Z=K(R,Z);const H=Z>-1?1:0;t.glyphOffsetArray.length>=65535&&j("Too many glyphs being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907"),void 0!==b.sortKey&&t.addToSortKeyRanges(t.symbolInstances.length,b.sortKey),t.symbolInstances.emplaceBack(e.x,e.y,$.x,$.y,$.z,U.right>=0?U.right:-1,U.center>=0?U.center:-1,U.left>=0?U.left:-1,U.vertical>=0?U.vertical:-1,N,O,q,void 0!==P?P:t.collisionBoxArray.length,void 0!==P?P+1:t.collisionBoxArray.length,void 0!==z?z:t.collisionBoxArray.length,void 0!==z?z+1:t.collisionBoxArray.length,void 0!==E?E:t.collisionBoxArray.length,void 0!==E?E+1:t.collisionBoxArray.length,T||t.collisionBoxArray.length,T?T+1:t.collisionBoxArray.length,c,L,F,D,V,H,0,Y,X,Z,0,G?1:0);}(t,o,y,s,r,n,i,V,t.layers[0],t.collisionBoxArray,e.index,e.sourceLayerIndex,t.index,S,P,l,0,I,E,g,e,a,u,c,h,f,d);};if("line"===z)for(const i of hy(e.geometry,0,0,Tr,Tr)){const e=uy(i,A,k,r.vertical||x,n,_,M,t.overscaling,Tr);for(const r of e)x&&qy(t,x.text,T,r)||L(i,r,h);}else if("line-center"===z){for(const t of e.geometry)if(t.length>1){const e=ly(t,k,r.vertical||x,n,_,M);e&&L(t,e,h);}}else if("Polygon"===e.type)for(const t of nf(e.geometry,0)){const e=Ey(t,16);L(t[0],new ny(e.x,e.y,0,0,void 0),h);}else if("LineString"===e.type)for(const t of e.geometry)L(t,new ny(t[0].x,t[0].y,0,0,void 0),h);else if("Point"===e.type)for(const t of e.geometry)for(const e of t)L([e],new ny(e.x,e.y,0,0,void 0),h);}const Ly=255,Fy=Ly*am;function Ny(t,e,r,n,i,a,s,o,l,u,c,h,p,f,d,m,y,x){const v=function(t,e,r,n,i,a,s,o){const l=[];if(0===e.positionedLines.length)return l;const u=n.layout.get("text-rotate").evaluate(a,{})*Math.PI/180,c=function(t){const e=t[0],r=t[1],n=e*r;return n>0?[e,-r]:n<0?[-e,r]:0===e?[r,e]:[r,-e]}(r);let h=Math.abs(e.top-e.bottom);for(const t of e.positionedLines)h-=t.lineOffset;const p=e.positionedLines.length,f=h/p;let d=e.top-r[1];for(let t=0;tFy&&j(`${t.layerIds[0]}: Value for "text-size" is >= ${Ly}. Reduce your "text-size".`)):"composite"===b.kind&&(_=[am*d.compositeTextSizes[0].evaluate(o,{},y),am*d.compositeTextSizes[1].evaluate(o,{},y)],(_[0]>Fy||_[1]>Fy)&&j(`${t.layerIds[0]}: Value for "text-size" is >= ${Ly}. Reduce your "text-size".`)),t.addSymbols(t.text,v,_,l,s,o,c,e,r,u.lineStartIndex,u.lineLength,f,m,y,x,!1);for(const e of h)p[e]=t.text.placedSymbolArray.length-1;return 4*v.length}function Oy(t){for(const e in t)return t[e];return null}function Uy(t,e,r,n,i,a,s,o,l,u){let c=s.top,h=s.bottom,p=s.left,f=s.right;const d=s.collisionPadding;if(d&&(p-=d[0],c-=d[1],f+=d[2],h+=d[3]),l){const t=new g(p,c),e=new g(f,c),r=new g(p,h),n=new g(f,h),i=b(l);let a=new g(0,0);u&&(a=new g(u[0],u[1])),t._rotateAround(i,a),e._rotateAround(i,a),r._rotateAround(i,a),n._rotateAround(i,a),p=Math.min(t.x,e.x,r.x,n.x),f=Math.max(t.x,e.x,r.x,n.x),c=Math.min(t.y,e.y,r.y,n.y),h=Math.max(t.y,e.y,r.y,n.y);}return t.emplaceBack(e.x,e.y,e.z,r.x,r.y,p,c,f,h,o,n,i,a),t.length-1}function jy(t){t.collisionPadding&&(t.top-=t.collisionPadding[1],t.bottom+=t.collisionPadding[3]);const e=t.bottom-t.top;return e>0?Math.max(10,e):null}function qy(t,e,r,n){const i=t.compareText;if(e in i){const t=i[e];for(let e=t.length-1;e>=0;e--)if(n.dist(t[e])v&&(b(t,u,n,i,o,l),b(u,r,o,l,a,s));}b(h,p,n,a,i,a),b(p,f,i,a,i,s),b(f,d,i,s,n,s),b(d,h,n,s,n,a),m-=v,y-=v,g+=v,x+=v;const _=1/Math.max(g-m,x-y);return {scale:_,x:m*_,y:y*_,x2:g*_,y2:x*_,projection:e}}function Yy(t,{x:e,y:r},n=0){return new g(((e-n)*t.scale-t.x)*Tr,(r*t.scale-t.y)*Tr)}const Xy=t.a6.identity(new Float32Array(16));class Zy{constructor(t){this.spec=t,this.name=t.name,this.wrap=!1,this.requiresDraping=!1,this.supportsWorldCopies=!1,this.supportsTerrain=!1,this.supportsFog=!1,this.supportsFreeCamera=!1,this.zAxisUnit="meters",this.isReprojectedInTileSpace=!0,this.unsupportedLayers=["custom"],this.center=[0,0],this.range=[3.5,7];}project(t,e){return {x:0,y:0,z:0}}unproject(t,e){return new tl(0,0)}projectTilePoint(t,e,r){return {x:t,y:e,z:0}}locationPoint(t,e,r=!0){return t._coordinatePoint(t.locationCoordinate(e),r)}pixelsPerMeter(t,e){return dl(1,t)*e}pixelSpaceConversion(t,e,r){return 1}farthestPixelDistance(t){return $y(t,t.pixelsPerMeter)}pointCoordinate(t,e,r,n){const i=t.horizonLineFromTop(!1),a=new g(e,Math.max(i,r));return t.rayIntersectionCoordinate(t.pointRayIntersection(a,n))}pointCoordinate3D(t,e,r){const n=new g(e,r);if(t.elevation)return t.elevation.pointCoordinate(n);{const e=this.pointCoordinate(t,n.x,n.y,0);return [e.x,e.y,e.z]}}isPointAboveHorizon(t,e){if(t.elevation)return !this.pointCoordinate3D(t,e.x,e.y);const r=t.horizonLineFromTop();return e.y0?e<-ng+r&&(e=-ng+r):e>ng-r&&(e=ng-r);const a=i/Math.pow(ig(e),n);let s=a*Math.sin(n*t),o=i-a*Math.cos(n*t);return s=.5*(s/Math.PI+.5),o=.5*(o/Math.PI+.5),{x:s,y:this.southernCenter?o:1-o,z:0}}unproject(t,e){t=(2*t-.5)*Math.PI,this.southernCenter&&(e=1-e),e=(2*(1-e)-.5)*Math.PI;const{n:r,f:n}=this,i=n-e,a=Math.sign(i),s=Math.sign(r)*Math.sqrt(t*t+i*i);let o=Math.atan2(t,Math.abs(i))*a;i*r<0&&(o-=Math.PI*Math.sign(t)*a);const l=I(_(o/r)+this.center[0],-180,180),u=I(_(2*Math.atan(Math.pow(n/s,1/r))-ng),-xl,xl);return new tl(l,this.southernCenter?-u:u)}}class sg extends Zy{constructor(t){super(t),this.wrap=!0,this.supportsWorldCopies=!0,this.supportsTerrain=!0,this.supportsFog=!0,this.supportsFreeCamera=!0,this.isReprojectedInTileSpace=!1,this.unsupportedLayers=[],this.range=null;}project(t,e){return {x:pl(t),y:fl(e),z:0}}unproject(t,e){const r=ml(t),n=yl(e);return new tl(r,n)}}const og=b(xl);class lg extends Zy{project(t,e){const r=(e=b(e))*e,n=r*r;return {x:.5*((t=b(t))*(.8707-.131979*r+n*(n*(.003971*r-.001529*n)-.013791))/Math.PI+.5),y:1-.5*(e*(1.007226+r*(.015085+n*(.028874*r-.044475-.005916*n)))/Math.PI+1),z:0}}unproject(t,e){t=(2*t-.5)*Math.PI;let r=e=(2*(1-e)-1)*Math.PI,n=25,i=0,a=r*r;do{a=r*r;const t=a*a;i=(r*(1.007226+a*(.015085+t*(.028874*a-.044475-.005916*t)))-e)/(1.007226+a*(.045255+t*(.259866*a-.311325-.005916*11*t))),r=I(r-i,-og,og);}while(Math.abs(i)>1e-6&&--n>0);a=r*r;const s=I(_(t/(.8707+a*(a*(a*a*a*(.003971-.001529*a)-.013791)-.131979))),-180,180),o=_(r);return new tl(s,o)}}const ug=b(xl);class cg extends Zy{project(t,e){e=b(e),t=b(t);const r=Math.cos(e),n=2/Math.PI,i=Math.acos(r*Math.cos(t/2)),a=Math.sin(i)/i,s=.5*(t*n+2*r*Math.sin(t/2)/a)||0,o=.5*(e+Math.sin(e)/a)||0;return {x:.5*(s/Math.PI+.5),y:1-.5*(o/Math.PI+1),z:0}}unproject(t,e){let r=t=(2*t-.5)*Math.PI,n=e=(2*(1-e)-1)*Math.PI,i=25;const a=1e-6;let s=0,o=0;do{const i=Math.cos(n),a=Math.sin(n),l=2*a*i,u=a*a,c=i*i,h=Math.cos(r/2),p=Math.sin(r/2),f=2*h*p,d=p*p,m=1-c*h*h,y=m?1/m:0,g=m?Math.acos(i*h)*Math.sqrt(1/m):0,x=.5*(2*g*i*p+2*r/Math.PI)-t,v=.5*(g*a+n)-e,b=.5*y*(c*d+g*i*h*u)+1/Math.PI,_=y*(f*l/4-g*a*p),w=.125*y*(l*p-g*a*c*f),M=.5*y*(u*h+g*d*i)+.5,A=_*w-M*b;s=(v*_-x*M)/A,o=(x*w-v*b)/A,r=I(r-s,-Math.PI,Math.PI),n=I(n-o,-ug,ug);}while((Math.abs(s)>a||Math.abs(o)>a)&&--i>0);return new tl(_(r),_(n))}}class hg extends Zy{constructor(t){super(t),this.center=t.center||[0,0],this.parallels=t.parallels||[0,0],this.cosPhi=Math.max(.01,Math.cos(b(this.parallels[0]))),this.scale=1/(2*Math.max(Math.PI*this.cosPhi,1/this.cosPhi)),this.wrap=!0,this.supportsWorldCopies=!0;}project(t,e){const{scale:r,cosPhi:n}=this;return {x:b(t)*n*r+.5,y:-Math.sin(b(e))/n*r+.5,z:0}}unproject(t,e){const{scale:r,cosPhi:n}=this,i=-(e-.5)/r,a=I(_((t-.5)/r)/n,-180,180),s=Math.asin(I(i*n,-1,1)),o=I(_(s),-xl,xl);return new tl(a,o)}}class pg extends sg{constructor(t){super(t),this.requiresDraping=!0,this.supportsWorldCopies=!1,this.supportsFog=!0,this.zAxisUnit="pixels",this.unsupportedLayers=["debug"],this.range=[3,5];}projectTilePoint(e,r,n){const i=Zh(e,r,n),a=Wh(jh(n));return t.N.transformMat4(i,i,a),{x:i[0],y:i[1],z:i[2]}}locationPoint(e,r){const n=Wo(r.lat,r.lng),i=t.N.normalize([],n),a=e.elevation?e.elevation.getAtPointOrZero(e.locationCoordinate(r),e._centerAltitude):e._centerAltitude,s=dl(1,0)*Tr*a;t.N.scaleAndAdd(n,n,i,s);const o=t.a6.identity(new Float64Array(16));return t.a6.multiply(o,e.pixelMatrix,e.globeMatrix),t.N.transformMat4(n,n,o),new g(n[0],n[1])}pixelsPerMeter(t,e){return dl(1,0)*e}pixelSpaceConversion(t,e,r){const n=dl(1,t)*e,i=ue(dl(1,45)*e,n,r);return this.pixelsPerMeter(t,e)/i}createTileMatrix(e,r,n){const i=Jh(jh(n.canonical));return t.a6.multiply(new Float64Array(16),e.globeMatrix,i)}createInversionMatrix(e,r){const{center:n}=e,i=Wh(jh(r));return t.a6.rotateY(i,i,b(n.lng)),t.a6.rotateX(i,i,b(n.lat)),t.a6.scale(i,i,[e._pixelsPerMercatorPixel,e._pixelsPerMercatorPixel,1]),Float32Array.from(i)}pointCoordinate(t,e,r,n){return Nh(t,e,r,!0)||new Ml(0,0)}pointCoordinate3D(t,e,r){const n=this.pointCoordinate(t,e,r,0);return [n.x,n.y,n.z]}isPointAboveHorizon(t,e){return !Nh(t,e.x,e.y,!1)}farthestPixelDistance(e){const r=function(e,r){const n=e.cameraToCenterDistance,i=e._centerAltitude*r,a=e._camera,s=e._camera.forward(),o=t.N.add([],t.N.scale([],s,-n),[0,0,i]),l=e.worldSize/(2*Math.PI),u=[0,0,-l],c=e.width/e.height,h=Math.tan(e.fovAboveCenter),p=t.N.scale([],a.up(),h),f=t.N.scale([],a.right(),h*c),d=t.N.normalize([],t.N.add([],t.N.add([],s,p),f)),m=[];let y;if(new Sh(o,d).closestPointOnSphere(u,l,m)){const r=t.N.add([],m,u),n=t.N.sub([],r,o);y=Math.cos(e.fovAboveCenter)*t.N.length(n);}else {const e=t.N.sub([],o,u),r=t.N.sub([],u,o);t.N.normalize(r,r);const n=t.N.length(e)-l;y=Math.sqrt(n*(n+2*l));const i=Math.acos(y/(l+n))-Math.acos(t.N.dot(s,r));y*=Math.cos(i);}return 1.01*y}(e,this.pixelsPerMeter(e.center.lat,e.worldSize)),n=rp(e.zoom);if(n>0){const t=$y(e,dl(1,e.center.lat)*e.worldSize),i=e.worldSize/(2*Math.PI),a=Math.max(e.width,e.height)/e.worldSize*Math.PI;return ue(r,t+i*(1-Math.cos(a)),Math.pow(n,10))}return r}upVector(t,e,r){return Zh(e,r,t,1)}upVectorScale(t){return {metersToTile:Lh(Kh(jh(t)))}}}function fg(t){const e=t.parallels,r=!!e&&Math.abs(e[0]+e[1])<.01;switch(t.name){case"mercator":return new sg(t);case"equirectangular":return new rg(t);case"naturalEarth":return new lg(t);case"equalEarth":return new eg(t);case"winkelTripel":return new cg(t);case"albers":return r?new hg(t):new Ky(t);case"lambertConformalConic":return r?new hg(t):new ag(t);case"globe":return new pg(t)}throw new Error(`Invalid projection name: ${t.name}`)}const dg=zf.types,mg=[{name:"a_fade_opacity",components:1,type:"Uint8",offset:0}];function yg(t,e,r,n,i,a,s,o,l,u,c,h,p){const f=o?Math.min(Fy,Math.round(o[0])):0,d=o?Math.min(Fy,Math.round(o[1])):0;t.emplaceBack(e,r,Math.round(32*n),Math.round(32*i),a,s,(f<<1)+(l?1:0),d,16*u,16*c,256*h,256*p);}function gg(t,e,r){t.emplaceBack(e,r);}function xg(t,e,r,n,i,a,s){t.emplaceBack(e,r,n,i,a,s);}function vg(t,e,r,n,i){t.emplaceBack(e,r,n,i),t.emplaceBack(e,r,n,i),t.emplaceBack(e,r,n,i),t.emplaceBack(e,r,n,i);}function bg(t){for(const e of t.sections)if(ma(e.text))return !0;return !1}class _g{constructor(t){this.layoutVertexArray=new _s,this.indexArray=new Es,this.programConfigurations=t,this.segments=new eo,this.dynamicLayoutVertexArray=new gs,this.opacityVertexArray=new Ms,this.placedSymbolArray=new Gs,this.iconTransitioningVertexArray=new As,this.globeExtVertexArray=new ws,this.zOffsetVertexArray=new Bs;}isEmpty(){return 0===this.layoutVertexArray.length&&0===this.indexArray.length&&0===this.dynamicLayoutVertexArray.length&&0===this.opacityVertexArray.length&&0===this.iconTransitioningVertexArray.length}upload(t,e,r,n,i){this.isEmpty()||(r&&(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,Kd.members),this.indexBuffer=t.createIndexBuffer(this.indexArray,e),this.dynamicLayoutVertexBuffer=t.createVertexBuffer(this.dynamicLayoutVertexArray,Wd.members,!0),this.opacityVertexBuffer=t.createVertexBuffer(this.opacityVertexArray,mg,!0),this.iconTransitioningVertexArray.length>0&&(this.iconTransitioningVertexBuffer=t.createVertexBuffer(this.iconTransitioningVertexArray,Qd.members,!0)),this.globeExtVertexArray.length>0&&(this.globeExtVertexBuffer=t.createVertexBuffer(this.globeExtVertexArray,Hd.members,!0)),!this.zOffsetVertexBuffer&&(this.zOffsetVertexArray.length>0||i)&&(this.zOffsetVertexBuffer=t.createVertexBuffer(this.zOffsetVertexArray,Jd.members,!0)),this.opacityVertexBuffer.itemSize=1),(r||n)&&this.programConfigurations.upload(t));}destroy(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy(),this.dynamicLayoutVertexBuffer.destroy(),this.opacityVertexBuffer.destroy(),this.iconTransitioningVertexBuffer&&this.iconTransitioningVertexBuffer.destroy(),this.globeExtVertexBuffer&&this.globeExtVertexBuffer.destroy(),this.zOffsetVertexBuffer&&this.zOffsetVertexBuffer.destroy());}}ra(_g,"SymbolBuffers");class wg{constructor(t,e,r){this.layoutVertexArray=new t,this.layoutAttributes=e,this.indexArray=new r,this.segments=new eo,this.collisionVertexArray=new Ps,this.collisionVertexArrayExt=new gs;}upload(t){this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,this.layoutAttributes),this.indexBuffer=t.createIndexBuffer(this.indexArray),this.collisionVertexBuffer=t.createVertexBuffer(this.collisionVertexArray,tm.members,!0),this.collisionVertexBufferExt=t.createVertexBuffer(this.collisionVertexArrayExt,em.members,!0);}destroy(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.segments.destroy(),this.collisionVertexBuffer.destroy(),this.collisionVertexBufferExt.destroy());}}ra(wg,"CollisionBuffers");class Mg{constructor(e){this.collisionBoxArray=e.collisionBoxArray,this.zoom=e.zoom,this.overscaling=e.overscaling,this.layers=e.layers,this.layerIds=this.layers.map((t=>t.fqid)),this.index=e.index,this.pixelRatio=e.pixelRatio,this.sourceLayerIndex=e.sourceLayerIndex,this.hasPattern=!1,this.hasRTLText=!1,this.fullyClipped=!1,this.hasAnyIconTextFit=!1,this.sortKeyRanges=[],this.collisionCircleArray=[],this.placementInvProjMatrix=t.a6.identity([]),this.placementViewportMatrix=t.a6.identity([]);const r=this.layers[0]._unevaluatedLayout._values;this.textSizeData=sm(this.zoom,r["text-size"]),this.iconSizeData=sm(this.zoom,r["icon-size"]);const n=this.layers[0].layout,i=n.get("symbol-sort-key"),a=n.get("symbol-z-order");this.canOverlap=n.get("text-allow-overlap")||n.get("icon-allow-overlap")||n.get("text-ignore-placement")||n.get("icon-ignore-placement"),this.sortFeaturesByKey="viewport-y"!==a&&void 0!==i.constantOr(1),this.sortFeaturesByY=("viewport-y"===a||"auto"===a&&!this.sortFeaturesByKey)&&this.canOverlap,this.writingModes=n.get("text-writing-mode").map((t=>jm[t])),this.stateDependentLayerIds=this.layers.filter((t=>t.isStateDependent())).map((t=>t.id)),this.sourceID=e.sourceID,this.projection=e.projection,this.hasAnyZOffset=!1,this.zOffsetSortDirty=!1,this.zOffsetBuffersNeedUpload=n.get("symbol-z-elevate");}createArrays(){this.text=new _g(new Vo(this.layers,this.zoom,(t=>/^text/.test(t)))),this.icon=new _g(new Vo(this.layers,this.zoom,(t=>/^icon/.test(t)))),this.glyphOffsetArray=new Zs,this.lineVertexArray=new Ks,this.symbolInstances=new Xs;}calculateGlyphDependencies(t,e,r,n,i){for(let r=0;r0)&&("constant"!==l.value.kind||l.value.value.length>0),p="constant"!==c.value.kind||!!c.value.value||Object.keys(c.parameters).length>0,f=s.get("symbol-sort-key");if(this.features=[],!h&&!p)return;const d=r.iconDependencies,m=r.glyphDependencies,y=r.availableImages,g=new Pa(this.zoom);for(const{feature:r,id:u,index:c,sourceLayerIndex:x}of e){const e=a._featureFilter.needGeometry,v=Bl(r,e);if(!a._featureFilter.filter(g,v,n))continue;if(e||(v.geometry=Tl(r,n,i)),o&&1!==r.type&&n.z<=5){const e=v.geometry,r=.98078528056,i=(e,i)=>{const a=Zh(e.x,e.y,n,1),s=Zh(i.x,i.y,n,1);return t.N.dot(a,s)=0;for(const r of b.sections)if(r.image)d[r.image.namePrimary]=!0;else {const n=la(b.toString()),i=r.fontStack||t,a=m[i]=m[i]||{};this.calculateGlyphDependencies(r.text,a,e,this.allowVerticalPlacement,n);}}}"line"===s.get("symbol-placement")&&(this.features=function(t){const e={},r={},n=[];let i=0;function a(e){n.push(t[e]),i++;}function s(t,e,i){const a=r[t];return delete r[t],r[e]=a,n[a].geometry[0].pop(),n[a].geometry[0]=n[a].geometry[0].concat(i[0]),a}function o(t,r,i){const a=e[r];return delete e[r],e[t]=a,n[a].geometry[0].shift(),n[a].geometry[0]=i[0].concat(n[a].geometry[0]),a}function l(t,e,r){const n=r?e[0][e[0].length-1]:e[0][0];return `${t}:${n.x}:${n.y}`}for(let u=0;ut.geometry))}(this.features)),this.sortFeaturesByKey&&this.features.sort(((t,e)=>t.sortKey-e.sortKey));}update(t,e,r,n,i){const a=0!==Object.keys(t).length;if(a&&!this.stateDependentLayers.length)return;const s=a?this.stateDependentLayers:this.layers;this.text.programConfigurations.updatePaintArrays(t,e,s,r,n,i),this.icon.programConfigurations.updatePaintArrays(t,e,s,r,n,i);}updateZOffset(){const t=(t,e,n)=>{r+=e,r>t.length&&t.resize(r);for(let i=-e;i<0;i++)t.emplace(i+r,n);},e=(t,e,r)=>{n+=e,n>t.length&&t.resize(n);for(let i=-e;i<0;i++)t.emplace(i+n,r);};if(!this.zOffsetBuffersNeedUpload)return;this.zOffsetBuffersNeedUpload=!1;let r=0,n=0;for(let r=0;r0;if((i>0||a>0)&&(t(this.text.zOffsetVertexArray,i,o),t(this.text.zOffsetVertexArray,a,o)),l){const{placedIconSymbolIndex:t,verticalPlacedIconSymbolIndex:r}=n;t>=0&&e(this.icon.zOffsetVertexArray,s,o),r>=0&&e(this.icon.zOffsetVertexArray,n.numVerticalIconVertices,o);}}this.text.zOffsetVertexBuffer&&this.text.zOffsetVertexBuffer.updateData(this.text.zOffsetVertexArray),this.icon.zOffsetVertexBuffer&&this.icon.zOffsetVertexBuffer.updateData(this.icon.zOffsetVertexArray);}isEmpty(){return 0===this.symbolInstances.length&&!this.hasRTLText}uploadPending(){return !this.uploaded||this.text.programConfigurations.needsUpload||this.icon.programConfigurations.needsUpload}upload(t){!this.uploaded&&this.hasDebugData()&&(this.textCollisionBox.upload(t),this.iconCollisionBox.upload(t)),this.text.upload(t,this.sortFeaturesByY,!this.uploaded,this.text.programConfigurations.needsUpload,this.zOffsetBuffersNeedUpload),this.icon.upload(t,this.sortFeaturesByY,!this.uploaded,this.icon.programConfigurations.needsUpload,this.zOffsetBuffersNeedUpload),this.uploaded=!0;}destroyDebugData(){this.textCollisionBox.destroy(),this.iconCollisionBox.destroy();}getProjection(){return this.projectionInstance||(this.projectionInstance=fg(this.projection)),this.projectionInstance}destroy(){this.text.destroy(),this.icon.destroy(),this.hasDebugData()&&this.destroyDebugData();}addToLineVertexArray(t,e){const r=this.lineVertexArray.length;if(void 0!==t.segment)for(const{x:t,y:r}of e)this.lineVertexArray.emplaceBack(t,r);return {lineStartIndex:r,lineLength:this.lineVertexArray.length-r}}addSymbols(t,e,r,n,i,a,s,o,l,u,c,h,p,f,d,m){const y=t.indexArray,g=t.layoutVertexArray,x=t.globeExtVertexArray,v=t.segments.prepareSegment(4*e.length,g,y,this.canOverlap?a.sortKey:void 0),b=this.glyphOffsetArray.length,_=v.vertexLength,w=this.allowVerticalPlacement&&s===jm.vertical?Math.PI/2:0,M=a.text&&a.text.sections;for(let n=0;n=0?e.rightJustifiedTextSymbolIndex:e.centerJustifiedTextSymbolIndex>=0?e.centerJustifiedTextSymbolIndex:e.leftJustifiedTextSymbolIndex>=0?e.leftJustifiedTextSymbolIndex:e.verticalPlacedTextSymbolIndex>=0?e.verticalPlacedTextSymbolIndex:n),a=om(this.textSizeData,t,i)/im;return this.tilePixelRatio*a}getSymbolInstanceIconSize(t,e,r){const n=this.icon.placedSymbolArray.get(r),i=om(this.iconSizeData,t,n);return this.tilePixelRatio*i}_commitDebugCollisionVertexUpdate(t,e,r,n){t.emplaceBack(e,-r,-r,n),t.emplaceBack(e,r,-r,n),t.emplaceBack(e,r,r,n),t.emplaceBack(e,-r,r,n);}_updateTextDebugCollisionBoxes(t,e,r,n,i,a){for(let s=n;s0}hasIconData(){return this.icon.segments.get().length>0}hasDebugData(){return this.textCollisionBox&&this.iconCollisionBox}hasTextCollisionBoxData(){return this.hasDebugData()&&this.textCollisionBox.segments.get().length>0}hasIconCollisionBoxData(){return this.hasDebugData()&&this.iconCollisionBox.segments.get().length>0}hasIconTextFit(){return this.hasAnyIconTextFit}addIndicesForPlacedSymbol(t,e){const r=t.placedSymbolArray.get(e),n=r.vertexStartIndex+4*r.numGlyphs;for(let e=r.vertexStartIndex;en[t]-n[e]||i[e]-i[t])),a}getSortedIndexesByZOffset(){if(!this.zOffsetSortDirty)return this.symbolInstanceIndexesSortedZOffset;if(!this.symbolInstanceIndexesSortedZOffset){this.symbolInstanceIndexesSortedZOffset=[];for(let t=0;tthis.symbolInstances.get(e).zOffset-this.symbolInstances.get(t).zOffset))}addToSortKeyRanges(t,e){const r=this.sortKeyRanges[this.sortKeyRanges.length-1];r&&r.sortKey===e?r.symbolInstanceEnd=t+1:this.sortKeyRanges.push({sortKey:e,symbolInstanceStart:t,symbolInstanceEnd:t+1});}sortFeatures(t){if(this.sortFeaturesByY&&this.sortedAngle!==t&&!(this.text.segments.get().length>1||this.icon.segments.get().length>1)){this.symbolInstanceIndexes=this.getSortedSymbolIndexes(t),this.sortedAngle=t,this.text.indexArray.clear(),this.icon.indexArray.clear(),this.featureSortOrder=[];for(const t of this.symbolInstanceIndexes){const e=this.symbolInstances.get(t);this.featureSortOrder.push(e.featureIndex);const{rightJustifiedTextSymbolIndex:r,centerJustifiedTextSymbolIndex:n,leftJustifiedTextSymbolIndex:i,verticalPlacedTextSymbolIndex:a,placedIconSymbolIndex:s,verticalPlacedIconSymbolIndex:o}=e;r>=0&&this.addIndicesForPlacedSymbol(this.text,r),n>=0&&n!==r&&this.addIndicesForPlacedSymbol(this.text,n),i>=0&&i!==n&&i!==r&&this.addIndicesForPlacedSymbol(this.text,i),a>=0&&this.addIndicesForPlacedSymbol(this.text,a),s>=0&&this.addIndicesForPlacedSymbol(this.icon,s),o>=0&&this.addIndicesForPlacedSymbol(this.icon,o);}this.text.indexBuffer&&this.text.indexBuffer.updateData(this.text.indexArray),this.icon.indexBuffer&&this.icon.indexBuffer.updateData(this.icon.indexArray);}}}ra(Mg,"SymbolBucket",{omit:["layers","collisionBoxArray","features","compareText"]}),Mg.addDynamicAttributes=vg;const Ag=new Oa({"symbol-placement":new La(qa.layout_symbol["symbol-placement"]),"symbol-spacing":new La(qa.layout_symbol["symbol-spacing"]),"symbol-avoid-edges":new La(qa.layout_symbol["symbol-avoid-edges"]),"symbol-sort-key":new Fa(qa.layout_symbol["symbol-sort-key"]),"symbol-z-order":new La(qa.layout_symbol["symbol-z-order"]),"symbol-z-elevate":new La(qa.layout_symbol["symbol-z-elevate"]),"icon-allow-overlap":new La(qa.layout_symbol["icon-allow-overlap"]),"icon-ignore-placement":new La(qa.layout_symbol["icon-ignore-placement"]),"icon-optional":new La(qa.layout_symbol["icon-optional"]),"icon-rotation-alignment":new La(qa.layout_symbol["icon-rotation-alignment"]),"icon-size":new Fa(qa.layout_symbol["icon-size"]),"icon-text-fit":new Fa(qa.layout_symbol["icon-text-fit"]),"icon-text-fit-padding":new Fa(qa.layout_symbol["icon-text-fit-padding"]),"icon-image":new Fa(qa.layout_symbol["icon-image"]),"icon-rotate":new Fa(qa.layout_symbol["icon-rotate"]),"icon-padding":new La(qa.layout_symbol["icon-padding"]),"icon-keep-upright":new La(qa.layout_symbol["icon-keep-upright"]),"icon-offset":new Fa(qa.layout_symbol["icon-offset"]),"icon-anchor":new Fa(qa.layout_symbol["icon-anchor"]),"icon-pitch-alignment":new La(qa.layout_symbol["icon-pitch-alignment"]),"text-pitch-alignment":new La(qa.layout_symbol["text-pitch-alignment"]),"text-rotation-alignment":new La(qa.layout_symbol["text-rotation-alignment"]),"text-field":new Fa(qa.layout_symbol["text-field"]),"text-font":new Fa(qa.layout_symbol["text-font"]),"text-size":new Fa(qa.layout_symbol["text-size"]),"text-max-width":new Fa(qa.layout_symbol["text-max-width"]),"text-line-height":new Fa(qa.layout_symbol["text-line-height"]),"text-letter-spacing":new Fa(qa.layout_symbol["text-letter-spacing"]),"text-justify":new Fa(qa.layout_symbol["text-justify"]),"text-radial-offset":new Fa(qa.layout_symbol["text-radial-offset"]),"text-variable-anchor":new La(qa.layout_symbol["text-variable-anchor"]),"text-anchor":new Fa(qa.layout_symbol["text-anchor"]),"text-max-angle":new La(qa.layout_symbol["text-max-angle"]),"text-writing-mode":new La(qa.layout_symbol["text-writing-mode"]),"text-rotate":new Fa(qa.layout_symbol["text-rotate"]),"text-padding":new La(qa.layout_symbol["text-padding"]),"text-keep-upright":new La(qa.layout_symbol["text-keep-upright"]),"text-transform":new Fa(qa.layout_symbol["text-transform"]),"text-offset":new Fa(qa.layout_symbol["text-offset"]),"text-allow-overlap":new La(qa.layout_symbol["text-allow-overlap"]),"text-ignore-placement":new La(qa.layout_symbol["text-ignore-placement"]),"text-optional":new La(qa.layout_symbol["text-optional"]),visibility:new La(qa.layout_symbol.visibility)});var Sg={paint:new Oa({"icon-opacity":new Fa(qa.paint_symbol["icon-opacity"]),"icon-emissive-strength":new Fa(qa.paint_symbol["icon-emissive-strength"]),"text-emissive-strength":new Fa(qa.paint_symbol["text-emissive-strength"]),"icon-color":new Fa(qa.paint_symbol["icon-color"]),"icon-halo-color":new Fa(qa.paint_symbol["icon-halo-color"]),"icon-halo-width":new Fa(qa.paint_symbol["icon-halo-width"]),"icon-halo-blur":new Fa(qa.paint_symbol["icon-halo-blur"]),"icon-translate":new La(qa.paint_symbol["icon-translate"]),"icon-translate-anchor":new La(qa.paint_symbol["icon-translate-anchor"]),"icon-image-cross-fade":new Fa(qa.paint_symbol["icon-image-cross-fade"]),"text-opacity":new Fa(qa.paint_symbol["text-opacity"]),"text-color":new Fa(qa.paint_symbol["text-color"],{runtimeType:_e,getOverride:t=>t.textColor,hasOverride:t=>!!t.textColor}),"text-halo-color":new Fa(qa.paint_symbol["text-halo-color"]),"text-halo-width":new Fa(qa.paint_symbol["text-halo-width"]),"text-halo-blur":new Fa(qa.paint_symbol["text-halo-blur"]),"text-translate":new La(qa.paint_symbol["text-translate"]),"text-translate-anchor":new La(qa.paint_symbol["text-translate-anchor"]),"icon-color-saturation":new La(qa.paint_symbol["icon-color-saturation"])}),layout:Ag};class Ig{constructor(t){this.type=t.property.overrides?t.property.overrides.runtimeType:ge,this.defaultValue=t;}evaluate(t){if(t.formattedSection){const e=this.defaultValue.property.overrides;if(e&&e.hasOverride(t.formattedSection))return e.getOverride(t.formattedSection)}return t.feature&&t.featureState?this.defaultValue.evaluate(t.feature,t.featureState):this.defaultValue.property.specification.default}eachChild(t){this.defaultValue.isConstant()||t(this.defaultValue.value._styleExpression.expression);}outputDefined(){return !1}serialize(){return null}}ra(Ig,"FormatSectionOverride",{omit:["defaultValue"]});class kg extends ss{constructor(t,e,r){super(t,Sg,e,r);}recalculate(t,e){super.recalculate(t,e),"auto"===this.layout.get("icon-rotation-alignment")&&(this.layout._values["icon-rotation-alignment"]="point"!==this.layout.get("symbol-placement")?"map":"viewport"),"auto"===this.layout.get("text-rotation-alignment")&&(this.layout._values["text-rotation-alignment"]="point"!==this.layout.get("symbol-placement")?"map":"viewport"),"auto"===this.layout.get("text-pitch-alignment")&&(this.layout._values["text-pitch-alignment"]=this.layout.get("text-rotation-alignment")),"auto"===this.layout.get("icon-pitch-alignment")&&(this.layout._values["icon-pitch-alignment"]=this.layout.get("icon-rotation-alignment"));const r=this.layout.get("text-writing-mode");if(r){const t=[];for(const e of r)t.indexOf(e)<0&&t.push(e);this.layout._values["text-writing-mode"]=t;}else this.layout._values["text-writing-mode"]="point"===this.layout.get("symbol-placement")?["horizontal"]:["horizontal","vertical"];this._setPaintOverrides();}getValueAndResolveTokens(t,e,r,n){const i=this.layout.get(t).evaluate(e,{},r,n),a=this._unevaluatedLayout._values[t];return a.isDataDriven()||$i(a.value)||!i?i:function(t,e){return e.replace(/{([^{}]+)}/g,((e,r)=>r in t?String(t[r]):""))}(e.properties,i)}createBucket(t){return new Mg(t)}queryRadius(){return 0}queryIntersectsFeature(){return !1}_setPaintOverrides(){for(const t of Sg.paint.overridableProperties){if(!kg.hasPaintOverride(this.layout,t))continue;const e=this.paint.get(t),r=new Ig(e),n=new qi(r,e.property.specification,this.scope,this.options);let i=null;i="constant"===e.value.kind||"source"===e.value.kind?new Yi("source",n):new Xi("composite",n,e.value.zoomStops,e.value._interpolationType),this.paint._values[t]=new Da(e.property,i,e.parameters);}}_handleOverridablePaintPropertyUpdate(t,e,r){return !(!this.layout||e.isDataDriven()||r.isDataDriven())&&kg.hasPaintOverride(this.layout,t)}static hasPaintOverride(t,e){const r=t.get("text-field"),n=Sg.paint.properties[e];let i=!1;const a=t=>{for(const e of t)if(n.overrides&&n.overrides.hasOverride(e))return void(i=!0)};if("constant"===r.value.kind&&r.value.value instanceof De)a(r.value.value.sections);else if("source"===r.value.kind){const t=e=>{i||(e instanceof je&&Ne(e.value)===Se?a(e.value.sections):e instanceof Xe?a(e.sections):e.eachChild(t));},e=r.value;e._styleExpression&&t(e._styleExpression.expression);}return i}getProgramIds(){const t=0!==this.paint.get("icon-opacity").constantOr(1),e=0!==this.paint.get("text-opacity").constantOr(1),r=[];return t&&r.push("symbolIcon"),e&&r.push("symbolSDF"),r}getDefaultProgramParams(t,e){return {config:new Do(this,e),overrideFog:!1}}}const Pg=new Oa({visibility:new La(qa.layout_background.visibility)});var Eg={paint:new Oa({"background-color":new La(qa.paint_background["background-color"]),"background-pattern":new La(qa.paint_background["background-pattern"]),"background-opacity":new La(qa.paint_background["background-opacity"]),"background-emissive-strength":new La(qa.paint_background["background-emissive-strength"])}),layout:Pg};const zg=new Oa({visibility:new La(qa.layout_raster.visibility)});var Tg={paint:new Oa({"raster-opacity":new La(qa.paint_raster["raster-opacity"]),"raster-color":new Na(qa.paint_raster["raster-color"]),"raster-color-mix":new La(qa.paint_raster["raster-color-mix"]),"raster-color-range":new La(qa.paint_raster["raster-color-range"]),"raster-hue-rotate":new La(qa.paint_raster["raster-hue-rotate"]),"raster-brightness-min":new La(qa.paint_raster["raster-brightness-min"]),"raster-brightness-max":new La(qa.paint_raster["raster-brightness-max"]),"raster-saturation":new La(qa.paint_raster["raster-saturation"]),"raster-contrast":new La(qa.paint_raster["raster-contrast"]),"raster-resampling":new La(qa.paint_raster["raster-resampling"]),"raster-fade-duration":new La(qa.paint_raster["raster-fade-duration"]),"raster-emissive-strength":new La(qa.paint_raster["raster-emissive-strength"]),"raster-array-band":new La(qa.paint_raster["raster-array-band"]),"raster-elevation":new La(qa.paint_raster["raster-elevation"])}),layout:zg},Bg=cs([{name:"a_pos",type:"Int16",components:2},{name:"a_texture_pos",type:"Int16",components:2}]);class Cg{constructor(t,e,r,n){this.context=t,this.format=r,this.texture=t.gl.createTexture(),this.update(e,n);}update(t,e,r){const{width:n,height:i}=t,{context:a}=this,{gl:s}=a;if(s.bindTexture(s.TEXTURE_2D,this.texture),a.pixelStoreUnpackFlipY.set(!1),a.pixelStoreUnpack.set(1),a.pixelStoreUnpackPremultiplyAlpha.set(this.format===s.RGBA&&(!e||!1!==e.premultiply)),r||this.size&&this.size[0]===n&&this.size[1]===i){const{x:e,y:a}=r||{x:0,y:0};if(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement||t instanceof HTMLVideoElement||t instanceof ImageData||ImageBitmap&&t instanceof ImageBitmap)s.texSubImage2D(s.TEXTURE_2D,0,e,a,s.RGBA,s.UNSIGNED_BYTE,t);else {let r=this.format,o=s.UNSIGNED_BYTE;this.format===s.R32F&&(r=s.RED,o=s.FLOAT),s.texSubImage2D(s.TEXTURE_2D,0,e,a,n,i,r,o,t.data);}}else if(this.size=[n,i],t instanceof HTMLImageElement||t instanceof HTMLCanvasElement||t instanceof HTMLVideoElement||t instanceof ImageData||ImageBitmap&&t instanceof ImageBitmap){let e=this.format;this.format===s.R8&&(e=s.RED),s.texImage2D(s.TEXTURE_2D,0,this.format,e,s.UNSIGNED_BYTE,t);}else {let e=this.format,r=this.format,a=s.UNSIGNED_BYTE;this.format===s.DEPTH_COMPONENT&&(e=s.DEPTH_COMPONENT16,a=s.UNSIGNED_SHORT),this.format===s.R8&&(r=s.RED),this.format===s.R32F&&(a=s.FLOAT,r=s.RED),s.texImage2D(s.TEXTURE_2D,0,e,n,i,0,r,a,t.data);}this.useMipmap=Boolean(e&&e.useMipmap),this.useMipmap&&s.generateMipmap(s.TEXTURE_2D);}bind(t,e,r=!1){const{context:n}=this,{gl:i}=n;i.bindTexture(i.TEXTURE_2D,this.texture),t!==this.minFilter&&(i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,this.useMipmap&&!r?t===i.NEAREST?i.NEAREST_MIPMAP_NEAREST:i.LINEAR_MIPMAP_LINEAR:t),this.minFilter=t),e!==this.wrapS&&(i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,e),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,e),this.wrapS=e);}bindExtraParam(t,e,r,n){const{context:i}=this,{gl:a}=i;a.bindTexture(a.TEXTURE_2D,this.texture),e!==this.magFilter&&(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,e),this.magFilter=e),t!==this.minFilter&&(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,this.useMipmap?t===a.NEAREST?a.NEAREST_MIPMAP_NEAREST:a.LINEAR_MIPMAP_LINEAR:t),this.minFilter=t),r!==this.wrapS&&(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,r),this.wrapS=r),n!==this.wrapT&&(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,n),this.wrapT=n);}destroy(){const{gl:t}=this.context;t.deleteTexture(this.texture),this.texture=null;}}class Rg{constructor(t,e){this.context=t,this.texture=e;}bind(t,e){const{context:r}=this,{gl:n}=r;n.bindTexture(n.TEXTURE_2D,this.texture),t!==this.minFilter&&(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,t),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,t),this.minFilter=t),e!==this.wrapS&&(n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e),this.wrapS=e);}}function Dg(e,r,n,i,a,s,o,l){const u=[e,r,1,n,i,1,a,s,1],c=[o,l,1],h=t.co.adjoint([],u),[p,f,d]=t.N.transformMat3(c,c,h);return t.co.multiply(u,u,[p,0,0,0,f,0,0,0,d])}function Vg(e,r,n,i,a,s,o,l){const u=function(e,r,n,i,a,s,o,l){const u=Dg(0,0,1,0,1,1,0,1),c=Dg(e,r,n,i,a,s,o,l),h=t.co.adjoint([],u);return t.co.multiply(c,c,h)}(e,r,n,i,a,s,o,l);return [u[2]/u[8]/Tr,u[5]/u[8]/Tr]}function Lg(t){return [t[0],Math.min(Math.max(t[1],-xl),xl)]}class Fg extends ee{constructor(t,e,r,n){super(),this.id=t,this.dispatcher=r,this.coordinates=e.coordinates,this.type="image",this.minzoom=0,this.maxzoom=22,this.tileSize=512,this.tiles={},this._loaded=!1,this.onNorthPole=!1,this.onSouthPole=!1,this.setEventedParent(n),this.options=e,this._dirty=!1;}load(t,e){if(this._loaded=e||!1,this.fire(new Qt("dataloading",{dataType:"source"})),this.url=this.options.url,!this.url)return t&&(this.coordinates=t),this._loaded=!0,void this._finishLoading();this._imageRequest=Ct(this.map._requestManager.transformRequest(this.url,At.Image),((e,r)=>{this._imageRequest=null,this._loaded=!0,e?this.fire(new te(e)):r&&(this.image=r instanceof HTMLImageElement?st.getImageData(r):r,this._dirty=!0,this.width=this.image.width,this.height=this.image.height,t&&(this.coordinates=t),this._finishLoading());}));}loaded(){return this._loaded}updateImage(t){return t.url?(this._imageRequest&&t.url!==this.options.url&&(this._imageRequest.cancel(),this._imageRequest=null),this.options.url=t.url,this.load(t.coordinates,this._loaded),this):this}setTexture(t){if(!(t.handle instanceof WebGLTexture))throw new Error("The provided handle is not a WebGLTexture instance");return this.texture=new Rg(this.map.painter.context,t.handle),this.width=t.dimensions[0],this.height=t.dimensions[1],this._dirty=!1,this._loaded=!0,this._finishLoading(),this}_finishLoading(){this.map&&(this.setCoordinates(this.coordinates),this.fire(new Qt("data",{dataType:"source",sourceDataType:"metadata"})));}onAdd(t){this.map=t,this.load();}onRemove(){this._imageRequest&&(this._imageRequest.cancel(),this._imageRequest=null),!this.texture||this.texture instanceof Rg||this.texture.destroy(),this.boundsBuffer&&(this.boundsBuffer.destroy(),this.elevatedGlobeVertexBuffer&&this.elevatedGlobeVertexBuffer.destroy(),this.elevatedGlobeIndexBuffer&&this.elevatedGlobeIndexBuffer.destroy());}setCoordinates(t){if(this.coordinates=t,this._boundsArray=void 0,this._unsupportedCoords=!1,!t.length)return this;this.onNorthPole=!1,this.onSouthPole=!1;let e=t[0][1],r=t[0][1];for(const n of t)n[1]>r&&(r=n[1]),n[1]xl?this.onNorthPole=!0:n<-xl&&(this.onSouthPole=!0),!this.onNorthPole&&!this.onSouthPole){const e=t.map(Ml.fromLngLat);this.tileID=function(t){let e=1/0,r=1/0,n=-1/0,i=-1/0;for(const a of t)e=Math.min(e,a.x),r=Math.min(r,a.y),n=Math.max(n,a.x),i=Math.max(i,a.y);const a=Math.max(n-e,i-r),s=Math.max(0,Math.floor(-Math.log(a)/Math.LN2)),o=Math.pow(2,s);let l=Math.floor((e+n)/2*o);return l>1&&(l-=1),new il(s,l,Math.floor((r+i)/2*o))}(e),this.minzoom=this.maxzoom=this.tileID.z;}return this.fire(new Qt("data",{dataType:"source",sourceDataType:"content"})),this}_clear(){this._boundsArray=void 0,this._unsupportedCoords=!1;}_prepareData(e){for(const t in this.tiles){const e=this.tiles[t];"loaded"!==e.state&&(e.state="loaded",e.texture=this.texture);}if(this._boundsArray||this.onNorthPole||this.onSouthPole||this._unsupportedCoords)return;const r=Gy(new il(0,0,0),this.map.transform.projection),n=[r.projection.project(this.coordinates[0][0],this.coordinates[0][1]),r.projection.project(this.coordinates[1][0],this.coordinates[1][1]),r.projection.project(this.coordinates[2][0],this.coordinates[2][1]),r.projection.project(this.coordinates[3][0],this.coordinates[3][1])];if(!function(t){const e=t[1].x-t[0].x,r=t[1].y-t[0].y,n=t[2].x-t[1].x,i=t[2].y-t[1].y,a=t[3].x-t[2].x,s=t[3].y-t[2].y,o=t[0].x-t[3].x,l=t[0].y-t[3].y,u=e*i-n*r,c=n*s-a*i,h=a*l-o*s,p=o*r-e*l;return u>0&&c>0&&h>0&&p>0||u<0&&c<0&&h<0&&p<0}(n))return console.warn("Image source coordinates are defining non-convex area in the Mercator projection"),void(this._unsupportedCoords=!0);const i=Gy(this.tileID,this.map.transform.projection),[a,s,o,l]=this.coordinates.map((t=>{const e=i.projection.project(t[0],t[1]);return Yy(i,e)._round()}));this.perspectiveTransform=Vg(a.x,a.y,s.x,s.y,o.x,o.y,l.x,l.y);const u=this._boundsArray=new ds;u.emplaceBack(a.x,a.y,0,0),u.emplaceBack(s.x,s.y,Tr,0),u.emplaceBack(l.x,l.y,0,Tr),u.emplaceBack(o.x,o.y,Tr,Tr),this.boundsBuffer&&(this.boundsBuffer.destroy(),this.elevatedGlobeVertexBuffer&&this.elevatedGlobeVertexBuffer.destroy(),this.elevatedGlobeIndexBuffer&&this.elevatedGlobeIndexBuffer.destroy()),this.boundsBuffer=e.createVertexBuffer(u,Bg.members),this.boundsSegments=eo.simpleSegment(0,0,4,2);const c=[],h=[Lg((p=this.coordinates)[0]),Lg(p[1]),Lg(p[2]),Lg(p[3])];var p;const[f,d,m,y]=function(t){let e=t[0][0],r=e,n=t[0][1],i=n;for(let a=1;ar&&(r=t[a][0]),t[a][1]i&&(i=t[a][1]);return [e,n,r-e,i-n]}(h);{const i=new ds,[a,s,o,l]=function(t){let e=t[0].x,r=e,n=t[0].y,i=n;for(let a=1;ar&&(r=t[a].x),t[a].yi&&(i=t[a].y);return [e,n,r-e,i-n]}(n),u=t=>[(t.x-a)/o,(t.y-s)/l],[h,p,g,x]=n.map(u),v=function(e,r,n,i,a,s,o,l){const u=Dg(0,0,1,0,1,1,0,1),c=Dg(e,r,n,i,a,s,o,l),h=t.co.adjoint([],c);return t.co.multiply(u,u,h)}(h[0],h[1],p[0],p[1],g[0],g[1],x[0],x[1]);this.elevatedGlobePerspectiveTransform=Vg(h[0],h[1],p[0],p[1],g[0],g[1],x[0],x[1]);const b=(e,r)=>{c.push(e.lng);const n=Math.round((e.lng-f)/m*Tr),a=Math.round((e.lat-d)/y*Tr),s=u(r),o=t.N.transformMat3([],[s[0],s[1],1],v),l=Math.round(o[0]/o[2]*Tr),h=Math.round(o[1]/o[2]*Tr);i.emplaceBack(n,a,l,h);},_=n[3].x-n[0].x,w=n[3].y-n[0].y,M=n[2].x-n[1].x,A=n[2].y-n[1].y;for(let t=0;t<65;t++){const e=t/64,i=[n[0].x+e*_,n[0].y+e*w],a=[n[1].x+e*M,n[1].y+e*A],s=a[0]-i[0],o=a[1]-i[1];for(let t=0;t<65;t++){const e=t/64,n={x:i[0]+s*e,y:i[1]+o*e,z:0};b(r.projection.unproject(n.x,n.y),n);}}this.elevatedGlobeVertexBuffer=e.createVertexBuffer(i,Bg.members);}{this.maxLongitudeTriangleSize=0;let t=[],r=new Es;const n=(e,n,i)=>{r.emplaceBack(e,n,i);const a=c[e],s=c[n],o=c[i],l=Math.min(Math.min(a,s),o),u=Math.max(Math.max(a,s),o)-l;u>this.maxLongitudeTriangleSize&&(this.maxLongitudeTriangleSize=u),t.push(l+u/2);};for(let t=0;t<64;t++)for(let e=0;e<64;e++){const r=65*t+e,i=r+1,a=r+65,s=a+1;n(r,a,i),n(i,a,s);}[t,r]=function(t,e){const r=Array.from({length:t.length},((t,e)=>e));r.sort(((e,r)=>t[e]-t[r]));const n=[],i=new Es;for(let a=0;at+360*Math.round((e-t)/360))(t+180,r[0]);const i=new eo,a=(t,r)=>{i.segments.push({vertexOffset:0,primitiveOffset:t,vertexLength:e.segments[0].vertexLength,primitiveLength:r,sortKey:void 0,vaos:{}});},s=.51*this.maxLongitudeTriangleSize;if(Math.abs(r[0]-n)<=s){const t=it(r,0,r.length,n+s);return t===r.length||a(t,nt(r,t+1,r.length,n+360-s)-t),i}n{this.colorRampTexture&&this.colorRampTexture.destroy(),this.transformFeedbackObject&&t.painter.context.gl.deleteTransformFeedback(this.transformFeedbackObject),this.tileFramebuffer&&this.tileFramebuffer.destroy();},this.lastInvalidatedAt=st.now();}hasColorMap(){return !!this._transitionablePaint._values["raster-particle-color"].value.value}getProgramIds(){return ["rasterParticle"]}hasOffscreenPass(){return "none"!==this.visibility}isLayerDraped(t){return !1}_handleSpecialPaintPropertyUpdate(t){"raster-particle-color"!==t&&"raster-particle-max-speed"!==t||(this._updateColorRamp(),this._invalidateAnimationState()),"raster-particle-count"===t&&this._invalidateAnimationState();}_updateColorRamp(){if(!this.hasColorMap())return;const t=this._transitionablePaint._values["raster-particle-color"].value.expression,e=this._transitionablePaint._values["raster-particle-max-speed"].value.expression.evaluate({zoom:0});this.colorRamp=Ap({expression:t,evaluationKey:"rasterParticleSpeed",image:this.colorRamp,clips:[{start:0,end:e}],resolution:256}),this.colorRampTexture=null;}_invalidateAnimationState(){this.lastInvalidatedAt=st.now();}}class $g extends ss{constructor(t,e){super(t,{},e),this.implementation=t,t.slot&&(this.slot=t.slot);}is3D(){return "3d"===this.implementation.renderingMode}hasOffscreenPass(){return void 0!==this.implementation.prerender}isLayerDraped(t){return void 0!==this.implementation.renderToTile}shouldRedrape(){return !!this.implementation.shouldRerenderTiles&&this.implementation.shouldRerenderTiles()}recalculate(){}updateTransitions(){}hasTransition(){return !1}serialize(){}onAdd(t){this.implementation.onAdd&&this.implementation.onAdd(t,t.painter.context.gl);}onRemove(t){this.implementation.onRemove&&this.implementation.onRemove(t,t.painter.context.gl);}}const Gg=new Oa({visibility:new La(qa.layout_sky.visibility)});var Yg={paint:new Oa({"sky-type":new La(qa.paint_sky["sky-type"]),"sky-atmosphere-sun":new La(qa.paint_sky["sky-atmosphere-sun"]),"sky-atmosphere-sun-intensity":new La(qa.paint_sky["sky-atmosphere-sun-intensity"]),"sky-gradient-center":new La(qa.paint_sky["sky-gradient-center"]),"sky-gradient-radius":new La(qa.paint_sky["sky-gradient-radius"]),"sky-gradient":new Na(qa.paint_sky["sky-gradient"]),"sky-atmosphere-halo-color":new La(qa.paint_sky["sky-atmosphere-halo-color"]),"sky-atmosphere-color":new La(qa.paint_sky["sky-atmosphere-color"]),"sky-opacity":new La(qa.paint_sky["sky-opacity"])}),layout:Gg};function Xg(e,r,n){const i=[0,0,1],a=t.bi.identity([]);return t.bi.rotateY(a,a,n?-b(e)+Math.PI:b(e)),t.bi.rotateX(a,a,-b(r)),t.N.transformQuat(i,i,a),t.N.normalize(i,i)}var Zg={paint:new Oa({})};function Kg(e,r){const n=Wg(e.projection,e.zoom,e.width,e.height),i=function(e,r,n,i,a){const s=new tl(n.lng-180*Jg,n.lat),o=new tl(n.lng+180*Jg,n.lat),l=e.project(s.lng,s.lat),u=e.project(o.lng,o.lat),c=-Math.atan2(u.y-l.y,u.x-l.x),h=Ml.fromLngLat(n);h.y=I(h.y,-1+Jg,1-Jg);const p=h.toLngLat(),f=e.project(p.lng,p.lat),d=Ml.fromLngLat(p);d.x+=Jg;const m=d.toLngLat(),y=e.project(m.lng,m.lat),g=tx(y.x-f.x,y.y-f.y,c),x=Ml.fromLngLat(p);x.y+=Jg;const v=x.toLngLat(),b=e.project(v.lng,v.lat),_=tx(b.x-f.x,b.y-f.y,c),w=Math.abs(g.x)/Math.abs(_.y),M=t.a6.identity([]);t.a6.rotateZ(M,M,-c*(1-(a?0:i)));const A=t.a6.identity([]);return t.a6.scale(A,A,[1,1-(1-w)*i,1]),A[4]=-_.x/_.y*i,t.a6.rotateZ(A,A,c),t.a6.multiply(A,M,A),A}(e.projection,0,e.center,n,r),a=Hg(e);return t.a6.scale(i,i,[a,a,1]),i}function Hg(t){const e=t.projection,r=Wg(t.projection,t.zoom,t.width,t.height),n=Qg(e,t.center),i=Qg(e,tl.convert(e.center));return Math.pow(2,n*r+(1-r)*i)}function Wg(t,e,r,n,i=1/0){const a=t.range;if(!a)return 0;const s=Math.min(i,Math.max(r,n)),o=Math.log(s/1024)/Math.LN2;return k(a[0]+o,a[1]+o,e)}const Jg=1/4e4;function Qg(t,e){const r=I(e.lat,-xl,xl),n=new tl(e.lng-180*Jg,r),i=new tl(e.lng+180*Jg,r),a=t.project(n.lng,r),s=t.project(i.lng,r),o=Ml.fromLngLat(n),l=Ml.fromLngLat(i),u=s.x-a.x,c=s.y-a.y,h=l.x-o.x,p=l.y-o.y,f=Math.sqrt((h*h+p*p)/(u*u+c*c));return Math.log(f)/Math.LN2}function tx(t,e,r){const n=Math.cos(r),i=Math.sin(r);return {x:t*n-e*i,y:t*i+e*n}}function ex(e,r,n){t.a6.identity(e),t.a6.rotateZ(e,e,b(r[2])),t.a6.rotateX(e,e,b(r[0])),t.a6.rotateY(e,e,b(r[1])),t.a6.scale(e,e,n),t.a6.multiply(e,e,[1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1]);}function rx(e,r,n,i,a,s,o,l){const u=[n[0]-r[0],n[1]-r[1],0],c=[i[0]-r[0],i[1]-r[1],0];if(t.N.length(u)<1e-12||t.N.length(c)<1e-12)return t.bi.identity(e);const h=t.N.cross([],u,c);t.N.normalize(h,h),t.N.subtract(c,i,r),u[2]=(s-a)*l,c[2]=(o-a)*l;const p=u;return t.N.cross(p,u,c),t.N.normalize(p,p),t.bi.rotationTo(e,h,p)}function nx(e,r,n=!1){const i=rp(r.zoom),a=function(e,r,n){const i=r.worldSize,a=[e[12],e[13],e[14]],s=yl(a[1]/i),o=ml(a[0]/i),l=t.a6.identity([]),u=dl(1,s)*i,c=dl(1,0)*i*bl(s,r.zoom),h=1/Qh(i);let p=c*h;if(n){const t=Wg(r.projection,r.zoom,r.width,r.height,1024);p=h*r.projection.pixelSpaceConversion(r.center.lat,i,t);}const f=Wo(s,o);t.N.add(f,f,t.N.scale([],t.N.normalize([],f),u*p*a[2]));const d=function(e){const r=[e[0],e[1],e[2]];let n=[0,1,0];const i=t.N.cross([],n,r);return t.N.cross(n,r,i),0===t.N.squaredLength(n)&&(n=[0,1,0],t.N.cross(i,r,n)),t.N.normalize(i,i),t.N.normalize(n,n),t.N.normalize(r,r),[i[0],i[1],i[2],0,n[0],n[1],n[2],0,r[0],r[1],r[2],0,e[0],e[1],e[2],1]}(f);t.a6.scale(l,l,[p,p,p*u]),t.a6.translate(l,l,[-a[0],-a[1],-a[2]]);const m=t.a6.multiply([],r.globeMatrix,d);return t.a6.multiply(m,m,l),t.a6.multiply(m,m,e),m}(e,r,n);if(i>0){const n=function(e,r){const n=r.worldSize,i=dl(1,0)*n*bl(r.center.lat,r.zoom)/Qh(n),a=dl(1,r.center.lat)*n,s=t.a6.identity([]);return t.a6.rotateY(s,s,b(r.center.lng)),t.a6.rotateX(s,s,b(r.center.lat)),t.a6.translate(s,s,[0,0,jo]),t.a6.scale(s,s,[i,i,i*a]),t.a6.translate(s,s,[r.point.x-.5*n,r.point.y-.5*n,0]),t.a6.multiply(s,s,e),t.a6.multiply(s,r.globeMatrix,s)}(e,r);return function(e,r,n){const i=(e,r,n)=>{const i=t.N.length(e),a=t.N.length(r),s=qh(e,r,n);return t.N.scale(s,s,1/t.N.length(s)*ue(i,a,n))},a=i([e[0],e[1],e[2]],[r[0],r[1],r[2]],n),s=i([e[4],e[5],e[6]],[r[4],r[5],r[6]],n),o=i([e[8],e[9],e[10]],[r[8],r[9],r[10]],n),l=qh([e[12],e[13],e[14]],[r[12],r[13],r[14]],n);return [a[0],a[1],a[2],0,s[0],s[1],s[2],0,o[0],o[1],o[2],0,l[0],l[1],l[2],1]}(a,n,i)}return a}function ix(t,e,r,n){const i=Bh.projectAabbCorners(n,r);let a=Number.MAX_VALUE,s=-1;for(let t=0;tnew g(i[t][0],i[t][1]);let l;switch(s){case 0:case 6:l=[o(1),o(5),o(4),o(7),o(3),o(2),o(1)];break;case 1:case 7:l=[o(0),o(4),o(5),o(6),o(2),o(3),o(0)];break;case 3:case 5:l=[o(1),o(0),o(4),o(7),o(6),o(2),o(1)];break;default:l=[o(1),o(5),o(6),o(7),o(3),o(0),o(1)];}if(Vl(t,l))return a}const ax=cs([{name:"a_pos_3f",components:3,type:"Float32"}]),sx=cs([{name:"a_color_3f",components:3,type:"Float32"}]),ox=cs([{name:"a_color_4f",components:4,type:"Float32"}]),lx=cs([{name:"a_uv_2f",components:2,type:"Float32"}]),ux=cs([{name:"a_normal_3f",components:3,type:"Float32"}]),cx=cs([{name:"a_normal_matrix0",components:4,type:"Float32"},{name:"a_normal_matrix1",components:4,type:"Float32"},{name:"a_normal_matrix2",components:4,type:"Float32"},{name:"a_normal_matrix3",components:4,type:"Float32"}]),hx=cs([{name:"a_pbr",components:4,type:"Uint16"},{name:"a_heightBasedEmissiveStrength",components:3,type:"Float32"}]);class px{constructor(t,e){this.feature=t,this.instancedDataOffset=e,this.instancedDataCount=0,this.rotation=[0,0,0],this.scale=[1,1,1],this.translation=[0,0,0];}}class fx{constructor(){this.instancedDataArray=new Ns,this.instancesEvaluatedElevation=[],this.features=[],this.idToFeaturesIndex={};}}class dx{constructor(t){this.zoom=t.zoom,this.canonical=t.canonical,this.layers=t.layers,this.layerIds=this.layers.map((t=>t.fqid)),this.projection=t.projection,this.index=t.index,this.hasZoomDependentProperties=this.layers[0].isZoomDependent(),this.stateDependentLayerIds=this.layers.filter((t=>t.isStateDependent())).map((t=>t.id)),this.hasPattern=!1,this.instancesPerModel={},this.validForExaggeration=0,this.maxVerticalOffset=0,this.maxScale=0,this.maxHeight=0,this.lookupDim=this.zoom>this.canonical.z?256:this.zoom>15?75:100,this.instanceCount=0,this.terrainElevationMin=0,this.terrainElevationMax=0,this.validForDEMTile={id:null,timestamp:0};}populate(t,e,r,n){this.tileToMeter=wl(r);const i=this.layers[0]._featureFilter.needGeometry;this.lookup=new Uint8Array(this.lookupDim*this.lookupDim);for(const{feature:a,id:s,index:o,sourceLayerIndex:l}of t){const t=Bl(a,i);if(!this.layers[0]._featureFilter.filter(new Pa(this.zoom),t,r))continue;const u={id:s,sourceLayerIndex:l,index:o,geometry:i?t.geometry:Tl(a,r,n),properties:a.properties,type:a.type,patterns:{}},c=this.addFeature(u,u.geometry,t);c&&e.featureIndex.insert(a,u.geometry,o,l,this.index,this.instancesPerModel[c].instancedDataArray.length,Tr/32);}this.lookup=null;}update(t,e,r,n){for(const e in this.instancesPerModel){const r=this.instancesPerModel[e];for(const e in t)r.idToFeaturesIndex.hasOwnProperty(e)&&this.evaluate(r.features[r.idToFeaturesIndex[e]],t[e],r,!0);}this.maxHeight=0;}updateZoomBasedPaintProperties(){if(!this.hasZoomDependentProperties)return !1;let e=!1;for(const r in this.instancesPerModel){const n=this.instancesPerModel[r];for(const r of n.features){const i=this.layers[0],a=r.feature,s=this.canonical,o=i.paint.get("model-rotation").evaluate(a,{},s),l=i.paint.get("model-scale").evaluate(a,{},s),u=i.paint.get("model-translation").evaluate(a,{},s);t.N.exactEquals(r.rotation,o)&&t.N.exactEquals(r.scale,l)&&t.N.exactEquals(r.translation,u)||(this.evaluate(r,r.featureStates,n,!0),e=!0);}}return e}isEmpty(){for(const t in this.instancesPerModel)if(0!==this.instancesPerModel[t].instancedDataArray.length)return !1;return !0}uploadPending(){return !this.uploaded}upload(t){if(!this.uploaded)for(const e in this.instancesPerModel){const r=this.instancesPerModel[e];r.instancedDataArray.length<0||0===r.instancedDataArray.length||(r.instancedDataBuffer?r.instancedDataBuffer.updateData(r.instancedDataArray):r.instancedDataBuffer=t.createVertexBuffer(r.instancedDataArray,cx.members,!0,void 0,this.instanceCount));}this.uploaded=!0;}destroy(){for(const t in this.instancesPerModel){const e=this.instancesPerModel[t];0!==e.instancedDataArray.length&&e.instancedDataBuffer&&e.instancedDataBuffer.destroy();}}addFeature(t,e,r){const n=this.layers[0],i=n.layout.get("model-id").evaluate(r,{},this.canonical);if(!i)return j(`modelId is not evaluated for layer ${n.id} and it is not going to get rendered.`),i;this.instancesPerModel[i]||(this.instancesPerModel[i]=new fx);const a=this.instancesPerModel[i],s=a.instancedDataArray,o=new px(r,s.length);for(const t of e)for(const e of t){if(e.x<0||e.x>=Tr||e.y<0||e.y>=Tr)continue;const t=(this.lookupDim-1)/Tr,r=this.lookupDim*(e.y*t|0)+e.x*t|0;if(this.lookup){if(0!==this.lookup[r])continue;this.lookup[r]=1;}this.instanceCount++;const n=s.length;s.resize(n+1),a.instancesEvaluatedElevation.push(0),s.float32[16*n]=e.x,s.float32[16*n+1]=e.y;}return o.instancedDataCount=a.instancedDataArray.length-o.instancedDataOffset,o.instancedDataCount>0&&(t.id&&(a.idToFeaturesIndex[t.id]=a.features.length),a.features.push(o),this.evaluate(o,{},a,!1)),i}evaluate(t,e,r,n){const i=this.layers[0],a=t.feature,s=this.canonical,o=t.rotation=i.paint.get("model-rotation").evaluate(a,e,s),l=t.scale=i.paint.get("model-scale").evaluate(a,e,s),u=t.translation=i.paint.get("model-translation").evaluate(a,e,s),c=i.paint.get("model-color").evaluate(a,e,s);c.a=i.paint.get("model-color-mix-intensity").evaluate(a,e,s);const h=[];this.maxVerticalOffset10?this.tileToMeter:wl(s,f)),o[a+4]=u[0],o[a+5]=u[1],o[a+6]=u[2]+l,o[a+7]=h[0],o[a+8]=h[1],o[a+9]=h[2],o[a+10]=h[4],o[a+11]=h[5],o[a+12]=h[6],o[a+13]=h[8],o[a+14]=h[9],o[a+15]=h[10],r.instancesEvaluatedElevation[i]=u[2];}}}ra(dx,"ModelBucket",{omit:["layers"]}),ra(fx,"PerModelAttributes"),ra(px,"ModelFeature");const mx=new Oa({visibility:new La(qa.layout_model.visibility),"model-id":new Fa(qa.layout_model["model-id"])});var yx={paint:new Oa({"model-opacity":new La(qa.paint_model["model-opacity"]),"model-rotation":new Fa(qa.paint_model["model-rotation"]),"model-scale":new Fa(qa.paint_model["model-scale"]),"model-translation":new Fa(qa.paint_model["model-translation"]),"model-color":new Fa(qa.paint_model["model-color"]),"model-color-mix-intensity":new Fa(qa.paint_model["model-color-mix-intensity"]),"model-type":new La(qa.paint_model["model-type"]),"model-cast-shadows":new La(qa.paint_model["model-cast-shadows"]),"model-receive-shadows":new La(qa.paint_model["model-receive-shadows"]),"model-ambient-occlusion-intensity":new La(qa.paint_model["model-ambient-occlusion-intensity"]),"model-emissive-strength":new Fa(qa.paint_model["model-emissive-strength"]),"model-roughness":new Fa(qa.paint_model["model-roughness"]),"model-height-based-emissive-strength-multiplier":new Fa(qa.paint_model["model-height-based-emissive-strength-multiplier"]),"model-cutoff-fade-range":new La(qa.paint_model["model-cutoff-fade-range"])}),layout:mx};const gx=64,xx={CoordinateSpaceTile:1,CoordinateSpaceYUp:2,HasMapboxMeshFeatures:4,HasMeshoptCompression:8};function vx(e,r,n,i,a,s,o,l,u,c=!1){const h=n.zoom,p=n.project(i),f=bl(i.lat,h),d=1/f;t.a6.identity(e),t.a6.translate(e,e,[p.x+o[0]*d,p.y+o[1]*d,o[2]]);let m=1,y=1;const g=n.worldSize;if(c){if("mercator"===n.projection.name){let e=0;n.elevation&&(e=n.elevation.getAtPointOrZero(new Ml(p.x/g,p.y/g),0));const r=t.a7.transformMat4([],[p.x,p.y,e,1],n.projMatrix)[3]/n.cameraToCenterDistance;m=r,y=r*bl(n.center.lat,h);}else if("globe"===n.projection.name){const r=nx(e,n),a=t.a6.multiply([],n.projMatrix,r),s=[0,0,0,1];t.a7.transformMat4(s,s,a);const o=s[3]/n.cameraToCenterDistance,l=rp(h),u=n.projection.pixelsPerMeter(i.lat,g)*bl(i.lat,h),c=n.projection.pixelsPerMeter(n.center.lat,g)*bl(n.center.lat,h);m=o/ue(u,vl(n.center.lat),l),y=o*f/u,m*=c,y*=c;}}else m=d;t.a6.scale(e,e,[m,m,y]);const x=[...e],v=r.orientation,b=[];if(ex(b,[v[0]+a[0],v[1]+a[1],v[2]+a[2]],s),t.a6.multiply(e,x,b),l&&n.elevation){let a=0;const s=[];if(u&&n.elevation){a=function(e,r,n,i,a){const s=r.elevation;if(!s)return 0;const o=Bh.projectAabbCorners(n,i),l=dl(1,a.lat)*r.worldSize,u=function(e,r){const n=[0,0,1],i=[{corners:[0,1,3,2],dotProductWithUp:0},{corners:[1,5,2,6],dotProductWithUp:0},{corners:[0,4,1,5],dotProductWithUp:0},{corners:[2,6,3,7],dotProductWithUp:0},{corners:[4,7,5,6],dotProductWithUp:0},{corners:[0,3,4,7],dotProductWithUp:0}];for(const a of i){const i=e[a.corners[0]],s=e[a.corners[1]],o=e[a.corners[2]],l=[s[0]-i[0],s[1]-i[1],r*(s[2]-i[2])],u=t.N.cross(l,l,[o[0]-i[0],o[1]-i[1],r*(o[2]-i[2])]);t.N.normalize(u,u),a.dotProductWithUp=t.N.dot(u,n);}return i.sort(((t,e)=>t.dotProductWithUp-e.dotProductWithUp)),i[0].corners}(o,l),c=o[u[0]],h=o[u[1]],p=o[u[2]],f=o[u[3]],d=s.getAtPointOrZero(new Ml(c[0]/r.worldSize,c[1]/r.worldSize),0),m=s.getAtPointOrZero(new Ml(h[0]/r.worldSize,h[1]/r.worldSize),0),y=s.getAtPointOrZero(new Ml(p[0]/r.worldSize,p[1]/r.worldSize),0),g=s.getAtPointOrZero(new Ml(f[0]/r.worldSize,f[1]/r.worldSize),0),x=(d+g)/2,v=(m+y)/2;return x>v?m=e.gl.NEAREST_MIPMAP_NEAREST}),t.uploaded=!0,t.image=null);}function _x(t,e,r){t.indexBuffer=e.createIndexBuffer(t.indexArray,!1,!0),t.vertexBuffer=e.createVertexBuffer(t.vertexArray,ax.members,!1,!0),t.normalArray&&(t.normalBuffer=e.createVertexBuffer(t.normalArray,ux.members,!1,!0)),t.texcoordArray&&(t.texcoordBuffer=e.createVertexBuffer(t.texcoordArray,lx.members,!1,!0)),t.colorArray&&(t.colorBuffer=e.createVertexBuffer(t.colorArray,(12===t.colorArray.bytesPerElement?sx:ox).members,!1,!0)),t.featureArray&&(t.pbrBuffer=e.createVertexBuffer(t.featureArray,hx.members,!0)),t.segments=eo.simpleSegment(0,0,t.vertexArray.length,t.indexArray.length);const n=t.material;n.pbrMetallicRoughness.baseColorTexture&&bx(n.pbrMetallicRoughness.baseColorTexture,e),n.pbrMetallicRoughness.metallicRoughnessTexture&&bx(n.pbrMetallicRoughness.metallicRoughnessTexture,e),n.normalTexture&&bx(n.normalTexture,e),n.occlusionTexture&&bx(n.occlusionTexture,e,r),n.emissionTexture&&bx(n.emissionTexture,e);}function wx(t,e,r){if(t.meshes)for(const n of t.meshes)_x(n,e,r);if(t.children)for(const n of t.children)wx(n,e,r);}function Mx(t){if(t.meshes)for(const e of t.meshes)e.indexArray.destroy(),e.vertexArray.destroy(),e.colorArray&&e.colorArray.destroy(),e.normalArray&&e.normalArray.destroy(),e.texcoordArray&&e.texcoordArray.destroy(),e.featureArray&&e.featureArray.destroy();if(t.children)for(const e of t.children)Mx(e);}function Ax(t){if(t.meshes)for(const r of t.meshes)r.vertexBuffer&&(r.vertexBuffer.destroy(),r.indexBuffer.destroy(),r.normalBuffer&&r.normalBuffer.destroy(),r.texcoordBuffer&&r.texcoordBuffer.destroy(),r.colorBuffer&&r.colorBuffer.destroy(),r.pbrBuffer&&r.pbrBuffer.destroy(),r.segments.destroy(),r.material&&((e=r.material).pbrMetallicRoughness.baseColorTexture&&e.pbrMetallicRoughness.baseColorTexture.gfxTexture&&e.pbrMetallicRoughness.baseColorTexture.gfxTexture.destroy(),e.pbrMetallicRoughness.metallicRoughnessTexture&&e.pbrMetallicRoughness.metallicRoughnessTexture.gfxTexture&&e.pbrMetallicRoughness.metallicRoughnessTexture.gfxTexture.destroy(),e.normalTexture&&e.normalTexture.gfxTexture&&e.normalTexture.gfxTexture.destroy(),e.emissionTexture&&e.emissionTexture.gfxTexture&&e.emissionTexture.gfxTexture.destroy(),e.occlusionTexture&&e.occlusionTexture.gfxTexture&&e.occlusionTexture.gfxTexture.destroy()));var e;if(t.children)for(const e of t.children)Ax(e);}class Sx{constructor(t){this._callback=t,this._triggered=!1,"undefined"!=typeof MessageChannel&&(this._channel=new MessageChannel,this._channel.port2.onmessage=()=>{this._triggered=!1,this._callback();});}trigger(){this._triggered||(this._triggered=!0,this._channel?this._channel.port1.postMessage(!0):setTimeout((()=>{this._triggered=!1,this._callback();}),0));}remove(){this._channel=void 0,this._callback=()=>{};}}class Ix{constructor(){this.tasks={},this.taskQueue=[],V(["process"],this),this.invoker=new Sx(this.process),this.nextId=0;}add(t,e){const r=this.nextId++,n=function({type:t,isSymbolTile:e,zoom:r}){return r=r||0,"message"===t?0:"maybePrepare"!==t||e?"parseTile"!==t||e?"parseTile"===t&&e?300-r:"maybePrepare"===t&&e?400-r:500:200-r:100-r}(e);if(0===n){Y();try{t();}finally{}return null}return this.tasks[r]={fn:t,metadata:e,priority:n,id:r},this.taskQueue.push(r),this.invoker.trigger(),{cancel:()=>{delete this.tasks[r];}}}process(){Y();try{if(this.taskQueue=this.taskQueue.filter((t=>!!this.tasks[t])),!this.taskQueue.length)return;const t=this.pick();if(null===t)return;const e=this.tasks[t];if(delete this.tasks[t],this.taskQueue.length&&this.invoker.trigger(),!e)return;e.fn();}finally{}}pick(){let t=null,e=1/0;for(let r=0;r{r&&delete this.callbacks[s],this.target.postMessage({id:s,type:"",targetMapId:n,sourceMapId:this.mapId});}}}receive(t){const e=t.data,r=e.id;if(r&&(!e.targetMapId||this.mapId===e.targetMapId))if(""===e.type){const t=this.cancelCallbacks[r];delete this.cancelCallbacks[r],t&&t.cancel();}else if(e.mustQueue||Y()){const t=this.callbacks[r],n=this.scheduler.add((()=>this.processTask(r,e)),t&&t.metadata||{type:"message"});n&&(this.cancelCallbacks[r]=n);}else this.processTask(r,e);}processTask(t,e){if(delete this.cancelCallbacks[t],""===e.type){const r=this.callbacks[t];delete this.callbacks[t],r&&(e.error?r(sa(e.error)):r(null,sa(e.data)));}else {const r=new Set,n=e.hasCallback?(e,n)=>{this.target.postMessage({id:t,type:"",sourceMapId:this.mapId,error:e?aa(e):null,data:aa(n,r)},r);}:t=>{},i=sa(e.data);if(this.parent[e.type])this.parent[e.type](e.sourceMapId,i,n);else if(this.parent.getWorkerSource){const t=e.type.split(".");this.parent.getWorkerSource(e.sourceMapId,t[0],i.source,i.scope)[t[1]](i,n);}else n(new Error(`Could not find function ${e.type}`));}}remove(){this.scheduler.remove(),this.target.removeEventListener("message",this.receive,!1);}}class Px{constructor(t,e){this.workerPool=t,this.actors=[],this.currentActor=0,this.id=B();const r=this.workerPool.acquire(this.id);for(let t=0;t{this.ready=!0;}));}broadcast(t,e,r){E(this.actors,((r,n)=>{r.send(t,e,n);}),r=r||function(){});}getActor(){return this.currentActor=(this.currentActor+1)%this.actors.length,this.actors[this.currentActor]}remove(){this.actors.forEach((t=>{t.remove();})),this.actors=[],this.workerPool.release(this.id);}}Px.Actor=kx;var Ex={workerUrl:"",workerClass:null,workerParams:void 0};function zx(){return null!=Ex.workerClass?new Ex.workerClass:new self.Worker(Ex.workerUrl,Ex.workerParams)}const Tx="mapboxgl_preloaded_worker_pool";class Bx{constructor(){this.active={};}acquire(t){if(!this.workers)for(this.workers=[];this.workers.length{t.terminate();})),this.workers=null);}isPreloaded(){return !!this.active[Tx]}numActive(){return Object.keys(this.active).length}}let Cx;function Rx(){return Cx||(Cx=new Bx),Cx}Bx.workerCount=2;let Dx,Vx,Lx,Fx,Nx,Ox=null;function Ux(){return Y()&&self.worker&&self.worker.dracoUrl?self.worker.dracoUrl:Vx||n.DRACO_URL}function jx(){if(Y()&&self.worker&&self.worker.meshoptUrl)return self.worker.meshoptUrl;if(Fx)return Fx;const t=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]);if("object"!=typeof WebAssembly)throw new Error("WebAssembly not supported, cannot instantiate meshoptimizer");return Fx=WebAssembly.validate(t)?n.MESHOPT_SIMD_URL:n.MESHOPT_URL,Fx}const qx={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},$x={5120:"DT_INT8",5121:"DT_UINT8",5122:"DT_INT16",5123:"DT_UINT16",5125:"DT_UINT32",5126:"DT_FLOAT32"},Gx={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Yx(t,e,r){const n=r.json.bufferViews.length,i=r.buffers.length;e.bufferView=n,r.json.bufferViews[n]={buffer:i,byteLength:t.byteLength},r.buffers[i]=t;}const Xx="KHR_draco_mesh_compression";function Zx(t,e){const r=t.extensions&&t.extensions[Xx];if(!r)return;const n=new Lx.Decoder,i=ev(e,r.bufferView),a=new Lx.Mesh;if(!n.DecodeArrayToMesh(i,i.byteLength,a))throw new Error("Failed to decode Draco mesh");const s=e.json.accessors[t.indices],o=qx[s.componentType],l=s.count*o.BYTES_PER_ELEMENT,u=Lx._malloc(l);o===Uint16Array?n.GetTrianglesUInt16Array(a,l,u):n.GetTrianglesUInt32Array(a,l,u),Yx(Lx.memory.buffer.slice(u,u+l),s,e),Lx._free(u);for(const i of Object.keys(r.attributes)){const s=n.GetAttributeByUniqueId(a,r.attributes[i]),o=e.json.accessors[t.attributes[i]],l=$x[o.componentType],u=o.count*Gx[o.type]*qx[o.componentType].BYTES_PER_ELEMENT,c=Lx._malloc(u);n.GetAttributeDataArrayForAllPoints(a,s,Lx[l],u,c),Yx(Lx.memory.buffer.slice(c,c+u),o,e),Lx._free(c);}n.destroy(),a.destroy(),delete t.extensions[Xx];}const Kx="EXT_meshopt_compression";function Hx(t,e){if(!t.extensions||!t.extensions[Kx])return;const r=t.extensions[Kx],n=new Uint8Array(e.buffers[r.buffer],r.byteOffset||0,r.byteLength||0),i=new Uint8Array(r.count*r.byteStride);Nx.decodeGltfBuffer(i,r.count,r.byteStride,n,r.mode,r.filter),t.buffer=e.buffers.length,t.byteOffset=0,e.buffers[t.buffer]=i.buffer,delete t.extensions[Kx];}const Wx=1179937895,Jx=new TextDecoder("utf8");function Qx(t,e){return new URL(t,e).href}function tv(t,e,r,n){return fetch(Qx(t.uri,n)).then((t=>t.arrayBuffer())).then((t=>{e.buffers[r]=t;}))}function ev(t,e){const r=t.json.bufferViews[e];return new Uint8Array(t.buffers[r.buffer],r.byteOffset||0,r.byteLength)}function rv(t,e,r,n){if(t.uri){const i=Qx(t.uri,n);return fetch(i).then((t=>t.blob())).then((t=>createImageBitmap(t))).then((t=>{e.images[r]=t;}))}if(void 0!==t.bufferView){const n=ev(e,t.bufferView),i=new Blob([n],{type:t.mimeType});return createImageBitmap(i).then((t=>{e.images[r]=t;}))}}function nv(t,e=0,r){const n={json:null,images:[],buffers:[]};if(new Uint32Array(t,e,1)[0]===Wx){const r=new Uint32Array(t,e);let i=2;const a=(r[i++]>>2)-3,s=r[i++]>>2;if(i++,n.json=JSON.parse(Jx.decode(r.subarray(i,i+s))),i+=s,i{const t=[],e=o&&o.includes(Xx),i=o&&o.includes(Kx);if(e&&t.push(function(){if(!Lx)return Dx||(Dx=function(t){let e,r=null;function n(){e=new Uint8Array(r.buffer);}function i(){throw new Error("Unexpected Draco error.")}const a={a:{a:i,d:function(t,r,n){return e.copyWithin(t,r,r+n)},c:function(t){const i=e.length,a=Math.max(t>>>0,Math.ceil(1.2*i)),s=Math.ceil((a-i)/65536);try{return r.grow(s),n(),!0}catch(t){return !1}},b:i}};return (WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(t,a):t.then((t=>t.arrayBuffer())).then((t=>WebAssembly.instantiate(t,a)))).then((t=>{const{Rb:i,Qb:a,P:s,T:o,X:l,Ja:u,La:c,Qa:h,Va:p,Wa:f,eb:d,jb:m,f:y,e:g,yb:x,zb:v,Ab:b,Bb:_,Db:w,Gb:M}=t.instance.exports;r=g;const A=(()=>{let t=0,r=0,n=0,s=0;return o=>{n&&(i(s),i(t),r+=n,n=t=0),t||(r+=128,t=a(r));const l=o.length+7&-8;let u=t;l>=r&&(n=l,u=s=a(l));for(let t=0;t{Lx=t,Dx=void 0;})))}()),i&&t.push(function(){if(Nx)return;const t=function(t){let e;const r=WebAssembly.instantiateStreaming(t,{}).then((t=>{e=t.instance,e.exports.__wasm_call_ctors();})),n={NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp"},i={ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"};return {ready:r,supported:!0,decodeGltfBuffer(t,r,a,s,o,l){!function(t,e,r,n,i,a,s){const o=t.exports.sbrk,l=n+3&-4,u=o(l*i),c=o(a.length),h=new Uint8Array(t.exports.memory.buffer);h.set(a,c);const p=e(u,n,i,c,a.length);if(0===p&&s&&s(u,l,i),r.set(h.subarray(u,u+n*i)),o(u-o(0)),0!==p)throw new Error(`Malformed buffer data: ${p}`)}(e,e.exports[i[o]],t,r,a,s,e.exports[n[l]]);}}}(fetch(jx()));return t.ready.then((()=>{Nx=t;}))}()),a)for(let e=0;e{if(e&&s)for(const{primitives:t}of s)for(const e of t)Zx(e,n);if(i&&s&&l)for(const t of l)Hx(t,n);return n}))}))}class iv{constructor(t,e,r){if(this.triangleCount=e.length/3,this.min=new g(0,0),this.max=new g(0,0),this.xScale=0,this.yScale=0,this.cellsX=0,this.cellsY=0,this.cells=[],this.payload=[],0===this.triangleCount||0===t.length||0===r)return;const n=t.map((t=>t.x)),i=t.map((t=>t.y));this.min=new g(Math.min(...n),Math.min(...i)),this.max=new g(Math.max(...n),Math.max(...i));const a=this.max.sub(this.min);a.x=Math.max(a.x,1),a.y=Math.max(a.y,1);const s=Math.max(a.x,a.y)/r;this.cellsX=Math.max(1,Math.ceil(a.x/s)),this.cellsY=Math.max(1,Math.ceil(a.y/s)),this.xScale=1/s,this.yScale=1/s;const o=[];for(let r=0;rt.cellIdx-e.cellIdx||t.triIdx-e.triIdx));let l=0;for(;lthis.max.x||this.min.x>e.x)return;if(t.y>this.max.y||this.min.y>e.y)return;this.lookup||(this.lookup=new Uint8Array(Math.ceil(this.triangleCount/8)));for(let t=0;t0){for(let i=0;i0){a.texcoordArray=new Fs;const t=e.json.accessors[i.TEXCOORD_0];a.texcoordArray.resize(t.count);const r=sv(e,t);ov(e,t,a.texcoordArray,r);}if(void 0!==i._FEATURE_ID_RGBA4444){const t=e.json.accessors[i._FEATURE_ID_RGBA4444];e.json.extensionsUsed&&e.json.extensionsUsed.includes("EXT_meshopt_compression")&&(a.featureData=sv(e,t));}void 0!==i._FEATURE_RGBA4444&&(a.featureData=new Uint32Array(sv(e,e.json.accessors[i._FEATURE_RGBA4444]).buffer));const h=t.material;return a.material=function(t,e){const{emissiveFactor:r=[0,0,0],alphaMode:n="OPAQUE",alphaCutoff:i=.5,normalTexture:a,occlusionTexture:s,emissiveTexture:o,doubleSided:l}=t,{baseColorFactor:u=[1,1,1,1],metallicFactor:c=1,roughnessFactor:h=1,baseColorTexture:p,metallicRoughnessTexture:f}=t.pbrMetallicRoughness||{},d=s?e[s.index]:void 0;if(s&&s.extensions&&s.extensions.KHR_texture_transform&&d){const t=s.extensions.KHR_texture_transform;d.offsetScale=[t.offset[0],t.offset[1],t.scale[0],t.scale[1]];}return {pbrMetallicRoughness:{baseColorFactor:new le(...u),metallicFactor:c,roughnessFactor:h,baseColorTexture:p?e[p.index]:void 0,metallicRoughnessTexture:f?e[f.index]:void 0},doubleSided:l,emissiveFactor:r,alphaMode:n,alphaCutoff:i,normalTexture:a?e[a.index]:void 0,occlusionTexture:d,emissionTexture:o?e[o.index]:void 0,defined:void 0===t.defined}}(void 0!==h?e.json.materials[h]:{defined:!1},r),a}function uv(e,r,n){const{matrix:i,rotation:a,translation:s,scale:o,mesh:l,extras:u,children:c}=e,h={};if(h.matrix=i||t.a6.fromRotationTranslationScale([],a||[0,0,0,1],s||[0,0,0],o||[1,1,1]),void 0!==l){h.meshes=n[l];const t=h.anchor=[0,0];for(const e of h.meshes){const{min:r,max:n}=e.aabb;t[0]+=r[0]+n[0],t[1]+=r[1]+n[1];}t[0]=Math.floor(t[0]/h.meshes.length/2),t[1]=Math.floor(t[1]/h.meshes.length/2);}if(u&&(u.id&&(h.id=u.id),u.lights&&(h.lights=function(t){if(!t.length)return [];const e=function(t){const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t1&&n[n.length-1].equals(n[0])&&n.pop();let i=0;for(let t=0;t0&&n.reverse();const a=rf(n.flatMap((t=>[t.x,t.y])),[]);return 0===a.length?null:{vertices:n,indices:a}}function pv(t){const e=[],r=[];let n=0;for(const i of t){n=e.length;const t=i.vertexArray.float32,a=i.indexArray.uint16;for(let r=0;r0&&([r[t+1],r[t+2]]=[r[t+2],r[t+1]]);}return {vertices:e,indices:r}}function fv(t){const e=function(t,e){const r=[],n=WebGL2RenderingContext;if(t.json.textures)for(const i of t.json.textures){const a={magFilter:n.LINEAR,minFilter:n.NEAREST,wrapS:n.REPEAT,wrapT:n.REPEAT};void 0!==i.sampler&&Object.assign(a,t.json.samplers[i.sampler]),r.push({image:e[i.source],sampler:a,uploaded:!1});}return r}(t,t.images),r=function(t,e){const r=[];for(const n of t.json.meshes){const i=[];for(const r of n.primitives)i.push(lv(r,t,e));r.push(i);}return r}(t,e),{scenes:n,scene:i,nodes:a}=t.json,s=n?n[i||0].nodes:a,o=[];for(const e of s)o.push(uv(a[e],t,r));return function(t,e,r){const n={},i=new Set;for(let a=0;a0){const e=Array.from(i.values()).sort(((t,e)=>t-e));for(let r=e.length-1;r>=0;r--)t.splice(e[r],1);}}(o,s,t.json.nodes),o}function dv(t){t.heightmap=new Float32Array(4096),t.heightmap.fill(-1);const e=t.vertexArray.float32,r=t.aabb.min[0]-1,n=t.aabb.min[1]-1,i=gx/(t.aabb.max[0]-r+2),a=gx/(t.aabb.max[1]-n+2);for(let s=0;st.heightmap[u*gx+l]&&(t.heightmap[u*gx+l]=o);}}function mv(e,r){const n={};n.indexArray=new Es,n.indexArray.reserve(4*e.length),n.vertexArray=new Ls,n.vertexArray.reserve(10*e.length),n.colorArray=new gs,n.vertexArray.reserve(10*e.length);let i=0;for(const a of e){const e=Math.min(10,Math.max(4,1.3*a.height))*r,s=[-a.normal[1],a.normal[0],0],o=Math.min(.29,.1*a.width/a.depth),l=a.width-2*a.depth*r*(o+.01),u=t.N.scaleAndAdd([],a.pos,s,l/2),c=t.N.scaleAndAdd([],a.pos,s,-l/2),h=[u[0],u[1],u[2]+a.height],p=[c[0],c[1],c[2]+a.height],f=t.N.scaleAndAdd([],a.normal,s,o);t.N.scale(f,f,e);const d=t.N.scaleAndAdd([],a.normal,s,-o);t.N.scale(d,d,e),t.N.add(f,u,f),t.N.add(d,c,d),u[2]+=.1,c[2]+=.1,n.vertexArray.emplaceBack(f[0],f[1],f[2]),n.vertexArray.emplaceBack(d[0],d[1],d[2]),n.vertexArray.emplaceBack(u[0],u[1],u[2]),n.vertexArray.emplaceBack(c[0],c[1],c[2]),n.vertexArray.emplaceBack(h[0],h[1],h[2]),n.vertexArray.emplaceBack(p[0],p[1],p[2]),n.vertexArray.emplaceBack(u[0],u[1],u[2]),n.vertexArray.emplaceBack(c[0],c[1],c[2]),n.vertexArray.emplaceBack(f[0],f[1],f[2]),n.vertexArray.emplaceBack(d[0],d[1],d[2]);const m=l/e/2;n.colorArray.emplaceBack(-m-o,-1,m,.8),n.colorArray.emplaceBack(m+o,-1,m,.8),n.colorArray.emplaceBack(-m,0,m,1.3),n.colorArray.emplaceBack(m,0,m,1.3),n.colorArray.emplaceBack(m+o,-.8,m,.7),n.colorArray.emplaceBack(m+o,-.8,m,.7),n.colorArray.emplaceBack(0,0,m,1.3),n.colorArray.emplaceBack(0,0,m,1.3),n.colorArray.emplaceBack(m+o,-1.2,m,.8),n.colorArray.emplaceBack(m+o,-1.2,m,.8),n.indexArray.emplaceBack(6+i,4+i,8+i),n.indexArray.emplaceBack(7+i,9+i,5+i),n.indexArray.emplaceBack(0+i,1+i,2+i),n.indexArray.emplaceBack(1+i,3+i,2+i),i+=10;}const a={defined:!0,emissiveFactor:[0,0,0]},s={};return s.baseColorFactor=le.white,a.pbrMetallicRoughness=s,n.material=a,n.aabb=new Bh([1/0,1/0,1/0],[-1/0,-1/0,-1/0]),n}ra(iv,"TriangleGridIndex");class yv{constructor(t){this._stringToNumber={},this._numberToString=[];for(let e=0;e=0&&n[3]>=0&&l.insert(o,n[0],n[1],n[2],n[3]);}}loadVTLayers(){if(!this.vtLayers){this.vtLayers=new Ef(new Vm(this.rawTileData)).layers,this.sourceLayerCoder=new yv(this.vtLayers?Object.keys(this.vtLayers).sort():["_geojsonTileLayer"]),this.vtFeatures={};for(const t in this.vtLayers)this.vtFeatures[t]=[];}return this.vtLayers}query(t,e,r,n){this.loadVTLayers();const i=t.params||{},a=Ga(i.filter),s=t.tileResult,o=t.transform,l=s.bufferedTilespaceBounds,u=this.grid.query(l.min.x,l.min.y,l.max.x,l.max.y,((t,e,r,n)=>Yl(s.bufferedTilespaceGeometry,t,e,r,n)));u.sort(_v);let c=null;o.elevation&&u.length>0&&(c=Wf.create(o.elevation,this.tileID));const h={};let p;for(let l=0;l(m||(m=Tl(e,this.tileID.canonical,t.tileTransform)),r.queryIntersectsFeature(s,e,n,m,this.z,t.transform,t.pixelPosMatrix,c,i))));}return h}loadMatchingFeature(t,e,r,n,i,a,s,o,l){const{featureIndex:u,bucketIndex:c,sourceLayerIndex:h,layoutVertexArrayOffset:p}=e,f=this.bucketLayerIDs[c];if(n&&!function(t,e){for(let r=0;r=0)return !0;return !1}(n,f))return;const d=this.sourceLayerCoder.decode(h),m=this.vtLayers[d].feature(u);if(r.needGeometry){const t=Bl(m,!0);if(!r.filter(new Pa(this.tileID.overscaledZ),t,this.tileID.canonical))return}else if(!r.filter(new Pa(this.tileID.overscaledZ),m))return;const y=this.getId(m,d);for(let e=0;e{const s=e instanceof Va?e.get(a):null;return s&&s.evaluate?s.evaluate(r,n,i):s}))}function _v(t,e){return e-t}ra(vv,"FeatureIndex",{omit:["rawTileData","sourceLayerCoder"]});const wv=new Float32Array(262144),Mv=new Uint8Array(262144);function Av(t){let e=0;if(t.meshes)for(const r of t.meshes)e=Math.max(e,r.aabb.max[2]);if(t.children)for(const r of t.children)e=Math.max(e,Av(r));return e}function Sv(t,e,r){if(t.meshes)for(const n of t.meshes)n.aabb.min[0]!==1/0&&r.insert(e,n.aabb.min[0],n.aabb.min[1],n.aabb.max[0],n.aabb.max[1]);if(t.children)for(const n of t.children)Sv(n,e,r);}const Iv=["","wall","door","roof","window","lamp","logo"];class kv{constructor(t){this.node=t,this.evaluatedRMEA=[[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[.4,1,0,1],[1,0,0,1],[1,0,0,1]],this.hiddenByReplacement=!1,this.evaluatedScale=[1,1,1],this.evaluatedColor=[],this.emissionHeightBasedParams=[],this.feature={type:"Point",id:t.id,geometry:[],properties:{height:Av(t)}};}getLocalBounds(){if(!this.node.meshes)return new Bh([1/0,1/0,1/0],[-1/0,-1/0,-1/0]);if(!this.aabb){let t=0;const e=new Bh([1/0,1/0,1/0],[-1/0,-1/0,-1/0]);for(const r of this.node.meshes)this.node.lightMeshIndex!==t&&e.encapsulate(r.aabb),t++;this.aabb=e;}return this.aabb}}class Pv{constructor(t,e,r,n,i,a){this.id=e,this.modelTraits|=xx.CoordinateSpaceTile,this.uploaded=!1,this.hasPattern=!1,r&&(this.modelTraits|=xx.HasMapboxMeshFeatures),n&&(this.modelTraits|=xx.HasMeshoptCompression),this.zoom=-1,this.terrainExaggeration=1,this.projection={name:"mercator"},this.replacementUpdateTime=0,this.elevationReadFromZ=255,this.brightness=i,this.dirty=!0,this.needsUpload=!1,this.nodesInfo=[];for(const e of t)this.nodesInfo.push(new kv(e)),Sv(e,a.featureIndexArray.length,a.grid),a.featureIndexArray.emplaceBack(this.nodesInfo.length-1,0,a.bucketLayerIDs.length-1,0);}update(){console.log("Update 3D model bucket");}populate(){console.log("populate 3D model bucket");}uploadPending(){return !this.uploaded||this.needsUpload}upload(t){if(!this.needsUpload)return;const e=this.getNodesInfo();for(const r of e){const e=r.node;this.uploaded?this.updatePbrBuffer(e):wx(e,t,!0);}for(const t of e)Mx(t.node);this.uploaded=!0,this.needsUpload=!1;}updatePbrBuffer(t){let e=!1;if(!t.meshes)return e;for(const r of t.meshes)r.pbrBuffer&&(r.pbrBuffer.updateData(r.featureArray),e=!0);return e}needsReEvaluation(t,e,r){const n=t.transform.projectionOptions,i=t.style.getBrightness(),a=this.brightness!==i;return !!(!this.uploaded||this.dirty||n.name!==this.projection.name||Ev(r.paint.get("model-color").value,a)||Ev(r.paint.get("model-color-mix-intensity").value,a)||Ev(r.paint.get("model-roughness").value,a)||Ev(r.paint.get("model-emissive-strength").value,a)||Ev(r.paint.get("model-height-based-emissive-strength-multiplier").value,a))&&(this.projection=n,this.brightness=i,!0)}evaluateScale(t,e){if(t.transform.zoom===this.zoom)return;this.zoom=t.transform.zoom;const r=this.getNodesInfo(),n=this.id.canonical;for(const t of r){const r=t.feature;t.evaluatedScale=e.paint.get("model-scale").evaluate(r,{},n);}}evaluate(t){const e=this.getNodesInfo();for(const r of e){if(!r.node.meshes)continue;const e=r.feature,n=r.node.meshes&&r.node.meshes[0].featureData,i=r.evaluatedColor[2],a=r.evaluatedRMEA[2],s=this.id.canonical;if(r.hasTranslucentParts=!1,n){for(let n=0;n=t)continue;const h=wv[u],p=Math.abs(h);p>o&&(s=h,o=p,l=i,c=e);}if(o>.1){const a=1-(t+.5*Math.abs(l*c))/u;let o=e._dem.get(n,r)+s*a;const h=e._dem.get(n+l,r+c),p=e._dem.get(n-l,r-c,!0);(o-h)*(o-p)>0&&(o=(h+p)/2),wv[i]=e._dem.set(n,r,o),Mv[i]=t;}}}}}s&&(e._demTile.needsDEMTextureUpload=!0,e._dem._timestamp=st.now());}getNodesInfo(){return this.nodesInfo}destroy(){const t=this.getNodesInfo();for(const e of t)Mx(e.node),Ax(e.node);}isEmpty(){return !this.nodesInfo.length}updateReplacement(t,e){if(e.updateTime===this.replacementUpdateTime)return;this.replacementUpdateTime=e.updateTime;const r=e.getReplacementRegionsForTile(t.toUnwrapped()),n=this.getNodesInfo();for(let t=0;tt.footprint===e.footprint));}}getHeightAtTileCoord(t,e){const r=this.getNodesInfo(),n=[];for(let i=0;is.aabb.max[0]||e>s.aabb.max[1])continue;const o=(t-s.aabb.min[0])/(s.aabb.max[0]-s.aabb.min[0])*gx|0,l=Math.min(63,(e-s.aabb.min[1])/(s.aabb.max[1]-s.aabb.min[1])*gx|0)*gx+Math.min(63,o);if(!(s.heightmap[l]<0&&a.node.footprint)){if(a.hiddenByReplacement)return;return {height:s.heightmap[l],maxHeight:a.feature.properties.height,hidden:!1,verticalScale:a.evaluatedScale[2]}}if(a.node.footprint.grid.query(new g(t,e),new g(t,e),n),n.length>0)return {height:void 0,maxHeight:a.feature.properties.height,hidden:a.hiddenByReplacement,verticalScale:a.evaluatedScale[2]}}}}function Ev(t,e){return !t.isLightConstant&&e}function zv(t,e,r,n,i,a,s,o){let l=(61440&e|(61440&e)>>4)>>8,u=(3840&e|(3840&e)>>4)>>4,c=240&e|(240&e)>>4;r[3]>0&&(l=ue(l,255*r[0],r[3]),u=ue(u,255*r[1],r[3]),c=ue(c,255*r[2],r[3]));const h=l<<8|u,p=c<<8|Math.floor(255*n[3]),f=function(t){const e=I(t,0,2);return Math.min(Math.round(.5*e*255),255)}(n[2])<<8|15*n[0]<<4|15*n[1],d=I(i[0],0,1),m=I(i[1],0,1),y=I(i[2],0,1),g=I(i[3],0,1);let x,v,b,_;if(d!==m&&s!==a&&m!==d){const t=s-a;v=1/(t*(m-d)),b=-(a+t*d)/(t*(m-d));const e=I(i[4],-1,1);_=Math.pow(10,e),x=255*y<<8|255*g;}else x=65535,v=0,b=1,_=1;if(t.emplaceBack(h,p,f,x,v,b,_),o){const t=o.length;o.clear();for(let e=0;e>16&65535,o=a?e>>16&65535:65535&e,l=(15&o)<8?15&o:0,u=t.evaluatedRMEA[l],c=t.evaluatedColor[l],h=t.emissionHeightBasedParams[l];let p;if(s&&2===l&&n.lights&&(p=new Os,p.resize(10*n.lights.length)),zv(r.featureArray,i,c,u,h,r.aabb.min[2],r.aabb.max[2],p),p&&s){s=!1;const t=n.meshes[n.lightMeshIndex];t.featureArray=p,t.featureArray._trim();}}r.featureArray._trim(),i++;}}function Bv(t,e,r,n){const i=1<t.polygon)).flat());const x=d?l:null,[v,b]=function(e,r,n,i,a,s,o,l,u,c,h){return "globe"===e.projection.name?function(e,r,n,i,a,s,o,l,u,c,h){const p=[],f=[],d=e.projection.upVectorScale(h,e.center.lat,e.worldSize).metersToTile,m=[0,0,0,1],y=[0,0,0,1],g=(t,e,r,n)=>{t[0]=e,t[1]=r,t[2]=n,t[3]=1;},x=Md();n>0&&(n+=x),i+=x;for(const x of r){const r=[],v=[];for(const p of x){const f=p.x+a.x,x=p.y+a.y,b=e.projection.projectTilePoint(f,x,h),_=e.projection.upVector(h,p.x,p.y);let w=n,M=i;if(o){const t=Td(f,x,n,i,o,l,u,c);w+=t.base,M+=t.top;}0!==n?g(m,b.x+_[0]*d*w,b.y+_[1]*d*w,b.z+_[2]*d*w):g(m,b.x,b.y,b.z),g(y,b.x+_[0]*d*M,b.y+_[1]*d*M,b.z+_[2]*d*M),t.N.transformMat4(m,m,s),t.N.transformMat4(y,y,s),r.push(new Pd(m[0],m[1],m[2])),v.push(new Pd(y[0],y[1],y[2]));}p.push(r),f.push(v);}return [p,f]}(e,r,n,i,a,s,o,l,u,c,h):o?function(e,r,n,i,a,s,o,l,u){const c=[],h=[],p=[0,0,0,1];for(const f of e){const e=[],d=[];for(const c of f){const h=c.x+i.x,f=c.y+i.y,m=Td(h,f,r,n,s,o,l,u);p[0]=h,p[1]=f,p[2]=m.base,p[3]=1,t.a7.transformMat4(p,p,a),p[3]=Math.max(p[3],1e-5);const y=new Pd(p[0]/p[3],p[1]/p[3],p[2]/p[3]);p[0]=h,p[1]=f,p[2]=m.top,p[3]=1,t.a7.transformMat4(p,p,a),p[3]=Math.max(p[3],1e-5);const g=new Pd(p[0]/p[3],p[1]/p[3],p[2]/p[3]);e.push(y),d.push(g);}c.push(e),h.push(d);}return [c,h]}(r,n,i,a,s,o,l,u,c):function(t,e,r,n,i){const a=[],s=[],o=i[8]*e,l=i[9]*e,u=i[10]*e,c=i[11]*e,h=i[8]*r,p=i[9]*r,f=i[10]*r,d=i[11]*r;for(const e of t){const t=[],r=[];for(const a of e){const e=a.x+n.x,s=a.y+n.y,m=i[0]*e+i[4]*s+i[12],y=i[1]*e+i[5]*s+i[13],g=i[2]*e+i[6]*s+i[14],x=i[3]*e+i[7]*s+i[15],v=m+o,b=y+l,_=g+u,w=Math.max(x+c,1e-5),M=m+h,A=y+p,S=g+f,I=Math.max(x+d,1e-5);t.push(new Pd(v/w,b/w,_/w)),r.push(new Pd(M/I,A/I,S/I));}a.push(t),s.push(r);}return [a,s]}(r,n,i,a,s)}(s,i,p,h,c,o,x,f,m,s.center.lat,e.tileID.canonical),_=e.queryGeometry;return function(t,e,r){let n=1/0;Fl(r,e)&&(n=zd(r,e[0]));for(let i=0;i=3)for(let e=0;e
+ * @license BSD-3-Clause
+ * @version 11.2.5
+ */
+ class Vv{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e;}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev);}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null);}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0));}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,n=this.resetTtl){let i;if(r||this.has(t)){if(i=this.items[t],i.value=e,!1===r&&n&&(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==i){const t=this.last,e=i.next,r=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,t.next=i,null!==r&&(r.next=e),null!==e&&(e.prev=r);}}else this.max>0&&this.size===this.max&&this.evict(!0),i=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=i:this.last.next=i;return this.last=i,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}function Lv(t,e){if(4!==e.length)throw new Error(`Expected data of dimension 4 but got ${e.length}.`);let r=e[3];for(let n=2;n>=1;n--){const i=1===n?1:0,a=2===n?1:0;for(let n=0;n>>1^-(1&t[e]);return t}function Nv(t,e){switch(e){case"uint32":return t;case"uint16":for(let e=0;e>4|(61440&r)>>8|(240&n)<<4|61440&n,t[e+1]=15&r|(3840&r)>>4|(15&n)<<8|(3840&n)<<4;}return t;case"uint8":for(let e=0;e>6|(192&n)>>4|(192&i)>>2|192&a,t[e+1]=(48&r)>>4|(48&n)>>2|48&i|(48&a)<<2,t[e+2]=(12&r)>>2|12&n|(12&i)<<2|(12&a)<<4,t[e+3]=3&r|(3&n)<<2|(3&i)<<4|(3&a)<<6;}return t;default:throw new Error(`Invalid pixel format, "${e}"`)}}class Ov extends Error{constructor(t){super(t),this.name="MRTError";}}var Uv=Uint8Array,jv=Uint16Array,qv=Int32Array,$v=new Uv([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Gv=new Uv([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Yv=new Uv([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Xv=function(t,e){for(var r=new jv(31),n=0;n<31;++n)r[n]=e+=1<>1|(21845&Qv)<<1;Jv[Qv]=((65280&(tb=(61680&(tb=(52428&tb)>>2|(13107&tb)<<2))>>4|(3855&tb)<<4))>>8|(255&tb)<<8)>>1;}var eb=function(t,e,r){for(var n=t.length,i=0,a=new jv(e);i>l]=u;}else for(s=new jv(n),i=0;i>15-t[i]);return s},rb=new Uv(288);for(Qv=0;Qv<144;++Qv)rb[Qv]=8;for(Qv=144;Qv<256;++Qv)rb[Qv]=9;for(Qv=256;Qv<280;++Qv)rb[Qv]=7;for(Qv=280;Qv<288;++Qv)rb[Qv]=8;var nb=new Uv(32);for(Qv=0;Qv<32;++Qv)nb[Qv]=5;var ib=eb(rb,9,1),ab=eb(nb,5,1),sb=function(t){for(var e=t[0],r=1;re&&(e=t[r]);return e},ob=function(t,e,r){var n=e/8|0;return (t[n]|t[n+1]<<8)>>(7&e)&r},lb=function(t,e){var r=e/8|0;return (t[r]|t[r+1]<<8|t[r+2]<<16)>>(7&e)},ub=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],cb=function(t,e,r){var n=new Error(e||ub[t]);if(n.code=t,Error.captureStackTrace&&Error.captureStackTrace(n,cb),!r)throw n;return n},hb=new Uv(0),pb="undefined"!=typeof TextDecoder&&new TextDecoder;try{pb.decode(hb,{stream:!0});}catch(t){}const fb={gzip_data:"gzip"};const db={0:"uint32",1:"uint32",2:"uint16",3:"uint8"},mb={uint32:1,uint16:2,uint8:4},yb={uint32:Uint32Array,uint16:Uint16Array,uint8:Uint8Array};class gb{constructor(t=1){this.x=NaN,this.y=NaN,this.z=NaN,this.layers={},this._cacheSize=t;}getLayer(t){return this.layers[t]}getHeaderLength(t){const e=new Uint8Array(t),r=new DataView(t);if(13!==e[0])throw new Ov("File is not a valid MRT.");return r.getUint32(1,!0)}parseHeader(t){const e=new Uint8Array(t),r=this.getHeaderLength(t);if(e.length= ${r} but got buffer of length ${e.length}`);const n=new Vm(e.subarray(0,r)),i=Rv.read(n);if(!isNaN(this.x)&&(this.x!==i.x||this.y!==i.y||this.z!==i.z))throw new Ov(`Invalid attempt to parse header ${i.z}/${i.x}/${i.y} for tile ${this.z}/${this.x}/${this.y}`);this.x=i.x,this.y=i.y,this.z=i.z;for(const t of i.layers)this.layers[t.name]=new xb(t,{cacheSize:this._cacheSize});return this}createDecodingTask(t){const e=[],r=this.getLayer(t.layerName);for(let n=0;n