UNPKG

maplibre-gl

Version:

BSD licensed community fork of mapbox-gl, a WebGL interactive maps library

5 lines 563 kB
/** * MapLibre GL JS * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.3.0/LICENSE.txt */ import{$ as e,$n as t,$r as n,$t as r,A as i,Ai as a,An as o,Ar as s,At as c,B as l,Bn as u,Br as d,Bt as f,C as p,Ci as m,Cn as h,Cr as g,Ct as _,D as v,Di as y,Dn as b,Dr as x,Dt as S,E as C,Ei as w,En as T,Er as E,Et as D,Fi as O,Fn as k,Fr as A,Ft as ee,Gn as j,Gr as te,Gt as ne,H as re,Hn as ie,Hr as M,Ht as ae,I as oe,Ii as se,In as ce,Ir as le,It as ue,J as de,Jn as fe,Jr as pe,Jt as me,K as he,Kn as ge,Kr as _e,Kt as ve,L as ye,Li as be,Ln as xe,Lr as Se,Lt as Ce,M as we,Mi as Te,Mn as Ee,Mr as De,Mt as N,Ni as Oe,Nn as ke,Nr as Ae,Nt as je,O as Me,Oi as Ne,On as Pe,Or as Fe,Ot as Ie,P as Le,Pi as Re,Pn as ze,Pr as Be,Pt as Ve,Q as He,Qn as Ue,Qr as We,Qt as Ge,R as Ke,Ri as P,Rn as qe,Rr as F,Rt as Je,S as Ye,Si as Xe,Sn as Ze,Sr as Qe,St as $e,T as et,Ti as tt,Tn as nt,Tr as rt,Tt as it,U as at,Un as ot,Ur as st,Ut as ct,Vn as lt,Vr as ut,Vt as dt,Wn as ft,Wr as pt,Wt as mt,X as ht,Xn as I,Xr as gt,Xt as _t,Y as vt,Yn as yt,Yr as bt,Yt as xt,Z as St,Zn as Ct,Zr as wt,Zt as Tt,_ as Et,_i as Dt,_n as Ot,_r as kt,_t as At,a as jt,ai as Mt,an as Nt,ar as L,at as Pt,b as Ft,bi as It,bn as Lt,br as Rt,bt as zt,ci as Bt,cn as Vt,cr as Ht,ct as Ut,di as Wt,dn as Gt,ei as Kt,en as qt,er as Jt,et as Yt,f as Xt,fi as Zt,fn as Qt,fr as $t,ft as en,g as tn,gi as nn,gn as rn,gr as an,gt as on,h as sn,hi as cn,hn as ln,hr as un,ht as dn,ii as fn,ir as pn,it as mn,j as hn,ji as gn,jn as _n,jr as vn,jt as R,k as yn,ki as bn,kn as xn,kr as Sn,kt as Cn,li as wn,ln as Tn,lr as En,lt as z,mi as Dn,mn as On,mr as kn,mt as An,ni as jn,nn as Mn,nr as Nn,nt as B,oi as Pn,on as Fn,or as In,ot as Ln,pi as Rn,pr as zn,qn as Bn,qr as Vn,qt as Hn,r as Un,ri as Wn,rn as Gn,rr as Kn,rt as qn,s as Jn,si as Yn,sn as Xn,sr as Zn,st as Qn,t as $n,ti as er,tr,tt as nr,u as rr,ui as ir,un as V,ur as ar,ut as or,v as sr,vi as cr,vr as lr,vt as ur,w as dr,wi as fr,wn as pr,wr as mr,wt as hr,x as gr,xi as _r,xn as H,xr as vr,xt as yr,y as br,yi as xr,yn as Sr,yr as Cr,z as wr,zr as Tr,zt as Er}from"./maplibre-gl-shared.mjs";var Dr=`6.3.0`;function Or(){var e=new O(4);return O!=Float32Array&&(e[1]=0,e[2]=0),e[0]=1,e[3]=1,e}function kr(e,t){var n=t[0],r=t[1],i=t[2],a=t[3],o=n*a-i*r;return o?(o=1/o,e[0]=a*o,e[1]=-r*o,e[2]=-i*o,e[3]=n*o,e):null}function Ar(e){return e[0]*e[3]-e[2]*e[1]}function jr(e,t,n){var r=t[0],i=t[1],a=t[2],o=t[3],s=Math.sin(n),c=Math.cos(n);return e[0]=r*c+a*s,e[1]=i*c+o*s,e[2]=r*-s+a*c,e[3]=i*-s+o*c,e}let Mr,Nr,Pr;const Fr={frame(e,t,n,r){let i=r||window,a=i.requestAnimationFrame(e=>{o(),t(e)}),{unsubscribe:o}=Be(e.signal,`abort`,()=>{o(),i.cancelAnimationFrame(a),n(new ce(e.signal.reason))},!1)},frameAsync(e,t){return new Promise((n,r)=>{this.frame(e,n,r,t)})},getImageData(e,t=0){return this.getImageCanvasContext(e).getImageData(-t,-t,e.width+2*t,e.height+2*t)},getImageCanvasContext(e){let t=window.document.createElement(`canvas`),n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)throw Error(`failed to create canvas 2d context`);return t.width=e.width,t.height=e.height,n.drawImage(e,0,0,e.width,e.height),n},resolveURL(e){return Mr||=document.createElement(`a`),Mr.href=e,Mr.href},get hardwareConcurrency(){return typeof navigator<`u`&&navigator.hardwareConcurrency||4},get prefersReducedMotion(){return Pr===void 0?matchMedia?(Nr??=matchMedia(`(prefers-reduced-motion: reduce)`),Nr.matches):!1:Pr},set prefersReducedMotion(e){Pr=e}},Ir=new class{constructor(){this._frozenAt=null}getCurrentTime(){return this._frozenAt===null?performance.now():this._frozenAt}setNow(e){this._frozenAt=e}restoreNow(){this._frozenAt=null}isFrozen(){return this._frozenAt!==null}};function U(){return Ir.getCurrentTime()}function Lr(e){Ir.setNow(e)}function Rr(){Ir.restoreNow()}function zr(){return Ir.isFrozen()}var W=class e{static{this.docStyle=typeof window<`u`&&window.document?.documentElement.style}static{this.selectProp=!e.docStyle||`userSelect`in e.docStyle?`userSelect`:`webkitUserSelect`}static create(e,t,n){let r=window.document.createElement(e);return t!==void 0&&(r.className=t),n&&n.appendChild(r),r}static createNS(e,t){return window.document.createElementNS(e,t)}static disableDrag(){e.docStyle&&e.selectProp&&(e.userSelect=e.docStyle[e.selectProp],e.docStyle[e.selectProp]=`none`)}static enableDrag(){e.docStyle&&e.selectProp&&(e.docStyle[e.selectProp]=e.userSelect)}static suppressClickInternal(t){t.preventDefault(),t.stopPropagation(),window.removeEventListener(`click`,e.suppressClickInternal,!0)}static suppressClick(){window.addEventListener(`click`,e.suppressClickInternal,!0),window.setTimeout(()=>{window.removeEventListener(`click`,e.suppressClickInternal,!0)},0)}static getScale(e){let t=e.getBoundingClientRect();return{x:t.width/e.offsetWidth||1,y:t.height/e.offsetHeight||1,boundingClientRect:t}}static getPoint(e,t,n){let r=t.boundingClientRect;return new P((n.clientX-r.left)/t.x-e.clientLeft,(n.clientY-r.top)/t.y-e.clientTop)}static mousePos(t,n){let r=e.getScale(t);return e.getPoint(t,r,n)}static touchPos(t,n){let r=[],i=e.getScale(t);for(let a of n)r.push(e.getPoint(t,i,a));return r}static sanitize(t){let n=new DOMParser().parseFromString(t,`text/html`).body||document.createElement(`body`),r=n.querySelectorAll(`script`);for(let e of r)e.remove();return e.clean(n),n.innerHTML}static isPossiblyDangerous(e,t){let n=t.replace(/\s+/g,``).toLowerCase();if([`src`,`href`,`xlink:href`].includes(e)&&(n.includes(`javascript:`)||n.includes(`data:`))||e.startsWith(`on`))return!0}static clean(t){let n=t.children;for(let t of n)e.removeAttributes(t),e.clean(t)}static removeAttributes(t){for(let{name:n,value:r}of t.attributes)e.isPossiblyDangerous(n,r)&&t.removeAttribute(n)}};let Br;(function(e){let t,n,r,i;e.resetRequestQueue=()=>{t=[],n=0,r=0,i={}},e.addThrottleControl=e=>{let t=r++;return i[t]=e,t},e.removeThrottleControl=e=>{delete i[e],l()};let a=()=>{for(let e of Object.keys(i))if(i[e]())return!0;return!1};e.getImage=(e,n,r=!0,i)=>new Promise((a,o)=>{e.headers||={},e.headers.accept=`image/webp,*/*`,L(e,{type:`image`});let s={abortController:n,requestParameters:e,supportImageRefresh:r,imageBitmapOptions:i,state:`queued`,onError:e=>{o(e)},onSuccess:e=>{a(e)}};t.push(s),l()});let s=(e,t)=>typeof createImageBitmap==`function`?ot(e,t):ie(e),c=async e=>{e.state=`running`;let{requestParameters:t,supportImageRefresh:r,imageBitmapOptions:i,onError:a,onSuccess:c,abortController:d}=e,f=r===!1&&!i&&!lr(self)&&!ke(t.url)&&(!t.headers||Object.keys(t.headers).reduce((e,t)=>e&&t===`accept`,!0));n++;let p=f?u(t,d):o(t,d);try{let t=await p;delete e.abortController,e.state=`completed`,t.data instanceof HTMLImageElement||zn(t.data)?c(t):t.data&&c({data:await s(t.data,i),cacheControl:t.cacheControl,expires:t.expires})}catch(t){delete e.abortController,a(Kn(t))}finally{n--,l()}},l=()=>{let e=a()?k.MAX_PARALLEL_IMAGE_REQUESTS_PER_FRAME:k.MAX_PARALLEL_IMAGE_REQUESTS;for(let r=n;r<e&&t.length>0;r++){let e=t.shift();if(e.abortController.signal.aborted){r--;continue}c(e)}},u=(e,t)=>new Promise((n,r)=>{let i=new Image,a=e.url,o=e.credentials;o&&o===`include`?i.crossOrigin=`use-credentials`:(o&&o===`same-origin`||!_n(a))&&(i.crossOrigin=`anonymous`),t.signal.addEventListener(`abort`,()=>{i.src=``,r(new ce(t.signal.reason))}),i.fetchPriority=`high`,i.onload=()=>{i.onerror=i.onload=null,n({data:i})},i.onerror=()=>{i.onerror=i.onload=null,!t.signal.aborted&&r(Error(`Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.`))},i.src=a})})(Br||={}),Br.resetRequestQueue();var Vr=class{constructor(e){this._transformRequestFn=e??null}transformRequest(e,t){return this._transformRequestFn&&this._transformRequestFn(e,t)||{url:e}}setTransformRequest(e){this._transformRequestFn=e}},Hr=class extends Ze{},G=class extends Hr{},Ur=class extends Hr{constructor(e={}){super(`style.load`,e)}},Wr=class extends Hr{constructor(e,t={}){super(e,t),this.dataType=`style`}},K=class extends Hr{constructor(e,t={}){super(e,t),this.dataType=`source`}},Gr=class extends Hr{preventDefault(){this._defaultPrevented=!0}get defaultPrevented(){return this._defaultPrevented}constructor(e,t,n,r={}){n=n instanceof MouseEvent?n:new MouseEvent(e,n);let i=W.mousePos(t.getCanvas(),n),a=t.unproject(i);super(e,L({point:i,lngLat:a,originalEvent:n},r)),this._defaultPrevented=!1,this.target=t}},Kr=class extends Hr{preventDefault(){this._defaultPrevented=!0}get defaultPrevented(){return this._defaultPrevented}constructor(e,t,n){let r=e===`touchend`?n.changedTouches:n.touches,i=W.touchPos(t.getCanvasContainer(),r),a=i.map(e=>t.unproject(e)),o=i.reduce((e,t,n,r)=>e.add(t.div(r.length)),new P(0,0)),s=t.unproject(o);super(e,{points:i,point:o,lngLats:a,lngLat:s,originalEvent:n}),this._defaultPrevented=!1}},qr=class extends Hr{preventDefault(){this._defaultPrevented=!0}get defaultPrevented(){return this._defaultPrevented}constructor(e,t){super(`wheel`,{originalEvent:t}),this._defaultPrevented=!1}},Jr=class extends Hr{},Yr=class extends Hr{constructor(e={}){super(`terrain`,e)}},Xr=class extends Hr{constructor(e={}){super(`projectiontransition`,e)}},Zr=class extends Hr{},Qr=class extends Hr{constructor(e={}){super(`styleimagemissing`,e)}};function $r(e){let t=[];if(typeof e==`string`)t.push({id:`default`,url:e});else if(e&&e.length>0){let n=[];for(let{id:r,url:i}of e){let e=`${r}${i}`;n.includes(e)||(n.push(e),t.push({id:r,url:i}))}}return t}function ei(e,t,n){try{let r=new URL(e);return r.pathname+=`${t}${n}`,r.toString()}catch{throw Error(`Invalid sprite URL "${e}", must be absolute. Modify style specification directly or use TransformStyleFunction to correct the issue dynamically`)}}async function ti(e,t,n,r){let i=$r(e),a=n>1?`@2x`:``,o={},s={};for(let{id:e,url:n}of i){let i=await t.transformRequest(ei(n,a,`.json`),`SpriteJSON`);o[e]=b(i,r);let c=await t.transformRequest(ei(n,a,`.png`),`SpriteImage`);s[e]=Br.getImage(c,r)}return await Promise.all([...Object.values(o),...Object.values(s)]),ni(o,s)}async function ni(e,t){let n={};for(let r in e){n[r]={};let i=Fr.getImageCanvasContext((await t[r]).data),a=(await e[r]).data;for(let e in a){let{width:t,height:o,x:s,y:c,sdf:l,pixelRatio:u,stretchX:d,stretchY:f,content:p,textFitWidth:m,textFitHeight:h}=a[e],g={width:t,height:o,x:s,y:c,context:i};n[r][e]={data:null,pixelRatio:u,sdf:l,stretchX:d,stretchY:f,content:p,textFitWidth:m,textFitHeight:h,spriteData:g}}}return n}var ri=class extends h{constructor(){super(),this.images={},this.updatedImages={},this.callbackDispatchedThisFrame={},this.loaded=!1,this.requestors=[],this.missingImageResolver=null,this.patterns={},this.atlasImage=new D({width:1,height:1}),this.dirty=!0}destroy(){this.atlasTexture&&=(this.atlasTexture.destroy(),null);for(let e of Object.keys(this.images))this.removeImage(e);this.patterns={},this.atlasImage=new D({width:1,height:1}),this.dirty=!0}isLoaded(){return this.loaded}setLoaded(e){if(this.loaded!==e&&(this.loaded=e,e)){for(let{ids:e,promiseResolve:t}of this.requestors)t(this._getImagesForIds(e));this.requestors=[]}}getImage(e){let t=this.images[e];if(t&&!t.data&&t.spriteData){let e=t.spriteData;t.data=new D({width:e.width,height:e.height},e.context.getImageData(e.x,e.y,e.width,e.height).data),t.spriteData=null}return t}addImage(e,t){if(this.images[e])throw Error(`Image id ${e} already exist, use updateImage instead`);this._validate(e,t)&&(this.images[e]=t,t.isWebGLImage&&this.updateImage(e,t,!1))}_validate(e,t){let n=!0,r=t.data||t.spriteData;return this._validateStretch(t.stretchX,r?.width)||(this.fire(new H(Error(`Image "${e}" has invalid "stretchX" value`))),n=!1),this._validateStretch(t.stretchY,r?.height)||(this.fire(new H(Error(`Image "${e}" has invalid "stretchY" value`))),n=!1),this._validateContent(t.content,t)||(this.fire(new H(Error(`Image "${e}" has invalid "content" value`))),n=!1),n}_validateStretch(e,t){if(!e)return!0;let n=0;for(let r of e){if(r[0]<n||r[1]<r[0]||t<r[1])return!1;n=r[1]}return!0}_validateContent(e,t){if(!e)return!0;if(e.length!==4)return!1;let n=t.spriteData,r=n?.width||t.data.width,i=n?.height||t.data.height;return e[0]<0||r<e[0]||e[1]<0||i<e[1]||e[2]<0||r<e[2]||e[3]<0||i<e[3]||e[2]<e[0]?!1:e[3]>=e[1]}updateImage(e,t,n=!0){let r=this.getImage(e);if(n&&(r.data.width!==t.data.width||r.data.height!==t.data.height))throw Error(`size mismatch between old image (${r.data.width}x${r.data.height}) and new image (${t.data.width}x${t.data.height}).`);t.version=r.version+1,this.images[e]=t,this.updatedImages[e]=!0}removeImage(e){let t=this.images[e];delete this.images[e],delete this.patterns[e],t.userImage?.onRemove&&t.userImage.onRemove()}listImages(){return Object.keys(this.images)}setMissingImageResolver(e){this.missingImageResolver=e}getImages(e){return new Promise((t,n)=>{let r=!0;if(!this.isLoaded())for(let t of e)this.images[t]||(r=!1);this.isLoaded()||r?t(this._getImagesForIds(e)):this.requestors.push({ids:e,promiseResolve:t})})}async _getImagesForIds(e){let t=new Set(e.filter(e=>!this.getImage(e))),n=this.missingImageResolver;n&&await Promise.all(Array.from(t,e=>n(e)));let r={};for(let n of e){let e=this.getImage(n);e&&(t.delete(n),r[n]={data:e.data.clone(),pixelRatio:e.pixelRatio,sdf:e.sdf,version:e.version,stretchX:e.stretchX,stretchY:e.stretchY,content:e.content,textFitWidth:e.textFitWidth,textFitHeight:e.textFitHeight,hasRenderCallback:!!e.userImage?.render,isWebGLImage:e.isWebGLImage})}for(let e of t)this.fire(new Qr({id:e})),F(`Image "${e}" could not be loaded. Please make sure you have added the image before it is needed with map.addImage(), resolved it with map.setMissingStyleImageResolver(), or included it in a "sprite" property in your style.`);return r}getPixelSize(){let{width:e,height:t}=this.atlasImage;return{width:e,height:t}}getPattern(e){let t=this.patterns[e],n=this.getImage(e);if(!n)return null;if(t&&t.position.version===n.version)return t.position;if(t)t.position.version=n.version;else{let t={w:n.data.width+2,h:n.data.height+2,x:0,y:0},r=new oe(t,n);this.patterns[e]={bin:t,position:r}}return this._updatePatternAtlas(),this.patterns[e].position}bind(e){let t=e.gl;this.atlasTexture?this.dirty&&=(this.atlasTexture.update(this.atlasImage),!1):this.atlasTexture=new zt(e,this.atlasImage,t.RGBA),this.atlasTexture.bind(t.LINEAR,t.CLAMP_TO_EDGE)}_updatePatternAtlas(){let e=[];for(let t in this.patterns)e.push(this.patterns[t].bin);let{w:t,h:n}=ye(e),r=this.atlasImage;r.resize({width:t||1,height:n||1});for(let e in this.patterns){let{bin:t}=this.patterns[e],n=t.x+1,i=t.y+1,a=this.getImage(e).data,o=a.width,s=a.height;D.copy(a,r,{x:0,y:0},{x:n,y:i},{width:o,height:s}),D.copy(a,r,{x:0,y:s-1},{x:n,y:i-1},{width:o,height:1}),D.copy(a,r,{x:0,y:0},{x:n,y:i+s},{width:o,height:1}),D.copy(a,r,{x:o-1,y:0},{x:n-1,y:i},{width:1,height:s}),D.copy(a,r,{x:0,y:0},{x:n+o,y:i},{width:1,height:s})}this.dirty=!0}beginFrame(){this.callbackDispatchedThisFrame={}}dispatchRenderCallbacks(e){for(let t of e){if(this.callbackDispatchedThisFrame[t])continue;this.callbackDispatchedThisFrame[t]=!0;let e=this.getImage(t);e||F(`Image with ID: "${t}" was not found`),wr(e)&&this.updateImage(t,e)}}cloneImages(){let e={};for(let t in this.images){let n=this.images[t];e[t]={...n,data:n.data?n.data.clone():null}}return e}};async function ii(e,t,n,r){let i=t*256,a=i+255,o=await r.transformRequest(n.replace(`{fontstack}`,e).replace(`{range}`,`${i}-${a}`),`Glyphs`),s=await T(o,new AbortController);if(!s?.data)throw Error(`Could not load glyph range. range: ${t}, ${i}-${a}`);let c={};for(let e of l(s.data))c[e.id]=e;return c}const ai=0x56bc75e2d63100000,oi=new Float64Array(256);for(let e=0;e<256;e++){let t=.5-(e/255)**(1/2.2);oi[e]=t*Math.abs(t)}oi[255]=-0x56bc75e2d63100000;var si=class{constructor({fontSize:e=24,buffer:t=3,radius:n=8,cutoff:r=.25,fontFamily:i=`sans-serif`,fontWeight:a=`normal`,fontStyle:o=`normal`,lang:s=null}={}){this.buffer=t,this.radius=n,this.cutoff=r,this.lang=s;let c=this.size=e+t*4,l=this._createCanvas(c),u=this.ctx=l.getContext(`2d`,{willReadFrequently:!0});u.font=`${o} ${a} ${e}px ${i}`,u.textBaseline=`alphabetic`,u.textAlign=`left`,u.fillStyle=`black`,this.gridOuter=new Float64Array(c*c),this.gridInner=new Float64Array(c*c),this.f=new Float64Array(c),this.z=new Float64Array(c+1),this.v=new Uint16Array(c)}_createCanvas(e){if(typeof OffscreenCanvas<`u`)return new OffscreenCanvas(e,e);let t=document.createElement(`canvas`);return t.width=t.height=e,t}draw(e){let{width:t,actualBoundingBoxAscent:n,actualBoundingBoxDescent:r,actualBoundingBoxLeft:i,actualBoundingBoxRight:a}=this.ctx.measureText(e),o=Math.ceil(n),s=Math.floor(-i),c=Math.max(0,Math.min(this.size-this.buffer,Math.ceil(a)-s)),l=Math.max(0,Math.min(this.size-this.buffer,o+Math.ceil(r))),u=c+2*this.buffer,d=l+2*this.buffer,f=Math.max(u*d,0),p=new Uint8ClampedArray(f),m={data:p,width:u,height:d,glyphWidth:c,glyphHeight:l,glyphTop:o,glyphLeft:s,glyphAdvance:t};if(c===0||l===0)return m;let{ctx:h,buffer:g,gridInner:_,gridOuter:v}=this;this.lang&&(h.lang=this.lang),h.clearRect(g,g,c,l),h.fillText(e,g-s,g+o);let y=h.getImageData(g,g,c,l);v.fill(ai,0,f),_.fill(0,0,f);let b=3;for(let e=0;e<l;e++){let t=(e+g)*u+g;for(let e=0;e<c;e++,b+=4,t++){let e=y.data[b];if(e===0)continue;let n=oi[e];v[t]=Math.max(0,n),_[t]=Math.max(0,-n)}}ci(v,0,0,u,d,u,this.f,this.v,this.z);let x=Math.min(g,1);ci(_,g-x,g-x,c+2*x,l+2*x,u,this.f,this.v,this.z);let S=255/this.radius,C=255*(1-this.cutoff);for(let e=0;e<f;e++){let t=Math.sqrt(v[e])-Math.sqrt(_[e]);p[e]=Math.round(C-S*t)}return m}};function ci(e,t,n,r,i,a,o,s,c){for(let l=t;l<t+r;l++)li(e,n*a+l,a,i,o,s,c);for(let l=n;l<n+i;l++)li(e,l*a+t,1,r,o,s,c)}function li(e,t,n,r,i,a,o){a[0]=0,o[0]=-0x56bc75e2d63100000,o[1]=ai,i[0]=e[t];for(let s=1,c=0,l=0;s<r;s++){i[s]=e[t+s*n];let r=s*s;do{let e=a[c];l=(i[s]-i[e]+r-e*e)/(s-e)/2}while(l<=o[c]&&--c>-1);c++,a[c]=s,o[c]=l,o[c+1]=ai}for(let s=0,c=0;s<r;s++){for(;o[c+1]<s;)c++;let r=a[c],l=s-r;e[t+s*n]=i[r]+l*l}}const ui=Lt.layout_symbol[`text-font`].default.join(`,`);var di=class e{static{this.loadGlyphRange=ii}static{this.TinySDF=si}constructor(e,t,n){this.requestManager=e,this.localIdeographFontFamily=t,this.entries={},this.lang=n}setURL(e){this.url=e}async getGlyphs(e){let t=[];for(let n in e)for(let r of e[n])t.push(this._getAndCacheGlyphsPromise(n,r));let n=await Promise.all(t),r={};for(let{stack:e,id:t,glyph:i}of n)r[e]||={},r[e][t]=i&&{id:i.id,bitmap:i.bitmap.clone(),metrics:i.metrics};return r}async _getAndCacheGlyphsPromise(e,t){this.entries[e]??={glyphs:{},requests:{},ranges:{}};let n=this.entries[e],r=n.glyphs[t];return r===void 0?!this.url||this._charUsesLocalIdeographFontFamily(t)?(r=n.glyphs[t]=await this._drawGlyph(n,e,t),{stack:e,id:t,glyph:r}):await this._downloadAndCacheRangePromise(e,t):{stack:e,id:t,glyph:r}}async _downloadAndCacheRangePromise(t,n){let r=this.entries[t],i=Math.floor(n/256);if(r.ranges[i])return{stack:t,id:n,glyph:null};r.requests[i]||=e.loadGlyphRange(t,i,this.url,this.requestManager);try{let e=await r.requests[i];for(let t in e)r.glyphs[+t]=e[+t];return r.ranges[i]=!0,{stack:t,id:n,glyph:e[n]||null}}catch(e){let a=r.glyphs[n]=await this._drawGlyph(r,t,n);return this._warnOnMissingGlyphRange(a,i,n,Kn(e)),{stack:t,id:n,glyph:a}}}_warnOnMissingGlyphRange(e,t,n,r){let i=t*256,a=i+255,o=n.toString(16).padStart(4,`0`).toUpperCase();F(`Unable to load glyph range ${t}, ${i}-${a}. Rendering codepoint U+${o} locally instead. ${r}`)}_charUsesLocalIdeographFontFamily(e){return!!this.localIdeographFontFamily&&Mn(e)}async _drawGlyph(e,t,n){let r=t===ui&&this.localIdeographFontFamily!==``&&this._charUsesLocalIdeographFontFamily(n),i=r?`ideographTinySDF`:`tinySDF`;e[i]||=this._createTinySDF(r?this.localIdeographFontFamily:t);let a=(await e[i]).draw(String.fromCodePoint(n)),o=/^\p{gc=Cf}+$/u.test(String.fromCodePoint(n));return{id:n,bitmap:new it({width:a.width||60,height:a.height||60},a.data),metrics:{width:o?0:a.glyphWidth/2||24,height:a.glyphHeight/2||24,left:a.glyphLeft/2+.5||0,top:a.glyphTop/2-27.5||-8,advance:o?0:a.glyphAdvance/2||24,isDoubleResolution:!0}}}async _createTinySDF(t){let n=t?t.split(`,`):[];n.push(`sans-serif`);let r=n.map(e=>/[-\w]+/.test(e)?e:`'${CSS.escape(e)}'`).join(`,`),i=this._fontWeight(n[0]),a=this._fontStyle(n[0]);if(typeof document<`u`&&document.fonts?.load)try{await document.fonts.load(`${a} ${i||`normal`} 48px ${r}`)}catch(e){F(`Failed to load font "${r}": ${Kn(e).message}`)}return new e.TinySDF({fontSize:48,buffer:6,radius:16,cutoff:.25,fontFamily:r,fontWeight:i,fontStyle:a,lang:this.lang})}_fontStyle(e){return/italic/i.test(e)?`italic`:/oblique/i.test(e)?`oblique`:`normal`}_fontWeight(e){let t={thin:100,hairline:100,"extra light":200,"ultra light":200,light:300,normal:400,regular:400,medium:500,semibold:600,demibold:600,bold:700,"extra bold":800,"ultra bold":800,black:900,heavy:900,"extra black":950,"ultra black":950},n;for(let[r,i]of Object.entries(t))RegExp(`\\b${r}\\b`,`i`).test(e)&&(n=`${i}`);return n}destroy(){for(let e in this.entries){let t=this.entries[e];t.tinySDF=null,t.ideographTinySDF=null,t.glyphs={},t.requests={},t.ranges={}}this.entries={}}};let fi;const pi=()=>fi||=new Tt({anchor:new _t(Lt.light.anchor,`anchor`),position:new _t(Lt.light.position,`position`),color:new _t(Lt.light.color,`color`),intensity:new _t(Lt.light.intensity,`intensity`)});var mi=class extends h{constructor(e,t){super(),this._transitionable=new r(pi(),`light`,t),this.setLight(e),this._transitioning=this._transitionable.untransitioned()}getLight(){return this._transitionable.serialize()}getCartesianPosition(){return Ae(this.properties.get(`position`))}setLight(e,t={}){if(!this._validate(Vt.light,e,t))for(let t in e){let n=e[t];t.endsWith(`-transition`)?this._transitionable.setTransition(t.slice(0,-Ge.length),n):this._transitionable.setValue(t,n)}}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,n){return Xn(this,e,{value:t},n)}};let hi;const gi=()=>hi||=new Tt({"sky-color":new _t(Lt.sky[`sky-color`],`sky-color`),"horizon-color":new _t(Lt.sky[`horizon-color`],`horizon-color`),"fog-color":new _t(Lt.sky[`fog-color`],`fog-color`),"fog-ground-blend":new _t(Lt.sky[`fog-ground-blend`],`fog-ground-blend`),"horizon-fog-blend":new _t(Lt.sky[`horizon-fog-blend`],`horizon-fog-blend`),"sky-horizon-blend":new _t(Lt.sky[`sky-horizon-blend`],`sky-horizon-blend`),"atmosphere-blend":new _t(Lt.sky[`atmosphere-blend`],`atmosphere-blend`)});var _i=class extends h{constructor(e,t){super(),this._transitionable=new r(gi(),`sky`,t),this.setSky(e),this._transitioning=this._transitionable.untransitioned(),this.recalculate(new qt(0))}setSky(e,t={}){if(!this._validate(Vt.sky,e,t)){e||={"sky-color":`transparent`,"horizon-color":`transparent`,"fog-color":`transparent`,"fog-ground-blend":1,"atmosphere-blend":0};for(let t in e){let n=e[t];t.endsWith(`-transition`)?this._transitionable.setTransition(t.slice(0,-Ge.length),n):this._transitionable.setValue(t,n)}}}getSky(){return this._transitionable.serialize()}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,n={}){return Xn(this,e,{value:t},n)}calculateFogBlendOpacity(e){return e<60?0:e<70?(e-60)/10:1}},vi=class{constructor(e,t){this.width=e,this.height=t,this.nextRow=0,this.data=new Uint8Array(this.width*this.height),this.dashEntry={}}getDash(e,t){let n=e.join(`,`)+String(t);return this.dashEntry[n]||=this.addDash(e,t),this.dashEntry[n]}getDashRanges(e,t,n){let r=e.length%2==1,i=[],a=r?-e[e.length-1]*n:0,o=e[0]*n,s=!0;i.push({left:a,right:o,isDash:s,zeroLength:e[0]===0});let c=e[0];for(let t=1;t<e.length;t++){s=!s;let r=e[t];a=c*n,c+=r,o=c*n,i.push({left:a,right:o,isDash:s,zeroLength:r===0})}return i}addRoundDash(e,t,n){let r=t/2;for(let t=-n;t<=n;t++){let i=this.nextRow+n+t,a=this.width*i,o=0,s=e[o];for(let i=0;i<this.width;i++){i/s.right>1&&(s=e[++o]);let c=Math.abs(i-s.left),l=Math.abs(i-s.right),u=Math.min(c,l),d,f=t/n*(r+1);if(s.isDash){let e=r-Math.abs(f);d=Math.sqrt(u*u+e*e)}else d=r-Math.sqrt(u*u+f*f);this.data[a+i]=Math.max(0,Math.min(255,d+128))}}}addRegularDash(e){for(let t=e.length-1;t>=0;--t){let n=e[t],r=e[t+1];n.zeroLength?e.splice(t,1):r?.isDash===n.isDash&&(r.left=n.left,e.splice(t,1))}let t=e[0],n=e[e.length-1];t.isDash===n.isDash&&(t.left=n.left-this.width,n.right=t.right+this.width);let r=this.width*this.nextRow,i=0,a=e[i];for(let t=0;t<this.width;t++){t/a.right>1&&(a=e[++i]);let n=Math.abs(t-a.left),o=Math.abs(t-a.right),s=Math.min(n,o),c=a.isDash?s:-s;this.data[r+t]=Math.max(0,Math.min(255,c+128))}}addDash(e,t){let n=t?7:0,r=2*n+1;if(this.nextRow+r>this.height)return F(`LineAtlas out of space`),null;let i=0;for(let t of e)i+=t;if(i!==0){let r=this.width/i,a=this.getDashRanges(e,this.width,r);t?this.addRoundDash(a,r,n):this.addRegularDash(a)}let a={y:this.nextRow+n,height:2*n,width:i};return this.nextRow+=r,this.dirty=!0,a}bind(e){let t=e.gl;this.texture?(t.bindTexture(t.TEXTURE_2D,this.texture),this.dirty&&(this.dirty=!1,t.texSubImage2D(t.TEXTURE_2D,0,0,0,this.width,this.height,t.ALPHA,t.UNSIGNED_BYTE,this.data))):(this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.REPEAT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.REPEAT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.ALPHA,this.width,this.height,0,t.ALPHA,t.UNSIGNED_BYTE,this.data))}};function yi(e){if(!e)return!1;let t=globalThis.location;if(!t)return!1;try{return new URL(e,t.href).origin!==t.origin}catch{return!1}}function bi(){let e=import.meta.url;if(!/^https?:/.test(e))return``;let t=e.endsWith(`-dev.mjs`)?`maplibre-gl-worker-dev.mjs`:`maplibre-gl-worker.mjs`;return new URL(`./${t}`,e).href}function xi(e,t){if(t)try{return new Worker(e,{type:`module`})}catch(e){console.warn(`Module worker not supported, falling back to classic worker`,e)}return new Worker(e)}async function Si(e){let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch worker script (${t.status}): ${e}`);let n=await t.text(),r=new Blob([n],{type:`text/javascript`});return URL.createObjectURL(r)}function Ci(e){let t=new Blob([`import ${JSON.stringify(new URL(e,import.meta.url).href)}`],{type:`text/javascript`});return URL.createObjectURL(t)}async function wi(){let e=k.WORKER_URL||bi(),t=!e?.endsWith(`.cjs`);if(!yi(e))return xi(e,t);if(t){let n=Ci(e);try{return xi(n,t)}finally{URL.revokeObjectURL(n)}}let n=await Si(e);try{return xi(n,t)}finally{URL.revokeObjectURL(n)}}const Ti=`maplibre_preloaded_worker_pool`;var Ei=class e{constructor(){this.active={},this.workersPromise=null}async acquire(t){if(this.active[t]=!0,!this.workersPromise){let t=[];for(;t.length<e.workerCount;)t.push(wi());this.workersPromise=Promise.all(t)}return(await this.workersPromise).slice()}release(e){if(delete this.active[e],this.numActive()===0&&this.workersPromise){let e=this.workersPromise;this.workersPromise=null,e.then(e=>{for(let t of e)t.terminate()})}}isPreloaded(){return!!this.active[Ti]}numActive(){return Object.keys(this.active).length}};const Di=Math.floor(Fr.hardwareConcurrency/2);Ei.workerCount=un(globalThis)?Math.max(Math.min(Di,3),1):1;let Oi;function ki(){return Oi||=new Ei,Oi}function Ai(){ki().acquire(Ti)}function ji(){let e=Oi;e&&(e.isPreloaded()&&e.numActive()===1?(e.release(Ti),Oi=null):console.warn(`Could not clear WebWorkers since there are active Map instances that still reference it. The pre-warmed WebWorker pool can only be cleared when all map instances have been removed with map.remove()`))}var Mi=class{constructor(e,t){this.workerPool=e,this.actors=[],this.currentActor=0,this.id=t,this.removed=!1,this.actorsPromise=this.initActors(t)}async initActors(e){let t=await this.workerPool.acquire(e);if(this.removed)return[];if(this.actors=t.map((t,n)=>{let r=new Ye(t,e);return r.name=`Worker ${n}`,r}),!this.actors.length)throw Error(`No actors found`);return this.actors}async broadcast(e,t){let n=await this.actorsPromise;return Promise.all(n.map(n=>n.sendAsync({type:e,data:t})))}async getActor(){let e=await this.actorsPromise;return this.currentActor=(this.currentActor+1)%e.length,e[this.currentActor]}async waitForInitComplete(){this.actors.length===0&&await this.actorsPromise}getReadyActor(){return this.currentActor=(this.currentActor+1)%this.actors.length,this.actors[this.currentActor]}remove(e=!0){this.removed=!0;for(let e of this.actors)e.remove();this.actors=[],e&&this.workerPool.release(this.id)}async registerMessageHandler(e,t){let n=await this.actorsPromise;for(let r of n)r.registerMessageHandler(e,t)}async unregisterMessageHandler(e){let t=await this.actorsPromise;for(let n of t)n.unregisterMessageHandler(e)}};let Ni;function Pi(){return Ni||(Ni=new Mi(ki(),nt),Ni.registerMessageHandler(`GR`,(e,t,n)=>o(t,n))),Ni}function Fi(e,t){let n=xr();return Te(n,n,[1,1,0]),gn(n,n,[e.width*.5,e.height*.5,1]),e.calculatePosMatrix?tt(n,n,e.calculatePosMatrix(t.toUnwrapped())):n}function Ii(e,t,n){if(e)for(let r of e){let e=t[r];if(e?.source===n&&e.type===`fill-extrusion`)return!0}else for(let e in t){let r=t[e];if(r.source===n&&r.type===`fill-extrusion`)return!0}return!1}function Li(e,t,n,r,i,a,o){let s=Ii(i?.layers??null,t,e.id),c=a.maxPitchScaleFactor(),l=e.tilesIn(r,c,s);l.sort(Bi);let u=[];for(let r of l)u.push({wrappedTileID:r.tileID.wrapped().key,queryResults:r.tile.queryRenderedFeatures(t,n,e.getState(),r.queryGeometry,r.cameraQueryGeometry,r.scale,i,a,c,Fi(a,r.tileID),o?(e,t)=>o(r.tileID,e,t):void 0)});return Hi(Vi(u),e)}function Ri(e,t,n,r,i,a,o){let s={},c=a.queryRenderedSymbols(r),l=[];for(let e of Object.keys(c).map(Number))l.push(o[e]);l.sort(Bi);for(let n of l){let r=n.featureIndex.lookupSymbolFeatures(c[n.bucketInstanceId],t,n.bucketIndex,n.sourceLayerIndex,{filterSpec:i.filter,globalState:i.globalState},i.layers,i.availableImages,e);for(let e in r){s[e]||=[];let t=r[e];t.sort((e,t)=>{let r=n.featureSortOrder;if(r){let n=r.indexOf(e.featureIndex);return r.indexOf(t.featureIndex)-n}return t.featureIndex-e.featureIndex});for(let n of t)s[e].push(n)}}return Ui(s,e,n)}function zi(e,t){let n=e.getRenderableIds().map(t=>e.getTileByID(t)),r=[],i={};for(let e of n){let n=e.tileID.canonical.key;i[n]||(i[n]=!0,e.querySourceFeatures(r,t))}return r}function Bi(e,t){let n=e.tileID,r=t.tileID;return n.overscaledZ-r.overscaledZ||n.canonical.y-r.canonical.y||n.wrap-r.wrap||n.canonical.x-r.canonical.x}function Vi(e){let t={},n={};for(let{queryResults:r,wrappedTileID:i}of e){n[i]||={};let e=n[i];for(let n in r){let i=r[n];e[n]||={};let a=e[n];t[n]||=[];for(let e of i)a[e.featureIndex]||(a[e.featureIndex]=!0,t[n].push(e))}}return t}function Hi(e,t){for(let n in e)for(let r of e[n])Wi(r,t);return e}function Ui(e,t,n){for(let r in e)for(let i of e[r]){let e=n[t[r].source];Wi(i,e)}return e}function Wi(e,t){let n=e.feature,r=t.getFeatureState(n.layer[`source-layer`],n.id);n.source=n.layer.source,n.layer[`source-layer`]&&(n.sourceLayer=n.layer[`source-layer`]),n.state=r}async function Gi(e,t,n,r){let i=e;if(e.url?i=(await b(await t.transformRequest(e.url,`Source`),n)).data:await Fr.frameAsync(n,r),!i)return null;let a=mr(L(i,e),[`tiles`,`minzoom`,`maxzoom`,`attribution`,`bounds`,`scheme`,`tileSize`,`encoding`]);return`vector_layers`in i&&i.vector_layers&&(a.vectorLayerIds=i.vector_layers.map(e=>e.id)),a}var Ki=class e{constructor(e,t){e&&(t?this.setSouthWest(e).setNorthEast(t):Array.isArray(e)&&(e.length===4?this.setSouthWest([e[0],e[1]]).setNorthEast([e[2],e[3]]):this.setSouthWest(e[0]).setNorthEast(e[1])))}setNorthEast(e){return this._ne=e instanceof z?new z(e.lng,e.lat):z.convert(e),this}setSouthWest(e){return this._sw=e instanceof z?new z(e.lng,e.lat):z.convert(e),this}extend(t){let n=this._sw,r=this._ne,i,a;if(t instanceof z)i=t,a=t;else if(t instanceof e){if(i=t._sw,a=t._ne,!i||!a)return this}else{if(Array.isArray(t)){if(t.length===4||t.every(Array.isArray)){let n=t;return this.extend(e.convert(n))}{let e=t;return this.extend(z.convert(e))}}return t&&(`lng`in t||`lon`in t)&&`lat`in t?this.extend(z.convert(t)):this}return!n&&!r?(this._sw=new z(i.lng,i.lat),this._ne=new z(a.lng,a.lat)):(n.lng=Math.min(i.lng,n.lng),n.lat=Math.min(i.lat,n.lat),r.lng=Math.max(a.lng,r.lng),r.lat=Math.max(a.lat,r.lat)),this}getCenter(){return new z((this._sw.lng+this._ne.lng)/2,(this._sw.lat+this._ne.lat)/2)}getSouthWest(){return this._sw}getNorthEast(){return this._ne}getNorthWest(){return new z(this.getWest(),this.getNorth())}getSouthEast(){return new z(this.getEast(),this.getSouth())}getWest(){return this._sw.lng}getSouth(){return this._sw.lat}getEast(){return this._ne.lng}getNorth(){return this._ne.lat}toArray(){return[this._sw.toArray(),this._ne.toArray()]}toString(){return`LngLatBounds(${this._sw.toString()}, ${this._ne.toString()})`}isEmpty(){return!(this._sw&&this._ne)}contains(e){let{lng:t,lat:n}=z.convert(e),r=this._sw.lat<=n&&n<=this._ne.lat,i=this._sw.lng<=t&&t<=this._ne.lng;return this._sw.lng>this._ne.lng&&(i=this._sw.lng>=t&&t>=this._ne.lng),r&&i}intersects(t){if(t=e.convert(t),!(t.getNorth()>=this.getSouth()&&t.getSouth()<=this.getNorth()))return!1;let n=Math.abs(this.getEast()-this.getWest()),r=Math.abs(t.getEast()-t.getWest());if(n>=360||r>=360)return!0;let i=Tr(this.getWest(),-180,180),a=Tr(this.getEast(),-180,180),o=Tr(t.getWest(),-180,180),s=Tr(t.getEast(),-180,180),c=i>a,l=o>s;return c&&l?!0:c?s>=i||o<=a:l?a>=o||i<=s:o<=a&&s>=i}static convert(t){return t instanceof e||!t?t:new e(t)}static fromLngLat(t,n=0){let r=360*n/40075017,i=r/Math.cos(Math.PI/180*t.lat);return new e(new z(t.lng-i,t.lat-r),new z(t.lng+i,t.lat+r))}adjustAntiMeridian(){let t=new z(this._sw.lng,this._sw.lat),n=new z(this._ne.lng,this._ne.lat);return t.lng>n.lng?new e(t,new z(n.lng+360,n.lat)):new e(t,n)}},qi=class{constructor(e,t,n){this.bounds=Ki.convert(this.validateBounds(e)),this.minzoom=t||0,this.maxzoom=n||24}validateBounds(e){return!Array.isArray(e)||e.length!==4?[-180,-90,180,90]:[Math.max(-180,e[0]),Math.max(-90,e[1]),Math.min(180,e[2]),Math.min(90,e[3])]}contains(e){let t=2**e.z,n={minX:Math.floor(Ln(this.bounds.getWest())*t),minY:Math.floor(Qn(this.bounds.getNorth())*t),maxX:Math.ceil(Ln(this.bounds.getEast())*t),maxY:Math.ceil(Qn(this.bounds.getSouth())*t)};return e.x>=n.minX&&e.x<n.maxX&&e.y>=n.minY&&e.y<n.maxY}},Ji=class extends h{constructor(e,t,n,r){if(super(),this.id=e,this.dispatcher=n,this.type=`vector`,this.minzoom=0,this.maxzoom=22,this.scheme=`xyz`,this.tileSize=512,this.reparseOverscaled=!0,this.isTileClipped=!0,this._loaded=!1,L(this,mr(t,[`url`,`scheme`,`tileSize`,`promoteId`,`encoding`])),this._options=L({type:`vector`},t),this._collectResourceTiming=t.collectResourceTiming,this.tileSize!==512)throw Error(`vector tile sources must have a tileSize of 512`);this.setEventedParent(r)}async load(e=!1){this._loaded=!1,this.fire(new K(`dataloading`)),this._tileJSONRequest=new AbortController;try{let t=await Gi(this._options,this.map._requestManager,this._tileJSONRequest,this.map._ownerWindow);this._tileJSONRequest=null,this._loaded=!0,t&&(L(this,t),t.bounds&&(this.tileBounds=new qi(t.bounds,this.minzoom,this.maxzoom)),this.fire(new K(`data`,{sourceDataType:`metadata`})),this.fire(new K(`data`,{sourceDataType:`content`,sourceDataChanged:e})))}catch(e){this._tileJSONRequest=null,this._loaded=!0,xe(e)||this.fire(new H(Kn(e)))}}loaded(){return this._loaded}hasTile(e){return!this.tileBounds||this.tileBounds.contains(e.canonical)}onAdd(e){this.map=e,this.load()}setSourceProperty(e){this._tileJSONRequest&&this._tileJSONRequest.abort(),e(),this.load(!0)}setTiles(e){return this.setSourceProperty(()=>{this._options.tiles=e}),this}setUrl(e){return this.setSourceProperty(()=>{this.url=e,this._options.url=e}),this}onRemove(){this._tileJSONRequest&&=(this._tileJSONRequest.abort(),null)}serialize(){return L({},this._options)}async loadTile(e){let t=e.tileID.canonical.url(this.tiles,this.map.getPixelRatio(),this.scheme),n={request:await this.map._requestManager.transformRequest(t,`Tile`),uid:e.uid,tileID:e.tileID,zoom:e.tileID.overscaledZ,tileSize:this.tileSize*e.tileID.overscaleFactor(),type:this.type,source:this.id,pixelRatio:this.map.getPixelRatio(),showCollisionBoxes:this.map.showCollisionBoxes,promoteId:this.promoteId,subdivisionGranularity:this.map.style.projection.subdivisionGranularity,encoding:this.encoding,overzoomParameters:await this._getOverzoomParameters(e),etag:e.etag};n.request.collectResourceTiming=this._collectResourceTiming,await this.dispatcher.waitForInitComplete();let r=`RT`;if(!e.actor||e.state===`expired`)e.actor=this.dispatcher.getReadyActor(),r=`LT`;else if(e.state===`loading`)return new Promise((t,n)=>{e.reloadPromise={resolve:t,reject:n}});e.abortController=new AbortController;try{let t=await e.actor.sendAsync({type:r,data:n},e.abortController);if(delete e.abortController,e.aborted)return;this._afterTileLoadWorkerResponse(e,t);let i={};return t?.etagUnmodified&&(i.unmodified=!0),i}catch(t){if(delete e.abortController,e.aborted||xe(t))return;if(t&&t.status!==404)throw t;this._afterTileLoadWorkerResponse(e,null)}}async _getOverzoomParameters(e){if(e.tileID.canonical.z<=this.maxzoom||this.map._zoomLevelsToOverscale===void 0)return;let t=e.tileID.scaledTo(this.maxzoom).canonical,n=t.url(this.tiles,this.map.getPixelRatio(),this.scheme);return{maxZoomTileID:t,overzoomRequest:await this.map._requestManager.transformRequest(n,`Tile`)}}_afterTileLoadWorkerResponse(e,t){if(t?.resourceTiming&&(e.resourceTiming=t.resourceTiming),t&&this.map._refreshExpiredTiles&&e.setExpiryData(t),e.etag=t?.etag,e.loadVectorData(t,this.map.painter),e.reloadPromise){let t=e.reloadPromise;e.reloadPromise=null,this.loadTile(e).then(t.resolve).catch(t.reject)}}async abortTile(e){e.abortController&&(e.abortController.abort(),delete e.abortController),e.actor&&await e.actor.sendAsync({type:`AT`,data:{uid:e.uid,type:this.type,source:this.id}})}async unloadTile(e){e.unloadVectorData(),e.actor&&await e.actor.sendAsync({type:`RMT`,data:{uid:e.uid,type:this.type,source:this.id}})}hasTransition(){return!1}},Yi=class extends h{constructor(e,t,n,r){super(),this.id=e,this.dispatcher=n,this.setEventedParent(r),this.type=`raster`,this.minzoom=0,this.maxzoom=22,this.roundZoom=!0,this.scheme=`xyz`,this.tileSize=512,this._loaded=!1,this._premultiplyAlpha=!0,this._options=L({type:`raster`},t),L(this,mr(t,[`url`,`scheme`,`tileSize`]))}async load(e=!1){this._loaded=!1,this.fire(new K(`dataloading`)),this._tileJSONRequest=new AbortController;try{let t=await Gi(this._options,this.map._requestManager,this._tileJSONRequest,this.map._ownerWindow);this._tileJSONRequest=null,this._loaded=!0,t&&(L(this,t),t.bounds&&(this.tileBounds=new qi(t.bounds,this.minzoom,this.maxzoom)),this.fire(new K(`data`,{sourceDataType:`metadata`})),this.fire(new K(`data`,{sourceDataType:`content`,sourceDataChanged:e})))}catch(e){this._tileJSONRequest=null,this._loaded=!0,xe(e)||this.fire(new H(Kn(e)))}}loaded(){return this._loaded}onAdd(e){this.map=e,this.load()}onRemove(){this._tileJSONRequest&&=(this._tileJSONRequest.abort(),null)}setSourceProperty(e){this._tileJSONRequest&&=(this._tileJSONRequest.abort(),null),e(),this.load(!0)}setTiles(e){return this.setSourceProperty(()=>{this._options.tiles=e}),this}setUrl(e){return this.setSourceProperty(()=>{this.url=e,this._options.url=e}),this}serialize(){return L({},this._options)}setPremultiplyAlpha(e){return this._premultiplyAlpha===e||this.setSourceProperty(()=>{this._premultiplyAlpha=e}),this}hasTile(e){return!this.tileBounds||this.tileBounds.contains(e.canonical)}async loadTile(e){let t=e.tileID.canonical.url(this.tiles,this.map.getPixelRatio(),this.scheme),n=this._premultiplyAlpha,r=n?void 0:{premultiplyAlpha:`none`},i=await this.map._requestManager.transformRequest(t,`Tile`);e.abortController=new AbortController;try{let t=await Br.getImage(i,e.abortController,this.map._refreshExpiredTiles,r);if(delete e.abortController,e.aborted){e.state=`unloaded`;return}if(t?.data){this.map._refreshExpiredTiles&&(t.cacheControl||t.expires)&&e.setExpiryData({cacheControl:t.cacheControl,expires:t.expires});let r=this.map.painter.context,i=r.gl,a=t.data;e.texture=this.map.painter.getTileTexture(a.width),e.texture?e.texture.update(a,{useMipmap:!0,premultiply:n}):(e.texture=new zt(r,a,i.RGBA,{useMipmap:!0,premultiply:n}),e.texture.bind(i.LINEAR,i.CLAMP_TO_EDGE,i.LINEAR_MIPMAP_NEAREST)),e.state=`loaded`}}catch(t){if(delete e.abortController,e.aborted)e.state=`unloaded`;else if(t)throw e.state=`errored`,t}}async abortTile(e){e.abortController&&(e.abortController.abort(),delete e.abortController)}async unloadTile(e){e.texture&&this.map.painter.saveTileTexture(e.texture)}hasTransition(){return!1}},Xi=class extends Yi{constructor(e,t,n,r){super(e,t,n,r),this.type=`raster-dem`,this.maxzoom=22,this._options=L({type:`raster-dem`},t),this.encoding=t.encoding||`mapbox`,this.redFactor=t.redFactor,this.greenFactor=t.greenFactor,this.blueFactor=t.blueFactor,this.baseShift=t.baseShift}async loadTile(e){let t=e.tileID.canonical.url(this.tiles,this.map.getPixelRatio(),this.scheme),n=await this.map._requestManager.transformRequest(t,`Tile`);e.neighboringTiles=this._getNeighboringTiles(e.tileID),e.abortController=new AbortController;try{let t=await Br.getImage(n,e.abortController,this.map._refreshExpiredTiles);if(delete e.abortController,e.aborted){e.state=`unloaded`;return}if(t?.data){let n=t.data;this.map._refreshExpiredTiles&&(t.cacheControl||t.expires)&&e.setExpiryData({cacheControl:t.cacheControl,expires:t.expires});let r=zn(n)&&be()?n:await this.readImageNow(n),i={type:this.type,uid:e.uid,source:this.id,rawImageData:r,encoding:this.encoding,redFactor:this.redFactor,greenFactor:this.greenFactor,blueFactor:this.blueFactor,baseShift:this.baseShift};if(e.actor&&e.state!==`expired`&&e.state!==`reloading`)return;await this.dispatcher.waitForInitComplete(),(!e.actor||e.state===`expired`)&&(e.actor=this.dispatcher.getReadyActor()),e.dem=await e.actor.sendAsync({type:`LDT`,data:i}),e.needsHillshadePrepare=!0,e.needsTerrainPrepare=!0,e.state=`loaded`}}catch(t){if(delete e.abortController,e.aborted)e.state=`unloaded`;else if(t)throw e.state=`errored`,t}}async readImageNow(e){if(typeof VideoFrame<`u`&&se()){let t=e.width+2,n=e.height+2;try{return new D({width:t,height:n},await Fe(e,-1,-1,t,n))}catch{}}return Fr.getImageData(e,1)}_getNeighboringTiles(e){let t=e.canonical,n=2**t.z,r=(t.x-1+n)%n,i=t.x===0?e.wrap-1:e.wrap,a=(t.x+1+n)%n,o=t.x+1===n?e.wrap+1:e.wrap,s={};return s[new Et(e.overscaledZ,i,t.z,r,t.y).key]={backfilled:!1},s[new Et(e.overscaledZ,o,t.z,a,t.y).key]={backfilled:!1},t.y>0&&(s[new Et(e.overscaledZ,i,t.z,r,t.y-1).key]={backfilled:!1},s[new Et(e.overscaledZ,e.wrap,t.z,t.x,t.y-1).key]={backfilled:!1},s[new Et(e.overscaledZ,o,t.z,a,t.y-1).key]={backfilled:!1}),t.y+1<n&&(s[new Et(e.overscaledZ,i,t.z,r,t.y+1).key]={backfilled:!1},s[new Et(e.overscaledZ,e.wrap,t.z,t.x,t.y+1).key]={backfilled:!1},s[new Et(e.overscaledZ,o,t.z,a,t.y+1).key]={backfilled:!1}),s}async unloadTile(e){e.demTexture&&this.map.painter.saveTileTexture(e.demTexture),e.fbo&&(e.fbo.destroy(),delete e.fbo),e.dem&&delete e.dem,delete e.neighboringTiles,e.state=`unloaded`,e.actor&&await e.actor.sendAsync({type:`RDT`,data:{type:this.type,uid:e.uid,source:this.id}})}};function Zi(e,t){return t?e.properties[t]:e.id}function Qi(e,t){let n=new Map;if(e==null||e.type==null)return n;if(e.type===`Feature`){let r=Zi(e,t);return r==null?void 0:(n.set(r,e),n)}if(e.type===`FeatureCollection`){let r=new Set;for(let i of e.features){let e=Zi(i,t);if(e==null||r.has(e))return;r.add(e),n.set(e,i)}return n}}function $i(e,t,n){let r=[];if(t.removeAll)e.clear();else if(t.remove)for(let n of t.remove){let t=e.get(n);t&&(r.push(t.geometry),e.delete(n))}if(t.add)for(let i of t.add){let t=Zi(i,n);if(t==null)continue;let a=e.get(t);a&&r.push(a.geometry),r.push(i.geometry),e.set(t,i)}if(t.update)for(let n of t.update){let t=e.get(n.id);if(!t)continue;let i=!!n.newGeometry,a=n.removeAllProperties||n.removeProperties?.length>0||n.addOrUpdateProperties?.length>0;if(!i&&!a)continue;r.push(t.geometry);let o={...t};if(e.set(n.id,o),i&&(r.push(n.newGeometry),o.geometry=n.newGeometry),a){if(o.properties=n.removeAllProperties?{}:{...o.properties||{}},n.removeProperties)for(let e of n.removeProperties)delete o.properties[e];if(n.addOrUpdateProperties)for(let{key:e,value:t}of n.addOrUpdateProperties)o.properties[e]=t}}return r}function ea(e,t,n){if(!e)return t||{};if(!t)return e||{};n&&(ra(e.add,n),ra(t.add,n));let r=aa(e),i=aa(t);ta(r,i);let a={};if((r.removeAll||i.removeAll)&&(a.removeAll=!0),a.remove=new Set([...r.remove,...i.remove]),a.add=new Map([...r.add,...i.add]),a.update=new Map([...r.update,...i.update]),a.remove.size&&a.add.size)for(let e of a.add.keys())a.remove.delete(e);let o=oa(a);return n&&ia(o.add,n),o}function ta(e,t){t.removeAll&&(e.add.clear(),e.update.clear(),e.remove.clear(),t.remove.clear());for(let n of t.remove)e.add.delete(n),e.update.delete(n);for(let[n,r]of t.update){let i=e.update.get(n);i&&(t.update.set(n,na(i,r)),e.update.delete(n))}}function na(e,t){let n={id:e.id};if(t.removeAllProperties&&(delete e.removeProperties,delete e.addOrUpdateProperties,delete t.removeProperties),t.removeProperties)for(let n of t.removeProperties){let t=e.addOrUpdateProperties.findIndex(e=>e.key===n);t>-1&&e.addOrUpdateProperties.splice(t,1)}return(e.removeAllProperties||t.removeAllProperties)&&(n.removeAllProperties=!0),(e.removeProperties||t.removeProperties)&&(n.removeProperties=[...e.removeProperties||[],...t.removeProperties||[]]),(e.addOrUpdateProperties||t.addOrUpdateProperties)&&(n.addOrUpdateProperties=[...e.addOrUpdateProperties||[],...t.addOrUpdateProperties||[]]),(e.newGeometry||t.newGeometry)&&(n.newGeometry=t.newGeometry||e.newGeometry),n}function ra(e,t){if(e)for(let n of e){let e=Zi(n,t);e!=null&&(n.id=e)}}function ia(e,t){if(e)for(let n of e)Zi(n,t)!=null&&delete n.id}function aa(e){if(!e)return{};let t={};return t.removeAll=e.removeAll,t.remove=new Set(e.remove||[]),t.add=new Map(e.add?.map(e=>[e.id,e])),t.update=new Map(e.update?.map(e=>[e.id,e])),t}function oa(e){let t={};return e.removeAll&&(t.removeAll=e.removeAll),e.remove&&(t.remove=Array.from(e.remove)),e.add&&(t.add=Array.from(e.add.values())),e.update&&(t.update=Array.from(e.update.values())),t}function sa(e){return!e||e.length===0?[]:typeof e[0]==`number`?[e]:e.flatMap(e=>sa(e))}function ca(e){return e.type===`GeometryCollection`?e.geometries.flatMap(e=>ca(e)):sa(e.coordinates)}function la(e){let t=new Ki,n;switch(e.type){case`FeatureCollection`:n=e.features.flatMap(e=>ca(e.geometry));break;case`Feature`:n=ca(e.geometry);break;default:n=ca(e)}if(n.length===0)return t;for(let e of n){let[n,r]=e;t.extend([n,r])}return t}function ua({x:e,y:t,z:n},r=0){let i=Pt((e-r)/2**n),a=mn((t+1+r)/2**n),o=Pt((e+1+r)/2**n),s=mn((t-r)/2**n);return new Ki([i,a],[o,s])}var da=class extends h{constructor(e,t,n,r){super(),this.id=e,this.type=`geojson`,this.minzoom=0,this.maxzoom=18,this.tileSize=512,this.isTileClipped=!0,this.reparseOverscaled=!0,this._removed=!1,this._isUpdatingWorker=!1,this._pendingWorkerUpdate={data:t.data},this.actorPromise=n.getActor(),this.setEventedParent(r),this._data=typeof t.data==`string`?{url:t.data}:{geojson:t.data},this._options=L({},t),this._collectResourceTiming=t.collectResourceTiming,t.maxzoom!==void 0&&(this.maxzoom=t.maxzoom),t.type&&(this.type=t.type),t.attribution&&(this.attribution=t.attribution),this.promoteId=t.promoteId,t.clusterMaxZoom!==void 0&&this.maxzoom<=t.clusterMaxZoom&&F(`The maxzoom value "${this.maxzoom}" is expected to be greater than the clusterMaxZoom value "${t.clusterMaxZoom}".`),this.workerOptions=L({source:this.id,geojsonVtOptions:{buffer:this._pixelsToTileUnits(t.buffer===void 0?128:t.buffer),tolerance:this._pixelsToTileUnits(t.tolerance===void 0?.375:t.tolerance),extent:M,maxZoom:this.maxzoom,lineMetrics:t.lineMetrics||!1,generateId:t.generateId||!1,promoteId:typeof t.promoteId==`string`?t.promoteId:void 0,cluster:t.cluster||!1,clusterOptions:{maxZoom:this._getClusterMaxZoom(t.clusterMaxZoom),minPoints:Math.max(2,t.clusterMinPoints||2),extent:M,radius:this._pixelsToTileUnits(t.clusterRadius||50),log:!1,generateId:t.generateId||!1}},clusterProperties:t.clusterProperties,filter:t.filter},t.workerOptions)}_hasPendingWorkerUpdate(){return this._pendingWorkerUpdate.data!==void 0||this._pendingWorkerUpdate.diff!==void 0||this._pendingWorkerUpdate.updateCluster}_pixelsToTileUnits(e){return e*(M/this.tileSize)}_tileUnitsToPixels(e){return e/(M/this.tileSize)}_getClusterMaxZoom(e){let t=e?Math.round(e):this.maxzoom-1;return Number.isInteger(e)||e===void 0||F(`Integer expected for option 'clusterMaxZoom': provided value "${e}" rounded to "${t}"`),t}async load(){await this._updateWorkerData()}onAdd(e){this.map=e,this.load()}setData(e){return this._data=typeof e==`string`?{url:e}:{geojson:e},this._pendingWorkerUpdate={data:e},this._updateWorkerData()}updateData(e){return this._pendingWorkerUpdate.diff=ea(this._pendingWorkerUpdate.diff,e),this._updateWorkerData()}async getData(){return this._data.url&&await this.once(`data`),this._data.geojson?this._data.geojson:{type:`FeatureCollection`,features:Array.from(this._data.updateable.values())}}async getBounds(){return la(await this.getData())}setClusterOptions(e){return this.workerOptions.geojsonVtOptions.cluster=e.cluster,e.clusterRadius!==void 0&&(this.workerOptions.geojsonVtOptions.clusterOptions.radius=this._pixelsToTileUnits(e.clusterRadius)),e.clusterMaxZoom!==void 0&&(this.workerOptions.geojsonVtOptions.clusterOptions.maxZoom=this._getClusterMaxZoom(e.clusterMaxZoom)),this._pendingWorkerUpdate.updateCluster=!0,this._upda