@maptiler/client 1.6.0 → 1.8.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 (118) hide show
  1. package/.github/pull_request_template.md +11 -0
  2. package/.github/workflows/format-lint.yml +24 -0
  3. package/CHANGELOG.md +25 -0
  4. package/dist/maptiler-client.cjs +587 -332
  5. package/dist/maptiler-client.cjs.map +1 -1
  6. package/dist/maptiler-client.d.ts +291 -12
  7. package/dist/maptiler-client.min.mjs +1 -1
  8. package/dist/maptiler-client.mjs +580 -332
  9. package/dist/maptiler-client.mjs.map +1 -1
  10. package/package.json +29 -20
  11. package/readme.md +134 -2
  12. package/rollup.config.js +3 -3
  13. package/tsconfig.json +1 -1
  14. package/dist/maptiler-client.umd.js +0 -1368
  15. package/dist/maptiler-client.umd.js.map +0 -1
  16. package/dist/maptiler-client.umd.min.js +0 -1
  17. package/docs/.nojekyll +0 -1
  18. package/docs/assets/custom.css +0 -118
  19. package/docs/assets/highlight.css +0 -85
  20. package/docs/assets/main.js +0 -58
  21. package/docs/assets/search.js +0 -1
  22. package/docs/assets/style.css +0 -1280
  23. package/docs/classes/config.ClientConfig.html +0 -132
  24. package/docs/classes/services_ServiceError.ServiceError.html +0 -103
  25. package/docs/functions/language.getAutoLanguageGeocoding.html +0 -60
  26. package/docs/functions/services_simplify.default.html +0 -65
  27. package/docs/images/JS-logo.svg +0 -4
  28. package/docs/images/TS-logo.svg +0 -6
  29. package/docs/images/maptiler-client-logo.afdesign +0 -0
  30. package/docs/images/maptiler-client-logo.svg +0 -75
  31. package/docs/images/maptiler-logo-256.png +0 -0
  32. package/docs/images/maptiler-logo.svg +0 -23
  33. package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
  34. package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
  35. package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  36. package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  37. package/docs/images/screenshots/static-with-path.png +0 -0
  38. package/docs/index.html +0 -340
  39. package/docs/modules/config.html +0 -71
  40. package/docs/modules/language.html +0 -71
  41. package/docs/modules/services_ServiceError.html +0 -61
  42. package/docs/modules/services_coordinates.html +0 -84
  43. package/docs/modules/services_data.html +0 -66
  44. package/docs/modules/services_geocoding.html +0 -82
  45. package/docs/modules/services_geolocation.html +0 -68
  46. package/docs/modules/services_simplify.html +0 -61
  47. package/docs/modules/services_staticMaps.html +0 -74
  48. package/docs/modules.html +0 -59
  49. package/docs/types/config.FetchFunction.html +0 -71
  50. package/docs/types/language.LanguageGeocodingString.html +0 -58
  51. package/docs/types/services_coordinates.CoordinateExport.html +0 -71
  52. package/docs/types/services_coordinates.CoordinateGrid.html +0 -69
  53. package/docs/types/services_coordinates.CoordinateId.html +0 -71
  54. package/docs/types/services_coordinates.CoordinateSearch.html +0 -93
  55. package/docs/types/services_coordinates.CoordinateSearchResult.html +0 -75
  56. package/docs/types/services_coordinates.CoordinateTransformResult.html +0 -76
  57. package/docs/types/services_coordinates.CoordinateTransformation.html +0 -89
  58. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +0 -83
  59. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +0 -85
  60. package/docs/types/services_coordinates.XYZ.html +0 -73
  61. package/docs/types/services_data.GetDataOptions.html +0 -64
  62. package/docs/types/services_geocoding.ByIdGeocodingOptions.html +0 -63
  63. package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +0 -63
  64. package/docs/types/services_geocoding.Coordinates.html +0 -63
  65. package/docs/types/services_geocoding.FeatureHierarchy.html +0 -63
  66. package/docs/types/services_geocoding.GeocodingFeature.html +0 -63
  67. package/docs/types/services_geocoding.GeocodingOptions.html +0 -63
  68. package/docs/types/services_geocoding.GeocodingSearchResult.html +0 -80
  69. package/docs/types/services_geocoding.LanguageGeocodingOptions.html +0 -70
  70. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +0 -63
  71. package/docs/types/services_geolocation.GeolocationInfoOptions.html +0 -65
  72. package/docs/types/services_geolocation.GeolocationResult.html +0 -128
  73. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +0 -61
  74. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +0 -61
  75. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +0 -61
  76. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +0 -157
  77. package/docs/types/services_staticMaps.StaticMapMarker.html +0 -61
  78. package/docs/variables/config.config.html +0 -58
  79. package/docs/variables/language.LanguageGeocoding.html +0 -171
  80. package/docs/variables/services_coordinates.coordinates.html +0 -110
  81. package/docs/variables/services_data.data.html +0 -80
  82. package/docs/variables/services_geocoding.geocoding.html +0 -265
  83. package/docs/variables/services_geolocation.geolocation.html +0 -79
  84. package/docs/variables/services_staticMaps.staticMaps.html +0 -128
  85. package/docsmd/.nojekyll +0 -1
  86. package/docsmd/README.md +0 -873
  87. package/docsmd/assets/custom.css +0 -118
  88. package/docsmd/classes/ClientConfig.md +0 -90
  89. package/docsmd/classes/MapStyleVariant.md +0 -234
  90. package/docsmd/classes/ReferenceMapStyle.md +0 -169
  91. package/docsmd/classes/ServiceError.md +0 -52
  92. package/examples/test-browser-es.html +0 -103
  93. package/examples/test-browser-umd.html +0 -90
  94. package/examples/test-node.js +0 -52
  95. package/images/JS-logo.svg +0 -4
  96. package/images/TS-logo.svg +0 -6
  97. package/images/maptiler-client-logo.afdesign +0 -0
  98. package/images/maptiler-client-logo.svg +0 -75
  99. package/images/maptiler-logo-256.png +0 -0
  100. package/images/maptiler-logo.svg +0 -23
  101. package/images/screenshots/static-bounded-europe-1024.png +0 -0
  102. package/images/screenshots/static-bounded-europe-2048.png +0 -0
  103. package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  104. package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  105. package/images/screenshots/static-with-path.png +0 -0
  106. package/src/callFetch.ts +0 -18
  107. package/src/config.ts +0 -65
  108. package/src/defaults.ts +0 -11
  109. package/src/index.ts +0 -111
  110. package/src/language.ts +0 -87
  111. package/src/mapstyle.ts +0 -968
  112. package/src/services/ServiceError.ts +0 -10
  113. package/src/services/coordinates.ts +0 -258
  114. package/src/services/data.ts +0 -63
  115. package/src/services/geocoding.ts +0 -458
  116. package/src/services/geolocation.ts +0 -139
  117. package/src/services/simplify.ts +0 -87
  118. package/src/services/staticMaps.ts +0 -463
@@ -1,1368 +0,0 @@
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
- /**
19
- * MapTiler Cloud API key
20
- */
21
- this._apiKey = "";
22
- /**
23
- * The fetch function. To be set if in Node < 18, otherwise
24
- * will be automatically resolved.
25
- */
26
- this._fetch = tryGettingFetch();
27
- }
28
- /**
29
- * Set the MapTiler Cloud API key
30
- */
31
- set apiKey(k) {
32
- this._apiKey = k;
33
- }
34
- /**
35
- * Get the MapTiler Cloud API key
36
- */
37
- get apiKey() {
38
- return this._apiKey;
39
- }
40
- /**
41
- * Set a the custom fetch function to replace the default one
42
- */
43
- set fetch(f) {
44
- this._fetch = f;
45
- }
46
- /**
47
- * Get the fetch fucntion
48
- */
49
- get fetch() {
50
- return this._fetch;
51
- }
52
- }
53
- const config = new ClientConfig();
54
-
55
- const LanguageGeocoding = {
56
- AUTO: "auto",
57
- ALBANIAN: "sq",
58
- ARABIC: "ar",
59
- ARMENIAN: "hy",
60
- AZERBAIJANI: "az",
61
- BELORUSSIAN: "be",
62
- BOSNIAN: "bs",
63
- BRETON: "br",
64
- BULGARIAN: "bg",
65
- CATALAN: "ca",
66
- CHINESE: "zh",
67
- CROATIAN: "hr",
68
- CZECH: "cs",
69
- DANISH: "da",
70
- DUTCH: "nl",
71
- ENGLISH: "en",
72
- ESPERANTO: "eo",
73
- ESTONIAN: "et",
74
- FINNISH: "fi",
75
- FRENCH: "fr",
76
- FRISIAN: "fy",
77
- GEORGIAN: "ka",
78
- GERMAN: "de",
79
- GREEK: "el",
80
- HEBREW: "he",
81
- HUNGARIAN: "hu",
82
- ICELANDIC: "is",
83
- IRISH: "ga",
84
- ITALIAN: "it",
85
- JAPANESE: "ja",
86
- KANNADA: "kn",
87
- KAZAKH: "kk",
88
- KOREAN: "ko",
89
- ROMAN_LATIN: "la",
90
- LATVIAN: "lv",
91
- LITHUANIAN: "lt",
92
- LUXEMBOURGISH: "lb",
93
- MACEDONIAN: "mk",
94
- MALTESE: "mt",
95
- NORWEGIAN: "no",
96
- POLISH: "pl",
97
- PORTUGUESE: "pt",
98
- ROMANIAN: "ro",
99
- ROMANSH: "rm",
100
- RUSSIAN: "ru",
101
- SCOTTISH_GAELIC: "gd",
102
- SERBIAN_CYRILLIC: "sr",
103
- SLOVAK: "sk",
104
- SLOVENE: "sl",
105
- SPANISH: "es",
106
- SWEDISH: "sv",
107
- THAI: "th",
108
- TURKISH: "tr",
109
- UKRAINIAN: "uk",
110
- WELSH: "cy"
111
- };
112
- const languageCodeSet = new Set(Object.values(LanguageGeocoding));
113
- function getAutoLanguageGeocoding() {
114
- if (typeof navigator === "undefined") {
115
- return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];
116
- }
117
- const canditatelangs = Array.from(
118
- new Set(navigator.languages.map((l) => l.split("-")[0]))
119
- ).filter((l) => languageCodeSet.has(l));
120
- return canditatelangs.length ? canditatelangs[0] : LanguageGeocoding.ENGLISH;
121
- }
122
-
123
- var __async$4 = (__this, __arguments, generator) => {
124
- return new Promise((resolve, reject) => {
125
- var fulfilled = (value) => {
126
- try {
127
- step(generator.next(value));
128
- } catch (e) {
129
- reject(e);
130
- }
131
- };
132
- var rejected = (value) => {
133
- try {
134
- step(generator.throw(value));
135
- } catch (e) {
136
- reject(e);
137
- }
138
- };
139
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
140
- step((generator = generator.apply(__this, __arguments)).next());
141
- });
142
- };
143
- function callFetch(_0) {
144
- return __async$4(this, arguments, function* (resource, options = {}) {
145
- if (config.fetch === null) {
146
- throw new Error(
147
- "The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
148
- );
149
- }
150
- if (new URL(resource).searchParams.get("key").trim() === "") {
151
- throw new Error(
152
- "The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
153
- );
154
- }
155
- return config.fetch(resource, options);
156
- });
157
- }
158
-
159
- const defaults = {
160
- maptilerApiURL: "https://api.maptiler.com/",
161
- mapStyle: "streets-v2"
162
- };
163
- Object.freeze(defaults);
164
-
165
- class ServiceError extends Error {
166
- constructor(res, customMessage = "") {
167
- super(
168
- `Call to enpoint ${res.url} failed with the status code ${res.status}. ${customMessage}`
169
- );
170
- this.res = res;
171
- }
172
- }
173
-
174
- var __async$3 = (__this, __arguments, generator) => {
175
- return new Promise((resolve, reject) => {
176
- var fulfilled = (value) => {
177
- try {
178
- step(generator.next(value));
179
- } catch (e) {
180
- reject(e);
181
- }
182
- };
183
- var rejected = (value) => {
184
- try {
185
- step(generator.throw(value));
186
- } catch (e) {
187
- reject(e);
188
- }
189
- };
190
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
191
- step((generator = generator.apply(__this, __arguments)).next());
192
- });
193
- };
194
- const customMessages$3 = {
195
- 400: "Query too long / Invalid parameters",
196
- 403: "Key is missing, invalid or restricted"
197
- };
198
- function addLanguageGeocodingOptions(searchParams, options) {
199
- if (options.language == void 0) {
200
- return;
201
- }
202
- const languages = Array.from(
203
- new Set(
204
- (Array.isArray(options.language) ? options.language : [options.language]).map(
205
- (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
206
- )
207
- )
208
- ).join(",");
209
- searchParams.set("language", languages);
210
- }
211
- function addCommonForwardAndReverseGeocodingOptions(searchParams, options) {
212
- var _a;
213
- searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
214
- if (options.limit != void 0) {
215
- searchParams.set("limit", String(options.limit));
216
- }
217
- if (options.types != void 0) {
218
- searchParams.set("types", options.types.join(","));
219
- }
220
- addLanguageGeocodingOptions(searchParams, options);
221
- }
222
- function addForwardGeocodingOptions(searchParams, options) {
223
- addCommonForwardAndReverseGeocodingOptions(searchParams, options);
224
- if (options.bbox != void 0) {
225
- searchParams.set("bbox", options.bbox.join(","));
226
- }
227
- if (options.proximity != void 0) {
228
- searchParams.set("proximity", options.proximity.join(","));
229
- }
230
- if (options.country != void 0) {
231
- searchParams.set("country", options.country.join(","));
232
- }
233
- if (options.fuzzyMatch != void 0) {
234
- searchParams.set("fuzzyMatch", options.fuzzyMatch ? "true" : "false");
235
- }
236
- if (options.autocomplete != void 0) {
237
- searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
238
- }
239
- }
240
- function forward(_0) {
241
- return __async$3(this, arguments, function* (query, options = {}) {
242
- var _a;
243
- if (typeof query !== "string" || query.trim().length === 0) {
244
- throw new Error("The query must be a non-empty string");
245
- }
246
- const endpoint = new URL(
247
- `geocoding/${encodeURIComponent(query)}.json`,
248
- defaults.maptilerApiURL
249
- );
250
- const { searchParams } = endpoint;
251
- addForwardGeocodingOptions(searchParams, options);
252
- const urlWithParams = endpoint.toString();
253
- const res = yield callFetch(urlWithParams);
254
- if (!res.ok) {
255
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
256
- }
257
- const obj = yield res.json();
258
- return obj;
259
- });
260
- }
261
- function reverse(_0) {
262
- return __async$3(this, arguments, function* (position, options = {}) {
263
- var _a;
264
- if (!Array.isArray(position) || position.length < 2) {
265
- throw new Error("The position must be an array of form [lng, lat].");
266
- }
267
- const endpoint = new URL(
268
- `geocoding/${position[0]},${position[1]}.json`,
269
- defaults.maptilerApiURL
270
- );
271
- addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
272
- const urlWithParams = endpoint.toString();
273
- const res = yield callFetch(urlWithParams);
274
- if (!res.ok) {
275
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
276
- }
277
- const obj = yield res.json();
278
- return obj;
279
- });
280
- }
281
- function byId(_0) {
282
- return __async$3(this, arguments, function* (id, options = {}) {
283
- var _a;
284
- const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
285
- addLanguageGeocodingOptions(endpoint.searchParams, options);
286
- const urlWithParams = endpoint.toString();
287
- const res = yield callFetch(urlWithParams);
288
- if (!res.ok) {
289
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
290
- }
291
- const obj = yield res.json();
292
- return obj;
293
- });
294
- }
295
- function batch(_0) {
296
- return __async$3(this, arguments, function* (queries, options = {}) {
297
- var _a;
298
- if (!queries.length) {
299
- return [];
300
- }
301
- const joinedQuery = queries.map((query) => encodeURIComponent(query)).join(";");
302
- const endpoint = new URL(
303
- `geocoding/${joinedQuery}.json`,
304
- defaults.maptilerApiURL
305
- );
306
- const { searchParams } = endpoint;
307
- addForwardGeocodingOptions(searchParams, options);
308
- const urlWithParams = endpoint.toString();
309
- const res = yield callFetch(urlWithParams);
310
- if (!res.ok) {
311
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
312
- }
313
- const obj = yield res.json();
314
- return queries.length === 1 ? [obj] : obj;
315
- });
316
- }
317
- const geocoding = {
318
- forward,
319
- reverse,
320
- byId,
321
- batch,
322
- language: LanguageGeocoding
323
- };
324
-
325
- var __async$2 = (__this, __arguments, generator) => {
326
- return new Promise((resolve, reject) => {
327
- var fulfilled = (value) => {
328
- try {
329
- step(generator.next(value));
330
- } catch (e) {
331
- reject(e);
332
- }
333
- };
334
- var rejected = (value) => {
335
- try {
336
- step(generator.throw(value));
337
- } catch (e) {
338
- reject(e);
339
- }
340
- };
341
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
342
- step((generator = generator.apply(__this, __arguments)).next());
343
- });
344
- };
345
- const customMessages$2 = {
346
- 403: "Key is missing, invalid or restricted"
347
- };
348
- function info() {
349
- return __async$2(this, arguments, function* (options = {}) {
350
- var _a;
351
- const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
352
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
353
- const urlWithParams = endpoint.toString();
354
- const res = yield callFetch(urlWithParams);
355
- if (!res.ok) {
356
- throw new ServiceError(
357
- res,
358
- res.status in customMessages$2 ? customMessages$2[res.status] : ""
359
- );
360
- }
361
- const obj = yield res.json();
362
- return obj;
363
- });
364
- }
365
- const geolocation = {
366
- info
367
- };
368
-
369
- var __async$1 = (__this, __arguments, generator) => {
370
- return new Promise((resolve, reject) => {
371
- var fulfilled = (value) => {
372
- try {
373
- step(generator.next(value));
374
- } catch (e) {
375
- reject(e);
376
- }
377
- };
378
- var rejected = (value) => {
379
- try {
380
- step(generator.throw(value));
381
- } catch (e) {
382
- reject(e);
383
- }
384
- };
385
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
386
- step((generator = generator.apply(__this, __arguments)).next());
387
- });
388
- };
389
- const customMessages$1 = {
390
- 403: "Key is missing, invalid or restricted"
391
- };
392
- function search(_0) {
393
- return __async$1(this, arguments, function* (query, options = {}) {
394
- var _a;
395
- if (typeof query !== "string" || query.trim().length === 0) {
396
- throw new Error("The query must be a non-empty string");
397
- }
398
- const endpoint = new URL(
399
- `coordinates/search/${query}.json`,
400
- defaults.maptilerApiURL
401
- );
402
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
403
- if ("limit" in options) {
404
- endpoint.searchParams.set("limit", options.limit.toString());
405
- }
406
- if ("transformations" in options) {
407
- endpoint.searchParams.set(
408
- "transformations",
409
- options.transformations.toString()
410
- );
411
- }
412
- if ("exports" in options) {
413
- endpoint.searchParams.set("exports", options.exports.toString());
414
- }
415
- const urlWithParams = endpoint.toString();
416
- const res = yield callFetch(urlWithParams);
417
- if (!res.ok) {
418
- throw new ServiceError(
419
- res,
420
- res.status in customMessages$1 ? customMessages$1[res.status] : ""
421
- );
422
- }
423
- const obj = yield res.json();
424
- return obj;
425
- });
426
- }
427
- function transform(_0) {
428
- return __async$1(this, arguments, function* (positions, options = {}) {
429
- var _a;
430
- const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
431
- const endpoint = new URL(
432
- `coordinates/transform/${coordinatesStr}.json`,
433
- defaults.maptilerApiURL
434
- );
435
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
436
- if ("sourceCrs" in options) {
437
- endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
438
- }
439
- if ("targetCrs" in options) {
440
- endpoint.searchParams.set("t_srs", options.targetCrs.toString());
441
- }
442
- if ("operations" in options) {
443
- endpoint.searchParams.set(
444
- "ops",
445
- (Array.isArray(options.operations) ? options.operations : [options.operations]).join("|")
446
- );
447
- }
448
- const urlWithParams = endpoint.toString();
449
- const res = yield callFetch(urlWithParams);
450
- if (!res.ok) {
451
- throw new ServiceError(
452
- res,
453
- res.status in customMessages$1 ? customMessages$1[res.status] : ""
454
- );
455
- }
456
- const obj = yield res.json();
457
- return obj;
458
- });
459
- }
460
- const coordinates = {
461
- search,
462
- transform
463
- };
464
-
465
- var __async = (__this, __arguments, generator) => {
466
- return new Promise((resolve, reject) => {
467
- var fulfilled = (value) => {
468
- try {
469
- step(generator.next(value));
470
- } catch (e) {
471
- reject(e);
472
- }
473
- };
474
- var rejected = (value) => {
475
- try {
476
- step(generator.throw(value));
477
- } catch (e) {
478
- reject(e);
479
- }
480
- };
481
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
482
- step((generator = generator.apply(__this, __arguments)).next());
483
- });
484
- };
485
- const customMessages = {
486
- 403: "Key is missing, invalid or restricted"
487
- };
488
- function get(_0) {
489
- return __async(this, arguments, function* (dataId, options = {}) {
490
- var _a;
491
- if (typeof dataId !== "string" || dataId.trim().length === 0) {
492
- throw new Error("The data ID must be a non-empty string");
493
- }
494
- const endpoint = new URL(
495
- `data/${encodeURIComponent(dataId)}/features.json`,
496
- defaults.maptilerApiURL
497
- );
498
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
499
- const urlWithParams = endpoint.toString();
500
- const res = yield callFetch(urlWithParams);
501
- if (!res.ok) {
502
- throw new ServiceError(
503
- res,
504
- res.status in customMessages ? customMessages[res.status] : ""
505
- );
506
- }
507
- const obj = yield res.json();
508
- return obj;
509
- });
510
- }
511
- const data = {
512
- get
513
- };
514
-
515
- function expandMapStyle(style) {
516
- const maptilerDomainRegex = /^maptiler:\/\/(.*)/;
517
- let match;
518
- const trimmed = style.trim();
519
- let expandedStyle;
520
- if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
521
- expandedStyle = trimmed;
522
- } else if ((match = maptilerDomainRegex.exec(trimmed)) !== null) {
523
- expandedStyle = `https://api.maptiler.com/maps/${match[1]}/style.json`;
524
- } else {
525
- expandedStyle = `https://api.maptiler.com/maps/${trimmed}/style.json`;
526
- }
527
- return expandedStyle;
528
- }
529
- class MapStyleVariant {
530
- constructor(name, variantType, id, referenceStyle, description, imageURL) {
531
- this.name = name;
532
- this.variantType = variantType;
533
- this.id = id;
534
- this.referenceStyle = referenceStyle;
535
- this.description = description;
536
- this.imageURL = imageURL;
537
- }
538
- /**
539
- * Get the human-friendly name
540
- * @returns
541
- */
542
- getName() {
543
- return this.name;
544
- }
545
- getFullName() {
546
- return `${this.referenceStyle.getName()} ${this.name}`;
547
- }
548
- /**
549
- * Get the variant type (eg. "DEFAULT", "DARK", "PASTEL", etc.)
550
- * @returns
551
- */
552
- getType() {
553
- return this.variantType;
554
- }
555
- /**
556
- * Get the MapTiler Cloud id
557
- * @returns
558
- */
559
- getId() {
560
- return this.id;
561
- }
562
- /**
563
- * Get the human-friendly description
564
- */
565
- getDescription() {
566
- return this.description;
567
- }
568
- /**
569
- * Get the reference style this variant belongs to
570
- * @returns
571
- */
572
- getReferenceStyle() {
573
- return this.referenceStyle;
574
- }
575
- /**
576
- * Check if a variant of a given type exists for _this_ variants
577
- * (eg. if this is a "DARK", then we can check if there is a "LIGHT" variant of it)
578
- * @param variantType
579
- * @returns
580
- */
581
- hasVariant(variantType) {
582
- return this.referenceStyle.hasVariant(variantType);
583
- }
584
- /**
585
- * Retrieve the variant of a given type. If not found, will return the "DEFAULT" variant.
586
- * (eg. _this_ "DARK" variant does not have any "PASTEL" variant, then the "DEFAULT" is returned)
587
- * @param variantType
588
- * @returns
589
- */
590
- getVariant(variantType) {
591
- return this.referenceStyle.getVariant(variantType);
592
- }
593
- /**
594
- * Get all the variants for _this_ variants, except _this_ current one
595
- * @returns
596
- */
597
- getVariants() {
598
- return this.referenceStyle.getVariants().filter((v) => v !== this);
599
- }
600
- /**
601
- * Get the image URL that represent _this_ variant
602
- * @returns
603
- */
604
- getImageURL() {
605
- return this.imageURL;
606
- }
607
- /**
608
- * Get the style as usable by MapLibre, a string (URL) or a plain style description (StyleSpecification)
609
- * @returns
610
- */
611
- getExpandedStyleURL() {
612
- return expandMapStyle(this.getId());
613
- }
614
- }
615
- class ReferenceMapStyle {
616
- constructor(name, id) {
617
- this.name = name;
618
- this.id = id;
619
- /**
620
- * Variants that belong to this reference style, key being the reference type
621
- */
622
- this.variants = {};
623
- /**
624
- * Variants that belong to this reference style, ordered by relevance
625
- */
626
- this.orderedVariants = [];
627
- }
628
- /**
629
- * Get the human-friendly name of this reference style
630
- * @returns
631
- */
632
- getName() {
633
- return this.name;
634
- }
635
- /**
636
- * Get the id of _this_ reference style
637
- * @returns
638
- */
639
- getId() {
640
- return this.id;
641
- }
642
- /**
643
- * Add a variant to _this_ reference style
644
- * @param v
645
- */
646
- addVariant(v) {
647
- this.variants[v.getType()] = v;
648
- this.orderedVariants.push(v);
649
- }
650
- /**
651
- * Check if a given variant type exists for this reference style
652
- * @param variantType
653
- * @returns
654
- */
655
- hasVariant(variantType) {
656
- return variantType in this.variants;
657
- }
658
- /**
659
- * Get a given variant. If the given type of variant does not exist for this reference style,
660
- * then the most relevant default variant is returned instead
661
- * @param variantType
662
- * @returns
663
- */
664
- getVariant(variantType) {
665
- return variantType in this.variants ? this.variants[variantType] : this.orderedVariants[0];
666
- }
667
- /**
668
- * Get the list of variants for this reference style
669
- * @returns
670
- */
671
- getVariants() {
672
- return Object.values(this.variants);
673
- }
674
- /**
675
- * Get the defualt variant for this reference style
676
- * @returns
677
- */
678
- getDefaultVariant() {
679
- return this.orderedVariants[0];
680
- }
681
- }
682
- const mapStylePresetList = [
683
- {
684
- referenceStyleID: "STREETS",
685
- name: "Streets",
686
- description: "",
687
- variants: [
688
- {
689
- id: "streets-v2",
690
- name: "Default",
691
- variantType: "DEFAULT",
692
- description: "",
693
- imageURL: ""
694
- },
695
- {
696
- id: "streets-v2-dark",
697
- name: "Dark",
698
- variantType: "DARK",
699
- description: "",
700
- imageURL: ""
701
- },
702
- {
703
- id: "streets-v2-light",
704
- name: "Light",
705
- variantType: "LIGHT",
706
- description: "",
707
- imageURL: ""
708
- },
709
- {
710
- id: "streets-v2-night",
711
- name: "Night",
712
- variantType: "NIGHT",
713
- description: "",
714
- imageURL: ""
715
- },
716
- {
717
- id: "streets-v2-pastel",
718
- name: "Pastel",
719
- variantType: "PASTEL",
720
- description: "",
721
- imageURL: ""
722
- }
723
- ]
724
- },
725
- {
726
- referenceStyleID: "OUTDOOR",
727
- name: "Outdoor",
728
- description: "",
729
- variants: [
730
- {
731
- id: "outdoor-v2",
732
- name: "Default",
733
- variantType: "DEFAULT",
734
- description: "",
735
- imageURL: ""
736
- },
737
- {
738
- id: "outdoor-v2-dark",
739
- name: "Dark",
740
- variantType: "DARK",
741
- description: "",
742
- imageURL: ""
743
- }
744
- ]
745
- },
746
- {
747
- referenceStyleID: "WINTER",
748
- name: "Winter",
749
- description: "",
750
- variants: [
751
- {
752
- id: "winter-v2",
753
- name: "Default",
754
- variantType: "DEFAULT",
755
- description: "",
756
- imageURL: ""
757
- },
758
- {
759
- id: "winter-v2-dark",
760
- name: "Dark",
761
- variantType: "DARK",
762
- description: "",
763
- imageURL: ""
764
- }
765
- ]
766
- },
767
- {
768
- referenceStyleID: "SATELLITE",
769
- name: "Satellite",
770
- description: "",
771
- variants: [
772
- {
773
- id: "satellite",
774
- name: "Default",
775
- variantType: "DEFAULT",
776
- description: "",
777
- imageURL: ""
778
- }
779
- ]
780
- },
781
- {
782
- referenceStyleID: "HYBRID",
783
- name: "Hybrid",
784
- description: "",
785
- variants: [
786
- {
787
- id: "hybrid",
788
- name: "Default",
789
- variantType: "DEFAULT",
790
- description: "",
791
- imageURL: ""
792
- }
793
- ]
794
- },
795
- {
796
- referenceStyleID: "BASIC",
797
- name: "Basic",
798
- description: "",
799
- variants: [
800
- {
801
- id: "basic-v2",
802
- name: "Default",
803
- variantType: "DEFAULT",
804
- description: "",
805
- imageURL: ""
806
- },
807
- {
808
- id: "basic-v2-dark",
809
- name: "Dark",
810
- variantType: "DARK",
811
- description: "",
812
- imageURL: ""
813
- },
814
- {
815
- id: "basic-v2-light",
816
- name: "Light",
817
- variantType: "LIGHT",
818
- description: "",
819
- imageURL: ""
820
- }
821
- ]
822
- },
823
- {
824
- referenceStyleID: "BRIGHT",
825
- name: "Bright",
826
- description: "",
827
- variants: [
828
- {
829
- id: "bright-v2",
830
- name: "Default",
831
- variantType: "DEFAULT",
832
- description: "",
833
- imageURL: ""
834
- },
835
- {
836
- id: "bright-v2-dark",
837
- name: "Dark",
838
- variantType: "DARK",
839
- description: "",
840
- imageURL: ""
841
- },
842
- {
843
- id: "bright-v2-light",
844
- name: "Light",
845
- variantType: "LIGHT",
846
- description: "",
847
- imageURL: ""
848
- },
849
- {
850
- id: "bright-v2-pastel",
851
- name: "Pastel",
852
- variantType: "PASTEL",
853
- description: "",
854
- imageURL: ""
855
- }
856
- ]
857
- },
858
- {
859
- referenceStyleID: "OPENSTREETMAP",
860
- name: "OpenStreetMap",
861
- description: "",
862
- variants: [
863
- {
864
- id: "openstreetmap",
865
- name: "Default",
866
- variantType: "DEFAULT",
867
- description: "",
868
- imageURL: ""
869
- }
870
- ]
871
- },
872
- {
873
- referenceStyleID: "TOPO",
874
- name: "Topo",
875
- description: "",
876
- variants: [
877
- {
878
- id: "topo-v2",
879
- name: "Default",
880
- variantType: "DEFAULT",
881
- description: "",
882
- imageURL: ""
883
- },
884
- {
885
- id: "topo-v2-dark",
886
- name: "Dark",
887
- variantType: "DARK",
888
- description: "",
889
- imageURL: ""
890
- },
891
- {
892
- id: "topo-v2-shiny",
893
- name: "Shiny",
894
- variantType: "SHINY",
895
- description: "",
896
- imageURL: ""
897
- },
898
- {
899
- id: "topo-v2-pastel",
900
- name: "Pastel",
901
- variantType: "PASTEL",
902
- description: "",
903
- imageURL: ""
904
- },
905
- {
906
- id: "topo-v2-topographique",
907
- name: "Topographique",
908
- variantType: "TOPOGRAPHIQUE",
909
- description: "",
910
- imageURL: ""
911
- }
912
- ]
913
- },
914
- {
915
- referenceStyleID: "VOYAGER",
916
- name: "Voyager",
917
- description: "",
918
- variants: [
919
- {
920
- id: "voyager-v2",
921
- name: "Default",
922
- variantType: "DEFAULT",
923
- description: "",
924
- imageURL: ""
925
- },
926
- {
927
- id: "voyager-v2-darkmatter",
928
- name: "Darkmatter",
929
- variantType: "DARK",
930
- description: "",
931
- imageURL: ""
932
- },
933
- {
934
- id: "voyager-v2-positron",
935
- name: "Positron",
936
- variantType: "LIGHT",
937
- description: "",
938
- imageURL: ""
939
- },
940
- {
941
- id: "voyager-v2-vintage",
942
- name: "Vintage",
943
- variantType: "VINTAGE",
944
- description: "",
945
- imageURL: ""
946
- }
947
- ]
948
- },
949
- {
950
- referenceStyleID: "TONER",
951
- name: "Toner",
952
- description: "",
953
- variants: [
954
- {
955
- id: "toner-v2",
956
- name: "Default",
957
- variantType: "DEFAULT",
958
- description: "",
959
- imageURL: ""
960
- },
961
- {
962
- id: "toner-v2-background",
963
- name: "Background",
964
- variantType: "BACKGROUND",
965
- description: "",
966
- imageURL: ""
967
- },
968
- {
969
- id: "toner-v2-lite",
970
- name: "Lite",
971
- variantType: "LITE",
972
- description: "",
973
- imageURL: ""
974
- },
975
- {
976
- id: "toner-v2-lines",
977
- name: "Lines",
978
- variantType: "LINES",
979
- description: "",
980
- imageURL: ""
981
- }
982
- ]
983
- },
984
- {
985
- referenceStyleID: "DATAVIZ",
986
- name: "Dataviz",
987
- description: "",
988
- variants: [
989
- {
990
- id: "dataviz",
991
- name: "Default",
992
- variantType: "DEFAULT",
993
- description: "",
994
- imageURL: ""
995
- },
996
- {
997
- id: "dataviz-dark",
998
- name: "Dark",
999
- variantType: "DARK",
1000
- description: "",
1001
- imageURL: ""
1002
- },
1003
- {
1004
- id: "dataviz-light",
1005
- name: "Light",
1006
- variantType: "LIGHT",
1007
- description: "",
1008
- imageURL: ""
1009
- }
1010
- ]
1011
- },
1012
- {
1013
- referenceStyleID: "BACKDROP",
1014
- name: "Backdrop",
1015
- description: "",
1016
- variants: [
1017
- {
1018
- id: "backdrop",
1019
- name: "Default",
1020
- variantType: "DEFAULT",
1021
- description: "",
1022
- imageURL: ""
1023
- },
1024
- {
1025
- id: "backdrop-dark",
1026
- name: "Dark",
1027
- variantType: "DARK",
1028
- description: "",
1029
- imageURL: ""
1030
- },
1031
- {
1032
- id: "backdrop-light",
1033
- name: "Light",
1034
- variantType: "LIGHT",
1035
- description: "",
1036
- imageURL: ""
1037
- }
1038
- ]
1039
- },
1040
- {
1041
- referenceStyleID: "OCEAN",
1042
- name: "Ocean",
1043
- description: "",
1044
- variants: [
1045
- {
1046
- id: "ocean",
1047
- name: "Default",
1048
- variantType: "DEFAULT",
1049
- description: "",
1050
- imageURL: ""
1051
- }
1052
- ]
1053
- }
1054
- ];
1055
- function makeReferenceStyleProxy(referenceStyle) {
1056
- return new Proxy(referenceStyle, {
1057
- get(target, prop, receiver) {
1058
- if (target.hasVariant(prop)) {
1059
- return target.getVariant(prop);
1060
- }
1061
- if (prop.toString().toUpperCase() === prop) {
1062
- return referenceStyle.getDefaultVariant();
1063
- }
1064
- return Reflect.get(target, prop, receiver);
1065
- }
1066
- });
1067
- }
1068
- function buildMapStyles() {
1069
- const mapStyle = {};
1070
- for (let i = 0; i < mapStylePresetList.length; i += 1) {
1071
- const refStyleInfo = mapStylePresetList[i];
1072
- const refStyle = makeReferenceStyleProxy(
1073
- new ReferenceMapStyle(refStyleInfo.name, refStyleInfo.referenceStyleID)
1074
- );
1075
- for (let j = 0; j < refStyleInfo.variants.length; j += 1) {
1076
- const variantInfo = refStyleInfo.variants[j];
1077
- const variant = new MapStyleVariant(
1078
- variantInfo.name,
1079
- // name
1080
- variantInfo.variantType,
1081
- // variantType
1082
- variantInfo.id,
1083
- // id
1084
- refStyle,
1085
- // referenceStyle
1086
- variantInfo.description,
1087
- variantInfo.imageURL
1088
- // imageURL
1089
- );
1090
- refStyle.addVariant(variant);
1091
- }
1092
- mapStyle[refStyleInfo.referenceStyleID] = refStyle;
1093
- }
1094
- return mapStyle;
1095
- }
1096
- function styleToStyle(style) {
1097
- if (!style) {
1098
- return MapStyle[mapStylePresetList[0].referenceStyleID].getDefaultVariant().getId();
1099
- }
1100
- if (typeof style === "string" || style instanceof String) {
1101
- return style.trim().toLowerCase();
1102
- }
1103
- if (style instanceof MapStyleVariant) {
1104
- return style.getId();
1105
- }
1106
- if (style instanceof ReferenceMapStyle) {
1107
- return style.getDefaultVariant().getId();
1108
- }
1109
- }
1110
- const MapStyle = buildMapStyles();
1111
-
1112
- function getSqSegDist(p, p1, p2) {
1113
- let x = p1[0], y = p1[1], dx = p2[0] - x, dy = p2[1] - y;
1114
- if (dx !== 0 || dy !== 0) {
1115
- const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);
1116
- if (t > 1) {
1117
- x = p2[0];
1118
- y = p2[1];
1119
- } else if (t > 0) {
1120
- x += dx * t;
1121
- y += dy * t;
1122
- }
1123
- }
1124
- dx = p[0] - x;
1125
- dy = p[1] - y;
1126
- return dx * dx + dy * dy;
1127
- }
1128
- function simplifyDPStep(points, first, last, sqTolerance, simplified) {
1129
- let maxSqDist = sqTolerance, index;
1130
- for (let i = first + 1; i < last; i++) {
1131
- const sqDist = getSqSegDist(points[i], points[first], points[last]);
1132
- if (sqDist > maxSqDist) {
1133
- index = i;
1134
- maxSqDist = sqDist;
1135
- }
1136
- }
1137
- if (maxSqDist > sqTolerance) {
1138
- if (index - first > 1) {
1139
- simplifyDPStep(points, first, index, sqTolerance, simplified);
1140
- }
1141
- simplified.push(points[index]);
1142
- if (last - index > 1) {
1143
- simplifyDPStep(points, index, last, sqTolerance, simplified);
1144
- }
1145
- }
1146
- }
1147
- function simplifyDouglasPeucker(points, sqTolerance) {
1148
- const last = points.length - 1;
1149
- const simplified = [points[0]];
1150
- simplifyDPStep(points, 0, last, sqTolerance, simplified);
1151
- simplified.push(points[last]);
1152
- return simplified;
1153
- }
1154
- function simplify(points, tolerance) {
1155
- if (points.length <= 2) {
1156
- return points;
1157
- }
1158
- const sqTolerance = tolerance !== void 0 ? tolerance * tolerance : 1;
1159
- const simplePoints = simplifyDouglasPeucker(points, sqTolerance);
1160
- return simplePoints;
1161
- }
1162
-
1163
- function staticMapMarkerToString(marker, includeColor = true) {
1164
- let str = `${marker[0]},${marker[1]}`;
1165
- if (marker.length === 3 && includeColor) {
1166
- str += `,${marker[2]}`;
1167
- }
1168
- return str;
1169
- }
1170
- function simplifyAndStringify(path, maxNbChar = 3e3) {
1171
- let str = path.map((point) => point.join(",")).join("|");
1172
- let tolerance = 5e-6;
1173
- const toleranceStep = 1e-5;
1174
- while (str.length > maxNbChar) {
1175
- const simplerPath = simplify(path, tolerance);
1176
- str = simplerPath.map((point) => `${point[0]},${point[1]}`).join("|");
1177
- tolerance += toleranceStep;
1178
- }
1179
- return str;
1180
- }
1181
- function centered(center, zoom, options = {}) {
1182
- var _a, _b, _c, _d, _e;
1183
- const style = styleToStyle(options.style);
1184
- const scale = options.hiDPI ? "@2x" : "";
1185
- const format = (_a = options.format) != null ? _a : "png";
1186
- let width = ~~((_b = options.width) != null ? _b : 1024);
1187
- let height = ~~((_c = options.height) != null ? _c : 1024);
1188
- if (options.hiDPI) {
1189
- width = ~~(width / 2);
1190
- height = ~~(height / 2);
1191
- }
1192
- const endpoint = new URL(
1193
- `maps/${encodeURIComponent(style)}/static/${center[0]},${center[1]},${zoom}/${width}x${height}${scale}.${format}`,
1194
- defaults.maptilerApiURL
1195
- );
1196
- if ("attribution" in options) {
1197
- endpoint.searchParams.set("attribution", options.attribution.toString());
1198
- }
1199
- if ("markers" in options) {
1200
- let markerStr = "";
1201
- const hasIcon = "markerIcon" in options;
1202
- if (hasIcon) {
1203
- markerStr += `icon:${options.markerIcon}|`;
1204
- }
1205
- if (hasIcon && "markerAnchor" in options) {
1206
- markerStr += `anchor:${options.markerAnchor}|`;
1207
- }
1208
- if (hasIcon && options.hiDPI) {
1209
- markerStr += `scale:2|`;
1210
- }
1211
- const markerList = Array.isArray(options.markers[0]) ? options.markers : [options.markers];
1212
- markerStr += markerList.map((m) => staticMapMarkerToString(m, !hasIcon)).join("|");
1213
- endpoint.searchParams.set("markers", markerStr);
1214
- }
1215
- if ("path" in options) {
1216
- let pathStr = "";
1217
- pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
1218
- if ("pathStrokeColor" in options) {
1219
- pathStr += `stroke:${options.pathStrokeColor}|`;
1220
- }
1221
- if ("pathWidth" in options) {
1222
- const pathWidth = options.pathWidth / (options.hiDPI ? 2 : 1);
1223
- pathStr += `width:${pathWidth.toString()}|`;
1224
- }
1225
- pathStr += simplifyAndStringify(options.path);
1226
- endpoint.searchParams.set("path", pathStr);
1227
- }
1228
- endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
1229
- return endpoint.toString();
1230
- }
1231
- function bounded(boundingBox, options = {}) {
1232
- var _a, _b, _c, _d, _e;
1233
- const style = styleToStyle(options.style);
1234
- const scale = options.hiDPI ? "@2x" : "";
1235
- const format = (_a = options.format) != null ? _a : "png";
1236
- let width = ~~((_b = options.width) != null ? _b : 1024);
1237
- let height = ~~((_c = options.height) != null ? _c : 1024);
1238
- if (options.hiDPI) {
1239
- width = ~~(width / 2);
1240
- height = ~~(height / 2);
1241
- }
1242
- const endpoint = new URL(
1243
- `maps/${encodeURIComponent(style)}/static/${boundingBox[0]},${boundingBox[1]},${boundingBox[2]},${boundingBox[3]}/${width}x${height}${scale}.${format}`,
1244
- defaults.maptilerApiURL
1245
- );
1246
- if ("attribution" in options) {
1247
- endpoint.searchParams.set("attribution", options.attribution.toString());
1248
- }
1249
- if ("padding" in options) {
1250
- endpoint.searchParams.set("padding", options.padding.toString());
1251
- }
1252
- if ("markers" in options) {
1253
- let markerStr = "";
1254
- const hasIcon = "markerIcon" in options;
1255
- if (hasIcon) {
1256
- markerStr += `icon:${options.markerIcon}|`;
1257
- }
1258
- if (hasIcon && "markerAnchor" in options) {
1259
- markerStr += `anchor:${options.markerAnchor}|`;
1260
- }
1261
- if (hasIcon && options.hiDPI) {
1262
- markerStr += `scale:2|`;
1263
- }
1264
- const markerList = Array.isArray(options.markers[0]) ? options.markers : [options.markers];
1265
- markerStr += markerList.map((m) => staticMapMarkerToString(m, !hasIcon)).join("|");
1266
- endpoint.searchParams.set("markers", markerStr);
1267
- }
1268
- if ("path" in options) {
1269
- let pathStr = "";
1270
- pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
1271
- if ("pathStrokeColor" in options) {
1272
- pathStr += `stroke:${options.pathStrokeColor}|`;
1273
- }
1274
- if ("pathWidth" in options) {
1275
- const pathWidth = options.pathWidth / (options.hiDPI ? 2 : 1);
1276
- pathStr += `width:${pathWidth.toString()}|`;
1277
- }
1278
- pathStr += simplifyAndStringify(options.path);
1279
- endpoint.searchParams.set("path", pathStr);
1280
- }
1281
- endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
1282
- return endpoint.toString();
1283
- }
1284
- function automatic(options = {}) {
1285
- var _a, _b, _c, _d, _e;
1286
- if (!("markers" in options) && !("path" in options)) {
1287
- throw new Error(
1288
- "Automatic static maps require markers and/or path to be created."
1289
- );
1290
- }
1291
- const style = styleToStyle(options.style);
1292
- const scale = options.hiDPI ? "@2x" : "";
1293
- const format = (_a = options.format) != null ? _a : "png";
1294
- let width = ~~((_b = options.width) != null ? _b : 1024);
1295
- let height = ~~((_c = options.height) != null ? _c : 1024);
1296
- if (options.hiDPI) {
1297
- width = ~~(width / 2);
1298
- height = ~~(height / 2);
1299
- }
1300
- const endpoint = new URL(
1301
- `maps/${encodeURIComponent(
1302
- style
1303
- )}/static/auto/${width}x${height}${scale}.${format}`,
1304
- defaults.maptilerApiURL
1305
- );
1306
- if ("attribution" in options) {
1307
- endpoint.searchParams.set("attribution", options.attribution.toString());
1308
- }
1309
- if ("padding" in options) {
1310
- endpoint.searchParams.set("padding", options.padding.toString());
1311
- }
1312
- if ("markers" in options) {
1313
- let markerStr = "";
1314
- const hasIcon = "markerIcon" in options;
1315
- if (hasIcon) {
1316
- markerStr += `icon:${options.markerIcon}|`;
1317
- }
1318
- if (hasIcon && "markerAnchor" in options) {
1319
- markerStr += `anchor:${options.markerAnchor}|`;
1320
- }
1321
- if (hasIcon && options.hiDPI) {
1322
- markerStr += `scale:2|`;
1323
- }
1324
- const markerList = Array.isArray(options.markers[0]) ? options.markers : [options.markers];
1325
- markerStr += markerList.map((m) => staticMapMarkerToString(m, !hasIcon)).join("|");
1326
- endpoint.searchParams.set("markers", markerStr);
1327
- }
1328
- if ("path" in options) {
1329
- let pathStr = "";
1330
- pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
1331
- if ("pathStrokeColor" in options) {
1332
- pathStr += `stroke:${options.pathStrokeColor}|`;
1333
- }
1334
- if ("pathWidth" in options) {
1335
- const pathWidth = options.pathWidth / (options.hiDPI ? 2 : 1);
1336
- pathStr += `width:${pathWidth.toString()}|`;
1337
- }
1338
- pathStr += simplifyAndStringify(options.path);
1339
- endpoint.searchParams.set("path", pathStr);
1340
- }
1341
- endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
1342
- return endpoint.toString();
1343
- }
1344
- const staticMaps = {
1345
- centered,
1346
- bounded,
1347
- automatic
1348
- };
1349
-
1350
- exports.ClientConfig = ClientConfig;
1351
- exports.LanguageGeocoding = LanguageGeocoding;
1352
- exports.MapStyle = MapStyle;
1353
- exports.MapStyleVariant = MapStyleVariant;
1354
- exports.ReferenceMapStyle = ReferenceMapStyle;
1355
- exports.ServiceError = ServiceError;
1356
- exports.config = config;
1357
- exports.coordinates = coordinates;
1358
- exports.data = data;
1359
- exports.expandMapStyle = expandMapStyle;
1360
- exports.geocoding = geocoding;
1361
- exports.geolocation = geolocation;
1362
- exports.mapStylePresetList = mapStylePresetList;
1363
- exports.staticMaps = staticMaps;
1364
-
1365
- Object.defineProperty(exports, '__esModule', { value: true });
1366
-
1367
- }));
1368
- //# sourceMappingURL=maptiler-client.umd.js.map