@maptiler/client 1.8.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import At from"quick-lru";function Lt(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class q{constructor(){this._apiKey="",this._fetch=Lt(),this.tileCacheSize=200}set apiKey(e){this._apiKey=e}get apiKey(){return this._apiKey}set fetch(e){this._fetch=e}get fetch(){return this._fetch}}const m=new q,k={AUTO:"auto",ALBANIAN:"sq",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CROATIAN:"hr",CZECH:"cs",DANISH:"da",DUTCH:"nl",ENGLISH:"en",ESPERANTO:"eo",ESTONIAN:"et",FINNISH:"fi",FRENCH:"fr",FRISIAN:"fy",GEORGIAN:"ka",GERMAN:"de",GREEK:"el",HEBREW:"he",HUNGARIAN:"hu",ICELANDIC:"is",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALTESE:"mt",NORWEGIAN:"no",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},Tt=new Set(Object.values(k));function Y(){if(typeof navigator>"u")return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];const t=Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).filter(e=>Tt.has(e));return t.length?t[0]:k.ENGLISH}async function L(t,e={}){if(m.fetch===null)throw new Error("The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch");if(new URL(t).searchParams.get("key").trim()==="")throw new Error("The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com");return m.fetch(t,e)}const y={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(y);class A extends Error{constructor(e,n=""){super(`Call to enpoint ${e.url} failed with the status code ${e.status}. ${n}`),this.res=e}}const E={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function J(t,e){const{language:n}=e;if(n==null)return;const i=Array.from(new Set((Array.isArray(n)?n:[n]).map(a=>a===k.AUTO?Y():a))).join(",");t.set("language",i)}function Z(t,e){const{apiKey:n,limit:i,types:a,excludeTypes:r}=e;t.set("key",n??m.apiKey),i!=null&&t.set("limit",String(i)),a!=null&&t.set("types",a.join(",")),r!=null&&t.set("excludeTypes",String(r)),J(t,e)}function X(t,e){Z(t,e);const{bbox:n,proximity:i,country:a,fuzzyMatch:r,autocomplete:o}=e;n!=null&&t.set("bbox",n.join(",")),i!=null&&t.set("proximity",i==="ip"?i:i.join(",")),a!=null&&t.set("country",a.join(",")),r!=null&&t.set("fuzzyMatch",r?"true":"false"),o!=null&&t.set("autocomplete",o?"true":"false")}async function It(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`geocoding/${encodeURIComponent(t)}.json`,y.maptilerApiURL),{searchParams:i}=n;X(i,e);const a=n.toString(),r=await L(a);if(!r.ok)throw new A(r,E[r.status]??"");return await r.json()}async function wt(t,e={}){if(!Array.isArray(t)||t.length<2)throw new Error("The position must be an array of form [lng, lat].");const n=new URL(`geocoding/${t[0]},${t[1]}.json`,y.maptilerApiURL);Z(n.searchParams,e);const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,E[a.status]??"");return await a.json()}async function Rt(t,e={}){const n=new URL(`geocoding/${t}.json`,y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey),J(n.searchParams,e);const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,E[a.status]??"");return await a.json()}async function vt(t,e={}){if(!t.length)return[];const n=t.map(c=>encodeURIComponent(c)).join(";"),i=new URL(`geocoding/${n}.json`,y.maptilerApiURL),{searchParams:a}=i;X(a,e);const r=i.toString(),o=await L(r);if(!o.ok)throw new A(o,E[o.status]??"");const s=await o.json();return t.length===1?[s]:s}const Ut={forward:It,reverse:wt,byId:Rt,batch:vt,language:k},Q={403:"Key is missing, invalid or restricted"};async function Dt(t={}){const e=new URL("geolocation/ip.json",y.maptilerApiURL);e.searchParams.set("key",t.apiKey??m.apiKey);const n=e.toString(),i=await L(n);if(!i.ok)throw new A(i,i.status in Q?Q[i.status]:"");return await i.json()}const kt={info:Dt},P={403:"Key is missing, invalid or restricted"};async function $t(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The query must be a non-empty string");const n=new URL(`coordinates/search/${t}.json`,y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey),"limit"in e&&n.searchParams.set("limit",e.limit.toString()),"transformations"in e&&n.searchParams.set("transformations",e.transformations.toString()),"exports"in e&&n.searchParams.set("exports",e.exports.toString());const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,a.status in P?P[a.status]:"");return await a.json()}async function Et(t,e={}){const n=(Array.isArray(t[0])?t:[t]).map(o=>`${o[0]},${o[1]}`).join(";"),i=new URL(`coordinates/transform/${n}.json`,y.maptilerApiURL);i.searchParams.set("key",e.apiKey??m.apiKey),"sourceCrs"in e&&i.searchParams.set("s_srs",e.sourceCrs.toString()),"targetCrs"in e&&i.searchParams.set("t_srs",e.targetCrs.toString()),"operations"in e&&i.searchParams.set("ops",(Array.isArray(e.operations)?e.operations:[e.operations]).join("|"));const a=i.toString(),r=await L(a);if(!r.ok)throw new A(r,r.status in P?P[r.status]:"");return await r.json()}const Pt={search:$t,transform:Et},tt={403:"Key is missing, invalid or restricted"};async function Nt(t,e={}){if(typeof t!="string"||t.trim().length===0)throw new Error("The data ID must be a non-empty string");const n=new URL(`data/${encodeURIComponent(t)}/features.json`,y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey);const i=n.toString(),a=await L(i);if(!a.ok)throw new A(a,a.status in tt?tt[a.status]:"");return await a.json()}const Mt={get:Nt};function et(t){const e=/^maptiler:\/\/(.*)/;let n;const i=t.trim();let a;return i.startsWith("http://")||i.startsWith("https://")?a=i:(n=e.exec(i))!==null?a=`https://api.maptiler.com/maps/${n[1]}/style.json`:a=`https://api.maptiler.com/maps/${i}/style.json`,a}class C{constructor(e,n,i,a,r,o){this.name=e,this.variantType=n,this.id=i,this.referenceStyle=a,this.description=r,this.imageURL=o}getName(){return this.name}getFullName(){return`${this.referenceStyle.getName()} ${this.name}`}getType(){return this.variantType}getId(){return this.id}getDescription(){return this.description}getReferenceStyle(){return this.referenceStyle}hasVariant(e){return this.referenceStyle.hasVariant(e)}getVariant(e){return this.referenceStyle.getVariant(e)}getVariants(){return this.referenceStyle.getVariants().filter(e=>e!==this)}getImageURL(){return this.imageURL}getExpandedStyleURL(){return et(this.getId())}}class K{constructor(e,n){this.name=e,this.id=n,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(e){this.variants[e.getType()]=e,this.orderedVariants.push(e)}hasVariant(e){return e in this.variants}getVariant(e){return e in this.variants?this.variants[e]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0]}}const N=[{referenceStyleID:"STREETS",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"streets-v2-night",name:"Night",variantType:"NIGHT",description:"",imageURL:""},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"outdoor-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"WINTER",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"BASIC",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BRIGHT",name:"Bright",description:"",variants:[{id:"bright-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"bright-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"bright-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"bright-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OPENSTREETMAP",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"TOPO",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:""},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]},{referenceStyleID:"VOYAGER",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER",name:"Toner",description:"",variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",description:"",imageURL:""},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:""},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:""}]},{referenceStyleID:"DATAVIZ",name:"Dataviz",description:"",variants:[{id:"dataviz",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"dataviz-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"dataviz-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BACKDROP",name:"Backdrop",description:"",variants:[{id:"backdrop",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"backdrop-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"backdrop-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OCEAN",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]}];function bt(t){return new Proxy(t,{get(e,n,i){return e.hasVariant(n)?e.getVariant(n):n.toString().toUpperCase()===n?t.getDefaultVariant():Reflect.get(e,n,i)}})}function Ct(){const t={};for(let e=0;e<N.length;e+=1){const n=N[e],i=bt(new K(n.name,n.referenceStyleID));for(let a=0;a<n.variants.length;a+=1){const r=n.variants[a],o=new C(r.name,r.variantType,r.id,i,r.description,r.imageURL);i.addVariant(o)}t[n.referenceStyleID]=i}return t}function M(t){if(!t)return nt[N[0].referenceStyleID].getDefaultVariant().getId();if(typeof t=="string"||t instanceof String)return t.trim().toLowerCase();if(t instanceof C)return t.getId();if(t instanceof K)return t.getDefaultVariant().getId()}const nt=Ct();function Kt(t){const e=[];function n(r){(r.type==="LineString"||r.type==="MultiLineString")&&e.push(r)}function i(r){r.geometry&&n(r.geometry)}function a(r){for(const o of r.features)o.type==="Feature"?i(o):o.type==="FeatureCollection"&&a(o)}return t.type==="Feature"?i(t):t.type==="FeatureCollection"?a(t):n(t),e}function xt(t,e,n){let i=e[0],a=e[1],r=n[0]-i,o=n[1]-a;if(r!==0||o!==0){const s=((t[0]-i)*r+(t[1]-a)*o)/(r*r+o*o);s>1?(i=n[0],a=n[1]):s>0&&(i+=r*s,a+=o*s)}return r=t[0]-i,o=t[1]-a,r*r+o*o}function x(t,e,n,i,a){let r=i,o;for(let s=e+1;s<n;s++){const c=xt(t[s],t[e],t[n]);c>r&&(o=s,r=c)}r>i&&(o-e>1&&x(t,e,o,i,a),a.push(t[o]),n-o>1&&x(t,o,n,i,a))}function Ot(t,e){const n=t.length-1,i=[t[0]];return x(t,0,n,e,i),i.push(t[n]),i}function jt(t,e){if(t.length<=2)return t;const n=e!==void 0?e*e:1;return Ot(t,n)}const it={extractLineStrings:Kt,simplify:jt};function O(t,e=!0){let n=`${t[0]},${t[1]}`;return t.length===3&&e&&(n+=`,${t[2]}`),n}function j(t,e=3e3){let n=t.map(r=>r.join(",")).join("|"),i=5e-6;const a=1e-5;for(;n.length>e;)n=it.simplify(t,i).map(r=>`${r[0]},${r[1]}`).join("|"),i+=a;return n}function Ht(t,e,n={}){const i=M(n.style),a=n.hiDPI?"@2x":"",r=n.format??"png";let o=~~(n.width??1024),s=~~(n.height??1024);n.hiDPI&&(o=~~(o/2),s=~~(s/2));const c=new URL(`maps/${encodeURIComponent(i)}/static/${t[0]},${t[1]},${e}/${o}x${s}${a}.${r}`,y.maptilerApiURL);if("attribution"in n&&c.searchParams.set("attribution",n.attribution.toString()),"markers"in n){let h="";const l="markerIcon"in n;l&&(h+=`icon:${n.markerIcon}|`),l&&"markerAnchor"in n&&(h+=`anchor:${n.markerAnchor}|`),l&&n.hiDPI&&(h+="scale:2|");const S=Array.isArray(n.markers[0])?n.markers:[n.markers];h+=S.map(g=>O(g,!l)).join("|"),c.searchParams.set("markers",h)}if("path"in n){let h="";if(h+=`fill:${n.pathFillColor??"none"}|`,"pathStrokeColor"in n&&(h+=`stroke:${n.pathStrokeColor}|`),"pathWidth"in n){const l=n.pathWidth/(n.hiDPI?2:1);h+=`width:${l.toString()}|`}h+=j(n.path),c.searchParams.set("path",h)}return c.searchParams.set("key",n.apiKey??m.apiKey),c.toString()}function Vt(t,e={}){const n=M(e.style),i=e.hiDPI?"@2x":"",a=e.format??"png";let r=~~(e.width??1024),o=~~(e.height??1024);e.hiDPI&&(r=~~(r/2),o=~~(o/2));const s=new URL(`maps/${encodeURIComponent(n)}/static/${t[0]},${t[1]},${t[2]},${t[3]}/${r}x${o}${i}.${a}`,y.maptilerApiURL);if("attribution"in e&&s.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&s.searchParams.set("padding",e.padding.toString()),"markers"in e){let c="";const h="markerIcon"in e;h&&(c+=`icon:${e.markerIcon}|`),h&&"markerAnchor"in e&&(c+=`anchor:${e.markerAnchor}|`),h&&e.hiDPI&&(c+="scale:2|");const l=Array.isArray(e.markers[0])?e.markers:[e.markers];c+=l.map(S=>O(S,!h)).join("|"),s.searchParams.set("markers",c)}if("path"in e){let c="";if(c+=`fill:${e.pathFillColor??"none"}|`,"pathStrokeColor"in e&&(c+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const h=e.pathWidth/(e.hiDPI?2:1);c+=`width:${h.toString()}|`}c+=j(e.path),s.searchParams.set("path",c)}return s.searchParams.set("key",e.apiKey??m.apiKey),s.toString()}function Ft(t={}){if(!("markers"in t)&&!("path"in t))throw new Error("Automatic static maps require markers and/or path to be created.");const e=M(t.style),n=t.hiDPI?"@2x":"",i=t.format??"png";let a=~~(t.width??1024),r=~~(t.height??1024);t.hiDPI&&(a=~~(a/2),r=~~(r/2));const o=new URL(`maps/${encodeURIComponent(e)}/static/auto/${a}x${r}${n}.${i}`,y.maptilerApiURL);if("attribution"in t&&o.searchParams.set("attribution",t.attribution.toString()),"padding"in t&&o.searchParams.set("padding",t.padding.toString()),"markers"in t){let s="";const c="markerIcon"in t;c&&(s+=`icon:${t.markerIcon}|`),c&&"markerAnchor"in t&&(s+=`anchor:${t.markerAnchor}|`),c&&t.hiDPI&&(s+="scale:2|");const h=Array.isArray(t.markers[0])?t.markers:[t.markers];s+=h.map(l=>O(l,!c)).join("|"),o.searchParams.set("markers",s)}if("path"in t){let s="";if(s+=`fill:${t.pathFillColor??"none"}|`,"pathStrokeColor"in t&&(s+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const c=t.pathWidth/(t.hiDPI?2:1);s+=`width:${c.toString()}|`}s+=j(t.path),o.searchParams.set("path",s)}return o.searchParams.set("key",t.apiKey??m.apiKey),o.toString()}const Gt={centered:Ht,bounded:Vt,automatic:Ft},b=63710088e-1,at=2*Math.PI*b;function rt(t){return(180+t)/360}function ot(t){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+t*Math.PI/360)))/360}function st(t){const e=ht(t);return[rt(e[0]),ot(e[1])]}function ct(t){return t*360-180}function pt(t){const e=180-t*360;return 360/Math.PI*Math.atan(Math.exp(e*Math.PI/180))-90}function Bt(t){return[ct(t[0]),pt(t[1])]}function H(t,e){const n=Math.PI/180,i=t[1]*n,a=e[1]*n,r=Math.sin(i)*Math.sin(a)+Math.cos(i)*Math.cos(a)*Math.cos((e[0]-t[0])*n);return b*Math.acos(Math.min(r,1))}function _t(t){const e=Array(t.length);e[0]=0;const n=e.length;for(let i=1;i<n;i++)e[i]=H(t[i-1],t[i])+e[i-1];return e}function ht(t){const e=t[0],n=t[1],i=360,a=((e+180)%i+i)%i-180;return[a===-180?180:a,n]}function lt(t){return at*Math.cos(t*Math.PI/180)}function mt(t,e,n=!0){const i=2**e,a=[t[0]*i,t[1]*i];return n?[~~a[0],~~a[1]]:a}function zt(t,e,n=!0){const i=st(t);return mt(i,e,n)}function $(t){return t*Math.PI/180}function V(t){return t*180/Math.PI}function Wt(t,e,n){const i=H(t,e),a=$(t[0]),r=$(t[1]),o=$(e[0]),s=$(e[1]),c=i/b,h=Math.sin((1-n)*c)/Math.sin(c),l=Math.sin(n*c)/Math.sin(c),S=h*Math.cos(r)*Math.cos(a)+l*Math.cos(s)*Math.cos(o),g=h*Math.cos(r)*Math.sin(a)+l*Math.cos(s)*Math.sin(o),w=h*Math.sin(r)+l*Math.sin(s),v=Math.atan2(w,Math.sqrt(S*S+g*g)),R=Math.atan2(g,S);return[V(R),V(v)]}const F={EARTH_RADIUS:b,EARTH_CIRCUMFERENCE:at,longitudeToMercatorX:rt,latitudeToMercatorY:ot,wgs84ToMercator:st,mercatorXToLongitude:ct,mercatorYToLatitude:pt,mercatorToWgs84:Bt,haversineDistanceWgs84:H,wrapWgs84:ht,circumferenceAtLatitude:lt,mercatorToTileIndex:mt,wgs84ToTileIndex:zt,toRadians:$,toDegrees:V,haversineIntermediateWgs84:Wt,haversineCumulatedDistanceWgs84:_t};let G=null;function B(){return G||(G=new At({maxSize:m.tileCacheSize})),G}async function ut(t){const e=new Blob([t]),n=await createImageBitmap(e),i=document.createElement("canvas"),a=i.getContext("2d");i.width=n.width,i.height=n.height,a.drawImage(n,0,0);const r=a.getImageData(0,0,i.width,i.height);return{pixels:r.data,width:i.width,height:i.height,components:r.data.length/(i.width*i.height)}}function _(){if(m.bufferToPixelData)return m.bufferToPixelData;if(typeof window<"u")return ut;throw new Error("An image file buffer to pixel data parser is necessary. Specify it in `config.bufferToPixelData`")}const qt="tiles/terrain-rgb-v2/tiles.json";let I=null;const z={403:"Key is missing, invalid or restricted"};async function gt(t){const e=new URL(qt,y.maptilerApiURL);e.searchParams.set("key",t);const n=e.toString(),i=await L(n);if(i.ok)return I=await i.json(),I;if(!i.ok)throw new A(i,z[i.status]??"")}async function Yt(t,e={}){const n=e.apiKey??m.apiKey;I||await gt(n);const i=I.maxzoom;let a=~~(e.zoom??i);(a>i||a<0)&&(a=i);const r=F.wgs84ToTileIndex(t,a,!1),o=~~r[0],s=~~r[1];if(!I.tiles.length)throw new Error("Terrain tileJSON tile list is empty.");const c=`terrain_${a.toString()}_${o.toString()}_${s.toString()}`;let h;const l=B();if(l.has(c))h=l.get(c);else{const T=I.tiles[0].replace("{x}",o.toString()).replace("{y}",s.toString()).replace("{z}",a.toString()),u=await L(T);if(!u.ok)throw new A(u,z[u.status]??"");const d=await u.arrayBuffer();h=await _()(d),l.set(c,h)}const S=~~(h.width*(r[0]%1)),g=(~~(h.height*(r[1]%1))*h.width+S)*h.components,w=h.pixels[g],v=h.pixels[g+1],R=h.pixels[g+2],p=-1e4+(w*256*256+v*256+R)*.1;return[t[0],t[1],p]}async function W(t,e={}){const n=e.apiKey??m.apiKey;I||await gt(n);const i=_(),a=I.tiles[0],r=B(),o=I.maxzoom;let s=~~(e.zoom??o);(s>o||s<0)&&(s=o);const c=t.map(p=>F.wgs84ToTileIndex(p,s,!1)),h=c.map(p=>[~~p[0],~~p[1]]).map(p=>`terrain_${s.toString()}_${p[0].toString()}_${p[1].toString()}`),l=Array.from(new Set(h.filter(p=>!r.has(p)))).map(p=>p.split("_").slice(1)),S=l.map(p=>a.replace("{x}",p[1].toString()).replace("{y}",p[2].toString()).replace("{z}",p[0].toString())).map(p=>L(p)),g=(await Promise.allSettled(S)).map(p=>p.status==="fulfilled"?p.value:null).filter(p=>p),w=g.filter(p=>!p.ok);if(g.length!==S.length)throw new Error("Some tiles could not be fetched.");if(w.length)throw new A(w[0],z[w[0].status]??"");const v=await Promise.all(g.map(p=>p.arrayBuffer()));if(!v.every(p=>p.byteLength>0))throw new Error("Some tiles are not available.");(await Promise.all(v.map(p=>i(p)))).forEach((p,T)=>{const u=l[T],d=`terrain_${u[0].toString()}_${u[1].toString()}_${u[2].toString()}`;r.set(d,p)});const R=t.map((p,T)=>{const u=h[T],d=c[T],f=r.get(u),U=Math.min(Math.round(f.width*(d[0]%1)),f.width-1),D=(Math.min(Math.round(f.height*(d[1]%1)),f.height-1)*f.width+U)*f.components,dt=f.pixels[D],ft=f.pixels[D+1],yt=f.pixels[D+2],St=-1e4+(dt*256*256+ft*256+yt)*.1;return[p[0],p[1],~~(St*1e3)/1e3]});if(e.smoothingKernelSize){const p=~~(e.smoothingKernelSize/2)*2+1,T=R.map(d=>d[2]),u=~~(p/2);for(let d=u;d<T.length-u-1;d+=1){let f=0;for(let U=0;U<p;U+=1){const D=T[d-u+U];f+=D}f/=p,R[d][2]=f}}return R}async function Jt(t,e={}){if(t.type!=="LineString")throw new Error("The provided object is not a GeoJSON LineString");const n=structuredClone(t),i=await W(n.coordinates,e);return n.coordinates=i,n}async function Zt(t,e={}){if(t.type!=="MultiLineString")throw new Error("The provided object is not a GeoJSON MultiLineString");const n=structuredClone(t),i=n.coordinates.map(c=>c.length),a=n.coordinates.flat(),r=await W(a,e),o=[];let s=0;for(const c of i)o.push(r.slice(s,s+c)),s+=c;return n.coordinates=o,n}const Xt={at:Yt,batch:W,fromLineString:Jt,fromMultiLineString:Zt};export{q as ClientConfig,k as LanguageGeocoding,nt as MapStyle,C as MapStyleVariant,K as ReferenceMapStyle,A as ServiceError,ut as bufferToPixelDataBrowser,lt as circumferenceAtLatitude,m as config,Pt as coordinates,Mt as data,Xt as elevation,et as expandMapStyle,Ut as geocoding,kt as geolocation,Y as getAutoLanguageGeocoding,_ as getBufferToPixelDataParser,B as getTileCache,N as mapStylePresetList,F as math,it as misc,Gt as staticMaps,M as styleToStyle};
1
+ import we from"quick-lru";function Ee(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class X{constructor(){this._apiKey="",this._fetch=Ee(),this.tileCacheSize=200}set apiKey(n){this._apiKey=n}get apiKey(){return this._apiKey}set fetch(n){this._fetch=n}get fetch(){return this._fetch}}const m=new X,ee={AUTO:{code:null,flag:"auto",name:"Auto",latin:!1,isMode:!0,geocoding:!0},LATIN:{code:"latin",flag:"name:latin",name:"Latin",latin:!0,isMode:!1,geocoding:!1},NON_LATIN:{code:"nonlatin",flag:"name:nonlatin",name:"Non Latin",latin:!1,isMode:!1,geocoding:!1},LOCAL:{code:null,flag:"name",name:"Local",latin:!0,isMode:!1,geocoding:!1}},ne={ALBANIAN:{code:"sq",flag:"name:sq",name:"Albanian",latin:!0,isMode:!1,geocoding:!0},AMHARIC:{code:"am",flag:"name:am",name:"Amharic",latin:!1,isMode:!1,geocoding:!1},ARABIC:{code:"ar",flag:"name:ar",name:"Arabic",latin:!1,isMode:!1,geocoding:!0},ARMENIAN:{code:"hy",flag:"name:hy",name:"Armenian",latin:!1,isMode:!1,geocoding:!0},AZERBAIJANI:{code:"az",flag:"name:az",name:"Azerbaijani",latin:!0,isMode:!1,geocoding:!0},BASQUE:{code:"eu",flag:"name:eu",name:"Basque",latin:!0,isMode:!1,geocoding:!1},BELARUSIAN:{code:"be",flag:"name:be",name:"Belarusian",latin:!1,isMode:!1,geocoding:!0},BENGALI:{code:"bn",flag:"name:bn",name:"Bengali",latin:!0,isMode:!1,geocoding:!1},BOSNIAN:{code:"bs",flag:"name:bs",name:"Bosnian",latin:!0,isMode:!1,geocoding:!0},BRETON:{code:"br",flag:"name:br",name:"Breton",latin:!0,isMode:!1,geocoding:!0},BULGARIAN:{code:"bg",flag:"bg",name:"Bulgarian",latin:!1,isMode:!1,geocoding:!0},CATALAN:{code:"ca",flag:"name:ca",name:"Catalan",latin:!0,isMode:!1,geocoding:!0},CHINESE:{code:"zh",flag:"name:zh",name:"Chinese",latin:!1,isMode:!1,geocoding:!0},TRADITIONAL_CHINESE:{code:"zh-Hant",flag:"name:zh-Hant",name:"Chinese (traditional)",latin:!1,isMode:!1,geocoding:!1},SIMPLIFIED_CHINESE:{code:"zh-Hans",flag:"name:zh-Hans",name:"Chinese (simplified)",latin:!1,isMode:!1,geocoding:!1},CORSICAN:{code:"co",flag:"name:co",name:"Corsican",latin:!0,isMode:!1,geocoding:!1},CROATIAN:{code:"hr",flag:"name:hr",name:"Croatian",latin:!0,isMode:!1,geocoding:!0},CZECH:{code:"cs",flag:"name:cs",name:"Czech",latin:!0,isMode:!1,geocoding:!0},DANISH:{code:"da",flag:"name:da",name:"Danish",latin:!0,isMode:!1,geocoding:!0},DUTCH:{code:"nl",flag:"name:nl",name:"Dutch",latin:!0,isMode:!1,geocoding:!0},GERMAN:{code:"de",flag:"name:de",name:"German",latin:!0,isMode:!1,geocoding:!0},GREEK:{code:"el",flag:"name:el",name:"Greek",latin:!1,isMode:!1,geocoding:!0},ENGLISH:{code:"en",flag:"name:en",name:"English",latin:!0,isMode:!1,geocoding:!0},ESPERANTO:{code:"eo",flag:"name:eo",name:"Esperanto",latin:!0,isMode:!1,geocoding:!0},ESTONIAN:{code:"et",flag:"name:et",name:"Estonian",latin:!0,isMode:!1,geocoding:!0},FINNISH:{code:"fi",flag:"name:fi",name:"Finnish",latin:!0,isMode:!1,geocoding:!0},FRENCH:{code:"fr",flag:"name:fr",name:"French",latin:!0,isMode:!1,geocoding:!0},FRISIAN:{code:"fy",flag:"name:fy",name:"Frisian (West)",latin:!0,isMode:!1,geocoding:!0},GEORGIAN:{code:"ka",flag:"name:ka",name:"Georgian",latin:!1,isMode:!1,geocoding:!0},HEBREW:{code:"he",flag:"name:he",name:"Hebrew",latin:!1,isMode:!1,geocoding:!0},HINDI:{code:"hi",flag:"name:hi",name:"Hindi",latin:!1,isMode:!1,geocoding:!1},HUNGARIAN:{code:"hu",flag:"name:hu",name:"Hungarian",latin:!0,isMode:!1,geocoding:!0},ICELANDIC:{code:"is",flag:"name:is",name:"Icelandic",latin:!0,isMode:!1,geocoding:!0},INDONESIAN:{code:"id",flag:"name:id",name:"Indonesian",latin:!0,isMode:!1,geocoding:!1},IRISH:{code:"ga",flag:"name:ga",name:"Irish",latin:!0,isMode:!1,geocoding:!0},ITALIAN:{code:"it",flag:"name:it",name:"Italian",latin:!0,isMode:!1,geocoding:!0},JAPANESE:{code:"ja",flag:"name:ja",name:"Japanese",latin:!1,isMode:!1,geocoding:!0},JAPANESE_HIRAGANA:{code:"ja-Hira",flag:"name:ja-Hira",name:"Japanese Hiragana form",latin:!1,isMode:!1,geocoding:!1},JAPANESE_2018:{code:"ja-Latn",flag:"name:ja-Latn",name:"Japanese (Latin 2018)",latin:!0,isMode:!1,geocoding:!1},JAPANESE_KANA:{code:"ja_kana",flag:"name:ja_kana",name:"Japanese (Kana)",latin:!1,isMode:!1,geocoding:!1},JAPANESE_LATIN:{code:"ja_rm",flag:"name:ja_rm",name:"Japanese (Latin script)",latin:!0,isMode:!1,geocoding:!1},KANNADA:{code:"kn",flag:"name:kn",name:"Kannada",latin:!0,isMode:!1,geocoding:!0},KAZAKH:{code:"kk",flag:"name:kk",name:"Kazakh",latin:!1,isMode:!1,geocoding:!0},KOREAN:{code:"ko",flag:"name:ko",name:"Korean",latin:!1,isMode:!1,geocoding:!0},KOREAN_LATIN:{code:"ko-Latn",flag:"name:ko-Latn",name:"Korean (Latin script)",latin:!0,isMode:!1,geocoding:!1},KURDISH:{code:"ku",flag:"name:ku",name:"Kurdish",latin:!0,isMode:!1,geocoding:!1},CLASSICAL_LATIN:{code:"la",flag:"name:la",name:"Latin",latin:!0,isMode:!1,geocoding:!0},LATVIAN:{code:"lv",flag:"name:lv",name:"Latvian",latin:!0,isMode:!1,geocoding:!0},LITHUANIAN:{code:"lt",flag:"name:lt",name:"Lithuanian",latin:!0,isMode:!1,geocoding:!0},LUXEMBOURGISH:{code:"lb",flag:"name:lb",name:"Luxembourgish",latin:!0,isMode:!1,geocoding:!0},MACEDONIAN:{code:"mk",flag:"name:mk",name:"Macedonian",latin:!1,isMode:!1,geocoding:!0},MALAYALAM:{code:"ml",flag:"name:ml",name:"Malayalam",latin:!1,isMode:!1,geocoding:!1},MALTESE:{code:"mt",flag:"name:mt",name:"Maltese",latin:!0,isMode:!1,geocoding:!0},NORWEGIAN:{code:"no",flag:"name:no",name:"Norwegian",latin:!0,isMode:!1,geocoding:!0},OCCITAN:{code:"oc",flag:"name:oc",name:"Occitan",latin:!0,isMode:!1,geocoding:!1},PERSIAN:{code:"fa",flag:"name:fa",name:"Persian",latin:!1,isMode:!1,geocoding:!1},POLISH:{code:"pl",flag:"name:pl",name:"Polish",latin:!0,isMode:!1,geocoding:!0},PORTUGUESE:{code:"pt",flag:"name:pt",name:"Portuguese",latin:!0,isMode:!1,geocoding:!0},PUNJABI:{code:"pa",flag:"name:pa",name:"Punjabi",latin:!1,isMode:!1,geocoding:!1},WESTERN_PUNJABI:{code:"pnb",flag:"name:pnb",name:"Western Punjabi",latin:!1,isMode:!1,geocoding:!1},ROMANIAN:{code:"ro",flag:"name:ro",name:"Romanian",latin:!0,isMode:!1,geocoding:!0},ROMANSH:{code:"rm",flag:"name:rm",name:"Romansh",latin:!0,isMode:!1,geocoding:!0},RUSSIAN:{code:"ru",flag:"name:ru",name:"Russian",latin:!1,isMode:!1,geocoding:!0},SERBIAN_CYRILLIC:{code:"sr",flag:"name:sr",name:"Serbian (Cyrillic script)",latin:!1,isMode:!1,geocoding:!0},SERBIAN_LATIN:{code:"sr-Latn",flag:"name:sr-Latn",name:"Serbian (Latin script)",latin:!0,isMode:!1,geocoding:!1},SCOTTISH_GAELIC:{code:"gd",flag:"name:gd",name:"Scottish Gaelic",latin:!0,isMode:!1,geocoding:!0},SLOVAK:{code:"sk",flag:"name:sk",name:"Slovak",latin:!0,isMode:!1,geocoding:!0},SLOVENE:{code:"sl",flag:"name:sl",name:"Slovene",latin:!0,isMode:!1,geocoding:!0},SPANISH:{code:"es",flag:"name:es",name:"Spanish",latin:!0,isMode:!1,geocoding:!0},SWEDISH:{code:"sv",flag:"name:sv",name:"Swedish",latin:!0,isMode:!1,geocoding:!0},TAMIL:{code:"ta",flag:"name:ta",name:"Tamil",latin:!1,isMode:!1,geocoding:!1},TELUGU:{code:"te",flag:"name:te",name:"Telugu",latin:!1,isMode:!1,geocoding:!1},THAI:{code:"th",flag:"name:th",name:"Thai",latin:!1,isMode:!1,geocoding:!0},TURKISH:{code:"tr",flag:"name:tr",name:"Turkish",latin:!0,isMode:!1,geocoding:!0},UKRAINIAN:{code:"uk",flag:"name:uk",name:"Ukrainian",latin:!1,isMode:!1,geocoding:!0},VIETNAMESE:{code:"vi",flag:"name:vi",name:"Vietnamese (Latin script)",latin:!0,isMode:!1,geocoding:!1},WELSH:{code:"cy",flag:"name:cy",name:"Welsh",latin:!0,isMode:!1,geocoding:!0}},I={...ee,...ne};function te(e,n=I){return e in n?e[e]:null}function k(e,n=I){for(const t of Object.values(n))if(t.code===e)return t;return null}function N(e,n=I){for(const t of Object.values(n))if(t.flag===e)return t;return null}function O(){if(typeof navigator>"u"){const e=Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];return k(e)??I.ENGLISH}return Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).map(e=>k(e)).filter(e=>e)[0]??I.ENGLISH}function j(e){return e!==null&&typeof e=="object"&&"code"in e&&"flag"in e&&"name"in e&&"latin"in e&&"isMode"in e&&"geocoding"in e&&(typeof e.code=="string"||e.code===null)&&typeof e.flag=="string"&&typeof e.name=="string"&&typeof e.latin=="boolean"&&typeof e.isMode=="boolean"&&typeof e.geocoding=="boolean"}function H(e,n=I){return j(e)?N(e.flag,n):typeof e!="string"?null:te(e,n)||k(e,n)||N(e,n)||null}function Ue(e,n,t=I){const a=H(e,t),i=H(n,t);return a&&i&&a.flag===i.flag}async function S(e,n={}){if(m.fetch===null)throw new Error("The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch");if(new URL(e).searchParams.get("key").trim()==="")throw new Error("The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com");return m.fetch(e,n)}const y={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(y);class L extends Error{constructor(n,t=""){super(`Call to enpoint ${n.url} failed with the status code ${n.status}. ${t}`),this.res=n}}const P={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function ae(e,n){const{language:t}=n;if(t===void 0)return;const a=(Array.isArray(t)?t:[t]).map(o=>ke(o)).filter(o=>o),i=Array.from(new Set(a)).join(",");e.set("language",i)}function ke(e){const n=e===I.AUTO.flag?O():typeof e=="string"?k(e):j(e)?e.flag===I.AUTO.flag?O():N(e.flag):null;return n?.geocoding?n.code:null}function ie(e,n){const{apiKey:t,limit:a,types:i,excludeTypes:o}=n;e.set("key",t??m.apiKey),a!==void 0&&e.set("limit",String(a)),i!==void 0&&e.set("types",i.join(",")),o!==void 0&&e.set("excludeTypes",String(o)),ae(e,n)}function oe(e,n){ie(e,n);const{bbox:t,proximity:a,country:i,fuzzyMatch:o,autocomplete:r}=n;t!==void 0&&e.set("bbox",t.join(",")),a!==void 0&&e.set("proximity",a==="ip"?a:a.join(",")),i!==void 0&&e.set("country",i.join(",")),o!==void 0&&e.set("fuzzyMatch",o?"true":"false"),r!==void 0&&e.set("autocomplete",r?"true":"false")}async function De(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new Error("The query must be a non-empty string");const t=new URL(`geocoding/${encodeURIComponent(e)}.json`,y.maptilerApiURL);oe(t.searchParams,n);const a=await S(t.toString());if(!a.ok)throw new L(a,P[a.status]??"");return await a.json()}async function Ne(e,n={}){if(!Array.isArray(e)||e.length<2)throw new Error("The position must be an array of form [lng, lat].");const t=new URL(`geocoding/${e[0]},${e[1]}.json`,y.maptilerApiURL);ie(t.searchParams,n);const a=await S(t.toString());if(!a.ok)throw new L(a,P[a.status]??"");return await a.json()}async function Pe(e,n={}){const t=new URL(`geocoding/${e}.json`,y.maptilerApiURL);t.searchParams.set("key",n.apiKey??m.apiKey),ae(t.searchParams,n);const a=await S(t.toString());if(!a.ok)throw new L(a,P[a.status]??"");return await a.json()}async function $e(e,n={}){if(!e.length)return[];const t=e.map(r=>encodeURIComponent(r)).join(";"),a=new URL(`geocoding/${t}.json`,y.maptilerApiURL);oe(a.searchParams,n);const i=await S(a.toString());if(!i.ok)throw new L(i,P[i.status]??"");const o=await i.json();return e.length===1?[o]:o}const be={forward:De,reverse:Ne,byId:Pe,batch:$e},re={403:"Key is missing, invalid or restricted"};async function Ce(e={}){const n=new URL("geolocation/ip.json",y.maptilerApiURL);n.searchParams.set("key",e.apiKey??m.apiKey);const t=n.toString(),a=await S(t);if(!a.ok)throw new L(a,a.status in re?re[a.status]:"");return await a.json()}const Ke={info:Ce},$={403:"Key is missing, invalid or restricted"};async function Oe(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new Error("The query must be a non-empty string");const t=new URL(`coordinates/search/${e}.json`,y.maptilerApiURL);t.searchParams.set("key",n.apiKey??m.apiKey),"limit"in n&&t.searchParams.set("limit",n.limit.toString()),"transformations"in n&&t.searchParams.set("transformations",n.transformations.toString()),"exports"in n&&t.searchParams.set("exports",n.exports.toString());const a=t.toString(),i=await S(a);if(!i.ok)throw new L(i,i.status in $?$[i.status]:"");return await i.json()}async function je(e,n={}){const t=(Array.isArray(e[0])?e:[e]).map(r=>`${r[0]},${r[1]}`).join(";"),a=new URL(`coordinates/transform/${t}.json`,y.maptilerApiURL);a.searchParams.set("key",n.apiKey??m.apiKey),"sourceCrs"in n&&a.searchParams.set("s_srs",n.sourceCrs.toString()),"targetCrs"in n&&a.searchParams.set("t_srs",n.targetCrs.toString()),"operations"in n&&a.searchParams.set("ops",(Array.isArray(n.operations)?n.operations:[n.operations]).join("|"));const i=a.toString(),o=await S(i);if(!o.ok)throw new L(o,o.status in $?$[o.status]:"");return await o.json()}const He={search:Oe,transform:je},se={403:"Key is missing, invalid or restricted"};async function xe(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new Error("The data ID must be a non-empty string");const t=new URL(`data/${encodeURIComponent(e)}/features.json`,y.maptilerApiURL);t.searchParams.set("key",n.apiKey??m.apiKey);const a=t.toString(),i=await S(a);if(!i.ok)throw new L(i,i.status in se?se[i.status]:"");return await i.json()}const Fe={get:xe};function ce(e){const n=/^maptiler:\/\/(.*)/;let t;const a=e.trim();let i;return a.startsWith("http://")||a.startsWith("https://")?i=a:(t=n.exec(a))!==null?i=`https://api.maptiler.com/maps/${t[1]}/style.json`:i=`https://api.maptiler.com/maps/${a}/style.json`,i}class x{constructor(n,t,a,i,o,r){this.name=n,this.variantType=t,this.id=a,this.referenceStyle=i,this.description=o,this.imageURL=r}getName(){return this.name}getFullName(){return`${this.referenceStyle.getName()} ${this.name}`}getType(){return this.variantType}getId(){return this.id}getDescription(){return this.description}getReferenceStyle(){return this.referenceStyle}hasVariant(n){return this.referenceStyle.hasVariant(n)}getVariant(n){return this.referenceStyle.getVariant(n)}getVariants(){return this.referenceStyle.getVariants().filter(n=>n!==this)}getImageURL(){return this.imageURL}getExpandedStyleURL(){return ce(this.getId())}}class F{constructor(n,t){this.name=n,this.id=t,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(n){this.variants[n.getType()]=n,this.orderedVariants.push(n)}hasVariant(n){return n in this.variants}getVariant(n){return n in this.variants?this.variants[n]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0]}}const b=[{referenceStyleID:"STREETS",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"streets-v2-night",name:"Night",variantType:"NIGHT",description:"",imageURL:""},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"outdoor-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"WINTER",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"BASIC",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BRIGHT",name:"Bright",description:"",variants:[{id:"bright-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"bright-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"bright-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"bright-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"OPENSTREETMAP",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"TOPO",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:""},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]},{referenceStyleID:"VOYAGER",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER",name:"Toner",description:"",variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",description:"",imageURL:""},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:""},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:""}]},{referenceStyleID:"DATAVIZ",name:"Dataviz",description:"",variants:[{id:"dataviz",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"dataviz-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"dataviz-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"BACKDROP",name:"Backdrop",description:"",variants:[{id:"backdrop",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"backdrop-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"backdrop-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OCEAN",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]}];function _e(e){return new Proxy(e,{get(n,t,a){return n.hasVariant(t)?n.getVariant(t):t.toString().toUpperCase()===t?e.getDefaultVariant():Reflect.get(n,t,a)}})}function Be(){const e={};for(let n=0;n<b.length;n+=1){const t=b[n],a=_e(new F(t.name,t.referenceStyleID));for(let i=0;i<t.variants.length;i+=1){const o=t.variants[i],r=new x(o.name,o.variantType,o.id,a,o.description,o.imageURL);a.addVariant(r)}e[t.referenceStyleID]=a}return e}function C(e){if(!e)return ge[b[0].referenceStyleID].getDefaultVariant().getId();if(typeof e=="string"||e instanceof String)return e.trim().toLowerCase();if(e instanceof x)return e.getId();if(e instanceof F)return e.getDefaultVariant().getId()}const ge=Be();function Ge(e){const n=[];function t(o){(o.type==="LineString"||o.type==="MultiLineString")&&n.push(o)}function a(o){o.geometry&&t(o.geometry)}function i(o){for(const r of o.features)r.type==="Feature"?a(r):r.type==="FeatureCollection"&&i(r)}return e.type==="Feature"?a(e):e.type==="FeatureCollection"?i(e):t(e),n}function ze(e,n,t){let a=n[0],i=n[1],o=t[0]-a,r=t[1]-i;if(o!==0||r!==0){const s=((e[0]-a)*o+(e[1]-i)*r)/(o*o+r*r);s>1?(a=t[0],i=t[1]):s>0&&(a+=o*s,i+=r*s)}return o=e[0]-a,r=e[1]-i,o*o+r*r}function _(e,n,t,a,i){let o=a,r;for(let s=n+1;s<t;s++){const c=ze(e[s],e[n],e[t]);c>o&&(r=s,o=c)}o>a&&(r-n>1&&_(e,n,r,a,i),i.push(e[r]),t-r>1&&_(e,r,t,a,i))}function Ve(e,n){const t=e.length-1,a=[e[0]];return _(e,0,t,n,a),a.push(e[t]),a}function We(e,n){if(e.length<=2)return e;const t=n!==void 0?n*n:1;return Ve(e,t)}const le={extractLineStrings:Ge,simplify:We};function B(e,n=!0){let t=`${e[0]},${e[1]}`;return e.length===3&&n&&(t+=`,${e[2]}`),t}function G(e,n=3e3){let t=e.map(o=>o.join(",")).join("|"),a=5e-6;const i=1e-5;for(;t.length>n;)t=le.simplify(e,a).map(o=>`${o[0]},${o[1]}`).join("|"),a+=i;return t}function Je(e,n,t={}){const a=C(t.style),i=t.hiDPI?"@2x":"",o=t.format??"png";let r=~~(t.width??1024),s=~~(t.height??1024);t.hiDPI&&(r=~~(r/2),s=~~(s/2));const c=new URL(`maps/${encodeURIComponent(a)}/static/${e[0]},${e[1]},${n}/${r}x${s}${i}.${o}`,y.maptilerApiURL);if("attribution"in t&&c.searchParams.set("attribution",t.attribution.toString()),"markers"in t){let l="";const d="markerIcon"in t;d&&(l+=`icon:${t.markerIcon}|`),d&&"markerAnchor"in t&&(l+=`anchor:${t.markerAnchor}|`),d&&t.hiDPI&&(l+="scale:2|");const A=Array.isArray(t.markers[0])?t.markers:[t.markers];l+=A.map(h=>B(h,!d)).join("|"),c.searchParams.set("markers",l)}if("path"in t){let l="";if(l+=`fill:${t.pathFillColor??"none"}|`,"pathStrokeColor"in t&&(l+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const d=t.pathWidth/(t.hiDPI?2:1);l+=`width:${d.toString()}|`}l+=G(t.path),c.searchParams.set("path",l)}return c.searchParams.set("key",t.apiKey??m.apiKey),c.toString()}function qe(e,n={}){const t=C(n.style),a=n.hiDPI?"@2x":"",i=n.format??"png";let o=~~(n.width??1024),r=~~(n.height??1024);n.hiDPI&&(o=~~(o/2),r=~~(r/2));const s=new URL(`maps/${encodeURIComponent(t)}/static/${e[0]},${e[1]},${e[2]},${e[3]}/${o}x${r}${a}.${i}`,y.maptilerApiURL);if("attribution"in n&&s.searchParams.set("attribution",n.attribution.toString()),"padding"in n&&s.searchParams.set("padding",n.padding.toString()),"markers"in n){let c="";const l="markerIcon"in n;l&&(c+=`icon:${n.markerIcon}|`),l&&"markerAnchor"in n&&(c+=`anchor:${n.markerAnchor}|`),l&&n.hiDPI&&(c+="scale:2|");const d=Array.isArray(n.markers[0])?n.markers:[n.markers];c+=d.map(A=>B(A,!l)).join("|"),s.searchParams.set("markers",c)}if("path"in n){let c="";if(c+=`fill:${n.pathFillColor??"none"}|`,"pathStrokeColor"in n&&(c+=`stroke:${n.pathStrokeColor}|`),"pathWidth"in n){const l=n.pathWidth/(n.hiDPI?2:1);c+=`width:${l.toString()}|`}c+=G(n.path),s.searchParams.set("path",c)}return s.searchParams.set("key",n.apiKey??m.apiKey),s.toString()}function Ye(e={}){if(!("markers"in e)&&!("path"in e))throw new Error("Automatic static maps require markers and/or path to be created.");const n=C(e.style),t=e.hiDPI?"@2x":"",a=e.format??"png";let i=~~(e.width??1024),o=~~(e.height??1024);e.hiDPI&&(i=~~(i/2),o=~~(o/2));const r=new URL(`maps/${encodeURIComponent(n)}/static/auto/${i}x${o}${t}.${a}`,y.maptilerApiURL);if("attribution"in e&&r.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&r.searchParams.set("padding",e.padding.toString()),"markers"in e){let s="";const c="markerIcon"in e;c&&(s+=`icon:${e.markerIcon}|`),c&&"markerAnchor"in e&&(s+=`anchor:${e.markerAnchor}|`),c&&e.hiDPI&&(s+="scale:2|");const l=Array.isArray(e.markers[0])?e.markers:[e.markers];s+=l.map(d=>B(d,!c)).join("|"),r.searchParams.set("markers",s)}if("path"in e){let s="";if(s+=`fill:${e.pathFillColor??"none"}|`,"pathStrokeColor"in e&&(s+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const c=e.pathWidth/(e.hiDPI?2:1);s+=`width:${c.toString()}|`}s+=G(e.path),r.searchParams.set("path",s)}return r.searchParams.set("key",e.apiKey??m.apiKey),r.toString()}const Ze={centered:Je,bounded:qe,automatic:Ye},K=63710088e-1,de=2*Math.PI*K;function me(e){return(180+e)/360}function fe(e){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}function he(e){const n=ye(e);return[me(n[0]),fe(n[1])]}function pe(e){return e*360-180}function ue(e){const n=180-e*360;return 360/Math.PI*Math.atan(Math.exp(n*Math.PI/180))-90}function Qe(e){return[pe(e[0]),ue(e[1])]}function z(e,n){const t=Math.PI/180,a=e[1]*t,i=n[1]*t,o=Math.sin(a)*Math.sin(i)+Math.cos(a)*Math.cos(i)*Math.cos((n[0]-e[0])*t);return K*Math.acos(Math.min(o,1))}function Xe(e){const n=Array(e.length);n[0]=0;const t=n.length;for(let a=1;a<t;a++)n[a]=z(e[a-1],e[a])+n[a-1];return n}function ye(e){const n=e[0],t=e[1],a=360,i=((n+180)%a+a)%a-180;return[i===-180?180:i,t]}function Ae(e){return de*Math.cos(e*Math.PI/180)}function Le(e,n,t=!0){const a=2**n,i=[e[0]*a,e[1]*a];return t?[~~i[0],~~i[1]]:i}function en(e,n,t=!0){const a=he(e);return Le(a,n,t)}function D(e){return e*Math.PI/180}function V(e){return e*180/Math.PI}function nn(e,n,t){const a=z(e,n),i=D(e[0]),o=D(e[1]),r=D(n[0]),s=D(n[1]),c=a/K,l=Math.sin((1-t)*c)/Math.sin(c),d=Math.sin(t*c)/Math.sin(c),A=l*Math.cos(o)*Math.cos(i)+d*Math.cos(s)*Math.cos(r),h=l*Math.cos(o)*Math.sin(i)+d*Math.cos(s)*Math.sin(r),v=l*Math.sin(o)+d*Math.sin(s),w=Math.atan2(v,Math.sqrt(A*A+h*h)),R=Math.atan2(h,A);return[V(R),V(w)]}const W={EARTH_RADIUS:K,EARTH_CIRCUMFERENCE:de,longitudeToMercatorX:me,latitudeToMercatorY:fe,wgs84ToMercator:he,mercatorXToLongitude:pe,mercatorYToLatitude:ue,mercatorToWgs84:Qe,haversineDistanceWgs84:z,wrapWgs84:ye,circumferenceAtLatitude:Ae,mercatorToTileIndex:Le,wgs84ToTileIndex:en,toRadians:D,toDegrees:V,haversineIntermediateWgs84:nn,haversineCumulatedDistanceWgs84:Xe};let J=null;function q(){return J||(J=new we({maxSize:m.tileCacheSize})),J}async function Se(e){const n=new Blob([e]),t=await createImageBitmap(n),a=document.createElement("canvas"),i=a.getContext("2d");a.width=t.width,a.height=t.height,i.drawImage(t,0,0);const o=i.getImageData(0,0,a.width,a.height);return{pixels:o.data,width:a.width,height:a.height,components:o.data.length/(a.width*a.height)}}function Y(){if(m.bufferToPixelData)return m.bufferToPixelData;if(typeof window<"u")return Se;throw new Error("An image file buffer to pixel data parser is necessary. Specify it in `config.bufferToPixelData`")}const tn="tiles/terrain-rgb-v2/tiles.json";let T=null;const Z={403:"Key is missing, invalid or restricted"};async function Ie(e){const n=new URL(tn,y.maptilerApiURL);n.searchParams.set("key",e);const t=n.toString(),a=await S(t);if(a.ok)return T=await a.json(),T;if(!a.ok)throw new L(a,Z[a.status]??"")}async function an(e,n={}){const t=n.apiKey??m.apiKey;T||await Ie(t);const a=T.maxzoom;let i=~~(n.zoom??a);(i>a||i<0)&&(i=a);const o=W.wgs84ToTileIndex(e,i,!1),r=~~o[0],s=~~o[1];if(!T.tiles.length)throw new Error("Terrain tileJSON tile list is empty.");const c=`terrain_${i.toString()}_${r.toString()}_${s.toString()}`;let l;const d=q();if(d.has(c))l=d.get(c);else{const M=T.tiles[0].replace("{x}",r.toString()).replace("{y}",s.toString()).replace("{z}",i.toString()),f=await S(M);if(!f.ok)throw new L(f,Z[f.status]??"");const p=await f.arrayBuffer();l=await Y()(p),d.set(c,l)}const A=~~(l.width*(o[0]%1)),h=(~~(l.height*(o[1]%1))*l.width+A)*l.components,v=l.pixels[h],w=l.pixels[h+1],R=l.pixels[h+2],g=-1e4+(v*256*256+w*256+R)*.1;return[e[0],e[1],g]}async function Q(e,n={}){const t=n.apiKey??m.apiKey;T||await Ie(t);const a=Y(),i=T.tiles[0],o=q(),r=T.maxzoom;let s=~~(n.zoom??r);(s>r||s<0)&&(s=r);const c=e.map(g=>W.wgs84ToTileIndex(g,s,!1)),l=c.map(g=>[~~g[0],~~g[1]]).map(g=>`terrain_${s.toString()}_${g[0].toString()}_${g[1].toString()}`),d=Array.from(new Set(l.filter(g=>!o.has(g)))).map(g=>g.split("_").slice(1)),A=d.map(g=>i.replace("{x}",g[1].toString()).replace("{y}",g[2].toString()).replace("{z}",g[0].toString())).map(g=>S(g)),h=(await Promise.allSettled(A)).map(g=>g.status==="fulfilled"?g.value:null).filter(g=>g),v=h.filter(g=>!g.ok);if(h.length!==A.length)throw new Error("Some tiles could not be fetched.");if(v.length)throw new L(v[0],Z[v[0].status]??"");const w=await Promise.all(h.map(g=>g.arrayBuffer()));if(!w.every(g=>g.byteLength>0))throw new Error("Some tiles are not available.");(await Promise.all(w.map(g=>a(g)))).forEach((g,M)=>{const f=d[M],p=`terrain_${f[0].toString()}_${f[1].toString()}_${f[2].toString()}`;o.set(p,g)});const R=e.map((g,M)=>{const f=l[M],p=c[M],u=o.get(f),E=Math.min(Math.round(u.width*(p[0]%1)),u.width-1),U=(Math.min(Math.round(u.height*(p[1]%1)),u.height-1)*u.width+E)*u.components,Me=u.pixels[U],Te=u.pixels[U+1],ve=u.pixels[U+2],Re=-1e4+(Me*256*256+Te*256+ve)*.1;return[g[0],g[1],~~(Re*1e3)/1e3]});if(n.smoothingKernelSize){const g=~~(n.smoothingKernelSize/2)*2+1,M=R.map(p=>p[2]),f=~~(g/2);for(let p=f;p<M.length-f-1;p+=1){let u=0;for(let E=0;E<g;E+=1){const U=M[p-f+E];u+=U}u/=g,R[p][2]=u}}return R}async function on(e,n={}){if(e.type!=="LineString")throw new Error("The provided object is not a GeoJSON LineString");const t=structuredClone(e),a=await Q(t.coordinates,n);return t.coordinates=a,t}async function rn(e,n={}){if(e.type!=="MultiLineString")throw new Error("The provided object is not a GeoJSON MultiLineString");const t=structuredClone(e),a=t.coordinates.map(c=>c.length),i=t.coordinates.flat(),o=await Q(i,n),r=[];let s=0;for(const c of a)r.push(o.slice(s,s+c)),s+=c;return t.coordinates=r,t}const sn={at:an,batch:Q,fromLineString:on,fromMultiLineString:rn};export{X as ClientConfig,ne as ISOLanguage,I as Language,ge as MapStyle,x as MapStyleVariant,ee as NonISOLanguage,F as ReferenceMapStyle,L as ServiceError,Ue as areSameLanguages,Se as bufferToPixelDataBrowser,Ae as circumferenceAtLatitude,m as config,He as coordinates,Fe as data,sn as elevation,ce as expandMapStyle,be as geocoding,Ke as geolocation,O as getAutoLanguage,Y as getBufferToPixelDataParser,k as getLanguageInfoFromCode,N as getLanguageInfoFromFlag,te as getLanguageInfoFromKey,q as getTileCache,j as isLanguageInfo,b as mapStylePresetList,W as math,le as misc,Ze as staticMaps,C as styleToStyle,H as toLanguageInfo};