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