t&&0!==i){const t=this.calculateProjMatrix(r.tileID.toUnwrapped());let n;e.isTerrainDEM||(n=c.getMinMaxForTile(r.tileID)),n||(n={min:b,max:v});const o=function(e){const t=Math.round((e+45+360)%360/90)%4;return E[t]}(this.rotation),s=[o[0]*sr,o[1]*sr,n.max];Mu.transformMat4(s,s,t),l=(1-s[1])*this.height*.5e.distanceSq-t.distanceSq)).map((e=>e.tileID))}resize(e,t){this.width=e,this.height=t,this.pixelsToGLUnits=[2/e,-2/t],this._constrain(),this._calcMatrices();}get unmodified(){return this._unmodified}zoomScale(e){return Math.pow(2,e)}scaleZoom(e){return Math.log(e)/Math.LN2}project(e){const t=z(e.lat,-Xd,Xd),i=this.projection.project(e.lng,t);return new y(i.x*this.worldSize,i.y*this.worldSize)}unproject(e){return this.projection.unproject(e.x/this.worldSize,e.y/this.worldSize)}get point(){return this.project(this.center)}get pointMerc(){return this.point._div(this.worldSize)}get pixelsPerMeterRatio(){return this.pixelsPerMeter/Zd(1,this.center.lat)/this.worldSize}setLocationAtPoint(e,t){let i,r;const n=this.centerPoint;if(\"globe\"===this.projection.name){const e=this.worldSize;i=(t.x-n.x)/e,r=(t.y-n.y)/e;}else {const e=this.pointCoordinate(t),o=this.pointCoordinate(n);i=e.x-o.x,r=e.y-o.y;}const o=this.locationCoordinate(e);this.setLocation(new ep(o.x-i,o.y-r));}setLocation(e){this.center=this.coordinateLocation(e),this.projection.wrap&&(this.center=this.center.wrap());}locationPoint(e){return this.projection.locationPoint(this,e)}locationPoint3D(e){return this.projection.locationPoint(this,e,!0)}pointLocation(e){return this.coordinateLocation(this.pointCoordinate(e))}pointLocation3D(e){return this.coordinateLocation(this.pointCoordinate3D(e))}locationCoordinate(e,t){const i=t?Zd(t,e.lat):void 0,r=this.projection.project(e.lng,e.lat);return new ep(r.x,r.y,i)}coordinateLocation(e){return this.projection.unproject(e.x,e.y)}pointRayIntersection(e,t){const i=null!=t?t:this._centerAltitude,r=[e.x,e.y,0,1],n=[e.x,e.y,1,1];uu.transformMat4(r,r,this.pixelMatrixInverse),uu.transformMat4(n,n,this.pixelMatrixInverse);const o=n[3];uu.scale(r,r,1/r[3]),uu.scale(n,n,1/o);const s=r[2],a=n[2];return {p0:r,p1:n,t:s===a?0:(i-s)/(a-s)}}screenPointToMercatorRay(e){const t=[e.x,e.y,0,1],i=[e.x,e.y,1,1];return uu.transformMat4(t,t,this.pixelMatrixInverse),uu.transformMat4(i,i,this.pixelMatrixInverse),uu.scale(t,t,1/t[3]),uu.scale(i,i,1/i[3]),t[2]=Zd(t[2],this._center.lat)*this.worldSize,i[2]=Zd(i[2],this._center.lat)*this.worldSize,uu.scale(t,t,1/this.worldSize),uu.scale(i,i,1/this.worldSize),new Uu([t[0],t[1],t[2]],Mu.normalize([],Mu.sub([],i,t)))}rayIntersectionCoordinate(e){const{p0:t,p1:i,t:r}=e,n=Zd(t[2],this._center.lat),o=Zd(i[2],this._center.lat);return new ep(Wr(t[0],i[0],r)/this.worldSize,Wr(t[1],i[1],r)/this.worldSize,Wr(n,o,r))}pointCoordinate(e,t=this._centerAltitude){return this.projection.pointCoordinate(this,e.x,e.y,t)}pointCoordinate3D(e){if(!this.elevation)return this.pointCoordinate(e);let t=this.projection.pointCoordinate3D(this,e.x,e.y);if(t)return new ep(t[0],t[1],t[2]);let i=0,r=this.horizonLineFromTop();if(e.y>r)return this.pointCoordinate(e);const n=.02*r,o=e.clone();for(let e=0;e<10&&r-i>n;e++){o.y=Wr(i,r,.66);const e=this.projection.pointCoordinate3D(this,o.x,o.y);e?(r=o.y,t=e):i=o.y;}return t?new ep(t[0],t[1],t[2]):this.pointCoordinate(e)}isPointAboveHorizon(e){return this.projection.isPointAboveHorizon(this,e)}isPointOnSurface(e){if(e.y<0||e.y>this.height||e.x<0||e.x>this.width)return !1;if(this.elevation||this.zoom>=Xu)return !this.isPointAboveHorizon(e);const t=this.pointCoordinate(e);return t.y>=0&&t.y<=1}_coordinatePoint(e,t){const i=t&&this.elevation?this.elevation.getAtPointOrZero(e,this._centerAltitude):this._centerAltitude,r=[e.x*this.worldSize,e.y*this.worldSize,i+e.toAltitude(),1];return uu.transformMat4(r,r,this.pixelMatrix),r[3]>0?new y(r[0]/r[3],r[1]/r[3]):new y(Number.MAX_VALUE,Number.MAX_VALUE)}_getBoundsNonRectangular(){const{top:e,left:t}=this._edgeInsets,i=this.height-this._edgeInsets.bottom,r=this.width-this._edgeInsets.right,n=this.pointLocation3D(new y(t,e)),o=this.pointLocation3D(new y(r,e)),s=this.pointLocation3D(new y(r,i)),a=this.pointLocation3D(new y(t,i));let l=Math.min(n.lng,o.lng,s.lng,a.lng),c=Math.max(n.lng,o.lng,s.lng,a.lng),h=Math.min(n.lat,o.lat,s.lat,a.lat),u=Math.max(n.lat,o.lat,s.lat,a.lat);const d=Math.pow(2,-this.zoom)/16*270,p=\"globe\"===this.projection.name?1:4,f=(e,t,i,r,n)=>{const o=(e+i)/2,s=(t+r)/2,a=new y(o,s),{lng:m,lat:_}=this.pointLocation3D(a),g=Math.max(0,l-m,h-_,m-c,_-u);l=Math.min(l,m),c=Math.max(c,m),h=Math.min(h,_),u=Math.max(u,_),(nd)&&(f(e,t,o,s,n+1),f(o,s,i,r,n+1));};if(f(t,e,r,e,1),f(r,e,r,i,1),f(r,i,t,i,1),f(t,i,t,e,1),\"globe\"===this.projection.name){const[e,t]=function(e){const t=xu.identity(new Float64Array(16));xu.multiply(t,e.pixelMatrix,e.globeMatrix);const i=[0,ed,0],r=[0,td,0];return Mu.transformMat4(i,i,t),Mu.transformMat4(r,r,t),[i[0]>0&&i[0]<=e.width&&i[1]>0&&i[1]<=e.height&&!Dd(e,new Nd(e.center.lat,90)),r[0]>0&&r[0]<=e.width&&r[1]>0&&r[1]<=e.height&&!Dd(e,new Nd(e.center.lat,-90))]}(this);e?(u=90,c=180,l=-180):t&&(h=-90,c=180,l=-180);}return new Ql(new Nd(l,h),new Nd(c,u))}_getBoundsRectangular(e,t){const{top:i,left:r}=this._edgeInsets,n=this.height-this._edgeInsets.bottom,o=this.width-this._edgeInsets.right,s=new y(r,i),a=new y(o,i),l=new y(o,n),c=new y(r,n);let h=this.pointCoordinate(s,e),u=this.pointCoordinate(a,e);const d=this.pointCoordinate(l,t),p=this.pointCoordinate(c,t),f=(e,t)=>(t.y-e.y)/(t.x-e.x);return h.y>1&&u.y>=0?h=new ep((1-p.y)/f(p,h)+p.x,1):h.y<0&&u.y<=1&&(h=new ep(-p.y/f(p,h)+p.x,0)),u.y>1&&h.y>=0?u=new ep((1-d.y)/f(d,u)+d.x,1):u.y<0&&h.y<=1&&(u=new ep(-d.y/f(d,u)+d.x,0)),(new Ql).extend(this.coordinateLocation(h)).extend(this.coordinateLocation(u)).extend(this.coordinateLocation(p)).extend(this.coordinateLocation(d))}_getBoundsRectangularTerrain(){const e=this.elevation;if(!e.visibleDemTiles.length||e.isUsingMockSource())return this._getBoundsRectangular(0,0);const t=e.visibleDemTiles.reduce(((e,t)=>{if(t.dem){const i=t.dem.tree;e.min=Math.min(e.min,i.minimums[0]),e.max=Math.max(e.max,i.maximums[0]);}return e}),{min:Number.MAX_VALUE,max:0});return this._getBoundsRectangular(t.min*e.exaggeration(),t.max*e.exaggeration())}getBounds(){return \"mercator\"===this.projection.name||\"equirectangular\"===this.projection.name?this._terrainEnabled()?this._getBoundsRectangularTerrain():this._getBoundsRectangular(0,0):this._getBoundsNonRectangular()}horizonLineFromTop(e=!0){const t=this.height/2/Math.tan(this._fov/2)/Math.tan(Math.max(this._pitch,.1))-this.centerOffset.y,i=this.height/2-t*(1-this._horizonShift);return e?Math.max(0,i):i}getMaxBounds(){return this.maxBounds}setMaxBounds(e){this.maxBounds=e,this.minLat=-Xd,this.maxLat=Xd,this.minLng=-180,this.maxLng=180,e&&(this.minLat=e.getSouth(),this.maxLat=e.getNorth(),this.minLng=e.getWest(),this.maxLng=e.getEast(),this.maxLngh&&(s=h-l),h-ct&&(o=t-a),t-e{for(let n=0;n<16;n++)e[n]=pv(t[n],i[n],r);})(s,s,a,fv(this.pitch>=15?1:this.pitch/15));}else s=a;const l=xu.mul([],a,o);let c=xu.mul([],s,o);if(this.projection.isReprojectedInTileSpace){const e=this.locationCoordinate(this.center),t=xu.identity([]);xu.translate(t,t,[e.x*this.worldSize,e.y*this.worldSize,0]),xu.multiply(t,t,Gx(this)),xu.translate(t,t,[-e.x*this.worldSize,-e.y*this.worldSize,0]),xu.multiply(c,c,t),xu.multiply(l,l,t),this.inverseAdjustmentMatrix=function(e){const t=Gx(e,!0);return fu.invert([],[t[0],t[1],t[4],t[5]])}(this);}else this.inverseAdjustmentMatrix=[1,0,0,1];this.mercatorMatrix=xu.scale([],c,[this.worldSize,this.worldSize,this.worldSize/n,1]),this.projMatrix=c,this.invProjMatrix=xu.invert(new Float64Array(16),this.projMatrix);const h=xu.invert([],s);this.frustumCorners=Vu.fromInvProjectionMatrix(h,this.horizonLineFromTop(),this.height),this.cameraFrustum=$u.fromInvProjectionMatrix(this.invProjMatrix,this.worldSize,0,!t);const u=new Float32Array(16);xu.identity(u),xu.scale(u,u,[1,-1,1]),xu.rotateX(u,u,this._pitch),xu.rotateZ(u,u,this.angle);const d=xu.perspective(new Float32Array(16),this._fov,this.width/this.height,this._nearZ,this._farZ);this.starsProjMatrix=xu.clone(d);const p=(Math.PI/2-this._pitch)*(this.height/this._fov)*this._horizonShift;d[8]=2*-e.x/this.width,d[9]=2*(e.y+p)/this.height,this.skyboxMatrix=xu.multiply(u,d,u);const f=this.point,m=f.x,_=f.y,g=this.width%2/2,y=this.height%2/2,x=Math.cos(this.angle),v=Math.sin(this.angle),b=m-Math.round(m)+x*g+v*y,w=_-Math.round(_)+x*y+v*g,T=new Float64Array(c);if(xu.translate(T,T,[b>.5?b-1:b,w>.5?w-1:w,0]),this.alignedProjMatrix=T,c=xu.create(),xu.scale(c,c,[this.width/2,-this.height/2,1]),xu.translate(c,c,[1,-1,0]),this.labelPlaneMatrix=c,c=xu.create(),xu.scale(c,c,[1,-1,1]),xu.translate(c,c,[-1,-1,0]),xu.scale(c,c,[2/this.width,2/this.height,1]),this.glCoordMatrix=c,this.pixelMatrix=xu.multiply(new Float64Array(16),this.labelPlaneMatrix,l),this._calcFogMatrices(),this._distanceTileDataCache={},c=xu.invert(new Float64Array(16),this.pixelMatrix),!c)throw new Error(\"failed to invert matrix\");if(this.pixelMatrixInverse=c,\"globe\"===this.projection.name||this.mercatorFromTransition){this.globeMatrix=function(e){const{x:t,y:i}=e.point,{lng:r,lat:n}=e._center;return Td(t,i,e.worldSize,r,n)}(this);const e=[this.globeMatrix[12],this.globeMatrix[13],this.globeMatrix[14]];this.globeCenterInViewSpace=Mu.transformMat4(e,e,o),this.globeRadius=this.worldSize/2/Math.PI-1;}else this.globeMatrix=c;this._projMatrixCache={},this._alignedProjMatrixCache={},this._pixelsToTileUnitsCache={};}_calcFogMatrices(){this._fogTileMatrixCache={};const e=this.cameraWorldSizeForFog,t=this.cameraPixelsPerMeter,i=this._camera.position,r=1/this.height/this._pixelsPerMercatorPixel,n=[e,e,t];Mu.scale(n,n,r),Mu.scale(i,i,-1),Mu.multiply(i,i,n);const o=xu.create();xu.translate(o,o,i),xu.scale(o,o,n),this.mercatorFogMatrix=o,this.worldToFogMatrix=this._camera.getWorldToCameraPosition(e,t,r);}_computeCameraPosition(e){const t=(e=e||this.pixelsPerMeter)/this.pixelsPerMeter,i=this._camera.forward(),r=this.point,n=this._mercatorZfromZoom(this._seaLevelZoom?this._seaLevelZoom:this._zoom)*t-e/this.worldSize*this._centerAltitude;return [r.x/this.worldSize-i[0]*n,r.y/this.worldSize-i[1]*n,e/this.worldSize*this._centerAltitude-i[2]*n]}_updateCameraState(){this.height&&(this._camera.setPitchBearing(this._pitch,this.angle),this._camera.position=this._computeCameraPosition());}_translateCameraConstrained(e){const t=this._maxCameraBoundsDistance()*Math.cos(this._pitch),i=this._camera.position[2],r=e[2];let n=1;this.projection.wrap&&(this.center=this.center.wrap()),r>0&&(n=Math.min((t-i)/r,1)),this._camera.position=Mu.scaleAndAdd([],this._camera.position,e,n),this._updateStateFromCamera();}_updateStateFromCamera(){const e=this._camera.position,t=this._camera.forward(),{pitch:i,bearing:r}=this._camera.getPitchBearing(),n=Zd(this._centerAltitude,this.center.lat)*this._pixelsPerMercatorPixel,o=this._mercatorZfromZoom(this._maxZoom)*Math.cos(w(this._maxPitch)),s=Math.max((e[2]-n)/Math.cos(i),o),a=this._zoomFromMercatorZ(s);Mu.scaleAndAdd(e,e,t,s),this._pitch=z(i,w(this.minPitch),w(this.maxPitch)),this.angle=P(r,-Math.PI,Math.PI),this._setZoom(z(a,this._minZoom,this._maxZoom)),this._updateSeaLevelZoom(),this._center=this.coordinateLocation(new ep(e[0],e[1],e[2])),this._unmodified=!1,this._constrain(),this._calcMatrices();}_worldSizeFromZoom(e){return Math.pow(2,e)*this.tileSize}_mercatorZfromZoom(e){return this.cameraToCenterDistance/this._worldSizeFromZoom(e)}_minimumHeightOverTerrain(){const e=Math.min((null!=this._seaLevelZoom?this._seaLevelZoom:this._zoom)+4,this._maxZoom);return this._mercatorZfromZoom(e)}_zoomFromMercatorZ(e){return this.scaleZoom(this.cameraToCenterDistance/(e*this.tileSize))}zoomFromMercatorZAdjusted(e){let t=0,i=Xu,r=0,n=1/0;for(;i-t>1e-6&&i>t;){const o=t+.5*(i-t),s=this.tileSize*Math.pow(2,o),a=this.getCameraToCenterDistance(this.projection,o,s),l=this.scaleZoom(a/(e*this.tileSize)),c=Math.abs(o-l);cl||i.y>1)return !0}return !1}isHorizonVisible(){return this.pitch+T(this.fovAboveCenter)>88||this.anyCornerOffEdge(new y(0,0),new y(this.width,this.height))}zoomDeltaToMovement(e,t){const i=Mu.length(Mu.sub([],this._camera.position,e)),r=this._zoomFromMercatorZ(i)+t;return i-this._mercatorZfromZoom(r)}getCameraPoint(){if(\"globe\"===this.projection.name){const e=function([e,t,i],r){const n=[e,t,i,1];uu.transformMat4(n,n,r);const o=n[3]=Math.max(n[3],1e-6);return n[0]/=o,n[1]/=o,n[2]/=o,n}([this.globeMatrix[12],this.globeMatrix[13],this.globeMatrix[14]],this.pixelMatrix);return new y(e[0],e[1])}{const e=Math.tan(this._pitch)*(this.cameraToCenterDistance||1);return this.centerPoint.add(new y(0,e))}}getCameraToCenterDistance(e,t=this.zoom,i=this.worldSize){const r=Zx(e,t,this.width,this.height,1024),n=e.pixelSpaceConversion(this.center.lat,i,r);let o=.5/Math.tan(.5*this._fov)*this.height*n;return this.isOrthographic&&(o=pv(1,o,fv(this.pitch>=15?1:this.pitch/15))),o}getWorldToCameraMatrix(){const e=this._camera.getWorldToCamera(this.worldSize,\"meters\"===this.projection.zAxisUnit?this.pixelsPerMeter:1);return \"globe\"===this.projection.name&&xu.multiply(e,e,this.globeMatrix),e}getFrustum(e){return $u.fromInvProjectionMatrix(this.invProjMatrix,this.worldSize,e,\"meters\"===this.projection.zAxisUnit)}}function _v(e,t,i){xu.identity(e),xu.rotateZ(e,e,w(t[2])),xu.rotateX(e,e,w(t[0])),xu.rotateY(e,e,w(t[1])),xu.scale(e,e,i),xu.multiply(e,e,[1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1]);}function gv(e,t,i,r,n,o,s,a){const l=[i[0]-t[0],i[1]-t[1],0],c=[r[0]-t[0],r[1]-t[1],0];if(Mu.length(l)<1e-12||Mu.length(c)<1e-12)return bu.identity(e);const h=Mu.cross([],l,c);Mu.normalize(h,h),Mu.subtract(c,r,t),l[2]=(o-n)*a,c[2]=(s-n)*a;const u=l;return Mu.cross(u,l,c),Mu.normalize(u,u),bu.rotationTo(e,h,u)}function yv(e,t,i=!1){const r=Ed(t.zoom),n=function(e,t,i){const r=t.worldSize,n=[e[12],e[13],e[14]],o=Hd(n[1]/r),s=$d(n[0]/r),a=xu.identity([]),l=Zd(1,o)*r,c=Zd(1,0)*r*Kd(o,t.zoom),h=1/bd(r);let u=c*h;if(i){const e=Zx(t.projection,t.zoom,t.width,t.height,1024);u=h*t.projection.pixelSpaceConversion(t.center.lat,r,e);}const d=md(o,s);Mu.add(d,d,Mu.scale([],Mu.normalize([],d),l*u*n[2]));const p=function(e){const t=[e[0],e[1],e[2]];let i=[0,1,0];const r=Mu.cross([],i,t);return Mu.cross(i,t,r),0===Mu.squaredLength(i)&&(i=[0,1,0],Mu.cross(r,t,i)),Mu.normalize(r,r),Mu.normalize(i,i),Mu.normalize(t,t),[r[0],r[1],r[2],0,i[0],i[1],i[2],0,t[0],t[1],t[2],0,e[0],e[1],e[2],1]}(d);xu.scale(a,a,[u,u,u*l]),xu.translate(a,a,[-n[0],-n[1],-n[2]]);const f=xu.multiply([],t.globeMatrix,p);return xu.multiply(f,f,a),xu.multiply(f,f,e),f}(e,t,i);if(r>0){const i=function(e,t){const i=t.worldSize,r=Zd(1,0)*i*Kd(t.center.lat,t.zoom)/bd(i),n=Zd(1,t.center.lat)*i,o=xu.identity([]);return xu.rotateY(o,o,w(t.center.lng)),xu.rotateX(o,o,w(t.center.lat)),xu.translate(o,o,[0,0,Yu]),xu.scale(o,o,[r,r,r*n]),xu.translate(o,o,[t.point.x-.5*i,t.point.y-.5*i,0]),xu.multiply(o,o,e),xu.multiply(o,t.globeMatrix,o)}(e,t);return function(e,t,i){const r=(e,t,i)=>{const r=Mu.length(e),n=Mu.length(t),o=ld(e,t,i);return Mu.scale(o,o,1/Mu.length(o)*Wr(r,n,i))},n=r([e[0],e[1],e[2]],[t[0],t[1],t[2]],i),o=r([e[4],e[5],e[6]],[t[4],t[5],t[6]],i),s=r([e[8],e[9],e[10]],[t[8],t[9],t[10]],i),a=ld([e[12],e[13],e[14]],[t[12],t[13],t[14]],i);return [n[0],n[1],n[2],0,o[0],o[1],o[2],0,s[0],s[1],s[2],0,a[0],a[1],a[2],1]}(n,i,r)}return n}const xv=64,vv=[1,1,1];class bv{constructor(e,t,i,r){this.id=e,this.position=null!=t?new Nd(t[0],t[1]):new Nd(0,0),this.orientation=null!=i?i:[0,0,0],this.nodes=r,this.uploaded=!1,this.aabb=new Hu([1/0,1/0,1/0],[-1/0,-1/0,-1/0]),this.matrix=[];}_applyTransformations(e,t){if(xu.multiply(e.matrix,t,e.matrix),e.meshes)for(const t of e.meshes){const i=Hu.applyTransform(t.aabb,e.matrix);this.aabb.encapsulate(i);}if(e.children)for(const t of e.children)this._applyTransformations(t,e.matrix);}computeBoundsAndApplyParent(){const e=xu.identity([]);for(const t of this.nodes)this._applyTransformations(t,e);}_positionModelOnTerrain(e,t){const i=e.elevation;if(!i)return 0;const r=Hu.projectAabbCorners(this.aabb,this.matrix),n=Zd(1,this.position.lat)*e.worldSize,o=function(e,t){const i=[0,0,1],r=[{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 n of r){const r=e[n.corners[0]],o=e[n.corners[1]],s=e[n.corners[2]],a=[o[0]-r[0],o[1]-r[1],t*(o[2]-r[2])],l=Mu.cross(a,a,[s[0]-r[0],s[1]-r[1],t*(s[2]-r[2])]);Mu.normalize(l,l),n.dotProductWithUp=Mu.dot(l,i);}return r.sort(((e,t)=>e.dotProductWithUp-t.dotProductWithUp)),r[0].corners}(r,n),s=r[o[0]],a=r[o[1]],l=r[o[2]],c=r[o[3]],h=i.getAtPointOrZero(new ep(s[0]/e.worldSize,s[1]/e.worldSize),0),u=i.getAtPointOrZero(new ep(a[0]/e.worldSize,a[1]/e.worldSize),0),d=i.getAtPointOrZero(new ep(l[0]/e.worldSize,l[1]/e.worldSize),0),p=i.getAtPointOrZero(new ep(c[0]/e.worldSize,c[1]/e.worldSize),0),f=(h+p)/2,m=(u+d)/2;return f>m?u=t.gl.NEAREST_MIPMAP_NEAREST}),e.uploaded=!0,e.image=null);}function Tv(e,t,i){e.indexBuffer=t.createIndexBuffer(e.indexArray,!1,!0),e.vertexBuffer=t.createVertexBuffer(e.vertexArray,zx.members,!1,!0),e.normalArray&&(e.normalBuffer=t.createVertexBuffer(e.normalArray,Lx.members,!1,!0)),e.texcoordArray&&(e.texcoordBuffer=t.createVertexBuffer(e.texcoordArray,Rx.members,!1,!0)),e.colorArray&&(e.colorBuffer=t.createVertexBuffer(e.colorArray,(12===e.colorArray.bytesPerElement?Dx:Px).members,!1,!0)),e.featureArray&&(e.pbrBuffer=t.createVertexBuffer(e.featureArray,Ox.members,!0)),e.segments=dl.simpleSegment(0,0,e.vertexArray.length,e.indexArray.length);const r=e.material;r.pbrMetallicRoughness.baseColorTexture&&wv(r.pbrMetallicRoughness.baseColorTexture,t),r.pbrMetallicRoughness.metallicRoughnessTexture&&wv(r.pbrMetallicRoughness.metallicRoughnessTexture,t),r.normalTexture&&wv(r.normalTexture,t),r.occlusionTexture&&wv(r.occlusionTexture,t,i),r.emissionTexture&&wv(r.emissionTexture,t);}function Ev(e,t,i){if(e.meshes)for(const r of e.meshes)Tv(r,t,i);if(e.children)for(const r of e.children)Ev(r,t,i);}function Mv(e){if(e.meshes)for(const t of e.meshes)t.indexArray.destroy(),t.vertexArray.destroy(),t.colorArray&&t.colorArray.destroy(),t.normalArray&&t.normalArray.destroy(),t.texcoordArray&&t.texcoordArray.destroy(),t.featureArray&&t.featureArray.destroy();if(e.children)for(const t of e.children)Mv(t);}function Av(e){if(e.meshes)for(const i of e.meshes)i.vertexBuffer&&(i.vertexBuffer.destroy(),i.indexBuffer.destroy(),i.normalBuffer&&i.normalBuffer.destroy(),i.texcoordBuffer&&i.texcoordBuffer.destroy(),i.colorBuffer&&i.colorBuffer.destroy(),i.pbrBuffer&&i.pbrBuffer.destroy(),i.segments.destroy(),i.material&&((t=i.material).pbrMetallicRoughness.baseColorTexture&&t.pbrMetallicRoughness.baseColorTexture.gfxTexture&&t.pbrMetallicRoughness.baseColorTexture.gfxTexture.destroy(),t.pbrMetallicRoughness.metallicRoughnessTexture&&t.pbrMetallicRoughness.metallicRoughnessTexture.gfxTexture&&t.pbrMetallicRoughness.metallicRoughnessTexture.gfxTexture.destroy(),t.normalTexture&&t.normalTexture.gfxTexture&&t.normalTexture.gfxTexture.destroy(),t.emissionTexture&&t.emissionTexture.gfxTexture&&t.emissionTexture.gfxTexture.destroy(),t.occlusionTexture&&t.occlusionTexture.gfxTexture&&t.occlusionTexture.gfxTexture.destroy()));var t;if(e.children)for(const t of e.children)Av(t);}class Sv{constructor(e,t){this.feature=e,this.instancedDataOffset=t,this.instancedDataCount=0,this.rotation=[0,0,0],this.scale=[1,1,1],this.translation=[0,0,0];}}class Iv{constructor(){this.instancedDataArray=new Ya,this.instancesEvaluatedElevation=[],this.features=[],this.idToFeaturesIndex={};}}class Cv{constructor(e){this.zoom=e.zoom,this.canonical=e.canonical,this.layers=e.layers,this.layerIds=this.layers.map((e=>e.fqid)),this.projection=e.projection,this.index=e.index,this.hasZoomDependentProperties=this.layers[0].isZoomDependent(),this.stateDependentLayerIds=this.layers.filter((e=>e.isStateDependent())).map((e=>e.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(e,t,i,r){this.tileToMeter=Qd(i);const n=this.layers[0]._featureFilter.needGeometry;this.lookup=new Uint8Array(this.lookupDim*this.lookupDim);for(const{feature:o,id:s,index:a,sourceLayerIndex:l}of e){const e=cp(o,n);if(!this.layers[0]._featureFilter.filter(new ea(this.zoom),e,i))continue;const c={id:s,sourceLayerIndex:l,index:a,geometry:n?e.geometry:lp(o,i,r),properties:o.properties,type:o.type,patterns:{}},h=this.addFeature(c,c.geometry,e);h&&t.featureIndex.insert(o,c.geometry,a,l,this.index,this.instancesPerModel[h].instancedDataArray.length);}this.lookup=null;}update(e,t,i,r){for(const t in this.instancesPerModel){const i=this.instancesPerModel[t];for(const t in e)i.idToFeaturesIndex.hasOwnProperty(t)&&this.evaluate(i.features[i.idToFeaturesIndex[t]],e[t],i,!0);}this.maxHeight=0;}updateZoomBasedPaintProperties(){if(!this.hasZoomDependentProperties)return !1;let e=!1;for(const t in this.instancesPerModel){const i=this.instancesPerModel[t];for(const t of i.features){const r=this.layers[0],n=t.feature,o=this.canonical,s=r.paint.get(\"model-rotation\").evaluate(n,{},o),a=r.paint.get(\"model-scale\").evaluate(n,{},o),l=r.paint.get(\"model-translation\").evaluate(n,{},o);Mu.exactEquals(t.rotation,s)&&Mu.exactEquals(t.scale,a)&&Mu.exactEquals(t.translation,l)||(this.evaluate(t,t.featureStates,i,!0),e=!0);}}return e}isEmpty(){for(const e in this.instancesPerModel)if(0!==this.instancesPerModel[e].instancedDataArray.length)return !1;return !0}uploadPending(){return !this.uploaded}upload(e){if(!this.uploaded)for(const t in this.instancesPerModel){const i=this.instancesPerModel[t];i.instancedDataArray.length<0||0===i.instancedDataArray.length||(i.instancedDataBuffer?i.instancedDataBuffer.updateData(i.instancedDataArray):i.instancedDataBuffer=e.createVertexBuffer(i.instancedDataArray,kx.members,!0,void 0,this.instanceCount));}this.uploaded=!0;}destroy(){for(const e in this.instancesPerModel){const t=this.instancesPerModel[e];0!==t.instancedDataArray.length&&t.instancedDataBuffer&&t.instancedDataBuffer.destroy();}}addFeature(e,t,i){const r=this.layers[0],n=r.layout.get(\"model-id\").evaluate(i,{},this.canonical);if(!n)return W(`modelId is not evaluated for layer ${r.id} and it is not going to get rendered.`),n;this.instancesPerModel[n]||(this.instancesPerModel[n]=new Iv);const o=this.instancesPerModel[n],s=o.instancedDataArray,a=new Sv(i,s.length);for(const e of t)for(const t of e){if(t.x<0||t.x>=sr||t.y<0||t.y>=sr)continue;const e=(this.lookupDim-1)/sr,i=this.lookupDim*(t.y*e|0)+t.x*e|0;if(this.lookup){if(0!==this.lookup[i])continue;this.lookup[i]=1;}this.instanceCount++;const r=s.length;s.resize(r+1),o.instancesEvaluatedElevation.push(0),s.float32[16*r]=t.x,s.float32[16*r+1]=t.y;}return a.instancedDataCount=o.instancedDataArray.length-a.instancedDataOffset,a.instancedDataCount>0&&(e.id&&(o.idToFeaturesIndex[e.id]=o.features.length),o.features.push(a),this.evaluate(a,{},o,!1)),n}evaluate(e,t,i,r){const n=this.layers[0],o=e.feature,s=this.canonical,a=e.rotation=n.paint.get(\"model-rotation\").evaluate(o,t,s),l=e.scale=n.paint.get(\"model-scale\").evaluate(o,t,s),c=e.translation=n.paint.get(\"model-translation\").evaluate(o,t,s),h=n.paint.get(\"model-color\").evaluate(o,t,s);h.a=n.paint.get(\"model-color-mix-intensity\").evaluate(o,t,s);const u=[];this.maxVerticalOffset10?this.tileToMeter:Qd(s,p)),a[o+4]=c[0],a[o+5]=c[1],a[o+6]=c[2]+l,a[o+7]=u[0],a[o+8]=u[1],a[o+9]=u[2],a[o+10]=u[4],a[o+11]=u[5],a[o+12]=u[6],a[o+13]=u[8],a[o+14]=u[9],a[o+15]=u[10],i.instancesEvaluatedElevation[n]=c[2];}}}Is(Cv,\"ModelBucket\",{omit:[\"layers\"]}),Is(Iv,\"PerModelAttributes\"),Is(Sv,\"ModelFeature\");const zv=new da({visibility:new ca(Ct.layout_model.visibility),\"model-id\":new ha(Ct.layout_model[\"model-id\"])});var Dv={paint:new da({\"model-opacity\":new ca(Ct.paint_model[\"model-opacity\"]),\"model-rotation\":new ha(Ct.paint_model[\"model-rotation\"]),\"model-scale\":new ha(Ct.paint_model[\"model-scale\"]),\"model-translation\":new ha(Ct.paint_model[\"model-translation\"]),\"model-color\":new ha(Ct.paint_model[\"model-color\"]),\"model-color-mix-intensity\":new ha(Ct.paint_model[\"model-color-mix-intensity\"]),\"model-type\":new ca(Ct.paint_model[\"model-type\"]),\"model-cast-shadows\":new ca(Ct.paint_model[\"model-cast-shadows\"]),\"model-receive-shadows\":new ca(Ct.paint_model[\"model-receive-shadows\"]),\"model-ambient-occlusion-intensity\":new ca(Ct.paint_model[\"model-ambient-occlusion-intensity\"]),\"model-emissive-strength\":new ha(Ct.paint_model[\"model-emissive-strength\"]),\"model-roughness\":new ha(Ct.paint_model[\"model-roughness\"]),\"model-height-based-emissive-strength-multiplier\":new ha(Ct.paint_model[\"model-height-based-emissive-strength-multiplier\"]),\"model-cutoff-fade-range\":new ca(Ct.paint_model[\"model-cutoff-fade-range\"])}),layout:zv};const Pv=new Float32Array(262144),Rv=new Uint8Array(262144);function Lv(e){let t=0;if(e.meshes)for(const i of e.meshes)t=Math.max(t,i.aabb.max[2]);if(e.children)for(const i of e.children)t=Math.max(t,Lv(i));return t}const kv=[\"\",\"wall\",\"door\",\"roof\",\"window\",\"lamp\",\"logo\"];class Ov{constructor(e){this.node=e,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:e.id,geometry:[],properties:{height:Lv(e)}};}}class Bv{constructor(e,t,i,r){this.nodes=e,this.id=t,this.modelTraits|=1,this.uploaded=!1,this.hasPattern=!1,i&&(this.modelTraits|=4),this.zoom=-1,this.terrainExaggeration=1,this.projection={name:\"mercator\"},this.replacementUpdateTime=0,this.elevationReadFromZ=255,this.brightness=r,this.dirty=!0,this.needsUpload=!1;}update(){console.log(\"Update 3D model bucket\");}populate(){console.log(\"populate 3D model bucket\");}uploadPending(){return !this.uploaded||this.needsUpload}upload(e){if(!this.needsUpload)return;const t=this.getNodesInfo();for(const i of t){const t=i.node;this.uploaded?this.updatePbrBuffer(t):Ev(t,e,!0);}for(const e of t)Mv(e.node);this.uploaded=!0,this.needsUpload=!1;}updatePbrBuffer(e){let t=!1;if(!e.meshes)return t;for(const i of e.meshes)i.pbrBuffer&&(i.pbrBuffer.updateData(i.featureArray),t=!0);return t}needsReEvaluation(e,t,i){const r=e.transform.projectionOptions,n=e.style.getBrightness(),o=this.brightness!==n;return !!(!this.uploaded||this.dirty||r.name!==this.projection.name||Fv(i.paint.get(\"model-color\").value,o)||Fv(i.paint.get(\"model-color-mix-intensity\").value,o)||Fv(i.paint.get(\"model-roughness\").value,o)||Fv(i.paint.get(\"model-emissive-strength\").value,o)||Fv(i.paint.get(\"model-height-based-emissive-strength-multiplier\").value,o))&&(this.projection=r,this.brightness=n,!0)}evaluateScale(e,t){if(e.transform.zoom===this.zoom)return;this.zoom=e.transform.zoom;const i=this.getNodesInfo(),r=this.id.canonical;for(const e of i){const i=e.feature;e.evaluatedScale=t.paint.get(\"model-scale\").evaluate(i,{},r);}}evaluate(e){const t=this.getNodesInfo();for(const i of t){if(!i.node.meshes)continue;const t=i.feature,r=i.node.meshes&&i.node.meshes[0].featureData,n=i.evaluatedColor[2],o=i.evaluatedRMEA[2],s=this.id.canonical;if(i.hasTranslucentParts=!1,r){for(let r=0;r=e)continue;const u=Pv[c],d=Math.abs(u);d>a&&(s=u,a=d,l=n,h=t);}if(a>.1){const o=1-(e+.5*Math.abs(l*h))/c;let a=t._dem.get(r,i)+s*o;const u=t._dem.get(r+l,i+h),d=t._dem.get(r-l,i-h,!0);(a-u)*(a-d)>0&&(a=(u+d)/2),Pv[n]=t._dem.set(r,i,a),Rv[n]=e;}}}}}s&&(t._demTile.needsDEMTextureUpload=!0,t._dem._timestamp=ht.now());}getNodesInfo(){if(!this.nodesInfo){this.nodesInfo=[];for(const e of this.nodes)this.nodesInfo.push(new Ov(e));this.freeNodes();}return this.nodesInfo}freeNodes(){if(this.nodes){for(const e of this.nodes)Av(e);this.nodes.splice(0,this.nodes.length);}}destroy(){this.freeNodes();const e=this.getNodesInfo();for(const t of e)Mv(t.node),Av(t.node);}isEmpty(){return !this.nodes.length}updateReplacement(e,t){if(t.updateTime===this.replacementUpdateTime)return;this.replacementUpdateTime=t.updateTime;const i=t.getReplacementRegionsForTile(e.toUnwrapped()),r=this.getNodesInfo();for(let e=0;ee.footprint===t.footprint));}}getHeightAtTileCoord(e,t){const i=this.getNodesInfo(),r=[];for(let n=0;ns.aabb.max[0]||t>s.aabb.max[1])continue;const a=(e-s.aabb.min[0])/(s.aabb.max[0]-s.aabb.min[0])*xv|0,l=Math.min(63,(t-s.aabb.min[1])/(s.aabb.max[1]-s.aabb.min[1])*xv|0)*xv+Math.min(63,a);if(!(s.heightmap[l]<0&&o.node.footprint)){if(o.hiddenByReplacement)return;return {height:s.heightmap[l],maxHeight:o.feature.properties.height,hidden:!1,verticalScale:o.evaluatedScale[2]}}if(o.node.footprint.grid.query(new y(e,t),new y(e,t),r),r.length>0)return {height:void 0,maxHeight:o.feature.properties.height,hidden:o.hiddenByReplacement,verticalScale:o.evaluatedScale[2]}}}}function Fv(e,t){return !e.isLightConstant&&t}function Nv(e,t,i,r,n,o,s,a){let l=(61440&t|(61440&t)>>4)>>8,c=(3840&t|(3840&t)>>4)>>4,h=240&t|(240&t)>>4;i[3]>0&&(l=Wr(l,255*i[0],i[3]),c=Wr(c,255*i[1],i[3]),h=Wr(h,255*i[2],i[3]));const u=l<<8|c,d=h<<8|Math.floor(255*r[3]),p=function(e){const t=z(e,0,2);return Math.min(Math.round(.5*t*255),255)}(r[2])<<8|15*r[0]<<4|15*r[1],f=z(n[0],0,1),m=z(n[1],0,1),_=z(n[2],0,1),g=z(n[3],0,1);let y,x,v,b;if(f!==m&&s!==o&&m!==f){const e=s-o;x=1/(e*(m-f)),v=-(o+e*f)/(e*(m-f));const t=z(n[4],-1,1);b=Math.pow(10,t),y=255*_<<8|255*g;}else y=65535,x=0,v=1,b=1;if(e.emplaceBack(u,d,p,y,x,v,b),a){const e=a.length;a.clear();for(let t=0;t>16&65535,c=e.evaluatedRMEA[a],h=e.evaluatedColor[a],u=e.emissionHeightBasedParams[a];if(o&&2===a&&i.lights&&(r=new Ka,r.resize(10*i.lights.length)),Nv(n.featureArray,l,h,c,u,n.aabb.min[2],n.aabb.max[2],r),r&&o){o=!1;const e=i.meshes[i.lightMeshIndex];e.featureArray=r,e.featureArray._trim();}}n.featureArray._trim(),r++;}}Is(Bv,\"Tiled3dModelBucket\",{omit:[\"layers\"]}),Is(Ov,\"Tiled3dModelFeature\");class Vv{constructor(){this._updateTime=0,this._sourceIds=[],this._activeRegions=[],this._prevRegions=[];}clear(){this._activeRegions.length>0&&++this._updateTime,this._activeRegions=[],this._prevRegions=[];}get updateTime(){return this._updateTime}getReplacementRegionsForTile(e){const t=Zv(new y(0,0),new y(sr,sr),e),i=[];for(const r of this._activeRegions){if(r.hiddenByOverlap)continue;if(!qv(t,r))continue;const n=$v(r.min,r.max,e);i.push({min:n.min,max:n.max,sourceId:this._sourceIds[r.priority],footprint:r.footprint,footprintTileId:r.tileId});}return i}setSources(e){this._setSources(e.map((e=>({getSourceId:()=>e.cache.id,getFootprints:()=>{const t=[];for(const i of e.cache.getVisibleCoordinates()){const r=e.cache.getTile(i).buckets[e.layer];if(r)for(const e of r.getNodesInfo()){const r=e.node;r.footprint&&t.push({footprint:r.footprint,id:i.toUnwrapped()});}}return t}}))));}_addSource(e){const t=e.getFootprints();if(0!==t.length){for(const e of t){if(!e.footprint)continue;const t=Zv(e.footprint.min,e.footprint.max,e.id);this._activeRegions.push({min:t.min,max:t.max,hiddenByOverlap:!1,priority:this._sourceIds.length,tileId:e.id,footprint:e.footprint});}this._sourceIds.push(e.getSourceId());}}_computeReplacement(){this._activeRegions.sort(((e,t)=>e.priority-t.priority||jv(e.min,t.min)||jv(e.max,t.max)));let e=this._activeRegions.length!==this._prevRegions.length;if(!e){let t=0,i=0;for(;!e&&t!==this._activeRegions.length;){const r=this._activeRegions[t],n=this._prevRegions[i];e=r.priority!==n.priority||!Gv(r,n),++t,++i;}}if(e){++this._updateTime;const e=e=>{const t=this._activeRegions;if(e>=t.length)return e;const i=t[e].priority;for(;e1){let t=0,i=e(t);for(;t!==i;){let r=t;const n=t;for(;r!==i;){const e=this._activeRegions[r];e.hiddenByOverlap=!1;for(let t=0;t=0;t--)this._addSource(e[t]);this._computeReplacement();}}function jv(e,t){return e.x-t.x||e.y-t.y}function Gv(e,t){return 0===jv(e.min,t.min)&&0===jv(e.max,t.max)}function qv(e,t){return !(e.min.x>t.max.x||e.max.xt.max.y||e.max.ynew y(e.x*o.x*sr*a-s.x*sr,e.y*o.y*sr*a-s.y*sr)));}return Hv(i,n,e.indices,0,e.indices.length,0,0)}const Xv=im.types,Yv=[\"fill-extrusion-base\",\"fill-extrusion-height\",\"fill-extrusion-color\",\"fill-extrusion-pattern\",\"fill-extrusion-flood-light-wall-radius\"],Kv=[\"fill-extrusion-flood-light-ground-radius\"],Jv=Math.pow(2,13),Qv=Math.pow(2,15)-1,eb=new y(0,1),tb=2147483648;function ib(e,t,i,r,n,o,s,a){e.emplaceBack((t<<1)+s,(i<<1)+o,(Math.floor(r*Jv)<<1)+n,Math.round(a));}function rb(e,t,i,r,n,o){e.emplaceBack(t.x,t.y,(i.x<<1)+r,(i.y<<1)+n,o);}function nb(e,t,i){const r=16384;e.emplaceBack(t.x,t.y,t.z,i[0]*r,i[1]*r,i[2]*r);}class ob{constructor(){this.vertexOffset=0,this.vertexCount=0,this.indexOffset=0,this.indexCount=0;}}class sb{constructor(){this.centroidXY=new y(0,0),this.vertexArrayOffset=0,this.vertexCount=0,this.groundVertexArrayOffset=0,this.groundVertexCount=0,this.flags=0,this.footprintSegIdx=-1,this.footprintSegLen=0,this.min=new y(Number.MAX_VALUE,Number.MAX_VALUE),this.max=new y(-Number.MAX_VALUE,-Number.MAX_VALUE),this.height=0;}span(){return new y(this.max.x-this.min.x,this.max.y-this.min.y)}}class ab{constructor(){this.acc=new y(0,0),this.accCount=0,this.centroidDataIndex=0;}startRing(e,t){e.min.x===Number.MAX_VALUE&&(e.min.x=e.max.x=t.x,e.min.y=e.max.y=t.y);}appendEdge(e,t,i){this.accCount++,this.acc._add(t);let r=!!this.borders;t.xe.max.x&&(e.max.x=t.x,r=!0),t.ye.max.y&&(e.max.y=t.y,r=!0),((0===t.x||t.x===sr)&&t.x===i.x)!=((0===t.y||t.y===sr)&&t.y===i.y)&&this.processBorderOverlap(t,i),r&&this.checkBorderIntersection(t,i);}checkBorderIntersection(e,t){t.x<0!=e.x<0&&this.addBorderIntersection(0,Wr(t.y,e.y,(0-t.x)/(e.x-t.x))),t.x>sr!=e.x>sr&&this.addBorderIntersection(1,Wr(t.y,e.y,(sr-t.x)/(e.x-t.x))),t.y<0!=e.y<0&&this.addBorderIntersection(2,Wr(t.x,e.x,(0-t.y)/(e.y-t.y))),t.y>sr!=e.y>sr&&this.addBorderIntersection(3,Wr(t.x,e.x,(sr-t.y)/(e.y-t.y)));}addBorderIntersection(e,t){this.borders||(this.borders=[[Number.MAX_VALUE,-Number.MAX_VALUE],[Number.MAX_VALUE,-Number.MAX_VALUE],[Number.MAX_VALUE,-Number.MAX_VALUE],[Number.MAX_VALUE,-Number.MAX_VALUE]]);const i=this.borders[e];ti[1]&&(i[1]=t);}processBorderOverlap(e,t){if(e.x===t.x){if(e.y===t.y)return;const i=0===e.x?0:1;this.addBorderIntersection(i,t.y),this.addBorderIntersection(i,e.y);}else {const i=0===e.y?2:3;this.addBorderIntersection(i,t.x),this.addBorderIntersection(i,e.x);}}centroid(){return 0===this.accCount?new y(0,0):new y(Math.floor(Math.max(0,this.acc.x)/this.accCount),Math.floor(Math.max(0,this.acc.y)/this.accCount))}intersectsCount(){return this.borders?this.borders.reduce(((e,t)=>e+ +(t[0]!==Number.MAX_VALUE)),0):0}}function lb(e,t){const i=e.add(t)._unit(),r=z(e.x*i.x+e.y*i.y,-1,1);var n,o,s;return n=Math.acos(r),Math.min(4,Math.max(-4,Math.tan(n)))/4*Qv*((o=e).x*(s=t).y-o.y*s.x<0?-1:1)}const cb=[e=>e.x<0,e=>e.x>sr,e=>e.y<0,e=>e.y>sr];function hb(e,t,i,r){const n=[4];if(0===r)return n;i._mult(r);const o=e.sub(i),s=t.sub(i),a=[e,t,o,s];for(let e=0;e<4;e++)for(const t of a)if(cb[e](t)){n.push(e);break}return n}class ub{constructor(e){this.vertexArray=new Aa,this.indexArray=new Va,this.programConfigurations=new Hl(e.layers,e.zoom,(e=>Kv.includes(e))),this._segments=new dl,this.hiddenByLandmarkVertexArray=new Ja,this._segmentToGroundQuads={},this._segmentToGroundQuads[0]=[],this._segmentToRegionTriCounts={},this._segmentToRegionTriCounts[0]=[0,0,0,0,0],this.regionSegments={},this.regionSegments[4]=new dl;}getDefaultSegment(){return this.regionSegments[4]}hasData(){return 0!==this.vertexArray.length}addData(e,t,i,r=!1){const n=e.length;if(n>2){let o=Math.max(0,this._segments.get().length-1);const s=this._segments._prepareSegment(4*n,this.vertexArray.length,2*this._segmentToGroundQuads[o].length);let a;o!==this._segments.get().length-1&&(o++,this._segmentToGroundQuads[o]=[],this._segmentToRegionTriCounts[o]=[0,0,0,0,0]);{const t=e[0],i=e[1];a=lb(t.sub(e[n-1])._perp()._unit(),i.sub(t)._perp()._unit());}for(let l=0;le.region-t.region));for(let i=0;ie+t),0);let o=0;for(let e=0;e<=4;e++){const t=n[e];if(0!==t){let i=this.regionSegments[e];i||(i=this.regionSegments[e]=new dl);const n={vertexOffset:r.vertexOffset,primitiveOffset:r.primitiveOffset+o,vertexLength:r.vertexLength,primitiveLength:t};i.get().push(n);}o+=t;}for(let e=0;e0?this.hiddenByLandmarkVertexBuffer=e.createVertexBuffer(this.hiddenByLandmarkVertexArray,Uf.members,!0):this.hiddenByLandmarkVertexBuffer&&this.hiddenByLandmarkVertexBuffer.updateData(this.hiddenByLandmarkVertexArray),this._needsHiddenByLandmarkUpdate=!1);}destroy(){if(this.vertexBuffer){this.vertexBuffer.destroy(),this.indexBuffer.destroy(),this.hiddenByLandmarkVertexBuffer&&this.hiddenByLandmarkVertexBuffer.destroy(),this._segments&&this._segments.destroy(),this.programConfigurations.destroy();for(let e=0;e<=4;e++){const t=this.regionSegments[e];t&&t.destroy();}}}}class db{constructor(e){this.zoom=e.zoom,this.canonical=e.canonical,this.overscaling=e.overscaling,this.layers=e.layers,this.layerIds=this.layers.map((e=>e.fqid)),this.index=e.index,this.hasPattern=!1,this.edgeRadius=0,this.projection=e.projection,this.activeReplacements=[],this.replacementUpdateTime=0,this.centroidData=[],this.footprintIndices=new Va,this.footprintVertices=new Ta,this.footprintSegments=[],this.layoutVertexArray=new Ma,this.centroidVertexArray=new cl,this.indexArray=new Va,this.programConfigurations=new Hl(e.layers,e.zoom,(e=>Yv.includes(e))),this.segments=new dl,this.stateDependentLayerIds=this.layers.filter((e=>e.isStateDependent())).map((e=>e.id)),this.groundEffect=new ub(e),this.maxHeight=0,this.partLookup={};}populate(e,t,i,r){this.features=[],this.hasPattern=Pf(\"fill-extrusion\",this.layers,t),this.featuresOnBorder=[],this.borderFeatureIndices=[[],[],[],[]],this.borderDoneWithNeighborZ=[-1,-1,-1,-1],this.tileToMeter=Qd(i),this.edgeRadius=this.layers[0].layout.get(\"fill-extrusion-edge-radius\")/this.tileToMeter;for(const{feature:n,id:o,index:s,sourceLayerIndex:a}of e){const e=this.layers[0]._featureFilter.needGeometry,l=cp(n,e);if(!this.layers[0]._featureFilter.filter(new ea(this.zoom),l,i))continue;const c={id:o,sourceLayerIndex:a,index:s,geometry:e?l.geometry:lp(n,i,r),properties:n.properties,type:n.type,patterns:{}},h=this.layoutVertexArray.length;this.hasPattern?this.features.push(Rf(\"fill-extrusion\",this.layers,c,this.zoom,t)):this.addFeature(c,c.geometry,s,i,{},t.availableImages,r,t.brightness),t.featureIndex.insert(n,c.geometry,s,a,this.index,h);}this.sortBorders(),this.groundEffect.prepareBorderSegments();}addFeatures(e,t,i,r,n,o){for(const e of this.features){const{geometry:s}=e;this.addFeature(e,s,e.index,t,i,r,n,o);}this.sortBorders();}update(e,t,i,r,n){const o=0!==Object.keys(e).length;if(o&&!this.stateDependentLayers.length)return;const s=o?this.stateDependentLayers:this.layers;this.programConfigurations.updatePaintArrays(e,t,s,i,r,n),this.groundEffect.update(e,t,s,i,r,n);}isEmpty(){return 0===this.layoutVertexArray.length}uploadPending(){return !this.uploaded||this.programConfigurations.needsUpload||this.groundEffect.programConfigurations.needsUpload}upload(e){this.uploaded||(this.layoutVertexBuffer=e.createVertexBuffer(this.layoutVertexArray,jf),this.indexBuffer=e.createIndexBuffer(this.indexArray),this.layoutVertexExtArray&&(this.layoutVertexExtBuffer=e.createVertexBuffer(this.layoutVertexExtArray,Vf.members,!0)),this.groundEffect.upload(e)),this.groundEffect.uploadPaintProperties(e),this.programConfigurations.upload(e),this.uploaded=!0;}uploadCentroid(e){this.groundEffect.uploadHiddenByLandmark(e),this.needsCentroidUpdate&&(!this.centroidVertexBuffer&&this.centroidVertexArray.length>0?this.centroidVertexBuffer=e.createVertexBuffer(this.centroidVertexArray,Nf.members,!0):this.centroidVertexBuffer&&this.centroidVertexBuffer.updateData(this.centroidVertexArray),this.needsCentroidUpdate=!1);}destroy(){this.layoutVertexBuffer&&(this.layoutVertexBuffer.destroy(),this.centroidVertexBuffer&&this.centroidVertexBuffer.destroy(),this.layoutVertexExtBuffer&&this.layoutVertexExtBuffer.destroy(),this.groundEffect.destroy(),this.indexBuffer.destroy(),this.programConfigurations.destroy(),this.segments.destroy());}addFeature(e,t,i,r,n,o,s,a){const l=this.layers[0].paint.get(\"fill-extrusion-flood-light-ground-radius\").evaluate(e,{})/this.tileToMeter,c=[new y(0,0),new y(sr,sr)],h=s.projection,u=\"globe\"===h.name,d=\"Polygon\"===Xv[e.type],p=new ab;p.centroidDataIndex=this.centroidData.length;const f=new sb,m=this.layers[0].paint.get(\"fill-extrusion-base\").evaluate(e,{},r)<=0,_=this.layers[0].paint.get(\"fill-extrusion-height\").evaluate(e,{},r);f.height=_,f.vertexArrayOffset=this.layoutVertexArray.length,f.groundVertexArrayOffset=this.groundEffect.vertexArray.length,u&&!this.layoutVertexExtArray&&(this.layoutVertexExtArray=new Da);const g=zf(t,500);for(let e=g.length-1;e>=0;e--){const t=g[e];(0===t.length||(x=t[0]).every((e=>e.x<=0))||x.every((e=>e.x>=sr))||x.every((e=>e.y<=0))||x.every((e=>e.y>=sr)))&&g.splice(e,1);}var x;let v;if(u)v=bb(g,c,r);else {v=[];for(const e of g)v.push({polygon:e,bounds:c});}const b=d?this.edgeRadius:0,w=b>0&&this.zoom<17,T=(e,t)=>{if(0===e.length)return !1;const i=e[e.length-1];return t.x===i.x&&t.y===i.y};for(const{polygon:e,bounds:t}of v){let i=0,n=0;for(const t of e)d&&!t[0].equals(t[t.length-1])&&t.push(t[0]),n+=d?t.length-1:t.length;const o=this.segments.prepareSegment((d?5:4)*n,this.layoutVertexArray,this.indexArray);f.footprintSegIdx<0&&(f.footprintSegIdx=this.footprintSegments.length);const s=new ob;if(s.vertexOffset=this.footprintVertices.length,s.indexOffset=3*this.footprintIndices.length,s.ringIndices=[],d){const n=[],a=[];i=o.vertexLength;for(let i=0;i4&&yb(s[s.length-2],s[0],s[1]),c=b?fb(s[s.length-2],s[0],s[1],b):0;const _=[];let g,y,x;y=s[1].sub(s[0])._perp()._unit();let v=!0;for(let e=1,n=0;e0?1:0,S=l.dist(d);if(n+S>32768&&(n=0),b){x=w.sub(d)._perp()._unit();let e=mb(l,d,w,pb(y,x),b);isNaN(e)&&(e=0);const t=d.sub(l)._unit();l=l.add(t.mult(c))._round(),d=d.add(t.mult(-e))._round(),c=e,y=x,m&&this.zoom>=17&&(T(_,l)||_.push(l),T(_,d)||_.push(d));}const I=o.vertexLength,C=s.length>4&&yb(l,d,w);let z=xb(n,a,v);if(ib(this.layoutVertexArray,l.x,l.y,M,A,0,0,z),ib(this.layoutVertexArray,l.x,l.y,M,A,0,1,z),n+=S,z=xb(n,C,!v),a=C,ib(this.layoutVertexArray,d.x,d.y,M,A,0,0,z),ib(this.layoutVertexArray,d.x,d.y,M,A,0,1,z),o.vertexLength+=4,this.indexArray.emplaceBack(I+0,I+1,I+2),this.indexArray.emplaceBack(I+1,I+3,I+2),o.primitiveLength+=2,b){const r=i+(1===e?s.length-2:e-2),n=1===e?i:r+1;if(this.indexArray.emplaceBack(I+1,r,I+3),this.indexArray.emplaceBack(r,n,I+3),o.primitiveLength+=2,void 0===g&&(g=I),!_b(w,s[e],t)){const t=e===s.length-1?g:o.vertexLength;this.indexArray.emplaceBack(I+2,I+3,t),this.indexArray.emplaceBack(I+3,t+1,t),this.indexArray.emplaceBack(I+3,n,t+1),o.primitiveLength+=3;}v=!v;}if(u){const e=this.layoutVertexExtArray,t=h.projectTilePoint(l.x,l.y,r),i=h.projectTilePoint(d.x,d.y,r),n=h.upVector(r,l.x,l.y),o=h.upVector(r,d.x,d.y);nb(e,t,n),nb(e,t,n),nb(e,i,o),nb(e,i,o);}}d&&(i+=s.length-1),m&&b&&this.zoom>=17&&(0!==_.length&&T(_,_[0])&&_.pop(),this.groundEffect.addData(_,t,l,b>0));}this.footprintSegments.push(s),++f.footprintSegLen;}if(f.vertexCount=this.layoutVertexArray.length-f.vertexArrayOffset,f.groundVertexCount=this.groundEffect.vertexArray.length-f.groundVertexArrayOffset,0!==f.vertexCount){if(f.centroidXY=p.borders?eb:this.encodeCentroid(p,f),this.centroidData.push(f),p.borders){this.featuresOnBorder.push(p);const e=this.featuresOnBorder.length-1;for(let t=0;tthis.featuresOnBorder[t].borders[e][0]-this.featuresOnBorder[i].borders[e][0]));}encodeCentroid(e,t){const i=e.centroid(),r=t.span(),n=Math.min(7,Math.round(r.x*this.tileToMeter/10)),o=Math.min(7,Math.round(r.y*this.tileToMeter/10));return new y(z(i.x,1,sr-1)<<3|n,z(i.y,1,sr-1)<<3|o)}showCentroid(e){const t=this.centroidData[e.centroidDataIndex];t.flags&=tb,t.centroidXY.x=0,t.centroidXY.y=0,this.writeCentroidToBuffer(t);}writeCentroidToBuffer(e){this.groundEffect.updateHiddenByLandmark(e);const t=e.vertexArrayOffset,i=e.vertexCount+e.vertexArrayOffset,r=e.flags&tb?eb:e.centroidXY,n=this.centroidVertexArray.geta_centroid_pos0(t);if(this.centroidVertexArray.geta_centroid_pos1(t)!==r.y||n!==r.x){for(let e=t;en.max.x||n.min.x>t.max.x||t.min.y>n.max.y||n.min.y>t.max.y))for(let o=0;ot!=l>t&&e<(this.footprintVertices.int16[2*(a+o.vertexOffset)+0]-i)*(t-s)/(l-s)+i&&(r=!r);}s=i;}}return r}getHeightAtTileCoord(e,t){let i=Number.NEGATIVE_INFINITY,r=!0;const n=4*(e+sr)*sr+(t+sr);if(this.partLookup.hasOwnProperty(n)){const e=this.partLookup[n];return e?{height:e.height,hidden:!!(e.flags&tb)}:void 0}for(const o of this.centroidData)e>o.max.x||o.min.x>e||t>o.max.y||o.min.y>t||this.footprintContainsPoint(e,t,o)&&o&&o.height>i&&(i=o.height,this.partLookup[n]=o,r=!!(o.flags&tb));if(i!==Number.NEGATIVE_INFINITY)return {height:i,hidden:r};this.partLookup[n]=void 0;}}function pb(e,t){const i=e.add(t)._unit();return e.x*i.x+e.y*i.y}function fb(e,t,i,r){const n=t.sub(e)._perp()._unit(),o=i.sub(t)._perp()._unit();return mb(e,t,i,pb(n,o),r)}function mb(e,t,i,r,n){const o=Math.sqrt(1-r*r);return Math.min(e.dist(t)/3,t.dist(i)/3,n*o/r)}function _b(e,t,i){return e.xi[1].x&&t.x>i[1].x||e.yi[1].y&&t.y>i[1].y}function gb(e,t){return e.xt[1].x||e.yt[1].y}function yb(e,t,i){if(e.x<0||e.x>=sr||t.x<0||t.x>=sr||i.x<0||i.x>=sr)return !1;const r=i.sub(t),n=r.perp(),o=e.sub(t);return (r.x*o.x+r.y*o.y)/Math.sqrt((r.x*r.x+r.y*r.y)*(o.x*o.x+o.y*o.y))>-.866&&n.x*o.x+n.y*o.y<0}function xb(e,t,i){const r=t?2|e:-3&e;return i?1|r:-2&r}function vb(){const e=Math.PI/32,t=Math.tan(e),i=Od;return i*Math.sqrt(1+2*t*t)-i}function bb(e,t,i){const r=1<{for(const i of e)s.push({polygon:i,bounds:t});},l=Math.ceil(Math.log2(i)),c=Math.ceil(Math.log2(r)),h=l-c,u=[];for(let e=0;e0?0:1);for(let e=0;et+1?p.push({polygons:d,bounds:e,depth:t+1}):a(d,e);}if(f.length){const e=[new y(0===i?h:r.x,1===i?h:r.y),s];u.length>t+1?p.push({polygons:f,bounds:e,depth:t+1}):a(f,e);}}return s}(e,t,Math.ceil((o-n)/11.25),Math.ceil((s-a)/11.25),1,((e,t,n)=>{if(0===e)return .5*(t+n);{const e=Hd((i.y+t/sr)/r);return (qd(.5*(Hd((i.y+n/sr)/r)+e))*r-i.y)*sr}}))}function wb(e,t,i,r,n,o){const s=Math.pow(2,r.z-n.z);for(let a=0;a{const a=e.transform,l=a.calculatePixelsToTileUnitsMatrix(t);return {u_matrix:Lb(e,t,i,r),u_pixels_to_tile_units:l,u_device_pixel_ratio:o,u_units_to_pixels:[1/a.pixelsToGLUnits[0],1/a.pixelsToGLUnits[1]],u_dash_image:0,u_gradient_image:1,u_image_height:n,u_texsize:Ob(i)?t.lineAtlasTexture.size:[0,0],u_tile_units_to_pixels:Rb(t,e.transform),u_alpha_discard_threshold:0,u_trim_offset:s,u_emissive_strength:i.paint.get(\"line-emissive-strength\")}},Pb=(e,t,i,r,n)=>{const o=e.transform;return {u_matrix:Lb(e,t,i,r),u_texsize:t.imageAtlasTexture.size,u_pixels_to_tile_units:o.calculatePixelsToTileUnitsMatrix(t),u_device_pixel_ratio:n,u_image:0,u_tile_units_to_pixels:Rb(t,o),u_units_to_pixels:[1/o.pixelsToGLUnits[0],1/o.pixelsToGLUnits[1]],u_alpha_discard_threshold:0}};function Rb(e,t){return 1/Xx(e,1,t.tileZoom)}function Lb(e,t,i,r){return e.translatePosMatrix(r||t.tileID.projMatrix,t,i.paint.get(\"line-translate\"),i.paint.get(\"line-translate-anchor\"))}const kb=e=>{const t=[];Ob(e)&&t.push(\"RENDER_LINE_DASH\"),e.paint.get(\"line-gradient\")&&t.push(\"RENDER_LINE_GRADIENT\");const i=e.paint.get(\"line-trim-offset\");return 0===i[0]&&0===i[1]||t.push(\"RENDER_LINE_TRIM_OFFSET\"),0!==e.paint.get(\"line-border-width\").constantOr(1)&&t.push(\"RENDER_LINE_BORDER\"),t};function Ob(e){const t=e.paint.get(\"line-dasharray\").value;return t.value||\"constant\"!==t.kind}const Bb=new class extends ha{possiblyEvaluate(e,t){return t=new ea(Math.floor(t.zoom),{now:t.now,fadeDuration:t.fadeDuration,transition:t.transition}),super.possiblyEvaluate(e,t)}evaluate(e,t,i,r){return t=k({},t,{zoom:Math.floor(t.zoom)}),super.evaluate(e,t,i,r)}}(zb.paint.properties[\"line-width\"].specification);function Fb(e,t){return t>0?t+2*e:e}Bb.useIntegerZoom=!0;const Nb=new da({visibility:new ca(Ct.layout_background.visibility)});var Ub={paint:new da({\"background-color\":new ca(Ct.paint_background[\"background-color\"]),\"background-pattern\":new ca(Ct.paint_background[\"background-pattern\"]),\"background-opacity\":new ca(Ct.paint_background[\"background-opacity\"]),\"background-emissive-strength\":new ca(Ct.paint_background[\"background-emissive-strength\"])}),layout:Nb};const Vb=new da({visibility:new ca(Ct.layout_raster.visibility)});var jb={paint:new da({\"raster-opacity\":new ca(Ct.paint_raster[\"raster-opacity\"]),\"raster-color\":new ua(Ct.paint_raster[\"raster-color\"]),\"raster-color-mix\":new ca(Ct.paint_raster[\"raster-color-mix\"]),\"raster-color-range\":new ca(Ct.paint_raster[\"raster-color-range\"]),\"raster-hue-rotate\":new ca(Ct.paint_raster[\"raster-hue-rotate\"]),\"raster-brightness-min\":new ca(Ct.paint_raster[\"raster-brightness-min\"]),\"raster-brightness-max\":new ca(Ct.paint_raster[\"raster-brightness-max\"]),\"raster-saturation\":new ca(Ct.paint_raster[\"raster-saturation\"]),\"raster-contrast\":new ca(Ct.paint_raster[\"raster-contrast\"]),\"raster-resampling\":new ca(Ct.paint_raster[\"raster-resampling\"]),\"raster-fade-duration\":new ca(Ct.paint_raster[\"raster-fade-duration\"])}),layout:Vb};function Gb(e,t,i,r,n,o,s,a){const l=[e,i,n,t,r,o,1,1,1],c=[s,a,1],h=gu.adjoint([],l),[u,d,p]=Mu.transformMat3(c,c,gu.transpose(h,h));return gu.multiply(l,[u,0,0,0,d,0,0,0,p],l)}class qb extends It{constructor(e,t,i,r){super(),this.id=e,this.dispatcher=i,this.coordinates=t.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(r),this.options=t,this._dirty=!1;}load(e,i){if(this._loaded=i||!1,this.fire(new At(\"dataloading\",{dataType:\"source\"})),this.url=this.options.url,!this.url)return e&&(this.coordinates=e),this._loaded=!0,void this._finishLoading();this._imageRequest=Ie(this.map._requestManager.transformRequest(this.url,ye.Image),((i,r)=>{if(this._imageRequest=null,this._loaded=!0,i)this.fire(new St(i));else if(r){const{HTMLImageElement:i}=t;this.image=r instanceof i?ht.getImageData(r):r,this._dirty=!0,this.width=this.image.width,this.height=this.image.height,e&&(this.coordinates=e),this._finishLoading();}}));}loaded(){return this._loaded}updateImage(e){return this.image&&e.url?(this._imageRequest&&e.url!==this.options.url&&(this._imageRequest.cancel(),this._imageRequest=null),this.options.url=e.url,this.load(e.coordinates,this._loaded),this):this}setTexture(e){if(!(e.handle instanceof WebGLTexture))throw new Error(\"The provided handle is not a WebGLTexture instance\");return this.texture=new yy(this.map.painter.context,e.handle),this.width=e.dimensions[0],this.height=e.dimensions[1],this._dirty=!1,this._loaded=!0,this._finishLoading(),this}_finishLoading(){this.map&&(this.setCoordinates(this.coordinates),this.fire(new At(\"data\",{dataType:\"source\",sourceDataType:\"metadata\"})));}onAdd(e){this.map=e,this.load();}onRemove(){this._imageRequest&&(this._imageRequest.cancel(),this._imageRequest=null),!this.texture||this.texture instanceof yy||this.texture.destroy();}setCoordinates(e){if(this.coordinates=e,this._boundsArray=void 0,!e.length)return this;this.onNorthPole=!1,this.onSouthPole=!1;let t=e[0][1],i=e[0][1];for(const r of e)r[1]>i&&(i=r[1]),r[1]Xd?this.onNorthPole=!0:r<-Xd&&(this.onSouthPole=!0),!this.onNorthPole&&!this.onSouthPole){const t=e.map(ep.fromLngLat);this.tileID=function(e){let t=1/0,i=1/0,r=-1/0,n=-1/0;for(const o of e)t=Math.min(t,o.x),i=Math.min(i,o.y),r=Math.max(r,o.x),n=Math.max(n,o.y);const o=Math.max(r-t,n-i),s=Math.max(0,Math.floor(-Math.log(o)/Math.LN2)),a=Math.pow(2,s);return new ku(s,Math.floor((t+r)/2*a),Math.floor((i+n)/2*a))}(t),this.minzoom=this.maxzoom=this.tileID.z;}return this.fire(new At(\"data\",{dataType:\"source\",sourceDataType:\"content\"})),this}_clear(){this._boundsArray=void 0;}_prepareData(e){for(const e in this.tiles){const t=this.tiles[e];\"loaded\"!==t.state&&(t.state=\"loaded\",t.texture=this.texture);}if(this._boundsArray)return;const t=Tg(this.tileID,this.map.transform.projection),[i,r,n,o]=this.coordinates.map((e=>{const i=t.projection.project(e[0],e[1]);return Mg(t,i)._round()}));this.perspectiveTransform=function(e,t,i,r,n,o,s,a,l,c){const h=Gb(0,0,e,0,0,t,e,t),u=Gb(i,r,n,o,s,a,l,c);return gu.multiply(u,gu.adjoint(h,h),u),[u[6]/u[8]*e/sr,u[7]/u[8]*t/sr]}(this.width,this.height,i.x,i.y,r.x,r.y,o.x,o.y,n.x,n.y);const s=this._boundsArray=new Ma;s.emplaceBack(i.x,i.y,0,0),s.emplaceBack(r.x,r.y,sr,0),s.emplaceBack(o.x,o.y,0,sr),s.emplaceBack(n.x,n.y,sr,sr),this.boundsBuffer&&this.boundsBuffer.destroy(),this.boundsBuffer=e.createVertexBuffer(s,Ay.members),this.boundsSegments=dl.simpleSegment(0,0,4,2);}prepare(){const e=0!==Object.keys(this.tiles).length;if(this.tileID&&!e)return;const t=this.map.painter.context,i=t.gl;!this._dirty||this.texture instanceof yy||(this.texture?this.texture.update(this.image):(this.texture=new gy(t,this.image,i.RGBA),this.texture.bind(i.LINEAR,i.CLAMP_TO_EDGE)),this._dirty=!1),e&&this._prepareData(t);}loadTile(e,t){this.tileID&&this.tileID.equals(e.tileID.canonical)?(this.tiles[String(e.tileID.wrap)]=e,e.buckets={},t(null)):(e.state=\"errored\",t(null));}serialize(){return {type:\"image\",url:this.options.url,coordinates:this.coordinates}}hasTransition(){return !1}}class Zb extends _a{constructor(e){super(e,{}),this.implementation=e,e.slot&&(this.slot=e.slot);}is3D(){return \"3d\"===this.implementation.renderingMode}hasOffscreenPass(){return void 0!==this.implementation.prerender}isLayerDraped(e){return void 0!==this.implementation.renderToTile}shouldRedrape(){return !!this.implementation.shouldRerenderTiles&&this.implementation.shouldRerenderTiles()}recalculate(){}updateTransitions(){}hasTransition(){return !1}serialize(){}onAdd(e){this.implementation.onAdd&&this.implementation.onAdd(e,e.painter.context.gl);}onRemove(e){this.implementation.onRemove&&this.implementation.onRemove(e,e.painter.context.gl);}}const $b=new da({visibility:new ca(Ct.layout_sky.visibility)});var Hb={paint:new da({\"sky-type\":new ca(Ct.paint_sky[\"sky-type\"]),\"sky-atmosphere-sun\":new ca(Ct.paint_sky[\"sky-atmosphere-sun\"]),\"sky-atmosphere-sun-intensity\":new ca(Ct.paint_sky[\"sky-atmosphere-sun-intensity\"]),\"sky-gradient-center\":new ca(Ct.paint_sky[\"sky-gradient-center\"]),\"sky-gradient-radius\":new ca(Ct.paint_sky[\"sky-gradient-radius\"]),\"sky-gradient\":new ua(Ct.paint_sky[\"sky-gradient\"]),\"sky-atmosphere-halo-color\":new ca(Ct.paint_sky[\"sky-atmosphere-halo-color\"]),\"sky-atmosphere-color\":new ca(Ct.paint_sky[\"sky-atmosphere-color\"]),\"sky-opacity\":new ca(Ct.paint_sky[\"sky-opacity\"])}),layout:$b};function Wb(e,t,i){const r=[0,0,1],n=bu.identity([]);return bu.rotateY(n,n,i?-w(e)+Math.PI:w(e)),bu.rotateX(n,n,-w(t)),Mu.transformQuat(r,r,n),Mu.normalize(r,r)}var Xb={paint:new da({})};const Yb={circle:class extends _a{constructor(e,t){super(e,Pp,t);}createBucket(e){return new dp(e)}queryRadius(e){const t=e;return Sp(\"circle-radius\",this,t)+Sp(\"circle-stroke-width\",this,t)+Ip(this.paint.get(\"circle-translate\"))}queryIntersectsFeature(e,t,i,r,n,o,s,a){const l=zp(this.paint.get(\"circle-translate\"),this.paint.get(\"circle-translate-anchor\"),o.angle,e.pixelToTileUnitsFactor),c=this.paint.get(\"circle-radius\").evaluate(t,i)+this.paint.get(\"circle-stroke-width\").evaluate(t,i);return Op(e,r,o,s,a,\"map\"===this.paint.get(\"circle-pitch-alignment\"),\"map\"===this.paint.get(\"circle-pitch-scale\"),l,c)}getProgramIds(){return [\"circle\"]}getDefaultProgramParams(e,t){const i=kp(this);return {config:new $l(this,t),defines:i,overrideFog:!1}}},heatmap:class extends _a{createBucket(e){return new Vp(e)}constructor(e,t){super(e,Xp,t),this._updateColorRamp();}_handleSpecialPaintPropertyUpdate(e){\"heatmap-color\"===e&&this._updateColorRamp();}_updateColorRamp(){this.colorRamp=Yp({expression:this._transitionablePaint._values[\"heatmap-color\"].value.expression,evaluationKey:\"heatmapDensity\",image:this.colorRamp}),this.colorRampTexture=null;}resize(){this.heatmapFbo&&(this.heatmapFbo.destroy(),this.heatmapFbo=null);}queryRadius(e){return Sp(\"heatmap-radius\",this,e)}queryIntersectsFeature(e,t,i,r,n,o,s,a){const l=this.paint.get(\"heatmap-radius\").evaluate(t,i);return Op(e,r,o,s,a,!0,!0,new y(0,0),l)}hasOffscreenPass(){return 0!==this.paint.get(\"heatmap-opacity\")&&\"none\"!==this.visibility}getProgramIds(){return [\"heatmap\",\"heatmapTexture\"]}getDefaultProgramParams(e,t){return \"heatmap\"===e?{config:new $l(this,t),overrideFog:!1}:{}}},hillshade:class extends _a{constructor(e,t){super(e,Jp,t);}hasOffscreenPass(){return 0!==this.paint.get(\"hillshade-exaggeration\")&&\"none\"!==this.visibility}getProgramIds(){return [\"hillshade\",\"hillshadePrepare\"]}getDefaultProgramParams(e,t){return {overrideFog:!1}}},fill:class extends _a{constructor(e,t){super(e,Of,t);}getProgramIds(){const e=this.paint.get(\"fill-pattern\"),t=e&&e.constantOr(1),i=[t?\"fillPattern\":\"fill\"];return this.paint.get(\"fill-antialias\")&&i.push(t&&!this.getPaintProperty(\"fill-outline-color\")?\"fillOutlinePattern\":\"fillOutline\"),i}getDefaultProgramParams(e,t){return {config:new $l(this,t),overrideFog:!1}}recalculate(e,t){super.recalculate(e,t);const i=this.paint._values[\"fill-outline-color\"];\"constant\"===i.value.kind&&void 0===i.value.value&&(this.paint._values[\"fill-outline-color\"]=this.paint._values[\"fill-color\"]);}createBucket(e){return new Lf(e)}queryRadius(){return Ip(this.paint.get(\"fill-translate\"))}queryIntersectsFeature(e,t,i,r,n,o){return !e.queryGeometry.isAboveHorizon&&mp(Cp(e.tilespaceGeometry,this.paint.get(\"fill-translate\"),this.paint.get(\"fill-translate-anchor\"),o.angle,e.pixelToTileUnitsFactor),r)}isTileClipped(){return !0}},\"fill-extrusion\":class extends _a{constructor(e,t){super(e,Eb,t);}createBucket(e){return new db(e)}queryRadius(){return Ip(this.paint.get(\"fill-extrusion-translate\"))}is3D(){return !0}hasShadowPass(){return !0}cutoffRange(){return this.paint.get(\"fill-extrusion-cutoff-fade-range\")}canCastShadows(){return !0}getProgramIds(){return [this.paint.get(\"fill-extrusion-pattern\").constantOr(1)?\"fillExtrusionPattern\":\"fillExtrusion\"]}queryIntersectsFeature(e,t,i,r,n,o,s,a,l){const c=zp(this.paint.get(\"fill-extrusion-translate\"),this.paint.get(\"fill-extrusion-translate-anchor\"),o.angle,e.pixelToTileUnitsFactor),h=this.paint.get(\"fill-extrusion-height\").evaluate(t,i),u=this.paint.get(\"fill-extrusion-base\").evaluate(t,i),d=[0,0],p=a&&o.elevation,f=o.elevation?o.elevation.exaggeration():1,m=e.tile.getBucket(this);if(p&&m instanceof db){const e=m.centroidVertexArray,t=l+1;te.polygon)).flat());const _=p?a:null,[g,x]=function(e,t,i,r,n,o,s,a,l,c,h){return \"globe\"===e.projection.name?function(e,t,i,r,n,o,s,a,l,c,h){const u=[],d=[],p=e.projection.upVectorScale(h,e.center.lat,e.worldSize).metersToTile,f=[0,0,0,1],m=[0,0,0,1],_=(e,t,i,r)=>{e[0]=t,e[1]=i,e[2]=r,e[3]=1;},g=vb();i>0&&(i+=g),r+=g;for(const g of t){const t=[],y=[];for(const u of g){const d=u.x+n.x,g=u.y+n.y,x=e.projection.projectTilePoint(d,g,h),v=e.projection.upVector(h,u.x,u.y);let b=i,w=r;if(s){const e=Ib(d,g,i,r,s,a,l,c);b+=e.base,w+=e.top;}0!==i?_(f,x.x+v[0]*p*b,x.y+v[1]*p*b,x.z+v[2]*p*b):_(f,x.x,x.y,x.z),_(m,x.x+v[0]*p*w,x.y+v[1]*p*w,x.z+v[2]*p*w),Mu.transformMat4(f,f,o),Mu.transformMat4(m,m,o),t.push(new Mb(f[0],f[1],f[2])),y.push(new Mb(m[0],m[1],m[2]));}u.push(t),d.push(y);}return [u,d]}(e,t,i,r,n,o,s,a,l,c,h):s?function(e,t,i,r,n,o,s,a,l){const c=[],h=[],u=[0,0,0,1];for(const d of e){const e=[],p=[];for(const c of d){const h=c.x+r.x,d=c.y+r.y,f=Ib(h,d,t,i,o,s,a,l);u[0]=h,u[1]=d,u[2]=f.base,u[3]=1,uu.transformMat4(u,u,n),u[3]=Math.max(u[3],1e-5);const m=new Mb(u[0]/u[3],u[1]/u[3],u[2]/u[3]);u[0]=h,u[1]=d,u[2]=f.top,u[3]=1,uu.transformMat4(u,u,n),u[3]=Math.max(u[3],1e-5);const _=new Mb(u[0]/u[3],u[1]/u[3],u[2]/u[3]);e.push(m),p.push(_);}c.push(e),h.push(p);}return [c,h]}(t,i,r,n,o,s,a,l,c):function(e,t,i,r,n){const o=[],s=[],a=n[8]*t,l=n[9]*t,c=n[10]*t,h=n[11]*t,u=n[8]*i,d=n[9]*i,p=n[10]*i,f=n[11]*i;for(const t of e){const e=[],i=[];for(const o of t){const t=o.x+r.x,s=o.y+r.y,m=n[0]*t+n[4]*s+n[12],_=n[1]*t+n[5]*s+n[13],g=n[2]*t+n[6]*s+n[14],y=n[3]*t+n[7]*s+n[15],x=m+a,v=_+l,b=g+c,w=Math.max(y+h,1e-5),T=m+u,E=_+d,M=g+p,A=Math.max(y+f,1e-5);e.push(new Mb(x/w,v/w,b/w)),i.push(new Mb(T/A,E/A,M/A));}o.push(e),s.push(i);}return [o,s]}(t,i,r,n,o)}(o,r,u,h,c,s,_,d,f,o.center.lat,e.tileID.canonical),v=e.queryGeometry;return function(e,t,i){let r=1/0;mp(i,t)&&(r=Sb(i,t[0]));for(let n=0;n=3)for(let t=0;t=0)r=t;else {const n=e.points[i-4];r=Xr(n,t,n[2]/(n[2]-t[2]));}if(cw(this.state,r[0],r[1],0,this._transform)>=sw)return !0}return !1}updateTransitions(e){this._transitioning=this._transitionable.transitioned(e,this._transitioning);}hasTransition(){return this._transitioning.hasTransition()}recalculate(e){this.properties=this._transitioning.possiblyEvaluate(e);}_validate(e,t,i){return (!i||!1!==i.validate)&&ws(this,e.call(hs,k({value:t,style:{glyphs:!0,sprite:!0},styleSpec:Ct})))}}class pw{constructor(e){this._callback=e,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 fw{constructor(){this.tasks={},this.taskQueue=[],j([\"process\"],this),this.invoker=new pw(this.process),this.nextId=0;}add(e,t){const i=this.nextId++,r=function({type:e,isSymbolTile:t,zoom:i}){return i=i||0,\"message\"===e?0:\"maybePrepare\"!==e||t?\"parseTile\"!==e||t?\"parseTile\"===e&&t?300-i:\"maybePrepare\"===e&&t?400-i:500:200-i:100-i}(t);if(0===r){Q();try{e();}finally{}return {cancel:()=>{}}}return this.tasks[i]={fn:e,metadata:t,priority:r,id:i},this.taskQueue.push(i),this.invoker.trigger(),{cancel:()=>{delete this.tasks[i];}}}process(){Q();try{if(this.taskQueue=this.taskQueue.filter((e=>!!this.tasks[e])),!this.taskQueue.length)return;const e=this.pick();if(null===e)return;const t=this.tasks[e];if(delete this.tasks[e],this.taskQueue.length&&this.invoker.trigger(),!t)return;t.fn();}finally{}}pick(){let e=null,t=1/0;for(let i=0;i{i&&delete this.callbacks[s],this.target.postMessage({id:s,type:\"\",targetMapId:r,sourceMapId:this.mapId});}}}receive(e){const t=e.data,i=t.id;if(i&&(!t.targetMapId||this.mapId===t.targetMapId))if(\"