>1),d=r.zoom+1;let p=r.aabb.quadrant(u);if(i.terrain){const o=new e.S(d,r.wrap,d,c,h),a=i.terrain.getMinMaxElevation(o),l=null!==(n=a.minElevation)&&void 0!==n?n:t.elevation,u=null!==(s=a.maxElevation)&&void 0!==s?s:t.elevation;p=new Oe([p.min[0],p.min[1],l],[p.max[0],p.max[1],u])}y.push({aabb:p,zoom:d,x:c,y:h,wrap:r.wrap,fullyVisible:l})}}return x.sort(((t,e)=>t.distanceSq-e.distanceSq)).map((t=>t.tileID))}(this,t,this._invViewProjMatrix)}recalculateZoom(t){const i=this.elevation,r=Math.cos(this._helper._pitch)*this._cameraToCenterDistance/this._helper._pixelPerMeter,n=this.screenPointToLocation(this.centerPoint,t),s=t.getElevationForLngLatZoom(n,this._helper._tileZoom);if(!(this.elevation-s))return;const o=r+i-s,a=Wt(Math.cos(this._helper._pitch)*this._cameraToCenterDistance/o/e.aD(1,n.lat)/this.tileSize);this._helper._elevation=s,this._helper._center=n,this.setZoom(a)}setLocationAtPoint(t,i){const r=this.screenPointToMercatorCoordinate(i),n=this.screenPointToMercatorCoordinate(this.centerPoint),s=Jt(t),o=new e.Y(s.x-(r.x-n.x),s.y-(r.y-n.y));this.setCenter(Qt(o)),this._helper._renderWorldCopies&&this.setCenter(this.center.wrap())}locationToScreenPoint(t,e){return e?this.coordinatePoint(Jt(t),e.getElevationForLngLatZoom(t,this._helper._tileZoom),this._pixelMatrix3D):this.coordinatePoint(Jt(t))}screenPointToLocation(t,e){return Qt(this.screenPointToMercatorCoordinate(t,e))}screenPointToMercatorCoordinate(t,i){if(i){const e=i.pointCoordinate(t);if(null!=e)return e}const r=[t.x,t.y,0,1],n=[t.x,t.y,1,1];e.af(r,r,this._pixelMatrixInverse),e.af(n,n,this._pixelMatrixInverse);const s=r[3],o=n[3],a=r[1]/s,l=n[1]/o,c=r[2]/s,h=n[2]/o,u=c===h?0:(0-c)/(h-c);return new e.Y(e.y.number(r[0]/s,n[0]/o,u)/this.worldSize,e.y.number(a,l,u)/this.worldSize)}coordinatePoint(t,i=0,r=this._pixelMatrix){const n=[t.x*this.worldSize,t.y*this.worldSize,i,1];return e.af(n,n,r),new e.P(n[0]/n[3],n[1]/n[3])}getBounds(){const t=Math.max(0,this._helper._height/2-ie(this));return(new tt).extend(this.screenPointToLocation(new e.P(0,t))).extend(this.screenPointToLocation(new e.P(this._helper._width,t))).extend(this.screenPointToLocation(new e.P(this._helper._width,this._helper._height))).extend(this.screenPointToLocation(new e.P(0,this._helper._height)))}isPointOnMapSurface(t,e){return e?null!=e.pointCoordinate(t):t.y>this.height/2-ie(this)}calculatePosMatrix(t,i=!1){const r=e.aE(t.wrap,t.canonical.z,t.canonical.z,t.canonical.x,t.canonical.y),n=i?this._alignedPosMatrixCache:this._posMatrixCache;if(n[r])return n[r];const s=re(t,this.worldSize);return e.L(s,i?this._alignedProjMatrix:this._viewProjMatrix,s),n[r]=s,n[r]}calculateFogMatrix(t){const i=t.key,r=this._fogMatrixCache;if(r[i])return r[i];const n=re(t,this.worldSize);return e.L(n,this._fogMatrix,n),r[i]=n,r[i]}getConstrained(t,i){i=e.a9(+i,this.minZoom,this.maxZoom);const r={center:new e.N(t.lng,t.lat),zoom:i};let n=this._helper._lngRange;if(!this._helper._renderWorldCopies&&null===n){const t=180-1e-10;n=[-t,t]}const s=this.tileSize*Xt(r.zoom);let o=0,a=s,l=0,c=s,h=0,u=0;const{x:d,y:p}=this.size;if(this._helper._latRange){const t=this._helper._latRange;o=e.Q(t[1])*s,a=e.Q(t[0])*s,a-oa&&(g=a-t)}if(n){const t=(l+c)/2;let i=f;this._helper._renderWorldCopies&&(i=e.ai(f,t-s/2,t+s/2));const r=d/2;i-rc&&(_=c-r)}if(void 0!==_||void 0!==g){const t=new e.P(null!=_?_:f,null!=g?g:m);r.center=ee(s,t).wrap()}return r}_calcMatrices(){if(!this._helper._height)return;const t=this._helper._fov/2,i=this.centerOffset,r=te(this.worldSize,this.center),n=r.x,s=r.y;this._cameraToCenterDistance=.5/Math.tan(t)*this._helper._height,this._helper._pixelPerMeter=e.aD(1,this.center.lat)*this.worldSize;const o=this._cameraToCenterDistance+this._helper._elevation*this._helper._pixelPerMeter/Math.cos(this._helper._pitch),a=Math.min(this.elevation,this.minElevationForCurrentTile),l=o-a*this._helper._pixelPerMeter/Math.cos(this._helper._pitch),c=a<0?l:o,h=Math.PI/2+this._helper._pitch,u=this._helper._fov*(.5+i.y/this._helper._height),d=Math.sin(u)*c/Math.sin(e.a9(Math.PI-h-u,.01,Math.PI-.01)),p=ie(this),f=2*Math.atan(p/this._cameraToCenterDistance)*(.5+i.y/(2*p)),m=Math.sin(f)*c/Math.sin(e.a9(Math.PI-h-f,.01,Math.PI-.01)),_=Math.min(d,m);let g;this._farZ=1.01*(Math.cos(Math.PI/2-this._helper._pitch)*_+c),this._nearZ=this._helper._height/50,g=new Float64Array(16),e.aF(g,this._helper._fov,this._helper._width/this._helper._height,this._nearZ,this._farZ),this._invProjMatrix=new Float64Array(16),e.ah(this._invProjMatrix,g),g[8]=2*-i.x/this._helper._width,g[9]=2*i.y/this._helper._height,this._projectionMatrix=e.aG(g),e.K(g,g,[1,-1,1]),e.J(g,g,[0,0,-this._cameraToCenterDistance]),e.aH(g,g,this._helper._pitch),e.aa(g,g,this._helper._angle),e.J(g,g,[-n,-s,0]),this._mercatorMatrix=e.K([],g,[this.worldSize,this.worldSize,this.worldSize]),e.K(g,g,[1,1,this._helper._pixelPerMeter]),this._pixelMatrix=e.L(new Float64Array(16),this.clipSpaceToPixelsMatrix,g),e.J(g,g,[0,0,-this.elevation]),this._viewProjMatrix=g,this._invViewProjMatrix=e.ah([],g);const y=[0,0,-1,1];e.af(y,y,this._invViewProjMatrix),this._cameraPosition=[y[0]/y[3],y[1]/y[3],y[2]/y[3]],this._fogMatrix=new Float64Array(16),e.aF(this._fogMatrix,this._helper._fov,this.width/this.height,o,this._farZ),this._fogMatrix[8]=2*-i.x/this.width,this._fogMatrix[9]=2*i.y/this.height,e.K(this._fogMatrix,this._fogMatrix,[1,-1,1]),e.J(this._fogMatrix,this._fogMatrix,[0,0,-this.cameraToCenterDistance]),e.aH(this._fogMatrix,this._fogMatrix,this._helper._pitch),e.aa(this._fogMatrix,this._fogMatrix,this.angle),e.J(this._fogMatrix,this._fogMatrix,[-n,-s,0]),e.K(this._fogMatrix,this._fogMatrix,[1,1,this._helper._pixelPerMeter]),e.J(this._fogMatrix,this._fogMatrix,[0,0,-this.elevation]),this._pixelMatrix3D=e.L(new Float64Array(16),this.clipSpaceToPixelsMatrix,g);const x=this._helper._width%2/2,v=this._helper._height%2/2,b=Math.cos(this._helper._angle),w=Math.sin(this._helper._angle),T=n-Math.round(n)+b*x+w*v,P=s-Math.round(s)+b*v+w*x,S=new Float64Array(g);if(e.J(S,S,[T>.5?T-1:T,P>.5?P-1:P,0]),this._alignedProjMatrix=S,g=e.ah(new Float64Array(16),this._pixelMatrix),!g)throw new Error("failed to invert matrix");this._pixelMatrixInverse=g,this._posMatrixCache={},this._fogMatrixCache={},this._alignedPosMatrixCache={}}maxPitchScaleFactor(){if(!this._pixelMatrixInverse)return 1;const t=this.screenPointToMercatorCoordinate(new e.P(0,0)),i=[t.x*this.worldSize,t.y*this.worldSize,0,1];return e.af(i,i,this._pixelMatrix)[3]/this._cameraToCenterDistance}getCameraPoint(){const t=Math.tan(this._helper._pitch)*(this._cameraToCenterDistance||1);return this.centerPoint.add(new e.P(0,t))}getCameraAltitude(){return Math.cos(this._helper._pitch)*this._cameraToCenterDistance/this._helper._pixelPerMeter+this.elevation}lngLatToCameraDepth(t,i){const r=Jt(t),n=[r.x*this.worldSize,r.y*this.worldSize,i,1];return e.af(n,n,this._viewProjMatrix),n[2]/n[3]}isRenderingDirty(){return!1}getProjectionData(t,i,r){return function(t,i,r){let n,s;if(t){const i=t.canonical.z>=0?1<{if(c&&t.setZoom(e.y.number(r,f,a)),n!==i.bearing&&t.setBearing(e.y.number(n,i.bearing,a)),s!==i.pitch&&t.setPitch(e.y.number(s,i.pitch,a)),l&&(t.interpolatePadding(o,i.padding,a),u=t.centerPoint.add(i.offsetAsPoint)),i.around)t.setLocationAtPoint(i.around,i.aroundPoint);else{const e=Xt(t.zoom-r),i=f>r?Math.min(2,g):Math.max(.5,g),n=Math.pow(i,1-a),s=ee(t.worldSize,m.add(_.mult(a*n)).mult(e));t.setLocationAtPoint(t.renderWorldCopies?s.wrap():s,u)}},isZooming:c,elevationCenter:p}}handleFlyTo(t,i){const r=void 0!==i.zoom,n=t.zoom,s=t.getConstrained(e.N.convert(i.center||i.locationAtOffset),r?+i.zoom:n),o=s.center,a=s.zoom;qt(t,o);const l=te(t.worldSize,i.locationAtOffset),c=te(t.worldSize,o).sub(l),h=c.mag(),u=Xt(a-n);let d;if(void 0!==i.minZoom){const e=Math.min(+i.minZoom,n,a);d=Xt(t.getConstrained(o,e).zoom-n)}return{easeFunc:(e,i,r,s)=>{t.setZoom(1===e?a:n+Wt(i));const h=1===e?o:ee(t.worldSize,l.add(c.mult(r)).mult(i));t.setLocationAtPoint(t.renderWorldCopies?h.wrap():h,s)},scaleOfZoom:u,targetCenter:o,scaleOfMinZoom:d,pixelPathLength:h}}}class Ue{constructor(t,e,i){this.blendFunction=t,this.blendColor=e,this.mask=i}}Ue.Replace=[1,0],Ue.disabled=new Ue(Ue.Replace,e.aL.transparent,[!1,!1,!1,!1]),Ue.unblended=new Ue(Ue.Replace,e.aL.transparent,[!0,!0,!0,!0]),Ue.alphaBlended=new Ue([1,771],e.aL.transparent,[!0,!0,!0,!0]);const Ze=2305;class Ge{constructor(t,e,i){this.enable=t,this.mode=e,this.frontFace=i}}Ge.disabled=new Ge(!1,1029,Ze),Ge.backCCW=new Ge(!0,1029,Ze),Ge.frontCCW=new Ge(!0,1028,Ze);class $e{constructor(t,e,i){this.func=t,this.mask=e,this.range=i}}$e.ReadOnly=!1,$e.ReadWrite=!0,$e.disabled=new $e(519,$e.ReadOnly,[0,1]);const qe=7680;class Xe{constructor(t,e,i,r,n,s){this.test=t,this.ref=e,this.mask=i,this.fail=r,this.depthFail=n,this.pass=s}}Xe.disabled=new Xe({func:519,mask:0},0,0,qe,qe,qe);const We=new WeakMap;function He(t){var e;if(We.has(t))return We.get(t);{const i=null===(e=t.getParameter(t.VERSION))||void 0===e?void 0:e.startsWith("WebGL 2.0");return We.set(t,i),i}}class Ke{get awaitingQuery(){return!!this._readbackQueue}constructor(t){this._readbackWaitFrames=4,this._measureWaitFrames=6,this._texWidth=1,this._texHeight=1,this._measuredError=0,this._updateCount=0,this._lastReadbackFrame=-1e3,this._readbackQueue=null,this._cachedRenderContext=t;const i=t.context,r=i.gl;this._texFormat=r.RGBA,this._texType=r.UNSIGNED_BYTE;const n=new e.ax;n.emplaceBack(-1,-1),n.emplaceBack(2,-1),n.emplaceBack(-1,2);const s=new e.az;s.emplaceBack(0,1,2),this._fullscreenTriangle=new ke(i.createVertexBuffer(n,De.members),i.createIndexBuffer(s),e.ay.simpleSegment(0,0,n.length,s.length)),this._resultBuffer=new Uint8Array(4),i.activeTexture.set(r.TEXTURE1);const o=r.createTexture();r.bindTexture(r.TEXTURE_2D,o),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texImage2D(r.TEXTURE_2D,0,this._texFormat,this._texWidth,this._texHeight,0,this._texFormat,this._texType,null),this._fbo=i.createFramebuffer(this._texWidth,this._texHeight,!1,!1),this._fbo.colorAttachment.set(o),He(r)&&(this._pbo=r.createBuffer(),r.bindBuffer(r.PIXEL_PACK_BUFFER,this._pbo),r.bufferData(r.PIXEL_PACK_BUFFER,4,r.STREAM_READ),r.bindBuffer(r.PIXEL_PACK_BUFFER,null))}destroy(){const t=this._cachedRenderContext.context.gl;this._fullscreenTriangle.destroy(),this._fbo.destroy(),t.deleteBuffer(this._pbo),this._fullscreenTriangle=null,this._fbo=null,this._pbo=null,this._resultBuffer=null}updateErrorLoop(t,e){const i=this._updateCount;return this._readbackQueue?i>=this._readbackQueue.frameNumberIssued+this._readbackWaitFrames&&this._tryReadback():i>=this._lastReadbackFrame+this._measureWaitFrames&&this._renderErrorTexture(t,e),this._updateCount++,this._measuredError}_bindFramebuffer(){const t=this._cachedRenderContext.context,e=t.gl;t.activeTexture.set(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,this._fbo.colorAttachment.get()),t.bindFramebuffer.set(this._fbo.framebuffer)}_renderErrorTexture(t,i){const r=this._cachedRenderContext.context,n=r.gl;if(this._bindFramebuffer(),r.viewport.set([0,0,this._texWidth,this._texHeight]),r.clear({color:e.aL.transparent}),this._cachedRenderContext.useProgram("projectionErrorMeasurement").draw(r,n.TRIANGLES,$e.disabled,Xe.disabled,Ue.unblended,Ge.disabled,((t,e)=>({u_input:t,u_output_expected:e}))(t,i),null,null,"$clipping",this._fullscreenTriangle.vertexBuffer,this._fullscreenTriangle.indexBuffer,this._fullscreenTriangle.segments),this._pbo&&He(n)){n.bindBuffer(n.PIXEL_PACK_BUFFER,this._pbo),n.readBuffer(n.COLOR_ATTACHMENT0),n.readPixels(0,0,this._texWidth,this._texHeight,this._texFormat,this._texType,0),n.bindBuffer(n.PIXEL_PACK_BUFFER,null);const t=n.fenceSync(n.SYNC_GPU_COMMANDS_COMPLETE,0);n.flush(),this._readbackQueue={frameNumberIssued:this._updateCount,sync:t}}else this._readbackQueue={frameNumberIssued:this._updateCount,sync:null}}_tryReadback(){const t=this._cachedRenderContext.context.gl;if(this._pbo&&this._readbackQueue&&He(t)){const i=t.clientWaitSync(this._readbackQueue.sync,0,0);if(i===t.WAIT_FAILED)return e.w("WebGL2 clientWaitSync failed."),this._readbackQueue=null,void(this._lastReadbackFrame=this._updateCount);if(i===t.TIMEOUT_EXPIRED)return;t.bindBuffer(t.PIXEL_PACK_BUFFER,this._pbo),t.getBufferSubData(t.PIXEL_PACK_BUFFER,0,this._resultBuffer,0,4),t.bindBuffer(t.PIXEL_PACK_BUFFER,null)}else this._bindFramebuffer(),t.readPixels(0,0,this._texWidth,this._texHeight,this._texFormat,this._texType,this._resultBuffer);this._readbackQueue=null,this._measuredError=Ke._parseRGBA8float(this._resultBuffer),this._lastReadbackFrame=this._updateCount}static _parseRGBA8float(t){let e=0;return e+=t[0]/256,e+=t[1]/65536,e+=t[2]/16777216,t[3]<127&&(e=-e),e/128}}const Ye=e.X/128;function Je(t,i){const r=void 0!==t.granularity?Math.max(t.granularity,1):1,n=r+(t.generateBorders?2:0),s=r+(t.extendToNorthPole||t.generateBorders?1:0)+(t.extendToSouthPole||t.generateBorders?1:0),o=n+1,a=s+1,l=t.generateBorders?-1:0,c=t.generateBorders||t.extendToNorthPole?-1:0,h=r+(t.generateBorders?1:0),u=r+(t.generateBorders||t.extendToSouthPole?1:0),d=o*a,p=n*s*6,f=o*a>65536;if(f&&"16bit"===i)throw new Error("Granularity is too large and meshes would not fit inside 16 bit vertex indices.");const m=f||"32bit"===i,_=new Int16Array(2*d);let g;g=m?{vertices:_,indices:new Uint32Array(p),uses32bitIndices:!0}:{vertices:_,indices:new Uint16Array(p),uses32bitIndices:!1};const y=g.indices;let x=0;for(let b=c;b<=u;b++)for(let i=l;i<=h;i++){let n=i/r*e.X;-1===i&&(n=-Ye),i===r+1&&(n=e.X+Ye);let s=b/r*e.X;-1===b&&(s=t.extendToNorthPole?e.aN:-Ye),b===r+1&&(s=t.extendToSouthPole?e.aO:e.X+Ye),_[x++]=n,_[x++]=s}let v=0;for(let e=0;e