@maptiler/client 3.1.0-rc.6 → 4.0.0-rc.1
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.
|
@@ -75,6 +75,10 @@ declare class ClientConfig {
|
|
|
75
75
|
* will be automatically resolved.
|
|
76
76
|
*/
|
|
77
77
|
private _fetch;
|
|
78
|
+
/**
|
|
79
|
+
* Whether to use the EU-based `api.maptiler.eu` host instead of the default `api.maptiler.com`
|
|
80
|
+
*/
|
|
81
|
+
private _useEuEndpoints;
|
|
78
82
|
/**
|
|
79
83
|
* Number of tiles to keep in cache
|
|
80
84
|
*/
|
|
@@ -96,6 +100,24 @@ declare class ClientConfig {
|
|
|
96
100
|
* Get the fetch fucntion
|
|
97
101
|
*/
|
|
98
102
|
get fetch(): FetchFunction | null;
|
|
103
|
+
/**
|
|
104
|
+
* Switch between the default `api.maptiler.com` host and the EU-based `api.maptiler.eu` host.
|
|
105
|
+
* Set to `false` to switch back to the default.
|
|
106
|
+
*/
|
|
107
|
+
set useEuEndpoints(value: boolean);
|
|
108
|
+
/**
|
|
109
|
+
* Whether the EU-based `api.maptiler.eu` host is currently in use instead of the default `api.maptiler.com`
|
|
110
|
+
*/
|
|
111
|
+
get useEuEndpoints(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* The host currently used for the MapTiler API requests (`api.maptiler.com` or `api.maptiler.eu`)
|
|
114
|
+
*/
|
|
115
|
+
get apiHost(): string;
|
|
116
|
+
/**
|
|
117
|
+
* The base URL currently used for the MapTiler API requests
|
|
118
|
+
* (`https://api.maptiler.com/` or `https://api.maptiler.eu/`)
|
|
119
|
+
*/
|
|
120
|
+
get apiURL(): string;
|
|
99
121
|
}
|
|
100
122
|
/**
|
|
101
123
|
* Configuration object
|
|
@@ -1269,7 +1291,7 @@ interface RoutingOptions {
|
|
|
1269
1291
|
/**
|
|
1270
1292
|
* Extra options to pass to the underlying [fetch](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) call.
|
|
1271
1293
|
*/
|
|
1272
|
-
fetchExtras?:
|
|
1294
|
+
fetchExtras?: RequestInit;
|
|
1273
1295
|
}
|
|
1274
1296
|
/** Full routing request body for POST /routing/directions. */
|
|
1275
1297
|
interface RoutingRequest {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import be from"quick-lru";function Ne(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class Z{constructor(){this._apiKey="",this._fetch=Ne(),this.tileCacheSize=200}set apiKey(a){this._apiKey=a}get apiKey(){return this._apiKey}set fetch(a){this._fetch=a}get fetch(){return this._fetch}}const m=new Z,X={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}},ee={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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},PERSIAN:{code:"fa",flag:"name:fa",name:"Persian",latin:!1,isMode:!1,geocoding:!0},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:!0},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:!0},TELUGU:{code:"te",flag:"name:te",name:"Telugu",latin:!1,isMode:!1,geocoding:!0},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:!0},WELSH:{code:"cy",flag:"name:cy",name:"Welsh",latin:!0,isMode:!1,geocoding:!0}},y={...X,...ee};function ae(e,a=y){return e in a?a[e]:null}function I(e,a=y){for(const t of Object.values(a))if(t.code===e)return t;return null}function U(e,a=y){for(const t of Object.values(a))if(t.flag===e)return t;return null}function K(){if(typeof navigator>"u"){const e=Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];return I(e)??y.ENGLISH}return Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).map(e=>I(e)).filter(e=>e)[0]??y.ENGLISH}function _(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 j(e,a=y){return _(e)?U(e.flag,a):typeof e!="string"?null:ae(e,a)||I(e,a)||U(e,a)||null}function $e(e,a,t=y){const n=j(e,t),i=j(a,t);return n!==null&&i!==null&&n.flag===i.flag}async function f(e,a={}){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,a)}const u={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(u);class h extends Error{constructor(a,t=""){super(`Call to enpoint ${a.url} failed with the status code ${a.status}. ${t}`),this.res=a}}const k={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function w(e,a){const{adjustSearchParams:t,apiKey:n}=a;typeof t=="function"&&t(e),e.set("key",n??m.apiKey)}function P(e,a){const{language:t}=a;if(t===void 0)return;const n=(Array.isArray(t)?t:[t]).map(r=>Oe(r)).filter(r=>r),i=Array.from(new Set(n)).join(",");e.set("language",i)}function Oe(e){const a=e===y.AUTO.flag?K():typeof e=="string"?I(e):_(e)?e.flag===y.AUTO.flag?K():U(e.flag):null;return a?.geocoding?a.code:null}function H(e,a){const{limit:t,types:n,excludeTypes:i}=a;t!==void 0&&e.set("limit",String(t)),n!==void 0&&e.set("types",n.join(",")),i!==void 0&&e.set("excludeTypes",String(i))}function te(e,a){const{bbox:t,proximity:n,country:i,fuzzyMatch:r,autocomplete:o}=a;t!==void 0&&e.set("bbox",t.join(",")),n!==void 0&&e.set("proximity",n==="ip"?n:n.join(",")),i!==void 0&&e.set("country",i.join(",")),r!==void 0&&e.set("fuzzyMatch",r?"true":"false"),o!==void 0&&e.set("autocomplete",o?"true":"false")}async function Ve(e,a={}){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`,u.maptilerApiURL);w(t.searchParams,a),P(t.searchParams,a),H(t.searchParams,a),te(t.searchParams,a);const n=await f(t.toString());if(!n.ok)throw new h(n,k[n.status]??"");return await n.json()}async function Ce(e,a={}){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`,u.maptilerApiURL);w(t.searchParams,a),P(t.searchParams,a),H(t.searchParams,a);const n=await f(t.toString());if(!n.ok)throw new h(n,k[n.status]??"");return await n.json()}async function Ke(e,a={}){const t=new URL(`geocoding/${e}.json`,u.maptilerApiURL);w(t.searchParams,a),P(t.searchParams,a);const n=await f(t.toString());if(!n.ok)throw new h(n,k[n.status]??"");return await n.json()}async function _e(e,a={}){if(!e.length)return[];const t=e.map(o=>encodeURIComponent(o)).join(";"),n=new URL(`geocoding/${t}.json`,u.maptilerApiURL);w(n.searchParams,a),P(n.searchParams,a),H(n.searchParams,a),te(n.searchParams,a);const i=await f(n.toString());if(!i.ok)throw new h(i,k[i.status]??"");const r=await i.json();return e.length===1?[r]:r}const je={forward:Ve,reverse:Ce,byId:Ke,batch:_e},ne={403:"Key is missing, invalid or restricted"};async function He(e={}){const a=new URL("geolocation/ip.json",u.maptilerApiURL);a.searchParams.set("key",e.apiKey??m.apiKey),"elevation"in e&&a.searchParams.set("elevation",e.elevation?"true":"false");const t=a.toString(),n=await f(t);if(!n.ok)throw new h(n,n.status in ne?ne[n.status]:"");return await n.json()}const xe={info:He};var Fe=function(e,a){for(var t=Math.pow(10,a),n=e.length,i=new Array(Math.floor(e.length/2)),r=0,o=0,s=0,d=0;r<n;++d){var c=1,g=0,p=void 0;do p=e.charCodeAt(r++)-63-1,c+=p<<g,g+=5;while(p>=31);o+=c&1?~(c>>1):c>>1,c=1,g=0;do p=e.charCodeAt(r++)-63-1,c+=p<<g,g+=5;while(p>=31);s+=c&1?~(c>>1):c>>1,i[d]=[o/t,s/t]}return i.length=d,i};function Be(e,a){for(const t of a)e.append("location",`${t.lon},${t.lat}`)}function Ge(e,a){a&&(a.units&&e.set("response.units",a.units),a.language&&e.set("response.language",a.language),a.alternates!==void 0&&e.set("alternates",String(a.alternates)),a.additionalData?.detailLevel&&e.set("response.additionalData.detailLevel",a.additionalData.detailLevel))}function ze(e,a,t){if(t){if(a==="car"){const n=t;n.mode&&e.set("car.mode",n.mode),n.topSpeed&&e.set("topSpeed",String(n.topSpeed)),n.avoidances?.tolls!==void 0&&e.set("avoidances.tolls",String(n.avoidances.tolls)),n.avoidances?.ferry!==void 0&&e.set("avoidances.ferry",String(n.avoidances.ferry)),n.avoidances?.highway!==void 0&&e.set("avoidances.highway",String(n.avoidances.highway))}if(a==="truck"){const n=t;n.height&&e.set("truck.height",String(n.height)),n.weight&&e.set("truck.weight",String(n.weight)),n.axleLoad&&e.set("truck.axleLoad",String(n.axleLoad)),n.hazmat!==void 0&&e.set("truck.hazmat",String(n.hazmat)),n.topSpeed&&e.set("topSpeed",String(n.topSpeed)),n.avoidances?.tolls!==void 0&&e.set("avoidances.tolls",String(n.avoidances.tolls))}if(a==="bicycle"){const n=t;n.type&&e.set("bicycle.type",n.type),n.cyclingSpeed&&e.set("bicycle.cyclingSpeed",String(n.cyclingSpeed))}if(a==="pedestrian"){const n=t;n.walkingSpeed&&e.set("pedestrian.walkingSpeed",String(n.walkingSpeed))}}}function ie(e,a){const{adjustSearchParams:t}=a;typeof t=="function"&&t(e),e.set("key",m.apiKey)}function re(e){return typeof e.geometry=="string"?Fe(e.geometry,6).map(([a,t])=>[t,a]):e.geometry}async function oe(e){if(!e.ok)throw new h(e);const a=await e.json();for(const t of a.route.legs)t.geometry=re(t);if(a.alternates)for(const t of a.alternates)for(const n of t.legs)n.geometry=re(n);return a}async function We(e,a={}){const{fetchExtras:t}=a,n=new URL("routing/v1/directions",u.maptilerApiURL);ie(n.searchParams,a);const i=new Headers(t?.headers);i.set("content-type","application/json");const r=await f(n.toString(),{...t,method:"POST",headers:i,body:JSON.stringify(e)});return await oe(r)}async function qe(e,a={}){const{fetchExtras:t}=a,n=new URL("routing/v1/directions",u.maptilerApiURL),i=n.searchParams;i.set("profile",e.profile),e.id&&i.set("id",e.id),e.departureTime&&i.set("departureTime",e.departureTime),e.arrivalTime&&i.set("arrivalTime",e.arrivalTime),Be(i,e.locations),Ge(i,e.response),ze(i,e.profile,e.profileOptions),ie(i,a);const r=await f(n.toString(),{...t,method:"GET",body:null});return await oe(r)}const Je={directionsPost:We,directionsGet:qe},b={403:"Key is missing, invalid or restricted"};async function Ye(e,a={}){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`,u.maptilerApiURL);t.searchParams.set("key",a.apiKey??m.apiKey),"limit"in a&&t.searchParams.set("limit",a.limit.toString()),"transformations"in a&&t.searchParams.set("transformations",a.transformations.toString()),"exports"in a&&t.searchParams.set("exports",a.exports.toString());const n=t.toString(),i=await f(n);if(!i.ok)throw new h(i,i.status in b?b[i.status]:"");return await i.json()}async function Qe(e,a={}){const t=(Array.isArray(e[0])?e:[e]).map(o=>`${o[0]},${o[1]}`).join(";"),n=new URL(`coordinates/transform/${t}.json`,u.maptilerApiURL);n.searchParams.set("key",a.apiKey??m.apiKey),"sourceCrs"in a&&n.searchParams.set("s_srs",a.sourceCrs.toString()),"targetCrs"in a&&n.searchParams.set("t_srs",a.targetCrs.toString()),"operations"in a&&n.searchParams.set("ops",(Array.isArray(a.operations)?a.operations:[a.operations]).join("|"));const i=n.toString(),r=await f(i);if(!r.ok)throw new h(r,r.status in b?b[r.status]:"");return await r.json()}const Ze={search:Ye,transform:Qe},se={403:"Key is missing, invalid or restricted"};async function Xe(e,a={}){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`,u.maptilerApiURL);t.searchParams.set("key",a.apiKey??m.apiKey);const n=t.toString(),i=await f(n);if(!i.ok)throw new h(i,i.status in se?se[i.status]:"");return await i.json()}const ea={get:Xe};function de(e){const a=/^maptiler:\/\/(.*)/;let t;const n=e.trim();let i;return n.startsWith("http://")||n.startsWith("https://")?i=n:(t=a.exec(n))!==null?i=`https://api.maptiler.com/maps/${t[1]}/style.json`:i=`https://api.maptiler.com/maps/${n}/style.json`,i}class x{constructor(a,t,n,i,r,o,s=!1,d){this.name=a,this.variantType=t,this.id=n,this.referenceStyle=i,this.description=r,this.imageURL=o,this.deprecated=s,this.deprecationMessage=d}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(a){return this.referenceStyle.hasVariant(a)}getVariant(a){const t=this.referenceStyle.getVariant(a);return this.warnIfDeprecated(t),t}getVariants(){return this.referenceStyle.getVariants().filter(a=>a!==this).map(a=>(this.warnIfDeprecated(a),a))}getImageURL(){return this.imageURL}getExpandedStyleURL(){return de(this.getId())}warnIfDeprecated(a=this){if(!a.deprecated)return a;if(a.deprecationMessage)console.warn(a.deprecationMessage);else{const t=a.getFullName();console.warn(`Style "${t}" is deprecated and will be removed in a future version.`)}return a}}class F{constructor(a,t){this.name=a,this.id=t,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(a){this.variants[a.getType()]=a,this.orderedVariants.push(a)}hasVariant(a){return a in this.variants}getVariant(a){return a in this.variants?this.variants[a]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0].warnIfDeprecated()}}const aa=[{referenceStyleID:"STREETS_V2",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2" is deprecated, use "streets-v4" instead'},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-dark" is deprecated, use "streets-v4-dark" instead'},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-light" is deprecated, use "streets-v4-light" instead'},{id:"streets-v2-night",name:"Night",variantType:"NIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-night" is deprecated, use "streets-v4-night" instead'},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-pastel" is deprecated, use "streets-v4-pastel" instead'}]},{referenceStyleID:"STREETS_V4",name:"Streets",description:"",variants:[{id:"streets-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v4-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"BASE_V4",name:"Base",description:"",variants:[{id:"base-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"base-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"base-v4-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"base-v4-ai",name:"AI",variantType:"AI",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR_V2",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"outdoor-v2" is deprecated, use "outdoor-v4" instead'},{id:"outdoor-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"outdoor-v2-dark" is deprecated, use "outdoor-v4-dark" instead'}]},{referenceStyleID:"WINTER_V2",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"WINTER_V4",name:"Winter",description:"",variants:[{id:"winter-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE_V2",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"satellite" is deprecated, use "satellite-v4" instead'}]},{referenceStyleID:"HYBRID_V2",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID_V4",name:"Hybrid",description:"",variants:[{id:"hybrid-v4",name:"Default",variantType:"DEFAULT",imageURL:""},{id:"hybrid-v4-dark",name:"Dark",variantType:"DARK",imageURL:""}]},{referenceStyleID:"BASIC_V2",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"basic-v2" is deprecated, use "base-v4" instead'},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecationMessage:'"basic-v2" is deprecated, use "base-v4" instead'},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"basic-v2" is deprecated, use "base-v4" instead'}]},{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_V2",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"openstreetmap-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"TOPO_V2",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2" is deprecated, use "topo-v4" instead'},{id:"topo-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2-dark" is deprecated, use "topo-v4-dark" instead'},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:"",deprecated:!0},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2-pastel" is deprecated, use "topo-v4-pastel" instead'},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2-topographique" is deprecated, use "topo-v4-topographique" instead'}]},{referenceStyleID:"VOYAGER_V2",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",deprecated:!0,variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",deprecated:!0,variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",deprecated:!0,variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",deprecated:!0,variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER_V2",name:"Toner",description:"",deprecated:!0,deprecationMessage:'"toner-v2" is deprecated, and will be no longer be a default style in the future',variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"toner-v2" is deprecated, and may be removed in future versions.'},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",deprecated:!0,description:"",imageURL:"",deprecationMessage:'"toner-v2-background" is deprecated, and may be removed in future versions.'},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"toner-v2-lite" is deprecated, and may be removed in future versions.'},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"toner-v2-lines" is deprecated, and may be removed in future versions.'}]},{referenceStyleID:"DATAVIZ_V2",name:"Dataviz",description:"",variants:[{id:"dataviz",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"dataviz" is deprecated, use "dataviz-v4" instead'},{id:"dataviz-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"dataviz-dark" is deprecated, use "dataviz-v4-dark" instead'},{id:"dataviz-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"dataviz-light" is deprecated, use "dataviz-v4-light" instead'}]},{referenceStyleID:"BACKDROP_V2",name:"Backdrop",description:"",variants:[{id:"backdrop",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"backdrop" is deprecated, use "backdrop-v4" instead'},{id:"backdrop-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"backdrop-dark" is deprecated, use "backdrop-v4-dark" instead'},{id:"backdrop-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"backdrop-light" is deprecated, use "backdrop-v4-light" instead'}]},{referenceStyleID:"OCEAN_V2",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"ocean" is deprecated, use "ocean-v4" instead'}]},{referenceStyleID:"AQUARELLE_V2",name:"Aquarelle",description:"Watercolor map for creative use",variants:[{id:"aquarelle",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"aquarelle" is deprecated, use "aquarelle-v4" instead'},{id:"aquarelle-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"aquarelle-dark" is deprecated, use "aquarelle-v4-dark" instead'},{id:"aquarelle-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"aquarelle-vivid" is deprecated, use "aquarelle-v4-vivid" instead'}]},{referenceStyleID:"LANDSCAPE_V2",name:"Landscape",description:"Terrain map for data overlays and visualisations",variants:[{id:"landscape",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"landscape" is deprecated, use "landscape-v4" instead'},{id:"landscape-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"landscape-dark" is deprecated, use "landscape-v4-dark" instead'},{id:"landscape-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"landscape-vivid" is deprecated, use "landscape-v4-vivid" instead'}]},{referenceStyleID:"LANDSCAPE_V4",name:"Landscape",description:"Terrain map for data overlays and visualisations",variants:[{id:"landscape-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"landscape-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"landscape-v4-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE_V4",name:"Satellite",description:"",variants:[{id:"satellite-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"satellite-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"DATAVIZ_V4",name:"Dataviz",description:"",variants:[{id:"dataviz-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"dataviz-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"dataviz-v4-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR_V4",name:"Outdoor",description:"",variants:[{id:"outdoor-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"outdoor-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"BACKDROP_V4",name:"Backdrop",description:"",variants:[{id:"backdrop-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"backdrop-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"backdrop-v4-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"AQUARELLE_V4",name:"Aquarelle",description:"Watercolor map for creative use",variants:[{id:"aquarelle-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"aquarelle-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"aquarelle-v4-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:""}]},{referenceStyleID:"OCEAN_V4",name:"Ocean",description:"",variants:[{id:"ocean-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"ocean-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"TOPO_V4",name:"Topo",description:"",variants:[{id:"topo-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"topo-v4-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v4-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]}],ce={STREETS:"STREETS_V4",BASIC:"BASIC_V2",BASE:"BASE_V4",LANDSCAPE:"LANDSCAPE_V4",AQUARELLE:"AQUARELLE_V4",SATELLITE:"SATELLITE_V4",WINTER:"WINTER_V4",HYBRID:"HYBRID_V4",OCEAN:"OCEAN_V4",OUTDOOR:"OUTDOOR_V4",TONER:"TONER_V2",TOPO:"TOPO_V4",OPENSTREETMAP:"OPENSTREETMAP_V2",DATAVIZ:"DATAVIZ_V4",BACKDROP:"BACKDROP_V4",VOYAGER:"VOYAGER_V2"},T=[...aa];function ta(e,a){T.find(i=>i.referenceStyleID===e)&&console.warn(`Default reference style ${e} already exists, it will be overwritten...`);const t=T.find(i=>i.referenceStyleID===a);if(!t)throw new Error(`Versioned map style not found for reference style: ${a}`);const n={...t,referenceStyleID:e};T.push(n)}Object.entries(ce).forEach(([e,a])=>{ta(e,a)});function na(e){return new Proxy(e,{get(a,t,n){return a.hasVariant(t)?a.getVariant(t):t.toString().toUpperCase()===t?e.getDefaultVariant():Reflect.get(a,t,n)}})}function ia(){const e={};for(let a=0;a<T.length;a+=1){const t=T[a],n=na(new F(t.name,t.referenceStyleID));for(let i=0;i<t.variants.length;i+=1){const r=t.variants[i],o=new x(r.name,r.variantType,r.id,n,r.description,r.imageURL,r.deprecated);n.addVariant(o)}e[t.referenceStyleID]=n}return e}function N(e){if(!e)return le[T[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 le=ia();function ra(e){const a=[];function t(r){(r.type==="LineString"||r.type==="MultiLineString")&&a.push(r)}function n(r){r.geometry&&t(r.geometry)}function i(r){for(const o of r.features)o.type==="Feature"?n(o):o.type==="FeatureCollection"&&i(o)}return e.type==="Feature"?n(e):e.type==="FeatureCollection"?i(e):t(e),a}function oa(e,a,t){let n=a[0],i=a[1],r=t[0]-n,o=t[1]-i;if(r!==0||o!==0){const s=((e[0]-n)*r+(e[1]-i)*o)/(r*r+o*o);s>1?(n=t[0],i=t[1]):s>0&&(n+=r*s,i+=o*s)}return r=e[0]-n,o=e[1]-i,r*r+o*o}function B(e,a,t,n,i){let r=n,o;for(let s=a+1;s<t;s++){const d=oa(e[s],e[a],e[t]);d>r&&(o=s,r=d)}r>n&&(o-a>1&&B(e,a,o,n,i),i.push(e[o]),t-o>1&&B(e,o,t,n,i))}function sa(e,a){const t=e.length-1,n=[e[0]];return B(e,0,t,a,n),n.push(e[t]),n}function da(e,a){if(e.length<=2)return e;const t=a!==void 0?a*a:1;return sa(e,t)}const ge={extractLineStrings:ra,simplify:da};function G(e,a=!0){let t=`${e[0]},${e[1]}`;return e.length===3&&a&&(t+=`,${e[2]}`),t}function z(e,a=3e3){let t=e.map(r=>r.join(",")).join("|"),n=5e-6;const i=1e-5;for(;t.length>a;)t=ge.simplify(e,n).map(r=>`${r[0]},${r[1]}`).join("|"),n+=i;return t}function ca(e,a,t={}){const n=N(t.style),i=t.hiDPI?"@2x":"",r=t.format??"png";let o=~~(t.width??1024),s=~~(t.height??1024);t.hiDPI&&(o=~~(o/2),s=~~(s/2));const d=new URL(`maps/${encodeURIComponent(n)}/static/${e[0]},${e[1]},${a}/${o}x${s}${i}.${r}`,u.maptilerApiURL);if("attribution"in t&&d.searchParams.set("attribution",t.attribution.toString()),"markers"in t){let c="";const g="markerIcon"in t;g&&(c+=`icon:${t.markerIcon}|`),g&&"markerAnchor"in t&&(c+=`anchor:${t.markerAnchor}|`),g&&t.hiDPI&&(c+="scale:2|");const p=Array.isArray(t.markers[0])?t.markers:[t.markers];c+=p.map(L=>G(L,!g)).join("|"),d.searchParams.set("markers",c)}if("path"in t){let c="";if(c+=`fill:${t.pathFillColor??"none"}|`,"pathStrokeColor"in t&&(c+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const g=t.pathWidth/(t.hiDPI?2:1);c+=`width:${g.toString()}|`}c+=z(t.path),d.searchParams.set("path",c)}return d.searchParams.set("key",t.apiKey??m.apiKey),d.toString()}function la(e,a={}){const t=N(a.style),n=a.hiDPI?"@2x":"",i=a.format??"png";let r=~~(a.width??1024),o=~~(a.height??1024);a.hiDPI&&(r=~~(r/2),o=~~(o/2));const s=new URL(`maps/${encodeURIComponent(t)}/static/${e[0]},${e[1]},${e[2]},${e[3]}/${r}x${o}${n}.${i}`,u.maptilerApiURL);if("attribution"in a&&s.searchParams.set("attribution",a.attribution.toString()),"padding"in a&&s.searchParams.set("padding",a.padding.toString()),"markers"in a){let d="";const c="markerIcon"in a;c&&(d+=`icon:${a.markerIcon}|`),c&&"markerAnchor"in a&&(d+=`anchor:${a.markerAnchor}|`),c&&a.hiDPI&&(d+="scale:2|");const g=Array.isArray(a.markers[0])?a.markers:[a.markers];d+=g.map(p=>G(p,!c)).join("|"),s.searchParams.set("markers",d)}if("path"in a){let d="";if(d+=`fill:${a.pathFillColor??"none"}|`,"pathStrokeColor"in a&&(d+=`stroke:${a.pathStrokeColor}|`),"pathWidth"in a){const c=a.pathWidth/(a.hiDPI?2:1);d+=`width:${c.toString()}|`}d+=z(a.path),s.searchParams.set("path",d)}return s.searchParams.set("key",a.apiKey??m.apiKey),s.toString()}function ga(e={}){if(!("markers"in e)&&!("path"in e))throw new Error("Automatic static maps require markers and/or path to be created.");const a=N(e.style),t=e.hiDPI?"@2x":"",n=e.format??"png";let i=~~(e.width??1024),r=~~(e.height??1024);e.hiDPI&&(i=~~(i/2),r=~~(r/2));const o=new URL(`maps/${encodeURIComponent(a)}/static/auto/${i}x${r}${t}.${n}`,u.maptilerApiURL);if("attribution"in e&&o.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&o.searchParams.set("padding",e.padding.toString()),"markers"in e){let s="";const d="markerIcon"in e;d&&(s+=`icon:${e.markerIcon}|`),d&&"markerAnchor"in e&&(s+=`anchor:${e.markerAnchor}|`),d&&e.hiDPI&&(s+="scale:2|");const c=Array.isArray(e.markers[0])?e.markers:[e.markers];s+=c.map(g=>G(g,!d)).join("|"),o.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 d=e.pathWidth/(e.hiDPI?2:1);s+=`width:${d.toString()}|`}s+=z(e.path),o.searchParams.set("path",s)}return o.searchParams.set("key",e.apiKey??m.apiKey),o.toString()}const pa={centered:ca,bounded:la,automatic:ga},$=63710088e-1,pe=2*Math.PI*$,me=85.0511287;function ue(e){return(180+e)/360}function fe(e){return e=Math.max(Math.min(e,me),-me),(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}function he(e){const a=Le(e);return[ue(a[0]),fe(a[1])]}function ve(e){return e*360-180}function ye(e){const a=180-e*360;return 360/Math.PI*Math.atan(Math.exp(a*Math.PI/180))-90}function ma(e){return[ve(e[0]),ye(e[1])]}function W(e,a){const t=Math.PI/180,n=e[1]*t,i=a[1]*t,r=Math.sin(n)*Math.sin(i)+Math.cos(n)*Math.cos(i)*Math.cos((a[0]-e[0])*t);return $*Math.acos(Math.min(r,1))}function ua(e){const a=Array(e.length);a[0]=0;const t=a.length;for(let n=1;n<t;n++)a[n]=W(e[n-1],e[n])+a[n-1];return a}function Le(e){const a=e[0],t=e[1],n=360,i=((a+180)%n+n)%n-180;return[i===-180?180:i,t]}function Ae(e){return pe*Math.cos(e*Math.PI/180)}function Te(e,a,t=!0){const n=2**a,i=[e[0]*n,e[1]*n];return t?[~~i[0],~~i[1]]:i}function fa(e,a,t=!0){const n=he(e);return Te(n,a,t)}function D(e){return e*Math.PI/180}function q(e){return e*180/Math.PI}function ha(e,a,t){const n=W(e,a),i=D(e[0]),r=D(e[1]),o=D(a[0]),s=D(a[1]),d=n/$,c=Math.sin((1-t)*d)/Math.sin(d),g=Math.sin(t*d)/Math.sin(d),p=c*Math.cos(r)*Math.cos(i)+g*Math.cos(s)*Math.cos(o),L=c*Math.cos(r)*Math.sin(i)+g*Math.cos(s)*Math.sin(o),R=c*Math.sin(r)+g*Math.sin(s),M=Math.atan2(R,Math.sqrt(p*p+L*L)),l=Math.atan2(L,p);return[q(l),q(M)]}const Se={EARTH_RADIUS:$,EARTH_CIRCUMFERENCE:pe,longitudeToMercatorX:ue,latitudeToMercatorY:fe,wgs84ToMercator:he,mercatorXToLongitude:ve,mercatorYToLatitude:ye,mercatorToWgs84:ma,haversineDistanceWgs84:W,wrapWgs84:Le,circumferenceAtLatitude:Ae,mercatorToTileIndex:Te,wgs84ToTileIndex:fa,toRadians:D,toDegrees:q,haversineIntermediateWgs84:ha,haversineCumulatedDistanceWgs84:ua};let J=null;function Re(){return J||(J=new be({maxSize:m.tileCacheSize})),J}async function Ie(e){const a=new Blob([e]),t=await createImageBitmap(a),n=document.createElement("canvas"),i=n.getContext("2d");n.width=t.width,n.height=t.height,i.drawImage(t,0,0);const r=i.getImageData(0,0,n.width,n.height);return{pixels:r.data,width:n.width,height:n.height,components:r.data.length/(n.width*n.height)}}function De(){if(m.bufferToPixelData)return m.bufferToPixelData;if(typeof window<"u")return Ie;throw new Error("An image file buffer to pixel data parser is necessary. Specify it in `config.bufferToPixelData`")}function Y(){return!!m.bufferToPixelData||typeof window<"u"}const va="terrain-rgb-v2",Q=50,ya=1e3;let O=null;const Me={403:"Key is missing, invalid or restricted"};async function La(e,a){e.length>ya&&console.warn("Computing elevation for complex geometries is discouraged - simplify the geometry before proceeding");const t=Math.ceil(e.length/Q),n=Array.from({length:t},()=>null).map((r,o)=>{const s=o*Q,d=e.slice(s,s+Q).map(g=>g.join(",")).join(";"),c=new URL(`elevation/${d}.json`,u.maptilerApiURL);return c.searchParams.set("key",a),f(c.toString())}),i=await Promise.allSettled(n);return(await Promise.all(i.map(async r=>{if(r.status==="rejected")throw new Error(`Some segments could not be fetched, error: ${r.reason}`);if(!r.value.ok)throw new Error(`Some segments could not be fetched, response: ${r.value.status} ${await r.value.text()}, url: ${r.value.url}`);return r.value.json()}))).flat()}async function Aa(e,a,t){if(!O){const l=new URL(`tiles/${va}/tiles.json`,u.maptilerApiURL);l.searchParams.set("key",a);const S=l.toString(),v=await f(S);if(v.ok)O=await v.json();else throw new h(v,Me[v.status]??"")}const n=De(),i=O.tiles[0],r=Re(),o=O.maxzoom;let s=~~(t??o);(s>o||s<0)&&(s=o);const d=e.map(l=>Se.wgs84ToTileIndex(l,s,!1)),c=d.map(l=>[~~l[0],~~l[1]]).map(l=>`terrain_${s.toString()}_${l[0].toString()}_${l[1].toString()}`),g=Array.from(new Set(c.filter(l=>!r.has(l)))).map(l=>l.split("_").slice(1)),p=g.map(l=>i.replace("{x}",l[1].toString()).replace("{y}",l[2].toString()).replace("{z}",l[0].toString())).map(l=>f(l)),L=(await Promise.allSettled(p)).map(l=>l.status==="fulfilled"?l.value:null).filter(l=>l),R=L.filter(l=>!l.ok);if(L.length!==p.length)throw new Error("Some tiles could not be fetched.");if(R.length)throw new h(R[0],Me[R[0].status]??"");const M=await Promise.all(L.map(l=>l.arrayBuffer()));if(!M.every(l=>l.byteLength>0))throw new Error("Some tiles are not available.");return(await Promise.all(M.map(l=>n(l)))).forEach((l,S)=>{const v=g[S],E=`terrain_${v[0].toString()}_${v[1].toString()}_${v[2].toString()}`;r.set(E,l)}),e.map((l,S)=>{const v=c[S],E=d[S],A=r.get(v),Ee=Math.min(Math.round(A.width*(E[0]%1)),A.width-1),C=(Math.min(Math.round(A.height*(E[1]%1)),A.height-1)*A.width+Ee)*A.components,Ue=A.pixels[C],ke=A.pixels[C+1],we=A.pixels[C+2],Pe=-1e4+(Ue*256*256+ke*256+we)*.1;return[l[0],l[1],~~(Pe*1e3)/1e3]})}async function Ta(e,a={}){return(await V([e],a))[0]}async function V(e,a={}){if(e.length===0)return[];const t=a.apiKey??m.apiKey,n=a.computeOn==="client"?await Aa(e,t,a.zoom):await La(e,t);if(a.smoothingKernelSize){const i=~~(a.smoothingKernelSize/2)*2+1,r=n.map(s=>s[2]),o=~~(i/2);for(let s=o;s<r.length-o;s+=1){let d=0;for(let c=0;c<i;c+=1){const g=r[s-o+c];d+=g}d/=i,n[s][2]=d}}return n}async function Sa(e,a={}){if(e.type!=="LineString")throw new Error("The provided object is not a GeoJSON LineString");a.computeOn??(a.computeOn=Y()?"client":"server");const t=structuredClone(e),n=await V(t.coordinates,a);return t.coordinates=n,t}async function Ra(e,a={}){if(e.type!=="MultiLineString")throw new Error("The provided object is not a GeoJSON MultiLineString");a.computeOn??(a.computeOn=Y()?"client":"server");const t=structuredClone(e),n=t.coordinates.map(d=>d.length),i=t.coordinates.flat(),r=await V(i,a),o=[];let s=0;for(const d of n)o.push(r.slice(s,s+d)),s+=d;return t.coordinates=o,t}const Ia={at:Ta,batch:V,fromLineString:Sa,fromMultiLineString:Ra};export{Z as ClientConfig,ee as ISOLanguage,y as Language,le as MapStyle,x as MapStyleVariant,X as NonISOLanguage,F as ReferenceMapStyle,h as ServiceError,$e as areSameLanguages,Ie as bufferToPixelDataBrowser,Y as canParsePixelData,Ae as circumferenceAtLatitude,m as config,Ze as coordinates,ea as data,ce as defaultReferenceStyleMap,Ia as elevation,de as expandMapStyle,je as geocoding,xe as geolocation,K as getAutoLanguage,De as getBufferToPixelDataParser,I as getLanguageInfoFromCode,U as getLanguageInfoFromFlag,ae as getLanguageInfoFromKey,Re as getTileCache,_ as isLanguageInfo,T as mapStylePresetList,Se as math,ge as misc,Je as routing,pa as staticMaps,N as styleToStyle,j as toLanguageInfo};
|
|
1
|
+
import{decode as $e}from"@googlemaps/polyline-codec";import be from"quick-lru";const Ne="api.maptiler.com",Oe="api.maptiler.eu";function Ve(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class Q{constructor(){this._apiKey="",this._fetch=Ve(),this._useEuEndpoints=!1,this.tileCacheSize=200}set apiKey(a){this._apiKey=a}get apiKey(){return this._apiKey}set fetch(a){this._fetch=a}get fetch(){return this._fetch}set useEuEndpoints(a){this._useEuEndpoints=a}get useEuEndpoints(){return this._useEuEndpoints}get apiHost(){return this._useEuEndpoints?Oe:Ne}get apiURL(){return`https://${this.apiHost}/`}}const l=new Q,Z={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}},X={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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},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:!0},PERSIAN:{code:"fa",flag:"name:fa",name:"Persian",latin:!1,isMode:!1,geocoding:!0},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:!0},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:!0},TELUGU:{code:"te",flag:"name:te",name:"Telugu",latin:!1,isMode:!1,geocoding:!0},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:!0},WELSH:{code:"cy",flag:"name:cy",name:"Welsh",latin:!0,isMode:!1,geocoding:!0}},v={...Z,...X};function ee(e,a=v){return e in a?a[e]:null}function R(e,a=v){for(const t of Object.values(a))if(t.code===e)return t;return null}function E(e,a=v){for(const t of Object.values(a))if(t.flag===e)return t;return null}function C(){if(typeof navigator>"u"){const e=Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];return R(e)??v.ENGLISH}return Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).map(e=>R(e)).filter(e=>e)[0]??v.ENGLISH}function _(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 K(e,a=v){return _(e)?E(e.flag,a):typeof e!="string"?null:ee(e,a)||R(e,a)||E(e,a)||null}function Ce(e,a,t=v){const n=K(e,t),i=K(a,t);return n!==null&&i!==null&&n.flag===i.flag}async function u(e,a={}){if(l.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 l.fetch(e,a)}class m extends Error{constructor(a,t=""){super(`Call to enpoint ${a.url} failed with the status code ${a.status}. ${t}`),this.res=a}}const U={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function k(e,a){const{adjustSearchParams:t,apiKey:n}=a;typeof t=="function"&&t(e),e.set("key",n??l.apiKey)}function w(e,a){const{language:t}=a;if(t===void 0)return;const n=(Array.isArray(t)?t:[t]).map(r=>_e(r)).filter(r=>r),i=Array.from(new Set(n)).join(",");e.set("language",i)}function _e(e){const a=e===v.AUTO.flag?C():typeof e=="string"?R(e):_(e)?e.flag===v.AUTO.flag?C():E(e.flag):null;return a?.geocoding?a.code:null}function H(e,a){const{limit:t,types:n,excludeTypes:i}=a;t!==void 0&&e.set("limit",String(t)),n!==void 0&&e.set("types",n.join(",")),i!==void 0&&e.set("excludeTypes",String(i))}function ae(e,a){const{bbox:t,proximity:n,country:i,fuzzyMatch:r,autocomplete:o}=a;t!==void 0&&e.set("bbox",t.join(",")),n!==void 0&&e.set("proximity",n==="ip"?n:n.join(",")),i!==void 0&&e.set("country",i.join(",")),r!==void 0&&e.set("fuzzyMatch",r?"true":"false"),o!==void 0&&e.set("autocomplete",o?"true":"false")}async function Ke(e,a={}){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`,l.apiURL);k(t.searchParams,a),w(t.searchParams,a),H(t.searchParams,a),ae(t.searchParams,a);const n=await u(t.toString());if(!n.ok)throw new m(n,U[n.status]??"");return await n.json()}async function He(e,a={}){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`,l.apiURL);k(t.searchParams,a),w(t.searchParams,a),H(t.searchParams,a);const n=await u(t.toString());if(!n.ok)throw new m(n,U[n.status]??"");return await n.json()}async function je(e,a={}){const t=new URL(`geocoding/${e}.json`,l.apiURL);k(t.searchParams,a),w(t.searchParams,a);const n=await u(t.toString());if(!n.ok)throw new m(n,U[n.status]??"");return await n.json()}async function xe(e,a={}){if(!e.length)return[];const t=e.map(o=>encodeURIComponent(o)).join(";"),n=new URL(`geocoding/${t}.json`,l.apiURL);k(n.searchParams,a),w(n.searchParams,a),H(n.searchParams,a),ae(n.searchParams,a);const i=await u(n.toString());if(!i.ok)throw new m(i,U[i.status]??"");const r=await i.json();return e.length===1?[r]:r}const Fe={forward:Ke,reverse:He,byId:je,batch:xe},te={403:"Key is missing, invalid or restricted"};async function Be(e={}){const a=new URL("geolocation/ip.json",l.apiURL);a.searchParams.set("key",e.apiKey??l.apiKey),"elevation"in e&&a.searchParams.set("elevation",e.elevation?"true":"false");const t=a.toString(),n=await u(t);if(!n.ok)throw new m(n,n.status in te?te[n.status]:"");return await n.json()}const Ge={info:Be};function ze(e,a){for(const t of a)e.append("location",`${t.lon},${t.lat}`)}function We(e,a){a&&(a.units&&e.set("response.units",a.units),a.language&&e.set("response.language",a.language),a.alternates!==void 0&&e.set("alternates",String(a.alternates)),a.additionalData?.detailLevel&&e.set("response.additionalData.detailLevel",a.additionalData.detailLevel))}function qe(e,a,t){if(t){if(a==="car"){const n=t;n.mode&&e.set("car.mode",n.mode),n.topSpeed&&e.set("topSpeed",String(n.topSpeed)),n.avoidances?.tolls!==void 0&&e.set("avoidances.tolls",String(n.avoidances.tolls)),n.avoidances?.ferry!==void 0&&e.set("avoidances.ferry",String(n.avoidances.ferry)),n.avoidances?.highway!==void 0&&e.set("avoidances.highway",String(n.avoidances.highway))}if(a==="truck"){const n=t;n.height&&e.set("truck.height",String(n.height)),n.weight&&e.set("truck.weight",String(n.weight)),n.axleLoad&&e.set("truck.axleLoad",String(n.axleLoad)),n.hazmat!==void 0&&e.set("truck.hazmat",String(n.hazmat)),n.topSpeed&&e.set("topSpeed",String(n.topSpeed)),n.avoidances?.tolls!==void 0&&e.set("avoidances.tolls",String(n.avoidances.tolls))}if(a==="bicycle"){const n=t;n.type&&e.set("bicycle.type",n.type),n.cyclingSpeed&&e.set("bicycle.cyclingSpeed",String(n.cyclingSpeed))}if(a==="pedestrian"){const n=t;n.walkingSpeed&&e.set("pedestrian.walkingSpeed",String(n.walkingSpeed))}}}function ne(e,a){const{adjustSearchParams:t}=a;typeof t=="function"&&t(e),e.set("key",l.apiKey)}function ie(e){return typeof e.geometry=="string"?$e(e.geometry,6).map(([a,t])=>[t,a]):e.geometry}async function re(e){if(!e.ok)throw new m(e);const a=await e.json();for(const t of a.route.legs)t.geometry=ie(t);if(a.alternates)for(const t of a.alternates)for(const n of t.legs)n.geometry=ie(n);return a}async function Je(e,a={}){const{fetchExtras:t}=a,n=new URL("routing/v1/directions",l.apiURL);ne(n.searchParams,a);const i=new Headers(t?.headers);i.set("content-type","application/json");const r=await u(n.toString(),{...t,method:"POST",headers:i,body:JSON.stringify(e)});return await re(r)}async function Ye(e,a={}){const{fetchExtras:t}=a,n=new URL("routing/v1/directions",l.apiURL),i=n.searchParams;i.set("profile",e.profile),e.id&&i.set("id",e.id),e.departureTime&&i.set("departureTime",e.departureTime),e.arrivalTime&&i.set("arrivalTime",e.arrivalTime),ze(i,e.locations),We(i,e.response),qe(i,e.profile,e.profileOptions),ne(i,a);const r=await u(n.toString(),{...t,method:"GET",body:null});return await re(r)}const Qe={directionsPost:Je,directionsGet:Ye},P={403:"Key is missing, invalid or restricted"};async function Ze(e,a={}){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`,l.apiURL);t.searchParams.set("key",a.apiKey??l.apiKey),"limit"in a&&t.searchParams.set("limit",a.limit.toString()),"transformations"in a&&t.searchParams.set("transformations",a.transformations.toString()),"exports"in a&&t.searchParams.set("exports",a.exports.toString());const n=t.toString(),i=await u(n);if(!i.ok)throw new m(i,i.status in P?P[i.status]:"");return await i.json()}async function Xe(e,a={}){const t=(Array.isArray(e[0])?e:[e]).map(o=>`${o[0]},${o[1]}`).join(";"),n=new URL(`coordinates/transform/${t}.json`,l.apiURL);n.searchParams.set("key",a.apiKey??l.apiKey),"sourceCrs"in a&&n.searchParams.set("s_srs",a.sourceCrs.toString()),"targetCrs"in a&&n.searchParams.set("t_srs",a.targetCrs.toString()),"operations"in a&&n.searchParams.set("ops",(Array.isArray(a.operations)?a.operations:[a.operations]).join("|"));const i=n.toString(),r=await u(i);if(!r.ok)throw new m(r,r.status in P?P[r.status]:"");return await r.json()}const ea={search:Ze,transform:Xe},oe={403:"Key is missing, invalid or restricted"};async function aa(e,a={}){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`,l.apiURL);t.searchParams.set("key",a.apiKey??l.apiKey);const n=t.toString(),i=await u(n);if(!i.ok)throw new m(i,i.status in oe?oe[i.status]:"");return await i.json()}const ta={get:aa};function se(e){const a=/^maptiler:\/\/(.*)/;let t;const n=e.trim();let i;return n.startsWith("http://")||n.startsWith("https://")?i=n:(t=a.exec(n))!==null?i=`${l.apiURL}maps/${t[1]}/style.json`:i=`${l.apiURL}maps/${n}/style.json`,i}class j{constructor(a,t,n,i,r,o,s=!1,d){this.name=a,this.variantType=t,this.id=n,this.referenceStyle=i,this.description=r,this.imageURL=o,this.deprecated=s,this.deprecationMessage=d}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(a){return this.referenceStyle.hasVariant(a)}getVariant(a){const t=this.referenceStyle.getVariant(a);return this.warnIfDeprecated(t),t}getVariants(){return this.referenceStyle.getVariants().filter(a=>a!==this).map(a=>(this.warnIfDeprecated(a),a))}getImageURL(){return this.imageURL}getExpandedStyleURL(){return se(this.getId())}warnIfDeprecated(a=this){if(!a.deprecated)return a;if(a.deprecationMessage)console.warn(a.deprecationMessage);else{const t=a.getFullName();console.warn(`Style "${t}" is deprecated and will be removed in a future version.`)}return a}}class x{constructor(a,t){this.name=a,this.id=t,this.variants={},this.orderedVariants=[]}getName(){return this.name}getId(){return this.id}addVariant(a){this.variants[a.getType()]=a,this.orderedVariants.push(a)}hasVariant(a){return a in this.variants}getVariant(a){return a in this.variants?this.variants[a]:this.orderedVariants[0]}getVariants(){return Object.values(this.variants)}getDefaultVariant(){return this.orderedVariants[0].warnIfDeprecated()}}const na=[{referenceStyleID:"STREETS_V2",name:"Streets",description:"",variants:[{id:"streets-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2" is deprecated, use "streets-v4" instead'},{id:"streets-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-dark" is deprecated, use "streets-v4-dark" instead'},{id:"streets-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-light" is deprecated, use "streets-v4-light" instead'},{id:"streets-v2-night",name:"Night",variantType:"NIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-night" is deprecated, use "streets-v4-night" instead'},{id:"streets-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"streets-v2-pastel" is deprecated, use "streets-v4-pastel" instead'}]},{referenceStyleID:"STREETS_V4",name:"Streets",description:"",variants:[{id:"streets-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"streets-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"streets-v4-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""}]},{referenceStyleID:"BASE_V4",name:"Base",description:"",variants:[{id:"base-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"base-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"base-v4-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""},{id:"base-v4-ai",name:"AI",variantType:"AI",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR_V2",name:"Outdoor",description:"",variants:[{id:"outdoor-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"outdoor-v2" is deprecated, use "outdoor-v4" instead'},{id:"outdoor-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"outdoor-v2-dark" is deprecated, use "outdoor-v4-dark" instead'}]},{referenceStyleID:"WINTER_V2",name:"Winter",description:"",variants:[{id:"winter-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"WINTER_V4",name:"Winter",description:"",variants:[{id:"winter-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"winter-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE_V2",name:"Satellite",description:"",variants:[{id:"satellite",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"satellite" is deprecated, use "satellite-v4" instead'}]},{referenceStyleID:"HYBRID_V2",name:"Hybrid",description:"",variants:[{id:"hybrid",name:"Default",variantType:"DEFAULT",description:"",imageURL:""}]},{referenceStyleID:"HYBRID_V4",name:"Hybrid",description:"",variants:[{id:"hybrid-v4",name:"Default",variantType:"DEFAULT",imageURL:""},{id:"hybrid-v4-dark",name:"Dark",variantType:"DARK",imageURL:""}]},{referenceStyleID:"BASIC_V2",name:"Basic",description:"",variants:[{id:"basic-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"basic-v2" is deprecated, use "base-v4" instead'},{id:"basic-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecationMessage:'"basic-v2" is deprecated, use "base-v4" instead'},{id:"basic-v2-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"basic-v2" is deprecated, use "base-v4" instead'}]},{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_V2",name:"OpenStreetMap",description:"",variants:[{id:"openstreetmap",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"openstreetmap-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"TOPO_V2",name:"Topo",description:"",variants:[{id:"topo-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2" is deprecated, use "topo-v4" instead'},{id:"topo-v2-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2-dark" is deprecated, use "topo-v4-dark" instead'},{id:"topo-v2-shiny",name:"Shiny",variantType:"SHINY",description:"",imageURL:"",deprecated:!0},{id:"topo-v2-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2-pastel" is deprecated, use "topo-v4-pastel" instead'},{id:"topo-v2-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"topo-v2-topographique" is deprecated, use "topo-v4-topographique" instead'}]},{referenceStyleID:"VOYAGER_V2",name:"Voyager",description:"",variants:[{id:"voyager-v2",name:"Default",deprecated:!0,variantType:"DEFAULT",description:"",imageURL:""},{id:"voyager-v2-darkmatter",name:"Darkmatter",deprecated:!0,variantType:"DARK",description:"",imageURL:""},{id:"voyager-v2-positron",name:"Positron",deprecated:!0,variantType:"LIGHT",description:"",imageURL:""},{id:"voyager-v2-vintage",name:"Vintage",deprecated:!0,variantType:"VINTAGE",description:"",imageURL:""}]},{referenceStyleID:"TONER_V2",name:"Toner",description:"",deprecated:!0,deprecationMessage:'"toner-v2" is deprecated, and will be no longer be a default style in the future',variants:[{id:"toner-v2",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"toner-v2" is deprecated, and may be removed in future versions.'},{id:"toner-v2-background",name:"Background",variantType:"BACKGROUND",deprecated:!0,description:"",imageURL:"",deprecationMessage:'"toner-v2-background" is deprecated, and may be removed in future versions.'},{id:"toner-v2-lite",name:"Lite",variantType:"LITE",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"toner-v2-lite" is deprecated, and may be removed in future versions.'},{id:"toner-v2-lines",name:"Lines",variantType:"LINES",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"toner-v2-lines" is deprecated, and may be removed in future versions.'}]},{referenceStyleID:"DATAVIZ_V2",name:"Dataviz",description:"",variants:[{id:"dataviz",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"dataviz" is deprecated, use "dataviz-v4" instead'},{id:"dataviz-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"dataviz-dark" is deprecated, use "dataviz-v4-dark" instead'},{id:"dataviz-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"dataviz-light" is deprecated, use "dataviz-v4-light" instead'}]},{referenceStyleID:"BACKDROP_V2",name:"Backdrop",description:"",variants:[{id:"backdrop",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"backdrop" is deprecated, use "backdrop-v4" instead'},{id:"backdrop-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"backdrop-dark" is deprecated, use "backdrop-v4-dark" instead'},{id:"backdrop-light",name:"Light",variantType:"LIGHT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"backdrop-light" is deprecated, use "backdrop-v4-light" instead'}]},{referenceStyleID:"OCEAN_V2",name:"Ocean",description:"",variants:[{id:"ocean",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"ocean" is deprecated, use "ocean-v4" instead'}]},{referenceStyleID:"AQUARELLE_V2",name:"Aquarelle",description:"Watercolor map for creative use",variants:[{id:"aquarelle",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"aquarelle" is deprecated, use "aquarelle-v4" instead'},{id:"aquarelle-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"aquarelle-dark" is deprecated, use "aquarelle-v4-dark" instead'},{id:"aquarelle-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"aquarelle-vivid" is deprecated, use "aquarelle-v4-vivid" instead'}]},{referenceStyleID:"LANDSCAPE_V2",name:"Landscape",description:"Terrain map for data overlays and visualisations",variants:[{id:"landscape",name:"Default",variantType:"DEFAULT",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"landscape" is deprecated, use "landscape-v4" instead'},{id:"landscape-dark",name:"Dark",variantType:"DARK",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"landscape-dark" is deprecated, use "landscape-v4-dark" instead'},{id:"landscape-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:"",deprecated:!0,deprecationMessage:'"landscape-vivid" is deprecated, use "landscape-v4-vivid" instead'}]},{referenceStyleID:"LANDSCAPE_V4",name:"Landscape",description:"Terrain map for data overlays and visualisations",variants:[{id:"landscape-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"landscape-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"landscape-v4-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:""}]},{referenceStyleID:"SATELLITE_V4",name:"Satellite",description:"",variants:[{id:"satellite-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"satellite-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"DATAVIZ_V4",name:"Dataviz",description:"",variants:[{id:"dataviz-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"dataviz-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"dataviz-v4-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"OUTDOOR_V4",name:"Outdoor",description:"",variants:[{id:"outdoor-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"outdoor-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"BACKDROP_V4",name:"Backdrop",description:"",variants:[{id:"backdrop-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"backdrop-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"backdrop-v4-light",name:"Light",variantType:"LIGHT",description:"",imageURL:""}]},{referenceStyleID:"AQUARELLE_V4",name:"Aquarelle",description:"Watercolor map for creative use",variants:[{id:"aquarelle-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"aquarelle-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"aquarelle-v4-vivid",name:"Vivid",variantType:"VIVID",description:"",imageURL:""}]},{referenceStyleID:"OCEAN_V4",name:"Ocean",description:"",variants:[{id:"ocean-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"ocean-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""}]},{referenceStyleID:"TOPO_V4",name:"Topo",description:"",variants:[{id:"topo-v4",name:"Default",variantType:"DEFAULT",description:"",imageURL:""},{id:"topo-v4-dark",name:"Dark",variantType:"DARK",description:"",imageURL:""},{id:"topo-v4-pastel",name:"Pastel",variantType:"PASTEL",description:"",imageURL:""},{id:"topo-v4-topographique",name:"Topographique",variantType:"TOPOGRAPHIQUE",description:"",imageURL:""}]}],de={STREETS:"STREETS_V4",BASIC:"BASIC_V2",BASE:"BASE_V4",LANDSCAPE:"LANDSCAPE_V4",AQUARELLE:"AQUARELLE_V4",SATELLITE:"SATELLITE_V4",WINTER:"WINTER_V4",HYBRID:"HYBRID_V4",OCEAN:"OCEAN_V4",OUTDOOR:"OUTDOOR_V4",TONER:"TONER_V2",TOPO:"TOPO_V4",OPENSTREETMAP:"OPENSTREETMAP_V2",DATAVIZ:"DATAVIZ_V4",BACKDROP:"BACKDROP_V4",VOYAGER:"VOYAGER_V2"},T=[...na];function ia(e,a){T.find(i=>i.referenceStyleID===e)&&console.warn(`Default reference style ${e} already exists, it will be overwritten...`);const t=T.find(i=>i.referenceStyleID===a);if(!t)throw new Error(`Versioned map style not found for reference style: ${a}`);const n={...t,referenceStyleID:e};T.push(n)}Object.entries(de).forEach(([e,a])=>{ia(e,a)});function ra(e){return new Proxy(e,{get(a,t,n){return a.hasVariant(t)?a.getVariant(t):t.toString().toUpperCase()===t?e.getDefaultVariant():Reflect.get(a,t,n)}})}function oa(){const e={};for(let a=0;a<T.length;a+=1){const t=T[a],n=ra(new x(t.name,t.referenceStyleID));for(let i=0;i<t.variants.length;i+=1){const r=t.variants[i],o=new j(r.name,r.variantType,r.id,n,r.description,r.imageURL,r.deprecated);n.addVariant(o)}e[t.referenceStyleID]=n}return e}function $(e){if(!e)return ce[T[0].referenceStyleID].getDefaultVariant().getId();if(typeof e=="string"||e instanceof String)return e.trim().toLowerCase();if(e instanceof j)return e.getId();if(e instanceof x)return e.getDefaultVariant().getId()}const ce=oa();function sa(e){const a=[];function t(r){(r.type==="LineString"||r.type==="MultiLineString")&&a.push(r)}function n(r){r.geometry&&t(r.geometry)}function i(r){for(const o of r.features)o.type==="Feature"?n(o):o.type==="FeatureCollection"&&i(o)}return e.type==="Feature"?n(e):e.type==="FeatureCollection"?i(e):t(e),a}function da(e,a,t){let n=a[0],i=a[1],r=t[0]-n,o=t[1]-i;if(r!==0||o!==0){const s=((e[0]-n)*r+(e[1]-i)*o)/(r*r+o*o);s>1?(n=t[0],i=t[1]):s>0&&(n+=r*s,i+=o*s)}return r=e[0]-n,o=e[1]-i,r*r+o*o}function F(e,a,t,n,i){let r=n,o;for(let s=a+1;s<t;s++){const d=da(e[s],e[a],e[t]);d>r&&(o=s,r=d)}r>n&&(o-a>1&&F(e,a,o,n,i),i.push(e[o]),t-o>1&&F(e,o,t,n,i))}function ca(e,a){const t=e.length-1,n=[e[0]];return F(e,0,t,a,n),n.push(e[t]),n}function la(e,a){if(e.length<=2)return e;const t=a!==void 0?a*a:1;return ca(e,t)}const le={extractLineStrings:sa,simplify:la};function B(e,a=!0){let t=`${e[0]},${e[1]}`;return e.length===3&&a&&(t+=`,${e[2]}`),t}function G(e,a=3e3){let t=e.map(r=>r.join(",")).join("|"),n=5e-6;const i=1e-5;for(;t.length>a;)t=le.simplify(e,n).map(r=>`${r[0]},${r[1]}`).join("|"),n+=i;return t}function ga(e,a,t={}){const n=$(t.style),i=t.hiDPI?"@2x":"",r=t.format??"png";let o=~~(t.width??1024),s=~~(t.height??1024);t.hiDPI&&(o=~~(o/2),s=~~(s/2));const d=new URL(`maps/${encodeURIComponent(n)}/static/${e[0]},${e[1]},${a}/${o}x${s}${i}.${r}`,l.apiURL);if("attribution"in t&&d.searchParams.set("attribution",t.attribution.toString()),"markers"in t){let g="";const p="markerIcon"in t;p&&(g+=`icon:${t.markerIcon}|`),p&&"markerAnchor"in t&&(g+=`anchor:${t.markerAnchor}|`),p&&t.hiDPI&&(g+="scale:2|");const f=Array.isArray(t.markers[0])?t.markers:[t.markers];g+=f.map(y=>B(y,!p)).join("|"),d.searchParams.set("markers",g)}if("path"in t){let g="";if(g+=`fill:${t.pathFillColor??"none"}|`,"pathStrokeColor"in t&&(g+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const p=t.pathWidth/(t.hiDPI?2:1);g+=`width:${p.toString()}|`}g+=G(t.path),d.searchParams.set("path",g)}return d.searchParams.set("key",t.apiKey??l.apiKey),d.toString()}function pa(e,a={}){const t=$(a.style),n=a.hiDPI?"@2x":"",i=a.format??"png";let r=~~(a.width??1024),o=~~(a.height??1024);a.hiDPI&&(r=~~(r/2),o=~~(o/2));const s=new URL(`maps/${encodeURIComponent(t)}/static/${e[0]},${e[1]},${e[2]},${e[3]}/${r}x${o}${n}.${i}`,l.apiURL);if("attribution"in a&&s.searchParams.set("attribution",a.attribution.toString()),"padding"in a&&s.searchParams.set("padding",a.padding.toString()),"markers"in a){let d="";const g="markerIcon"in a;g&&(d+=`icon:${a.markerIcon}|`),g&&"markerAnchor"in a&&(d+=`anchor:${a.markerAnchor}|`),g&&a.hiDPI&&(d+="scale:2|");const p=Array.isArray(a.markers[0])?a.markers:[a.markers];d+=p.map(f=>B(f,!g)).join("|"),s.searchParams.set("markers",d)}if("path"in a){let d="";if(d+=`fill:${a.pathFillColor??"none"}|`,"pathStrokeColor"in a&&(d+=`stroke:${a.pathStrokeColor}|`),"pathWidth"in a){const g=a.pathWidth/(a.hiDPI?2:1);d+=`width:${g.toString()}|`}d+=G(a.path),s.searchParams.set("path",d)}return s.searchParams.set("key",a.apiKey??l.apiKey),s.toString()}function ua(e={}){if(!("markers"in e)&&!("path"in e))throw new Error("Automatic static maps require markers and/or path to be created.");const a=$(e.style),t=e.hiDPI?"@2x":"",n=e.format??"png";let i=~~(e.width??1024),r=~~(e.height??1024);e.hiDPI&&(i=~~(i/2),r=~~(r/2));const o=new URL(`maps/${encodeURIComponent(a)}/static/auto/${i}x${r}${t}.${n}`,l.apiURL);if("attribution"in e&&o.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&o.searchParams.set("padding",e.padding.toString()),"markers"in e){let s="";const d="markerIcon"in e;d&&(s+=`icon:${e.markerIcon}|`),d&&"markerAnchor"in e&&(s+=`anchor:${e.markerAnchor}|`),d&&e.hiDPI&&(s+="scale:2|");const g=Array.isArray(e.markers[0])?e.markers:[e.markers];s+=g.map(p=>B(p,!d)).join("|"),o.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 d=e.pathWidth/(e.hiDPI?2:1);s+=`width:${d.toString()}|`}s+=G(e.path),o.searchParams.set("path",s)}return o.searchParams.set("key",e.apiKey??l.apiKey),o.toString()}const ma={centered:ga,bounded:pa,automatic:ua},b=63710088e-1,ge=2*Math.PI*b,pe=85.0511287;function ue(e){return(180+e)/360}function me(e){return e=Math.max(Math.min(e,pe),-pe),(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+e*Math.PI/360)))/360}function fe(e){const a=ye(e);return[ue(a[0]),me(a[1])]}function he(e){return e*360-180}function ve(e){const a=180-e*360;return 360/Math.PI*Math.atan(Math.exp(a*Math.PI/180))-90}function fa(e){return[he(e[0]),ve(e[1])]}function z(e,a){const t=Math.PI/180,n=e[1]*t,i=a[1]*t,r=Math.sin(n)*Math.sin(i)+Math.cos(n)*Math.cos(i)*Math.cos((a[0]-e[0])*t);return b*Math.acos(Math.min(r,1))}function ha(e){const a=Array(e.length);a[0]=0;const t=a.length;for(let n=1;n<t;n++)a[n]=z(e[n-1],e[n])+a[n-1];return a}function ye(e){const a=e[0],t=e[1],n=360,i=((a+180)%n+n)%n-180;return[i===-180?180:i,t]}function Le(e){return ge*Math.cos(e*Math.PI/180)}function Te(e,a,t=!0){const n=2**a,i=[e[0]*n,e[1]*n];return t?[~~i[0],~~i[1]]:i}function va(e,a,t=!0){const n=fe(e);return Te(n,a,t)}function I(e){return e*Math.PI/180}function W(e){return e*180/Math.PI}function ya(e,a,t){const n=z(e,a),i=I(e[0]),r=I(e[1]),o=I(a[0]),s=I(a[1]),d=n/b,g=Math.sin((1-t)*d)/Math.sin(d),p=Math.sin(t*d)/Math.sin(d),f=g*Math.cos(r)*Math.cos(i)+p*Math.cos(s)*Math.cos(o),y=g*Math.cos(r)*Math.sin(i)+p*Math.cos(s)*Math.sin(o),S=g*Math.sin(r)+p*Math.sin(s),D=Math.atan2(S,Math.sqrt(f*f+y*y)),c=Math.atan2(y,f);return[W(c),W(D)]}const Ae={EARTH_RADIUS:b,EARTH_CIRCUMFERENCE:ge,longitudeToMercatorX:ue,latitudeToMercatorY:me,wgs84ToMercator:fe,mercatorXToLongitude:he,mercatorYToLatitude:ve,mercatorToWgs84:fa,haversineDistanceWgs84:z,wrapWgs84:ye,circumferenceAtLatitude:Le,mercatorToTileIndex:Te,wgs84ToTileIndex:va,toRadians:I,toDegrees:W,haversineIntermediateWgs84:ya,haversineCumulatedDistanceWgs84:ha};let q=null;function Se(){return q||(q=new be({maxSize:l.tileCacheSize})),q}async function Re(e){const a=new Blob([e]),t=await createImageBitmap(a),n=document.createElement("canvas"),i=n.getContext("2d");n.width=t.width,n.height=t.height,i.drawImage(t,0,0);const r=i.getImageData(0,0,n.width,n.height);return{pixels:r.data,width:n.width,height:n.height,components:r.data.length/(n.width*n.height)}}function Ie(){if(l.bufferToPixelData)return l.bufferToPixelData;if(typeof window<"u")return Re;throw new Error("An image file buffer to pixel data parser is necessary. Specify it in `config.bufferToPixelData`")}function J(){return!!l.bufferToPixelData||typeof window<"u"}const La="terrain-rgb-v2",Y=50,Ta=1e3;let N=null,De=null;const Me={403:"Key is missing, invalid or restricted"};async function Aa(e,a){e.length>Ta&&console.warn("Computing elevation for complex geometries is discouraged - simplify the geometry before proceeding");const t=Math.ceil(e.length/Y),n=Array.from({length:t},()=>null).map((r,o)=>{const s=o*Y,d=e.slice(s,s+Y).map(p=>p.join(",")).join(";"),g=new URL(`elevation/${d}.json`,l.apiURL);return g.searchParams.set("key",a),u(g.toString())}),i=await Promise.allSettled(n);return(await Promise.all(i.map(async r=>{if(r.status==="rejected")throw new Error(`Some segments could not be fetched, error: ${r.reason}`);if(!r.value.ok)throw new Error(`Some segments could not be fetched, response: ${r.value.status} ${await r.value.text()}, url: ${r.value.url}`);return r.value.json()}))).flat()}async function Sa(e,a,t){if(!N||De!==l.apiHost){const c=new URL(`tiles/${La}/tiles.json`,l.apiURL);c.searchParams.set("key",a);const A=c.toString(),h=await u(A);if(h.ok)N=await h.json(),De=l.apiHost;else throw new m(h,Me[h.status]??"")}const n=Ie(),i=N.tiles[0],r=Se(),o=N.maxzoom;let s=~~(t??o);(s>o||s<0)&&(s=o);const d=e.map(c=>Ae.wgs84ToTileIndex(c,s,!1)),g=d.map(c=>[~~c[0],~~c[1]]).map(c=>`terrain_${s.toString()}_${c[0].toString()}_${c[1].toString()}`),p=Array.from(new Set(g.filter(c=>!r.has(c)))).map(c=>c.split("_").slice(1)),f=p.map(c=>i.replace("{x}",c[1].toString()).replace("{y}",c[2].toString()).replace("{z}",c[0].toString())).map(c=>u(c)),y=(await Promise.allSettled(f)).map(c=>c.status==="fulfilled"?c.value:null).filter(c=>c),S=y.filter(c=>!c.ok);if(y.length!==f.length)throw new Error("Some tiles could not be fetched.");if(S.length)throw new m(S[0],Me[S[0].status]??"");const D=await Promise.all(y.map(c=>c.arrayBuffer()));if(!D.every(c=>c.byteLength>0))throw new Error("Some tiles are not available.");return(await Promise.all(D.map(c=>n(c)))).forEach((c,A)=>{const h=p[A],M=`terrain_${h[0].toString()}_${h[1].toString()}_${h[2].toString()}`;r.set(M,c)}),e.map((c,A)=>{const h=g[A],M=d[A],L=r.get(h),Ee=Math.min(Math.round(L.width*(M[0]%1)),L.width-1),V=(Math.min(Math.round(L.height*(M[1]%1)),L.height-1)*L.width+Ee)*L.components,Ue=L.pixels[V],ke=L.pixels[V+1],we=L.pixels[V+2],Pe=-1e4+(Ue*256*256+ke*256+we)*.1;return[c[0],c[1],~~(Pe*1e3)/1e3]})}async function Ra(e,a={}){return(await O([e],a))[0]}async function O(e,a={}){if(e.length===0)return[];const t=a.apiKey??l.apiKey,n=a.computeOn==="client"?await Sa(e,t,a.zoom):await Aa(e,t);if(a.smoothingKernelSize){const i=~~(a.smoothingKernelSize/2)*2+1,r=n.map(s=>s[2]),o=~~(i/2);for(let s=o;s<r.length-o;s+=1){let d=0;for(let g=0;g<i;g+=1){const p=r[s-o+g];d+=p}d/=i,n[s][2]=d}}return n}async function Ia(e,a={}){if(e.type!=="LineString")throw new Error("The provided object is not a GeoJSON LineString");a.computeOn??(a.computeOn=J()?"client":"server");const t=structuredClone(e),n=await O(t.coordinates,a);return t.coordinates=n,t}async function Da(e,a={}){if(e.type!=="MultiLineString")throw new Error("The provided object is not a GeoJSON MultiLineString");a.computeOn??(a.computeOn=J()?"client":"server");const t=structuredClone(e),n=t.coordinates.map(d=>d.length),i=t.coordinates.flat(),r=await O(i,a),o=[];let s=0;for(const d of n)o.push(r.slice(s,s+d)),s+=d;return t.coordinates=o,t}const Ma={at:Ra,batch:O,fromLineString:Ia,fromMultiLineString:Da};export{Q as ClientConfig,X as ISOLanguage,v as Language,ce as MapStyle,j as MapStyleVariant,Z as NonISOLanguage,x as ReferenceMapStyle,m as ServiceError,Ce as areSameLanguages,Re as bufferToPixelDataBrowser,J as canParsePixelData,Le as circumferenceAtLatitude,l as config,ea as coordinates,ta as data,de as defaultReferenceStyleMap,Ma as elevation,se as expandMapStyle,Fe as geocoding,Ge as geolocation,C as getAutoLanguage,Ie as getBufferToPixelDataParser,R as getLanguageInfoFromCode,E as getLanguageInfoFromFlag,ee as getLanguageInfoFromKey,Se as getTileCache,_ as isLanguageInfo,T as mapStylePresetList,Ae as math,le as misc,Qe as routing,ma as staticMaps,$ as styleToStyle,K as toLanguageInfo};
|
package/dist/maptiler-client.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { decode } from '@googlemaps/polyline-codec';
|
|
1
2
|
import QuickLRU from 'quick-lru';
|
|
2
3
|
|
|
4
|
+
const DEFAULT_API_HOST = "api.maptiler.com";
|
|
5
|
+
const EU_API_HOST = "api.maptiler.eu";
|
|
3
6
|
function tryGettingFetch() {
|
|
4
7
|
if (typeof self !== "undefined") {
|
|
5
8
|
return fetch.bind(self);
|
|
@@ -20,6 +23,10 @@ class ClientConfig {
|
|
|
20
23
|
* will be automatically resolved.
|
|
21
24
|
*/
|
|
22
25
|
this._fetch = tryGettingFetch();
|
|
26
|
+
/**
|
|
27
|
+
* Whether to use the EU-based `api.maptiler.eu` host instead of the default `api.maptiler.com`
|
|
28
|
+
*/
|
|
29
|
+
this._useEuEndpoints = false;
|
|
23
30
|
/**
|
|
24
31
|
* Number of tiles to keep in cache
|
|
25
32
|
*/
|
|
@@ -49,6 +56,32 @@ class ClientConfig {
|
|
|
49
56
|
get fetch() {
|
|
50
57
|
return this._fetch;
|
|
51
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Switch between the default `api.maptiler.com` host and the EU-based `api.maptiler.eu` host.
|
|
61
|
+
* Set to `false` to switch back to the default.
|
|
62
|
+
*/
|
|
63
|
+
set useEuEndpoints(value) {
|
|
64
|
+
this._useEuEndpoints = value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether the EU-based `api.maptiler.eu` host is currently in use instead of the default `api.maptiler.com`
|
|
68
|
+
*/
|
|
69
|
+
get useEuEndpoints() {
|
|
70
|
+
return this._useEuEndpoints;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The host currently used for the MapTiler API requests (`api.maptiler.com` or `api.maptiler.eu`)
|
|
74
|
+
*/
|
|
75
|
+
get apiHost() {
|
|
76
|
+
return this._useEuEndpoints ? EU_API_HOST : DEFAULT_API_HOST;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The base URL currently used for the MapTiler API requests
|
|
80
|
+
* (`https://api.maptiler.com/` or `https://api.maptiler.eu/`)
|
|
81
|
+
*/
|
|
82
|
+
get apiURL() {
|
|
83
|
+
return `https://${this.apiHost}/`;
|
|
84
|
+
}
|
|
52
85
|
}
|
|
53
86
|
const config = new ClientConfig();
|
|
54
87
|
|
|
@@ -1018,12 +1051,6 @@ async function callFetch(resource, options = {}) {
|
|
|
1018
1051
|
return config.fetch(resource, options);
|
|
1019
1052
|
}
|
|
1020
1053
|
|
|
1021
|
-
const defaults = {
|
|
1022
|
-
maptilerApiURL: "https://api.maptiler.com/",
|
|
1023
|
-
mapStyle: "streets-v2"
|
|
1024
|
-
};
|
|
1025
|
-
Object.freeze(defaults);
|
|
1026
|
-
|
|
1027
1054
|
class ServiceError extends Error {
|
|
1028
1055
|
constructor(res, customMessage = "") {
|
|
1029
1056
|
super(
|
|
@@ -1096,7 +1123,7 @@ async function forward(query, options = {}) {
|
|
|
1096
1123
|
}
|
|
1097
1124
|
const endpoint = new URL(
|
|
1098
1125
|
`geocoding/${encodeURIComponent(query)}.json`,
|
|
1099
|
-
|
|
1126
|
+
config.apiURL
|
|
1100
1127
|
);
|
|
1101
1128
|
addBaseGeocodingOptions(endpoint.searchParams, options);
|
|
1102
1129
|
addLanguageGeocodingOptions(endpoint.searchParams, options);
|
|
@@ -1114,7 +1141,7 @@ async function reverse(position, options = {}) {
|
|
|
1114
1141
|
}
|
|
1115
1142
|
const endpoint = new URL(
|
|
1116
1143
|
`geocoding/${position[0]},${position[1]}.json`,
|
|
1117
|
-
|
|
1144
|
+
config.apiURL
|
|
1118
1145
|
);
|
|
1119
1146
|
addBaseGeocodingOptions(endpoint.searchParams, options);
|
|
1120
1147
|
addLanguageGeocodingOptions(endpoint.searchParams, options);
|
|
@@ -1126,7 +1153,7 @@ async function reverse(position, options = {}) {
|
|
|
1126
1153
|
return await res.json();
|
|
1127
1154
|
}
|
|
1128
1155
|
async function byId(id, options = {}) {
|
|
1129
|
-
const endpoint = new URL(`geocoding/${id}.json`,
|
|
1156
|
+
const endpoint = new URL(`geocoding/${id}.json`, config.apiURL);
|
|
1130
1157
|
addBaseGeocodingOptions(endpoint.searchParams, options);
|
|
1131
1158
|
addLanguageGeocodingOptions(endpoint.searchParams, options);
|
|
1132
1159
|
const res = await callFetch(endpoint.toString());
|
|
@@ -1140,10 +1167,7 @@ async function batch$1(queries, options = {}) {
|
|
|
1140
1167
|
return [];
|
|
1141
1168
|
}
|
|
1142
1169
|
const joinedQuery = queries.map((query) => encodeURIComponent(query)).join(";");
|
|
1143
|
-
const endpoint = new URL(
|
|
1144
|
-
`geocoding/${joinedQuery}.json`,
|
|
1145
|
-
defaults.maptilerApiURL
|
|
1146
|
-
);
|
|
1170
|
+
const endpoint = new URL(`geocoding/${joinedQuery}.json`, config.apiURL);
|
|
1147
1171
|
addBaseGeocodingOptions(endpoint.searchParams, options);
|
|
1148
1172
|
addLanguageGeocodingOptions(endpoint.searchParams, options);
|
|
1149
1173
|
addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
|
|
@@ -1166,7 +1190,7 @@ const customMessages$3 = {
|
|
|
1166
1190
|
403: "Key is missing, invalid or restricted"
|
|
1167
1191
|
};
|
|
1168
1192
|
async function info(options = {}) {
|
|
1169
|
-
const endpoint = new URL(`geolocation/ip.json`,
|
|
1193
|
+
const endpoint = new URL(`geolocation/ip.json`, config.apiURL);
|
|
1170
1194
|
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1171
1195
|
if ("elevation" in options) {
|
|
1172
1196
|
endpoint.searchParams.set(
|
|
@@ -1189,80 +1213,6 @@ const geolocation = {
|
|
|
1189
1213
|
info
|
|
1190
1214
|
};
|
|
1191
1215
|
|
|
1192
|
-
/**
|
|
1193
|
-
* Copyright 2020 Google LLC
|
|
1194
|
-
*
|
|
1195
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1196
|
-
* you may not use this file except in compliance with the License.
|
|
1197
|
-
* You may obtain a copy of the License at
|
|
1198
|
-
*
|
|
1199
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1200
|
-
*
|
|
1201
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1202
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1203
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1204
|
-
* See the License for the specific language governing permissions and
|
|
1205
|
-
* limitations under the License.
|
|
1206
|
-
*/
|
|
1207
|
-
/**
|
|
1208
|
-
* Decodes an encoded path string into a sequence of LatLngs.
|
|
1209
|
-
*
|
|
1210
|
-
* See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm}
|
|
1211
|
-
*
|
|
1212
|
-
* #### Example
|
|
1213
|
-
*
|
|
1214
|
-
* ```js
|
|
1215
|
-
* import { decode } from "@googlemaps/polyline-codec";
|
|
1216
|
-
*
|
|
1217
|
-
* const encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
|
|
1218
|
-
* console.log(decode(encoded, 5));
|
|
1219
|
-
* // [
|
|
1220
|
-
* // [38.5, -120.2],
|
|
1221
|
-
* // [40.7, -120.95],
|
|
1222
|
-
* // [43.252, -126.453],
|
|
1223
|
-
* // ]
|
|
1224
|
-
* ```
|
|
1225
|
-
*/
|
|
1226
|
-
var decode = function (encodedPath, precision) {
|
|
1227
|
-
var factor = Math.pow(10, precision);
|
|
1228
|
-
var len = encodedPath.length;
|
|
1229
|
-
// For speed we preallocate to an upper bound on the final length, then
|
|
1230
|
-
// truncate the array before returning.
|
|
1231
|
-
var path = new Array(Math.floor(encodedPath.length / 2));
|
|
1232
|
-
var index = 0;
|
|
1233
|
-
var lat = 0;
|
|
1234
|
-
var lng = 0;
|
|
1235
|
-
var pointIndex = 0;
|
|
1236
|
-
// This code has been profiled and optimized, so don't modify it without
|
|
1237
|
-
// measuring its performance.
|
|
1238
|
-
for (; index < len; ++pointIndex) {
|
|
1239
|
-
// Fully unrolling the following loops speeds things up about 5%.
|
|
1240
|
-
var result = 1;
|
|
1241
|
-
var shift = 0;
|
|
1242
|
-
var b = void 0;
|
|
1243
|
-
do {
|
|
1244
|
-
// Invariant: "result" is current partial result plus (1 << shift).
|
|
1245
|
-
// The following line effectively clears this bit by decrementing "b".
|
|
1246
|
-
b = encodedPath.charCodeAt(index++) - 63 - 1;
|
|
1247
|
-
result += b << shift;
|
|
1248
|
-
shift += 5;
|
|
1249
|
-
} while (b >= 0x1f); // See note above.
|
|
1250
|
-
lat += result & 1 ? ~(result >> 1) : result >> 1;
|
|
1251
|
-
result = 1;
|
|
1252
|
-
shift = 0;
|
|
1253
|
-
do {
|
|
1254
|
-
b = encodedPath.charCodeAt(index++) - 63 - 1;
|
|
1255
|
-
result += b << shift;
|
|
1256
|
-
shift += 5;
|
|
1257
|
-
} while (b >= 0x1f);
|
|
1258
|
-
lng += result & 1 ? ~(result >> 1) : result >> 1;
|
|
1259
|
-
path[pointIndex] = [lat / factor, lng / factor];
|
|
1260
|
-
}
|
|
1261
|
-
// truncate array
|
|
1262
|
-
path.length = pointIndex;
|
|
1263
|
-
return path;
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
1216
|
function addLocations(search, locations) {
|
|
1267
1217
|
for (const loc of locations) {
|
|
1268
1218
|
search.append("location", `${loc.lon},${loc.lat}`);
|
|
@@ -1347,7 +1297,7 @@ async function processDirectionsResponse(res) {
|
|
|
1347
1297
|
}
|
|
1348
1298
|
async function directionsPost(body, options = {}) {
|
|
1349
1299
|
const { fetchExtras } = options;
|
|
1350
|
-
const url = new URL("routing/v1/directions",
|
|
1300
|
+
const url = new URL("routing/v1/directions", config.apiURL);
|
|
1351
1301
|
addRoutingOptions(url.searchParams, options);
|
|
1352
1302
|
const headers = new Headers(fetchExtras?.headers);
|
|
1353
1303
|
headers.set("content-type", "application/json");
|
|
@@ -1361,7 +1311,7 @@ async function directionsPost(body, options = {}) {
|
|
|
1361
1311
|
}
|
|
1362
1312
|
async function directionsGet(req, options = {}) {
|
|
1363
1313
|
const { fetchExtras } = options;
|
|
1364
|
-
const url = new URL("routing/v1/directions",
|
|
1314
|
+
const url = new URL("routing/v1/directions", config.apiURL);
|
|
1365
1315
|
const search = url.searchParams;
|
|
1366
1316
|
search.set("profile", req.profile);
|
|
1367
1317
|
if (req.id) search.set("id", req.id);
|
|
@@ -1396,10 +1346,7 @@ async function search(query, options = {}) {
|
|
|
1396
1346
|
if (typeof query !== "string" || query.trim().length === 0) {
|
|
1397
1347
|
throw new Error("The query must be a non-empty string");
|
|
1398
1348
|
}
|
|
1399
|
-
const endpoint = new URL(
|
|
1400
|
-
`coordinates/search/${query}.json`,
|
|
1401
|
-
defaults.maptilerApiURL
|
|
1402
|
-
);
|
|
1349
|
+
const endpoint = new URL(`coordinates/search/${query}.json`, config.apiURL);
|
|
1403
1350
|
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1404
1351
|
if ("limit" in options) {
|
|
1405
1352
|
endpoint.searchParams.set("limit", options.limit.toString());
|
|
@@ -1428,7 +1375,7 @@ async function transform(positions, options = {}) {
|
|
|
1428
1375
|
const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
|
|
1429
1376
|
const endpoint = new URL(
|
|
1430
1377
|
`coordinates/transform/${coordinatesStr}.json`,
|
|
1431
|
-
|
|
1378
|
+
config.apiURL
|
|
1432
1379
|
);
|
|
1433
1380
|
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1434
1381
|
if ("sourceCrs" in options) {
|
|
@@ -1468,7 +1415,7 @@ async function get(dataId, options = {}) {
|
|
|
1468
1415
|
}
|
|
1469
1416
|
const endpoint = new URL(
|
|
1470
1417
|
`data/${encodeURIComponent(dataId)}/features.json`,
|
|
1471
|
-
|
|
1418
|
+
config.apiURL
|
|
1472
1419
|
);
|
|
1473
1420
|
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
|
|
1474
1421
|
const urlWithParams = endpoint.toString();
|
|
@@ -1494,9 +1441,9 @@ function expandMapStyle(style) {
|
|
|
1494
1441
|
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
|
|
1495
1442
|
expandedStyle = trimmed;
|
|
1496
1443
|
} else if ((match = maptilerDomainRegex.exec(trimmed)) !== null) {
|
|
1497
|
-
expandedStyle =
|
|
1444
|
+
expandedStyle = `${config.apiURL}maps/${match[1]}/style.json`;
|
|
1498
1445
|
} else {
|
|
1499
|
-
expandedStyle =
|
|
1446
|
+
expandedStyle = `${config.apiURL}maps/${trimmed}/style.json`;
|
|
1500
1447
|
}
|
|
1501
1448
|
return expandedStyle;
|
|
1502
1449
|
}
|
|
@@ -2718,7 +2665,7 @@ function centered(center, zoom, options = {}) {
|
|
|
2718
2665
|
}
|
|
2719
2666
|
const endpoint = new URL(
|
|
2720
2667
|
`maps/${encodeURIComponent(style)}/static/${center[0]},${center[1]},${zoom}/${width}x${height}${scale}.${format}`,
|
|
2721
|
-
|
|
2668
|
+
config.apiURL
|
|
2722
2669
|
);
|
|
2723
2670
|
if ("attribution" in options) {
|
|
2724
2671
|
endpoint.searchParams.set("attribution", options.attribution.toString());
|
|
@@ -2767,7 +2714,7 @@ function bounded(boundingBox, options = {}) {
|
|
|
2767
2714
|
}
|
|
2768
2715
|
const endpoint = new URL(
|
|
2769
2716
|
`maps/${encodeURIComponent(style)}/static/${boundingBox[0]},${boundingBox[1]},${boundingBox[2]},${boundingBox[3]}/${width}x${height}${scale}.${format}`,
|
|
2770
|
-
|
|
2717
|
+
config.apiURL
|
|
2771
2718
|
);
|
|
2772
2719
|
if ("attribution" in options) {
|
|
2773
2720
|
endpoint.searchParams.set("attribution", options.attribution.toString());
|
|
@@ -2826,7 +2773,7 @@ function automatic(options = {}) {
|
|
|
2826
2773
|
`maps/${encodeURIComponent(
|
|
2827
2774
|
style
|
|
2828
2775
|
)}/static/auto/${width}x${height}${scale}.${format}`,
|
|
2829
|
-
|
|
2776
|
+
config.apiURL
|
|
2830
2777
|
);
|
|
2831
2778
|
if ("attribution" in options) {
|
|
2832
2779
|
endpoint.searchParams.set("attribution", options.attribution.toString());
|
|
@@ -3023,6 +2970,7 @@ const TERRAIN_TILESET = "terrain-rgb-v2";
|
|
|
3023
2970
|
const API_BATCH_SIZE = 50;
|
|
3024
2971
|
const API_WARN_SIZE = 1e3;
|
|
3025
2972
|
let terrainTileJson = null;
|
|
2973
|
+
let terrainTileJsonHost = null;
|
|
3026
2974
|
const customMessages = {
|
|
3027
2975
|
403: "Key is missing, invalid or restricted"
|
|
3028
2976
|
};
|
|
@@ -3038,10 +2986,7 @@ async function computeOnServer(positions, apiKey) {
|
|
|
3038
2986
|
const startPos = part * API_BATCH_SIZE;
|
|
3039
2987
|
const batch2 = positions.slice(startPos, startPos + API_BATCH_SIZE);
|
|
3040
2988
|
const batchEncoded = batch2.map((pos) => pos.join(",")).join(";");
|
|
3041
|
-
const endpoint = new URL(
|
|
3042
|
-
`elevation/${batchEncoded}.json`,
|
|
3043
|
-
defaults.maptilerApiURL
|
|
3044
|
-
);
|
|
2989
|
+
const endpoint = new URL(`elevation/${batchEncoded}.json`, config.apiURL);
|
|
3045
2990
|
endpoint.searchParams.set("key", apiKey);
|
|
3046
2991
|
return callFetch(endpoint.toString());
|
|
3047
2992
|
}
|
|
@@ -3065,16 +3010,17 @@ async function computeOnServer(positions, apiKey) {
|
|
|
3065
3010
|
return jsons.flat();
|
|
3066
3011
|
}
|
|
3067
3012
|
async function computeOnClient(positions, apiKey, zoom) {
|
|
3068
|
-
if (!terrainTileJson) {
|
|
3013
|
+
if (!terrainTileJson || terrainTileJsonHost !== config.apiHost) {
|
|
3069
3014
|
const endpoint = new URL(
|
|
3070
3015
|
`tiles/${TERRAIN_TILESET}/tiles.json`,
|
|
3071
|
-
|
|
3016
|
+
config.apiURL
|
|
3072
3017
|
);
|
|
3073
3018
|
endpoint.searchParams.set("key", apiKey);
|
|
3074
3019
|
const urlWithParams = endpoint.toString();
|
|
3075
3020
|
const res = await callFetch(urlWithParams);
|
|
3076
3021
|
if (res.ok) {
|
|
3077
3022
|
terrainTileJson = await res.json();
|
|
3023
|
+
terrainTileJsonHost = config.apiHost;
|
|
3078
3024
|
} else {
|
|
3079
3025
|
throw new ServiceError(res, customMessages[res.status] ?? "");
|
|
3080
3026
|
}
|