@maptiler/client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.eslintrc.cjs +6 -0
  2. package/LICENSE +29 -0
  3. package/dist/maptiler-client.cjs +692 -0
  4. package/dist/maptiler-client.cjs.map +1 -0
  5. package/dist/maptiler-client.d.ts +702 -0
  6. package/dist/maptiler-client.min.mjs +1 -0
  7. package/dist/maptiler-client.mjs +680 -0
  8. package/dist/maptiler-client.mjs.map +1 -0
  9. package/dist/maptiler-client.umd.js +698 -0
  10. package/dist/maptiler-client.umd.js.map +1 -0
  11. package/dist/maptiler-client.umd.min.js +1 -0
  12. package/docs/.nojekyll +1 -0
  13. package/docs/assets/highlight.css +85 -0
  14. package/docs/assets/main.js +54 -0
  15. package/docs/assets/search.js +1 -0
  16. package/docs/assets/style.css +1257 -0
  17. package/docs/classes/ClientConfig.html +122 -0
  18. package/docs/classes/ServiceError.html +93 -0
  19. package/docs/images/JS-logo.svg +4 -0
  20. package/docs/images/TS-logo.svg +6 -0
  21. package/docs/images/maptiler-client-logo.afdesign +0 -0
  22. package/docs/images/maptiler-client-logo.svg +75 -0
  23. package/docs/images/maptiler-logo.svg +23 -0
  24. package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
  25. package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
  26. package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  27. package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  28. package/docs/images/screenshots/static-with-path.png +0 -0
  29. package/docs/index.html +280 -0
  30. package/docs/modules.html +119 -0
  31. package/docs/types/AutomaticStaticMapOptions.html +80 -0
  32. package/docs/types/BoundedStaticMapOptions.html +80 -0
  33. package/docs/types/CenteredStaticMapOptions.html +80 -0
  34. package/docs/types/CoordinateExport.html +85 -0
  35. package/docs/types/CoordinateGrid.html +83 -0
  36. package/docs/types/CoordinateId.html +85 -0
  37. package/docs/types/CoordinateSearch.html +107 -0
  38. package/docs/types/CoordinateSearchResult.html +89 -0
  39. package/docs/types/CoordinateTransformResult.html +90 -0
  40. package/docs/types/CoordinateTransformation.html +103 -0
  41. package/docs/types/Coordinates.html +78 -0
  42. package/docs/types/CoordinatesSearchOptions.html +97 -0
  43. package/docs/types/CoordinatesTransformOptions.html +99 -0
  44. package/docs/types/FeatureHierarchy.html +89 -0
  45. package/docs/types/FetchFunction.html +93 -0
  46. package/docs/types/GeocodingFeature.html +78 -0
  47. package/docs/types/GeocodingOptions.html +97 -0
  48. package/docs/types/GeocodingSearchResult.html +95 -0
  49. package/docs/types/GeolocationInfoOptions.html +87 -0
  50. package/docs/types/GeolocationResult.html +150 -0
  51. package/docs/types/GetDataOptions.html +87 -0
  52. package/docs/types/LanguageGeocodingString.html +80 -0
  53. package/docs/types/ReverseGeocodingOptions.html +89 -0
  54. package/docs/types/StaticMapBaseOptions.html +176 -0
  55. package/docs/types/StaticMapMarker.html +80 -0
  56. package/docs/types/XYZ.html +87 -0
  57. package/docs/variables/LanguageGeocoding.html +193 -0
  58. package/docs/variables/config.html +80 -0
  59. package/docs/variables/coordinates-1.html +124 -0
  60. package/docs/variables/data.html +103 -0
  61. package/docs/variables/geocoding.html +239 -0
  62. package/docs/variables/geolocation.html +101 -0
  63. package/docs/variables/staticMaps.html +147 -0
  64. package/docsmd/.nojekyll +1 -0
  65. package/docsmd/README.md +756 -0
  66. package/docsmd/classes/ClientConfig.md +90 -0
  67. package/docsmd/classes/ServiceError.md +52 -0
  68. package/docsmd/images/JS-logo.svg +4 -0
  69. package/docsmd/images/TS-logo.svg +6 -0
  70. package/docsmd/images/maptiler-client-logo.afdesign +0 -0
  71. package/docsmd/images/maptiler-client-logo.svg +75 -0
  72. package/docsmd/images/maptiler-logo.svg +23 -0
  73. package/docsmd/images/screenshots/static-bounded-europe-1024.png +0 -0
  74. package/docsmd/images/screenshots/static-bounded-europe-2048.png +0 -0
  75. package/docsmd/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  76. package/docsmd/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  77. package/docsmd/images/screenshots/static-with-path.png +0 -0
  78. package/examples/test-browser-es.html +102 -0
  79. package/examples/test-browser-umd.html +89 -0
  80. package/examples/test-node.js +52 -0
  81. package/images/JS-logo.svg +4 -0
  82. package/images/TS-logo.svg +6 -0
  83. package/images/maptiler-client-logo.afdesign +0 -0
  84. package/images/maptiler-client-logo.svg +75 -0
  85. package/images/maptiler-logo.svg +23 -0
  86. package/images/screenshots/static-bounded-europe-1024.png +0 -0
  87. package/images/screenshots/static-bounded-europe-2048.png +0 -0
  88. package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  89. package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  90. package/images/screenshots/static-with-path.png +0 -0
  91. package/package.json +69 -0
  92. package/readme.md +287 -0
  93. package/rollup.config.js +142 -0
  94. package/src/callFetch.ts +18 -0
  95. package/src/config.ts +65 -0
  96. package/src/defaults.ts +11 -0
  97. package/src/index.ts +90 -0
  98. package/src/language.ts +87 -0
  99. package/src/services/ServiceError.ts +10 -0
  100. package/src/services/coordinates.ts +258 -0
  101. package/src/services/data.ts +63 -0
  102. package/src/services/geocoding.ts +239 -0
  103. package/src/services/geolocation.ts +139 -0
  104. package/src/services/simplify.ts +87 -0
  105. package/src/services/staticMaps.ts +462 -0
  106. package/tsconfig.json +10 -0
  107. package/typedoc.json +10 -0
@@ -0,0 +1 @@
1
+ function j(){return typeof self<"u"?fetch.bind(self):typeof global<"u"&&global.fetch?global.fetch:null}class E{constructor(){this._apiKey="",this._fetch=j()}set apiKey(e){this._apiKey=e}get apiKey(){return this._apiKey}set fetch(e){this._fetch=e}get fetch(){return this._fetch}}const g=new E,S={AUTO:"auto",ALBANIAN:"sq",ARABIC:"ar",ARMENIAN:"hy",AZERBAIJANI:"az",BELORUSSIAN:"be",BOSNIAN:"bs",BRETON:"br",BULGARIAN:"bg",CATALAN:"ca",CHINESE:"zh",CROATIAN:"hr",CZECH:"cs",DANISH:"da",DUTCH:"nl",ENGLISH:"en",ESPERANTO:"eo",ESTONIAN:"et",FINNISH:"fi",FRENCH:"fr",FRISIAN:"fy",GEORGIAN:"ka",GERMAN:"de",GREEK:"el",HEBREW:"he",HUNGARIAN:"hu",ICELANDIC:"is",IRISH:"ga",ITALIAN:"it",JAPANESE:"ja",KANNADA:"kn",KAZAKH:"kk",KOREAN:"ko",ROMAN_LATIN:"la",LATVIAN:"lv",LITHUANIAN:"lt",LUXEMBOURGISH:"lb",MACEDONIAN:"mk",MALTESE:"mt",NORWEGIAN:"no",POLISH:"pl",PORTUGUESE:"pt",ROMANIAN:"ro",ROMANSH:"rm",RUSSIAN:"ru",SCOTTISH_GAELIC:"gd",SERBIAN_CYRILLIC:"sr",SLOVAK:"sk",SLOVENE:"sl",SPANISH:"es",SWEDISH:"sv",THAI:"th",TURKISH:"tr",UKRAINIAN:"uk",WELSH:"cy"},T=new Set(Object.values(S));function L(){if(typeof navigator>"u")return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];const n=Array.from(new Set(navigator.languages.map(e=>e.split("-")[0]))).filter(e=>T.has(e));return n.length?n[0]:S.ENGLISH}var O=(n,e,t)=>new Promise((s,r)=>{var o=i=>{try{c(t.next(i))}catch(l){r(l)}},a=i=>{try{c(t.throw(i))}catch(l){r(l)}},c=i=>i.done?s(i.value):Promise.resolve(i.value).then(o,a);c((t=t.apply(n,e)).next())});function k(n){return O(this,arguments,function*(e,t={}){if(g.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 g.fetch(e,t)})}const f={maptilerApiURL:"https://api.maptiler.com/",mapStyle:"streets-v2"};Object.freeze(f);class I extends Error{constructor(e,t=""){super(`Call to enpoint ${e.url} failed with the status code ${e.status}. ${t}`),this.res=e}}var U=(n,e,t)=>new Promise((s,r)=>{var o=i=>{try{c(t.next(i))}catch(l){r(l)}},a=i=>{try{c(t.throw(i))}catch(l){r(l)}},c=i=>i.done?s(i.value):Promise.resolve(i.value).then(o,a);c((t=t.apply(n,e)).next())});const w={400:"Query too long / Invalid parameters",403:"Key is missing, invalid or restricted"};function H(n){return U(this,arguments,function*(e,t={}){var s;if(typeof e!="string"||e.trim().length===0)throw new Error("The query must be a non-empty string");const r=new URL(`geocoding/${encodeURIComponent(e)}.json`,f.maptilerApiURL);if(r.searchParams.set("key",(s=t.apiKey)!=null?s:g.apiKey),"bbox"in t&&r.searchParams.set("bbox",t.bbox.join(",")),"proximity"in t&&r.searchParams.set("proximity",t.proximity.join(",")),"language"in t){const c=Array.from(new Set((Array.isArray(t.language)?t.language:[t.language]).map(i=>i===S.AUTO?L():i))).join(",");r.searchParams.set("language",c)}const o=r.toString(),a=yield k(o);if(!a.ok)throw new I(a,a.status in w?w[a.status]:"");return yield a.json()})}function D(n){return U(this,arguments,function*(e,t={}){var s;if(!Array.isArray(e)||e.length<2)throw new Error("The position must be an array of form [lng, lat].");const r=new URL(`geocoding/${e[0]},${e[1]}.json`,f.maptilerApiURL);if(r.searchParams.set("key",(s=t.apiKey)!=null?s:g.apiKey),"language"in t){const c=Array.from(new Set((Array.isArray(t.language)?t.language:[t.language]).map(i=>i===S.AUTO?L():i))).join(",");r.searchParams.set("language",c)}const o=r.toString(),a=yield k(o);if(!a.ok)throw new I(a,a.status in w?w[a.status]:"");return yield a.json()})}const G={forward:H,reverse:D,language:S};var M=(n,e,t)=>new Promise((s,r)=>{var o=i=>{try{c(t.next(i))}catch(l){r(l)}},a=i=>{try{c(t.throw(i))}catch(l){r(l)}},c=i=>i.done?s(i.value):Promise.resolve(i.value).then(o,a);c((t=t.apply(n,e)).next())});const C={403:"Key is missing, invalid or restricted"};function _(){return M(this,arguments,function*(n={}){var e;const t=new URL("geolocation/ip.json",f.maptilerApiURL);t.searchParams.set("key",(e=n.apiKey)!=null?e:g.apiKey);const s=t.toString(),r=yield k(s);if(!r.ok)throw new I(r,r.status in C?C[r.status]:"");return yield r.json()})}const B={info:_};var K=(n,e,t)=>new Promise((s,r)=>{var o=i=>{try{c(t.next(i))}catch(l){r(l)}},a=i=>{try{c(t.throw(i))}catch(l){r(l)}},c=i=>i.done?s(i.value):Promise.resolve(i.value).then(o,a);c((t=t.apply(n,e)).next())});const $={403:"Key is missing, invalid or restricted"};function W(n){return K(this,arguments,function*(e,t={}){var s;if(typeof e!="string"||e.trim().length===0)throw new Error("The query must be a non-empty string");const r=new URL(`coordinates/search/${e}.json`,f.maptilerApiURL);r.searchParams.set("key",(s=t.apiKey)!=null?s:g.apiKey),"limit"in t&&r.searchParams.set("limit",t.limit.toString()),"transformations"in t&&r.searchParams.set("transformations",t.transformations.toString()),"exports"in t&&r.searchParams.set("exports",t.exports.toString());const o=r.toString(),a=yield k(o);if(!a.ok)throw new I(a,a.status in $?$[a.status]:"");return yield a.json()})}function F(n){return K(this,arguments,function*(e,t={}){var s;const r=(Array.isArray(e[0])?e:[e]).map(i=>`${i[0]},${i[1]}`).join(";"),o=new URL(`coordinates/transform/${r}.json`,f.maptilerApiURL);o.searchParams.set("key",(s=t.apiKey)!=null?s:g.apiKey),"sourceCrs"in t&&o.searchParams.set("s_srs",t.sourceCrs.toString()),"targetCrs"in t&&o.searchParams.set("t_srs",t.targetCrs.toString()),"operations"in t&&o.searchParams.set("ops",(Array.isArray(t.operations)?t.operations:[t.operations]).join("|"));const a=o.toString(),c=yield k(a);if(!c.ok)throw new I(c,c.status in $?$[c.status]:"");return yield c.json()})}const q={search:W,transform:F};var z=(n,e,t)=>new Promise((s,r)=>{var o=i=>{try{c(t.next(i))}catch(l){r(l)}},a=i=>{try{c(t.throw(i))}catch(l){r(l)}},c=i=>i.done?s(i.value):Promise.resolve(i.value).then(o,a);c((t=t.apply(n,e)).next())});const b={403:"Key is missing, invalid or restricted"};function J(n){return z(this,arguments,function*(e,t={}){var s;if(typeof e!="string"||e.trim().length===0)throw new Error("The data ID must be a non-empty string");const r=new URL(`data/${encodeURIComponent(e)}/features.json`,f.maptilerApiURL);r.searchParams.set("key",(s=t.apiKey)!=null?s:g.apiKey);const o=r.toString(),a=yield k(o);if(!a.ok)throw new I(a,a.status in b?b[a.status]:"");return yield a.json()})}const V={get:J};function Z(n,e,t){let s=e[0],r=e[1],o=t[0]-s,a=t[1]-r;if(o!==0||a!==0){const c=((n[0]-s)*o+(n[1]-r)*a)/(o*o+a*a);c>1?(s=t[0],r=t[1]):c>0&&(s+=o*c,r+=a*c)}return o=n[0]-s,a=n[1]-r,o*o+a*a}function N(n,e,t,s,r){let o=s,a;for(let c=e+1;c<t;c++){const i=Z(n[c],n[e],n[t]);i>o&&(a=c,o=i)}o>s&&(a-e>1&&N(n,e,a,s,r),r.push(n[a]),t-a>1&&N(n,a,t,s,r))}function Q(n,e){const t=n.length-1,s=[n[0]];return N(n,0,t,e,s),s.push(n[t]),s}function X(n,e){if(n.length<=2)return n;const t=e!==void 0?e*e:1;return Q(n,t)}function R(n,e=!0){let t=`${n[0]},${n[1]}`;return n.length===3&&e&&(t+=`,${n[2]}`),t}function v(n,e=3e3){let t=n.map(o=>o.join(",")).join("|"),s=5e-6;const r=1e-5;for(;t.length>e;)t=X(n,s).map(o=>`${o[0]},${o[1]}`).join("|"),s+=r;return t}function Y(n,e,t={}){var s,r,o,a,c,i;const l=(s=t.style)!=null?s:f.mapStyle,d=t.hiDPI?"@2x":"",A=(r=t.format)!=null?r:"png";let p=~~((o=t.width)!=null?o:1024),u=~~((a=t.height)!=null?a:1024);t.hiDPI&&(p=~~(p/2),u=~~(u/2));const h=new URL(`maps/${encodeURIComponent(l)}/static/${n[0]},${n[1]},${e}/${p}x${u}${d}.${A}`,f.maptilerApiURL);if("attribution"in t&&h.searchParams.set("attribution",t.attribution.toString()),"markers"in t){let m="";const y="markerIcon"in t;y&&(m+=`icon:${t.markerIcon}|`),y&&"markerAnchor"in t&&(m+=`anchor:${t.markerAnchor}|`),y&&t.hiDPI&&(m+="scale:2|");const P=Array.isArray(t.markers[0])?t.markers:[t.markers];m+=P.map(x=>R(x,!y)).join("|"),h.searchParams.set("markers",m)}if("path"in t){let m="";if(m+=`fill:${(c=t.pathFillColor)!=null?c:"none"}|`,"pathStrokeColor"in t&&(m+=`stroke:${t.pathStrokeColor}|`),"pathWidth"in t){const y=t.pathWidth/(t.hiDPI?2:1);m+=`width:${y.toString()}|`}m+=v(t.path),h.searchParams.set("path",m)}return h.searchParams.set("key",(i=t.apiKey)!=null?i:g.apiKey),h.toString()}function tt(n,e={}){var t,s,r,o,a,c;const i=(t=e.style)!=null?t:f.mapStyle,l=e.hiDPI?"@2x":"",d=(s=e.format)!=null?s:"png";let A=~~((r=e.width)!=null?r:1024),p=~~((o=e.height)!=null?o:1024);e.hiDPI&&(A=~~(A/2),p=~~(p/2));const u=new URL(`maps/${encodeURIComponent(i)}/static/${n[0]},${n[1]},${n[2]},${n[3]}/${A}x${p}${l}.${d}`,f.maptilerApiURL);if("attribution"in e&&u.searchParams.set("attribution",e.attribution.toString()),"padding"in e&&u.searchParams.set("padding",e.padding.toString()),"markers"in e){let h="";const m="markerIcon"in e;m&&(h+=`icon:${e.markerIcon}|`),m&&"markerAnchor"in e&&(h+=`anchor:${e.markerAnchor}|`),m&&e.hiDPI&&(h+="scale:2|");const y=Array.isArray(e.markers[0])?e.markers:[e.markers];h+=y.map(P=>R(P,!m)).join("|"),u.searchParams.set("markers",h)}if("path"in e){let h="";if(h+=`fill:${(a=e.pathFillColor)!=null?a:"none"}|`,"pathStrokeColor"in e&&(h+=`stroke:${e.pathStrokeColor}|`),"pathWidth"in e){const m=e.pathWidth/(e.hiDPI?2:1);h+=`width:${m.toString()}|`}h+=v(e.path),u.searchParams.set("path",h)}return u.searchParams.set("key",(c=e.apiKey)!=null?c:g.apiKey),u.toString()}function et(n={}){var e,t,s,r,o,a;if(!("markers"in n)&&!("path"in n))throw new Error("Automatic static maps require markers and/or path to be created.");const c=(e=n.style)!=null?e:f.mapStyle,i=n.hiDPI?"@2x":"",l=(t=n.format)!=null?t:"png";let d=~~((s=n.width)!=null?s:1024),A=~~((r=n.height)!=null?r:1024);n.hiDPI&&(d=~~(d/2),A=~~(A/2));const p=new URL(`maps/${encodeURIComponent(c)}/static/auto/${d}x${A}${i}.${l}`,f.maptilerApiURL);if("attribution"in n&&p.searchParams.set("attribution",n.attribution.toString()),"padding"in n&&p.searchParams.set("padding",n.padding.toString()),"markers"in n){let u="";const h="markerIcon"in n;h&&(u+=`icon:${n.markerIcon}|`),h&&"markerAnchor"in n&&(u+=`anchor:${n.markerAnchor}|`),h&&n.hiDPI&&(u+="scale:2|");const m=Array.isArray(n.markers[0])?n.markers:[n.markers];u+=m.map(y=>R(y,!h)).join("|"),p.searchParams.set("markers",u)}if("path"in n){let u="";if(u+=`fill:${(o=n.pathFillColor)!=null?o:"none"}|`,"pathStrokeColor"in n&&(u+=`stroke:${n.pathStrokeColor}|`),"pathWidth"in n){const h=n.pathWidth/(n.hiDPI?2:1);u+=`width:${h.toString()}|`}u+=v(n.path),p.searchParams.set("path",u)}return p.searchParams.set("key",(a=n.apiKey)!=null?a:g.apiKey),p.toString()}const nt={centered:Y,bounded:tt,automatic:et};export{E as ClientConfig,S as LanguageGeocoding,I as ServiceError,g as config,q as coordinates,V as data,G as geocoding,B as geolocation,nt as staticMaps};
@@ -0,0 +1,680 @@
1
+ function tryGettingFetch() {
2
+ if (typeof self !== "undefined") {
3
+ return fetch.bind(self);
4
+ }
5
+ if (typeof global !== "undefined" && global.fetch) {
6
+ return global.fetch;
7
+ }
8
+ return null;
9
+ }
10
+ class ClientConfig {
11
+ constructor() {
12
+ this._apiKey = "";
13
+ this._fetch = tryGettingFetch();
14
+ }
15
+ set apiKey(k) {
16
+ this._apiKey = k;
17
+ }
18
+ get apiKey() {
19
+ return this._apiKey;
20
+ }
21
+ set fetch(f) {
22
+ this._fetch = f;
23
+ }
24
+ get fetch() {
25
+ return this._fetch;
26
+ }
27
+ }
28
+ const config = new ClientConfig();
29
+
30
+ const LanguageGeocoding = {
31
+ AUTO: "auto",
32
+ ALBANIAN: "sq",
33
+ ARABIC: "ar",
34
+ ARMENIAN: "hy",
35
+ AZERBAIJANI: "az",
36
+ BELORUSSIAN: "be",
37
+ BOSNIAN: "bs",
38
+ BRETON: "br",
39
+ BULGARIAN: "bg",
40
+ CATALAN: "ca",
41
+ CHINESE: "zh",
42
+ CROATIAN: "hr",
43
+ CZECH: "cs",
44
+ DANISH: "da",
45
+ DUTCH: "nl",
46
+ ENGLISH: "en",
47
+ ESPERANTO: "eo",
48
+ ESTONIAN: "et",
49
+ FINNISH: "fi",
50
+ FRENCH: "fr",
51
+ FRISIAN: "fy",
52
+ GEORGIAN: "ka",
53
+ GERMAN: "de",
54
+ GREEK: "el",
55
+ HEBREW: "he",
56
+ HUNGARIAN: "hu",
57
+ ICELANDIC: "is",
58
+ IRISH: "ga",
59
+ ITALIAN: "it",
60
+ JAPANESE: "ja",
61
+ KANNADA: "kn",
62
+ KAZAKH: "kk",
63
+ KOREAN: "ko",
64
+ ROMAN_LATIN: "la",
65
+ LATVIAN: "lv",
66
+ LITHUANIAN: "lt",
67
+ LUXEMBOURGISH: "lb",
68
+ MACEDONIAN: "mk",
69
+ MALTESE: "mt",
70
+ NORWEGIAN: "no",
71
+ POLISH: "pl",
72
+ PORTUGUESE: "pt",
73
+ ROMANIAN: "ro",
74
+ ROMANSH: "rm",
75
+ RUSSIAN: "ru",
76
+ SCOTTISH_GAELIC: "gd",
77
+ SERBIAN_CYRILLIC: "sr",
78
+ SLOVAK: "sk",
79
+ SLOVENE: "sl",
80
+ SPANISH: "es",
81
+ SWEDISH: "sv",
82
+ THAI: "th",
83
+ TURKISH: "tr",
84
+ UKRAINIAN: "uk",
85
+ WELSH: "cy"
86
+ };
87
+ const languageCodeSet = new Set(Object.values(LanguageGeocoding));
88
+ function getAutoLanguageGeocoding() {
89
+ if (typeof navigator === "undefined") {
90
+ return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];
91
+ }
92
+ const canditatelangs = Array.from(
93
+ new Set(navigator.languages.map((l) => l.split("-")[0]))
94
+ ).filter((l) => languageCodeSet.has(l));
95
+ return canditatelangs.length ? canditatelangs[0] : LanguageGeocoding.ENGLISH;
96
+ }
97
+
98
+ var __async$4 = (__this, __arguments, generator) => {
99
+ return new Promise((resolve, reject) => {
100
+ var fulfilled = (value) => {
101
+ try {
102
+ step(generator.next(value));
103
+ } catch (e) {
104
+ reject(e);
105
+ }
106
+ };
107
+ var rejected = (value) => {
108
+ try {
109
+ step(generator.throw(value));
110
+ } catch (e) {
111
+ reject(e);
112
+ }
113
+ };
114
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
115
+ step((generator = generator.apply(__this, __arguments)).next());
116
+ });
117
+ };
118
+ function callFetch(_0) {
119
+ return __async$4(this, arguments, function* (resource, options = {}) {
120
+ if (config.fetch === null) {
121
+ throw new Error(
122
+ "The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
123
+ );
124
+ }
125
+ if (new URL(resource).searchParams.get("key").trim() === "") {
126
+ throw new Error(
127
+ "The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
128
+ );
129
+ }
130
+ return config.fetch(resource, options);
131
+ });
132
+ }
133
+
134
+ const defaults = {
135
+ maptilerApiURL: "https://api.maptiler.com/",
136
+ mapStyle: "streets-v2"
137
+ };
138
+ Object.freeze(defaults);
139
+
140
+ class ServiceError extends Error {
141
+ constructor(res, customMessage = "") {
142
+ super(
143
+ `Call to enpoint ${res.url} failed with the status code ${res.status}. ${customMessage}`
144
+ );
145
+ this.res = res;
146
+ }
147
+ }
148
+
149
+ var __async$3 = (__this, __arguments, generator) => {
150
+ return new Promise((resolve, reject) => {
151
+ var fulfilled = (value) => {
152
+ try {
153
+ step(generator.next(value));
154
+ } catch (e) {
155
+ reject(e);
156
+ }
157
+ };
158
+ var rejected = (value) => {
159
+ try {
160
+ step(generator.throw(value));
161
+ } catch (e) {
162
+ reject(e);
163
+ }
164
+ };
165
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
166
+ step((generator = generator.apply(__this, __arguments)).next());
167
+ });
168
+ };
169
+ const customMessages$3 = {
170
+ 400: "Query too long / Invalid parameters",
171
+ 403: "Key is missing, invalid or restricted"
172
+ };
173
+ function forward(_0) {
174
+ return __async$3(this, arguments, function* (query, options = {}) {
175
+ var _a;
176
+ if (typeof query !== "string" || query.trim().length === 0) {
177
+ throw new Error("The query must be a non-empty string");
178
+ }
179
+ const endpoint = new URL(
180
+ `geocoding/${encodeURIComponent(query)}.json`,
181
+ defaults.maptilerApiURL
182
+ );
183
+ endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
184
+ if ("bbox" in options) {
185
+ endpoint.searchParams.set("bbox", options.bbox.join(","));
186
+ }
187
+ if ("proximity" in options) {
188
+ endpoint.searchParams.set("proximity", options.proximity.join(","));
189
+ }
190
+ if ("language" in options) {
191
+ const languages = Array.from(
192
+ new Set(
193
+ (Array.isArray(options.language) ? options.language : [options.language]).map(
194
+ (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
195
+ )
196
+ )
197
+ ).join(",");
198
+ endpoint.searchParams.set("language", languages);
199
+ }
200
+ const urlWithParams = endpoint.toString();
201
+ const res = yield callFetch(urlWithParams);
202
+ if (!res.ok) {
203
+ throw new ServiceError(
204
+ res,
205
+ res.status in customMessages$3 ? customMessages$3[res.status] : ""
206
+ );
207
+ }
208
+ const obj = yield res.json();
209
+ return obj;
210
+ });
211
+ }
212
+ function reverse(_0) {
213
+ return __async$3(this, arguments, function* (position, options = {}) {
214
+ var _a;
215
+ if (!Array.isArray(position) || position.length < 2) {
216
+ throw new Error("The position must be an array of form [lng, lat].");
217
+ }
218
+ const endpoint = new URL(
219
+ `geocoding/${position[0]},${position[1]}.json`,
220
+ defaults.maptilerApiURL
221
+ );
222
+ endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
223
+ if ("language" in options) {
224
+ const languages = Array.from(
225
+ new Set(
226
+ (Array.isArray(options.language) ? options.language : [options.language]).map(
227
+ (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
228
+ )
229
+ )
230
+ ).join(",");
231
+ endpoint.searchParams.set("language", languages);
232
+ }
233
+ const urlWithParams = endpoint.toString();
234
+ const res = yield callFetch(urlWithParams);
235
+ if (!res.ok) {
236
+ throw new ServiceError(
237
+ res,
238
+ res.status in customMessages$3 ? customMessages$3[res.status] : ""
239
+ );
240
+ }
241
+ const obj = yield res.json();
242
+ return obj;
243
+ });
244
+ }
245
+ const geocoding = {
246
+ forward,
247
+ reverse,
248
+ language: LanguageGeocoding
249
+ };
250
+
251
+ var __async$2 = (__this, __arguments, generator) => {
252
+ return new Promise((resolve, reject) => {
253
+ var fulfilled = (value) => {
254
+ try {
255
+ step(generator.next(value));
256
+ } catch (e) {
257
+ reject(e);
258
+ }
259
+ };
260
+ var rejected = (value) => {
261
+ try {
262
+ step(generator.throw(value));
263
+ } catch (e) {
264
+ reject(e);
265
+ }
266
+ };
267
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
268
+ step((generator = generator.apply(__this, __arguments)).next());
269
+ });
270
+ };
271
+ const customMessages$2 = {
272
+ 403: "Key is missing, invalid or restricted"
273
+ };
274
+ function info() {
275
+ return __async$2(this, arguments, function* (options = {}) {
276
+ var _a;
277
+ const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
278
+ endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
279
+ const urlWithParams = endpoint.toString();
280
+ const res = yield callFetch(urlWithParams);
281
+ if (!res.ok) {
282
+ throw new ServiceError(
283
+ res,
284
+ res.status in customMessages$2 ? customMessages$2[res.status] : ""
285
+ );
286
+ }
287
+ const obj = yield res.json();
288
+ return obj;
289
+ });
290
+ }
291
+ const geolocation = {
292
+ info
293
+ };
294
+
295
+ var __async$1 = (__this, __arguments, generator) => {
296
+ return new Promise((resolve, reject) => {
297
+ var fulfilled = (value) => {
298
+ try {
299
+ step(generator.next(value));
300
+ } catch (e) {
301
+ reject(e);
302
+ }
303
+ };
304
+ var rejected = (value) => {
305
+ try {
306
+ step(generator.throw(value));
307
+ } catch (e) {
308
+ reject(e);
309
+ }
310
+ };
311
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
312
+ step((generator = generator.apply(__this, __arguments)).next());
313
+ });
314
+ };
315
+ const customMessages$1 = {
316
+ 403: "Key is missing, invalid or restricted"
317
+ };
318
+ function search(_0) {
319
+ return __async$1(this, arguments, function* (query, options = {}) {
320
+ var _a;
321
+ if (typeof query !== "string" || query.trim().length === 0) {
322
+ throw new Error("The query must be a non-empty string");
323
+ }
324
+ const endpoint = new URL(
325
+ `coordinates/search/${query}.json`,
326
+ defaults.maptilerApiURL
327
+ );
328
+ endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
329
+ if ("limit" in options) {
330
+ endpoint.searchParams.set("limit", options.limit.toString());
331
+ }
332
+ if ("transformations" in options) {
333
+ endpoint.searchParams.set(
334
+ "transformations",
335
+ options.transformations.toString()
336
+ );
337
+ }
338
+ if ("exports" in options) {
339
+ endpoint.searchParams.set("exports", options.exports.toString());
340
+ }
341
+ const urlWithParams = endpoint.toString();
342
+ const res = yield callFetch(urlWithParams);
343
+ if (!res.ok) {
344
+ throw new ServiceError(
345
+ res,
346
+ res.status in customMessages$1 ? customMessages$1[res.status] : ""
347
+ );
348
+ }
349
+ const obj = yield res.json();
350
+ return obj;
351
+ });
352
+ }
353
+ function transform(_0) {
354
+ return __async$1(this, arguments, function* (positions, options = {}) {
355
+ var _a;
356
+ const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
357
+ const endpoint = new URL(
358
+ `coordinates/transform/${coordinatesStr}.json`,
359
+ defaults.maptilerApiURL
360
+ );
361
+ endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
362
+ if ("sourceCrs" in options) {
363
+ endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
364
+ }
365
+ if ("targetCrs" in options) {
366
+ endpoint.searchParams.set("t_srs", options.targetCrs.toString());
367
+ }
368
+ if ("operations" in options) {
369
+ endpoint.searchParams.set(
370
+ "ops",
371
+ (Array.isArray(options.operations) ? options.operations : [options.operations]).join("|")
372
+ );
373
+ }
374
+ const urlWithParams = endpoint.toString();
375
+ const res = yield callFetch(urlWithParams);
376
+ if (!res.ok) {
377
+ throw new ServiceError(
378
+ res,
379
+ res.status in customMessages$1 ? customMessages$1[res.status] : ""
380
+ );
381
+ }
382
+ const obj = yield res.json();
383
+ return obj;
384
+ });
385
+ }
386
+ const coordinates = {
387
+ search,
388
+ transform
389
+ };
390
+
391
+ var __async = (__this, __arguments, generator) => {
392
+ return new Promise((resolve, reject) => {
393
+ var fulfilled = (value) => {
394
+ try {
395
+ step(generator.next(value));
396
+ } catch (e) {
397
+ reject(e);
398
+ }
399
+ };
400
+ var rejected = (value) => {
401
+ try {
402
+ step(generator.throw(value));
403
+ } catch (e) {
404
+ reject(e);
405
+ }
406
+ };
407
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
408
+ step((generator = generator.apply(__this, __arguments)).next());
409
+ });
410
+ };
411
+ const customMessages = {
412
+ 403: "Key is missing, invalid or restricted"
413
+ };
414
+ function get(_0) {
415
+ return __async(this, arguments, function* (dataId, options = {}) {
416
+ var _a;
417
+ if (typeof dataId !== "string" || dataId.trim().length === 0) {
418
+ throw new Error("The data ID must be a non-empty string");
419
+ }
420
+ const endpoint = new URL(
421
+ `data/${encodeURIComponent(dataId)}/features.json`,
422
+ defaults.maptilerApiURL
423
+ );
424
+ endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
425
+ const urlWithParams = endpoint.toString();
426
+ const res = yield callFetch(urlWithParams);
427
+ if (!res.ok) {
428
+ throw new ServiceError(
429
+ res,
430
+ res.status in customMessages ? customMessages[res.status] : ""
431
+ );
432
+ }
433
+ const obj = yield res.json();
434
+ return obj;
435
+ });
436
+ }
437
+ const data = {
438
+ get
439
+ };
440
+
441
+ function getSqSegDist(p, p1, p2) {
442
+ let x = p1[0], y = p1[1], dx = p2[0] - x, dy = p2[1] - y;
443
+ if (dx !== 0 || dy !== 0) {
444
+ const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);
445
+ if (t > 1) {
446
+ x = p2[0];
447
+ y = p2[1];
448
+ } else if (t > 0) {
449
+ x += dx * t;
450
+ y += dy * t;
451
+ }
452
+ }
453
+ dx = p[0] - x;
454
+ dy = p[1] - y;
455
+ return dx * dx + dy * dy;
456
+ }
457
+ function simplifyDPStep(points, first, last, sqTolerance, simplified) {
458
+ let maxSqDist = sqTolerance, index;
459
+ for (let i = first + 1; i < last; i++) {
460
+ const sqDist = getSqSegDist(points[i], points[first], points[last]);
461
+ if (sqDist > maxSqDist) {
462
+ index = i;
463
+ maxSqDist = sqDist;
464
+ }
465
+ }
466
+ if (maxSqDist > sqTolerance) {
467
+ if (index - first > 1) {
468
+ simplifyDPStep(points, first, index, sqTolerance, simplified);
469
+ }
470
+ simplified.push(points[index]);
471
+ if (last - index > 1) {
472
+ simplifyDPStep(points, index, last, sqTolerance, simplified);
473
+ }
474
+ }
475
+ }
476
+ function simplifyDouglasPeucker(points, sqTolerance) {
477
+ const last = points.length - 1;
478
+ const simplified = [points[0]];
479
+ simplifyDPStep(points, 0, last, sqTolerance, simplified);
480
+ simplified.push(points[last]);
481
+ return simplified;
482
+ }
483
+ function simplify(points, tolerance) {
484
+ if (points.length <= 2) {
485
+ return points;
486
+ }
487
+ const sqTolerance = tolerance !== void 0 ? tolerance * tolerance : 1;
488
+ const simplePoints = simplifyDouglasPeucker(points, sqTolerance);
489
+ return simplePoints;
490
+ }
491
+
492
+ function staticMapMarkerToString(marker, includeColor = true) {
493
+ let str = `${marker[0]},${marker[1]}`;
494
+ if (marker.length === 3 && includeColor) {
495
+ str += `,${marker[2]}`;
496
+ }
497
+ return str;
498
+ }
499
+ function simplifyAndStringify(path, maxNbChar = 3e3) {
500
+ let str = path.map((point) => point.join(",")).join("|");
501
+ let tolerance = 5e-6;
502
+ const toleranceStep = 1e-5;
503
+ while (str.length > maxNbChar) {
504
+ const simplerPath = simplify(path, tolerance);
505
+ str = simplerPath.map((point) => `${point[0]},${point[1]}`).join("|");
506
+ tolerance += toleranceStep;
507
+ }
508
+ return str;
509
+ }
510
+ function centered(center, zoom, options = {}) {
511
+ var _a, _b, _c, _d, _e, _f;
512
+ const style = (_a = options.style) != null ? _a : defaults.mapStyle;
513
+ const scale = options.hiDPI ? "@2x" : "";
514
+ const format = (_b = options.format) != null ? _b : "png";
515
+ let width = ~~((_c = options.width) != null ? _c : 1024);
516
+ let height = ~~((_d = options.height) != null ? _d : 1024);
517
+ if (options.hiDPI) {
518
+ width = ~~(width / 2);
519
+ height = ~~(height / 2);
520
+ }
521
+ const endpoint = new URL(
522
+ `maps/${encodeURIComponent(style)}/static/${center[0]},${center[1]},${zoom}/${width}x${height}${scale}.${format}`,
523
+ defaults.maptilerApiURL
524
+ );
525
+ if ("attribution" in options) {
526
+ endpoint.searchParams.set("attribution", options.attribution.toString());
527
+ }
528
+ if ("markers" in options) {
529
+ let markerStr = "";
530
+ const hasIcon = "markerIcon" in options;
531
+ if (hasIcon) {
532
+ markerStr += `icon:${options.markerIcon}|`;
533
+ }
534
+ if (hasIcon && "markerAnchor" in options) {
535
+ markerStr += `anchor:${options.markerAnchor}|`;
536
+ }
537
+ if (hasIcon && options.hiDPI) {
538
+ markerStr += `scale:2|`;
539
+ }
540
+ const markerList = Array.isArray(options.markers[0]) ? options.markers : [options.markers];
541
+ markerStr += markerList.map((m) => staticMapMarkerToString(m, !hasIcon)).join("|");
542
+ endpoint.searchParams.set("markers", markerStr);
543
+ }
544
+ if ("path" in options) {
545
+ let pathStr = "";
546
+ pathStr += `fill:${(_e = options.pathFillColor) != null ? _e : "none"}|`;
547
+ if ("pathStrokeColor" in options) {
548
+ pathStr += `stroke:${options.pathStrokeColor}|`;
549
+ }
550
+ if ("pathWidth" in options) {
551
+ const pathWidth = options.pathWidth / (options.hiDPI ? 2 : 1);
552
+ pathStr += `width:${pathWidth.toString()}|`;
553
+ }
554
+ pathStr += simplifyAndStringify(options.path);
555
+ endpoint.searchParams.set("path", pathStr);
556
+ }
557
+ endpoint.searchParams.set("key", (_f = options.apiKey) != null ? _f : config.apiKey);
558
+ return endpoint.toString();
559
+ }
560
+ function bounded(boundingBox, options = {}) {
561
+ var _a, _b, _c, _d, _e, _f;
562
+ const style = (_a = options.style) != null ? _a : defaults.mapStyle;
563
+ const scale = options.hiDPI ? "@2x" : "";
564
+ const format = (_b = options.format) != null ? _b : "png";
565
+ let width = ~~((_c = options.width) != null ? _c : 1024);
566
+ let height = ~~((_d = options.height) != null ? _d : 1024);
567
+ if (options.hiDPI) {
568
+ width = ~~(width / 2);
569
+ height = ~~(height / 2);
570
+ }
571
+ const endpoint = new URL(
572
+ `maps/${encodeURIComponent(style)}/static/${boundingBox[0]},${boundingBox[1]},${boundingBox[2]},${boundingBox[3]}/${width}x${height}${scale}.${format}`,
573
+ defaults.maptilerApiURL
574
+ );
575
+ if ("attribution" in options) {
576
+ endpoint.searchParams.set("attribution", options.attribution.toString());
577
+ }
578
+ if ("padding" in options) {
579
+ endpoint.searchParams.set("padding", options.padding.toString());
580
+ }
581
+ if ("markers" in options) {
582
+ let markerStr = "";
583
+ const hasIcon = "markerIcon" in options;
584
+ if (hasIcon) {
585
+ markerStr += `icon:${options.markerIcon}|`;
586
+ }
587
+ if (hasIcon && "markerAnchor" in options) {
588
+ markerStr += `anchor:${options.markerAnchor}|`;
589
+ }
590
+ if (hasIcon && options.hiDPI) {
591
+ markerStr += `scale:2|`;
592
+ }
593
+ const markerList = Array.isArray(options.markers[0]) ? options.markers : [options.markers];
594
+ markerStr += markerList.map((m) => staticMapMarkerToString(m, !hasIcon)).join("|");
595
+ endpoint.searchParams.set("markers", markerStr);
596
+ }
597
+ if ("path" in options) {
598
+ let pathStr = "";
599
+ pathStr += `fill:${(_e = options.pathFillColor) != null ? _e : "none"}|`;
600
+ if ("pathStrokeColor" in options) {
601
+ pathStr += `stroke:${options.pathStrokeColor}|`;
602
+ }
603
+ if ("pathWidth" in options) {
604
+ const pathWidth = options.pathWidth / (options.hiDPI ? 2 : 1);
605
+ pathStr += `width:${pathWidth.toString()}|`;
606
+ }
607
+ pathStr += simplifyAndStringify(options.path);
608
+ endpoint.searchParams.set("path", pathStr);
609
+ }
610
+ endpoint.searchParams.set("key", (_f = options.apiKey) != null ? _f : config.apiKey);
611
+ return endpoint.toString();
612
+ }
613
+ function automatic(options = {}) {
614
+ var _a, _b, _c, _d, _e, _f;
615
+ if (!("markers" in options) && !("path" in options)) {
616
+ throw new Error(
617
+ "Automatic static maps require markers and/or path to be created."
618
+ );
619
+ }
620
+ const style = (_a = options.style) != null ? _a : defaults.mapStyle;
621
+ const scale = options.hiDPI ? "@2x" : "";
622
+ const format = (_b = options.format) != null ? _b : "png";
623
+ let width = ~~((_c = options.width) != null ? _c : 1024);
624
+ let height = ~~((_d = options.height) != null ? _d : 1024);
625
+ if (options.hiDPI) {
626
+ width = ~~(width / 2);
627
+ height = ~~(height / 2);
628
+ }
629
+ const endpoint = new URL(
630
+ `maps/${encodeURIComponent(
631
+ style
632
+ )}/static/auto/${width}x${height}${scale}.${format}`,
633
+ defaults.maptilerApiURL
634
+ );
635
+ if ("attribution" in options) {
636
+ endpoint.searchParams.set("attribution", options.attribution.toString());
637
+ }
638
+ if ("padding" in options) {
639
+ endpoint.searchParams.set("padding", options.padding.toString());
640
+ }
641
+ if ("markers" in options) {
642
+ let markerStr = "";
643
+ const hasIcon = "markerIcon" in options;
644
+ if (hasIcon) {
645
+ markerStr += `icon:${options.markerIcon}|`;
646
+ }
647
+ if (hasIcon && "markerAnchor" in options) {
648
+ markerStr += `anchor:${options.markerAnchor}|`;
649
+ }
650
+ if (hasIcon && options.hiDPI) {
651
+ markerStr += `scale:2|`;
652
+ }
653
+ const markerList = Array.isArray(options.markers[0]) ? options.markers : [options.markers];
654
+ markerStr += markerList.map((m) => staticMapMarkerToString(m, !hasIcon)).join("|");
655
+ endpoint.searchParams.set("markers", markerStr);
656
+ }
657
+ if ("path" in options) {
658
+ let pathStr = "";
659
+ pathStr += `fill:${(_e = options.pathFillColor) != null ? _e : "none"}|`;
660
+ if ("pathStrokeColor" in options) {
661
+ pathStr += `stroke:${options.pathStrokeColor}|`;
662
+ }
663
+ if ("pathWidth" in options) {
664
+ const pathWidth = options.pathWidth / (options.hiDPI ? 2 : 1);
665
+ pathStr += `width:${pathWidth.toString()}|`;
666
+ }
667
+ pathStr += simplifyAndStringify(options.path);
668
+ endpoint.searchParams.set("path", pathStr);
669
+ }
670
+ endpoint.searchParams.set("key", (_f = options.apiKey) != null ? _f : config.apiKey);
671
+ return endpoint.toString();
672
+ }
673
+ const staticMaps = {
674
+ centered,
675
+ bounded,
676
+ automatic
677
+ };
678
+
679
+ export { ClientConfig, LanguageGeocoding, ServiceError, config, coordinates, data, geocoding, geolocation, staticMaps };
680
+ //# sourceMappingURL=maptiler-client.mjs.map