@maptiler/client 1.5.0 → 1.7.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 (119) hide show
  1. package/dist/maptiler-client.cjs +482 -309
  2. package/dist/maptiler-client.cjs.map +1 -1
  3. package/dist/maptiler-client.d.ts +177 -13
  4. package/dist/maptiler-client.min.mjs +1 -1
  5. package/dist/maptiler-client.mjs +471 -309
  6. package/dist/maptiler-client.mjs.map +1 -1
  7. package/dist/maptiler-client.umd.js +483 -310
  8. package/dist/maptiler-client.umd.js.map +1 -1
  9. package/dist/maptiler-client.umd.min.js +1 -1
  10. package/examples/test-node.js +9 -9
  11. package/package.json +25 -18
  12. package/readme.md +1 -1
  13. package/rollup.config.js +3 -3
  14. package/src/callFetch.ts +2 -2
  15. package/src/config.ts +4 -1
  16. package/src/demProfiler/getElevation.ts +46 -0
  17. package/src/demProfiler/index.ts +240 -0
  18. package/src/demProfiler/tileCover.ts +96 -0
  19. package/src/geometry/area.ts +96 -0
  20. package/src/geometry/distance.ts +45 -0
  21. package/src/geometry/index.ts +3 -0
  22. package/src/geometry/util.ts +34 -0
  23. package/src/index.ts +3 -0
  24. package/src/language.ts +1 -1
  25. package/src/mapstyle.ts +5 -5
  26. package/src/services/ServiceError.ts +5 -2
  27. package/src/services/coordinates.ts +14 -9
  28. package/src/services/data.ts +3 -3
  29. package/src/services/geocoding.ts +113 -32
  30. package/src/services/geolocation.ts +2 -2
  31. package/src/services/simplify.ts +3 -3
  32. package/src/services/staticMaps.ts +9 -9
  33. package/tsconfig.json +1 -1
  34. package/docs/.nojekyll +0 -1
  35. package/docs/assets/custom.css +0 -118
  36. package/docs/assets/highlight.css +0 -85
  37. package/docs/assets/main.js +0 -58
  38. package/docs/assets/search.js +0 -1
  39. package/docs/assets/style.css +0 -1280
  40. package/docs/classes/config.ClientConfig.html +0 -132
  41. package/docs/classes/services_ServiceError.ServiceError.html +0 -103
  42. package/docs/functions/language.getAutoLanguageGeocoding.html +0 -60
  43. package/docs/functions/services_simplify.default.html +0 -65
  44. package/docs/images/JS-logo.svg +0 -4
  45. package/docs/images/TS-logo.svg +0 -6
  46. package/docs/images/maptiler-client-logo.afdesign +0 -0
  47. package/docs/images/maptiler-client-logo.svg +0 -75
  48. package/docs/images/maptiler-logo-256.png +0 -0
  49. package/docs/images/maptiler-logo.svg +0 -23
  50. package/docs/images/screenshots/static-bounded-europe-1024.png +0 -0
  51. package/docs/images/screenshots/static-bounded-europe-2048.png +0 -0
  52. package/docs/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  53. package/docs/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  54. package/docs/images/screenshots/static-with-path.png +0 -0
  55. package/docs/index.html +0 -340
  56. package/docs/modules/config.html +0 -71
  57. package/docs/modules/language.html +0 -71
  58. package/docs/modules/services_ServiceError.html +0 -61
  59. package/docs/modules/services_coordinates.html +0 -84
  60. package/docs/modules/services_data.html +0 -66
  61. package/docs/modules/services_geocoding.html +0 -82
  62. package/docs/modules/services_geolocation.html +0 -68
  63. package/docs/modules/services_simplify.html +0 -61
  64. package/docs/modules/services_staticMaps.html +0 -74
  65. package/docs/modules.html +0 -59
  66. package/docs/types/config.FetchFunction.html +0 -71
  67. package/docs/types/language.LanguageGeocodingString.html +0 -58
  68. package/docs/types/services_coordinates.CoordinateExport.html +0 -71
  69. package/docs/types/services_coordinates.CoordinateGrid.html +0 -69
  70. package/docs/types/services_coordinates.CoordinateId.html +0 -71
  71. package/docs/types/services_coordinates.CoordinateSearch.html +0 -93
  72. package/docs/types/services_coordinates.CoordinateSearchResult.html +0 -75
  73. package/docs/types/services_coordinates.CoordinateTransformResult.html +0 -76
  74. package/docs/types/services_coordinates.CoordinateTransformation.html +0 -89
  75. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +0 -83
  76. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +0 -85
  77. package/docs/types/services_coordinates.XYZ.html +0 -73
  78. package/docs/types/services_data.GetDataOptions.html +0 -64
  79. package/docs/types/services_geocoding.ByIdGeocodingOptions.html +0 -63
  80. package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +0 -63
  81. package/docs/types/services_geocoding.Coordinates.html +0 -63
  82. package/docs/types/services_geocoding.FeatureHierarchy.html +0 -74
  83. package/docs/types/services_geocoding.GeocodingFeature.html +0 -63
  84. package/docs/types/services_geocoding.GeocodingOptions.html +0 -63
  85. package/docs/types/services_geocoding.GeocodingSearchResult.html +0 -80
  86. package/docs/types/services_geocoding.LanguageGeocodingOptions.html +0 -70
  87. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +0 -63
  88. package/docs/types/services_geolocation.GeolocationInfoOptions.html +0 -65
  89. package/docs/types/services_geolocation.GeolocationResult.html +0 -128
  90. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +0 -61
  91. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +0 -61
  92. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +0 -61
  93. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +0 -157
  94. package/docs/types/services_staticMaps.StaticMapMarker.html +0 -61
  95. package/docs/variables/config.config.html +0 -58
  96. package/docs/variables/language.LanguageGeocoding.html +0 -171
  97. package/docs/variables/services_coordinates.coordinates.html +0 -110
  98. package/docs/variables/services_data.data.html +0 -80
  99. package/docs/variables/services_geocoding.geocoding.html +0 -265
  100. package/docs/variables/services_geolocation.geolocation.html +0 -79
  101. package/docs/variables/services_staticMaps.staticMaps.html +0 -128
  102. package/docsmd/.nojekyll +0 -1
  103. package/docsmd/README.md +0 -880
  104. package/docsmd/assets/custom.css +0 -118
  105. package/docsmd/classes/ClientConfig.md +0 -90
  106. package/docsmd/classes/MapStyleVariant.md +0 -234
  107. package/docsmd/classes/ReferenceMapStyle.md +0 -169
  108. package/docsmd/classes/ServiceError.md +0 -52
  109. package/images/JS-logo.svg +0 -4
  110. package/images/TS-logo.svg +0 -6
  111. package/images/maptiler-client-logo.afdesign +0 -0
  112. package/images/maptiler-client-logo.svg +0 -75
  113. package/images/maptiler-logo-256.png +0 -0
  114. package/images/maptiler-logo.svg +0 -23
  115. package/images/screenshots/static-bounded-europe-1024.png +0 -0
  116. package/images/screenshots/static-bounded-europe-2048.png +0 -0
  117. package/images/screenshots/static-bounded-portugal-1024x2048.png +0 -0
  118. package/images/screenshots/static-bounded-portugal-2048x2048.png +0 -0
  119. package/images/screenshots/static-with-path.png +0 -0
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
3
+ var webMercProjection = require('web-merc-projection');
4
4
 
5
5
  function tryGettingFetch() {
6
6
  if (typeof self !== "undefined") {
@@ -118,40 +118,18 @@ function getAutoLanguageGeocoding() {
118
118
  return canditatelangs.length ? canditatelangs[0] : LanguageGeocoding.ENGLISH;
119
119
  }
120
120
 
121
- var __async$4 = (__this, __arguments, generator) => {
122
- return new Promise((resolve, reject) => {
123
- var fulfilled = (value) => {
124
- try {
125
- step(generator.next(value));
126
- } catch (e) {
127
- reject(e);
128
- }
129
- };
130
- var rejected = (value) => {
131
- try {
132
- step(generator.throw(value));
133
- } catch (e) {
134
- reject(e);
135
- }
136
- };
137
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
138
- step((generator = generator.apply(__this, __arguments)).next());
139
- });
140
- };
141
- function callFetch(_0) {
142
- return __async$4(this, arguments, function* (resource, options = {}) {
143
- if (config.fetch === null) {
144
- throw new Error(
145
- "The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
146
- );
147
- }
148
- if (new URL(resource).searchParams.get("key").trim() === "") {
149
- throw new Error(
150
- "The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
151
- );
152
- }
153
- return config.fetch(resource, options);
154
- });
121
+ async function callFetch(resource, options = {}) {
122
+ if (config.fetch === null) {
123
+ throw new Error(
124
+ "The fetch function was not found. If on NodeJS < 18 please specify the fetch function with config.fetch"
125
+ );
126
+ }
127
+ if (new URL(resource).searchParams.get("key").trim() === "") {
128
+ throw new Error(
129
+ "The MapTiler Cloud API key is missing. Set it in `config.apiKey` or get one for free at https://maptiler.com"
130
+ );
131
+ }
132
+ return config.fetch(resource, options);
155
133
  }
156
134
 
157
135
  const defaults = {
@@ -169,26 +147,6 @@ class ServiceError extends Error {
169
147
  }
170
148
  }
171
149
 
172
- var __async$3 = (__this, __arguments, generator) => {
173
- return new Promise((resolve, reject) => {
174
- var fulfilled = (value) => {
175
- try {
176
- step(generator.next(value));
177
- } catch (e) {
178
- reject(e);
179
- }
180
- };
181
- var rejected = (value) => {
182
- try {
183
- step(generator.throw(value));
184
- } catch (e) {
185
- reject(e);
186
- }
187
- };
188
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
189
- step((generator = generator.apply(__this, __arguments)).next());
190
- });
191
- };
192
150
  const customMessages$3 = {
193
151
  400: "Query too long / Invalid parameters",
194
152
  403: "Key is missing, invalid or restricted"
@@ -207,8 +165,7 @@ function addLanguageGeocodingOptions(searchParams, options) {
207
165
  searchParams.set("language", languages);
208
166
  }
209
167
  function addCommonForwardAndReverseGeocodingOptions(searchParams, options) {
210
- var _a;
211
- searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
168
+ searchParams.set("key", options.apiKey ?? config.apiKey);
212
169
  if (options.limit != void 0) {
213
170
  searchParams.set("limit", String(options.limit));
214
171
  }
@@ -235,82 +192,71 @@ function addForwardGeocodingOptions(searchParams, options) {
235
192
  searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
236
193
  }
237
194
  }
238
- function forward(_0) {
239
- return __async$3(this, arguments, function* (query, options = {}) {
240
- var _a;
241
- if (typeof query !== "string" || query.trim().length === 0) {
242
- throw new Error("The query must be a non-empty string");
243
- }
244
- const endpoint = new URL(
245
- `geocoding/${encodeURIComponent(query)}.json`,
246
- defaults.maptilerApiURL
247
- );
248
- const { searchParams } = endpoint;
249
- addForwardGeocodingOptions(searchParams, options);
250
- const urlWithParams = endpoint.toString();
251
- const res = yield callFetch(urlWithParams);
252
- if (!res.ok) {
253
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
254
- }
255
- const obj = yield res.json();
256
- return obj;
257
- });
195
+ async function forward(query, options = {}) {
196
+ if (typeof query !== "string" || query.trim().length === 0) {
197
+ throw new Error("The query must be a non-empty string");
198
+ }
199
+ const endpoint = new URL(
200
+ `geocoding/${encodeURIComponent(query)}.json`,
201
+ defaults.maptilerApiURL
202
+ );
203
+ const { searchParams } = endpoint;
204
+ addForwardGeocodingOptions(searchParams, options);
205
+ const urlWithParams = endpoint.toString();
206
+ const res = await callFetch(urlWithParams);
207
+ if (!res.ok) {
208
+ throw new ServiceError(res, customMessages$3[res.status] ?? "");
209
+ }
210
+ const obj = await res.json();
211
+ return obj;
258
212
  }
259
- function reverse(_0) {
260
- return __async$3(this, arguments, function* (position, options = {}) {
261
- var _a;
262
- if (!Array.isArray(position) || position.length < 2) {
263
- throw new Error("The position must be an array of form [lng, lat].");
264
- }
265
- const endpoint = new URL(
266
- `geocoding/${position[0]},${position[1]}.json`,
267
- defaults.maptilerApiURL
268
- );
269
- addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
270
- const urlWithParams = endpoint.toString();
271
- const res = yield callFetch(urlWithParams);
272
- if (!res.ok) {
273
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
274
- }
275
- const obj = yield res.json();
276
- return obj;
277
- });
213
+ async function reverse(position, options = {}) {
214
+ if (!Array.isArray(position) || position.length < 2) {
215
+ throw new Error("The position must be an array of form [lng, lat].");
216
+ }
217
+ const endpoint = new URL(
218
+ `geocoding/${position[0]},${position[1]}.json`,
219
+ defaults.maptilerApiURL
220
+ );
221
+ addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
222
+ const urlWithParams = endpoint.toString();
223
+ const res = await callFetch(urlWithParams);
224
+ if (!res.ok) {
225
+ throw new ServiceError(res, customMessages$3[res.status] ?? "");
226
+ }
227
+ const obj = await res.json();
228
+ return obj;
278
229
  }
279
- function byId(_0) {
280
- return __async$3(this, arguments, function* (id, options = {}) {
281
- var _a;
282
- const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
283
- addLanguageGeocodingOptions(endpoint.searchParams, options);
284
- const urlWithParams = endpoint.toString();
285
- const res = yield callFetch(urlWithParams);
286
- if (!res.ok) {
287
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
288
- }
289
- const obj = yield res.json();
290
- return obj;
291
- });
230
+ async function byId(id, options = {}) {
231
+ const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
232
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
233
+ addLanguageGeocodingOptions(endpoint.searchParams, options);
234
+ const urlWithParams = endpoint.toString();
235
+ const res = await callFetch(urlWithParams);
236
+ if (!res.ok) {
237
+ throw new ServiceError(res, customMessages$3[res.status] ?? "");
238
+ }
239
+ const obj = await res.json();
240
+ return obj;
292
241
  }
293
- function batch(_0) {
294
- return __async$3(this, arguments, function* (queries, options = {}) {
295
- var _a;
296
- if (!queries.length) {
297
- return [];
298
- }
299
- const joinedQuery = queries.map((query) => encodeURIComponent(query)).join(";");
300
- const endpoint = new URL(
301
- `geocoding/${joinedQuery}.json`,
302
- defaults.maptilerApiURL
303
- );
304
- const { searchParams } = endpoint;
305
- addForwardGeocodingOptions(searchParams, options);
306
- const urlWithParams = endpoint.toString();
307
- const res = yield callFetch(urlWithParams);
308
- if (!res.ok) {
309
- throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
310
- }
311
- const obj = yield res.json();
312
- return queries.length === 1 ? [obj] : obj;
313
- });
242
+ async function batch(queries, options = {}) {
243
+ if (!queries.length) {
244
+ return [];
245
+ }
246
+ const joinedQuery = queries.map((query) => encodeURIComponent(query)).join(";");
247
+ const endpoint = new URL(
248
+ `geocoding/${joinedQuery}.json`,
249
+ defaults.maptilerApiURL
250
+ );
251
+ const { searchParams } = endpoint;
252
+ addForwardGeocodingOptions(searchParams, options);
253
+ const urlWithParams = endpoint.toString();
254
+ const res = await callFetch(urlWithParams);
255
+ if (!res.ok) {
256
+ throw new ServiceError(res, customMessages$3[res.status] ?? "");
257
+ }
258
+ const obj = await res.json();
259
+ return queries.length === 1 ? [obj] : obj;
314
260
  }
315
261
  const geocoding = {
316
262
  forward,
@@ -320,191 +266,119 @@ const geocoding = {
320
266
  language: LanguageGeocoding
321
267
  };
322
268
 
323
- var __async$2 = (__this, __arguments, generator) => {
324
- return new Promise((resolve, reject) => {
325
- var fulfilled = (value) => {
326
- try {
327
- step(generator.next(value));
328
- } catch (e) {
329
- reject(e);
330
- }
331
- };
332
- var rejected = (value) => {
333
- try {
334
- step(generator.throw(value));
335
- } catch (e) {
336
- reject(e);
337
- }
338
- };
339
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
340
- step((generator = generator.apply(__this, __arguments)).next());
341
- });
342
- };
343
269
  const customMessages$2 = {
344
270
  403: "Key is missing, invalid or restricted"
345
271
  };
346
- function info() {
347
- return __async$2(this, arguments, function* (options = {}) {
348
- var _a;
349
- const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
350
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
351
- const urlWithParams = endpoint.toString();
352
- const res = yield callFetch(urlWithParams);
353
- if (!res.ok) {
354
- throw new ServiceError(
355
- res,
356
- res.status in customMessages$2 ? customMessages$2[res.status] : ""
357
- );
358
- }
359
- const obj = yield res.json();
360
- return obj;
361
- });
272
+ async function info(options = {}) {
273
+ const endpoint = new URL(`geolocation/ip.json`, defaults.maptilerApiURL);
274
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
275
+ const urlWithParams = endpoint.toString();
276
+ const res = await callFetch(urlWithParams);
277
+ if (!res.ok) {
278
+ throw new ServiceError(
279
+ res,
280
+ res.status in customMessages$2 ? customMessages$2[res.status] : ""
281
+ );
282
+ }
283
+ const obj = await res.json();
284
+ return obj;
362
285
  }
363
286
  const geolocation = {
364
287
  info
365
288
  };
366
289
 
367
- var __async$1 = (__this, __arguments, generator) => {
368
- return new Promise((resolve, reject) => {
369
- var fulfilled = (value) => {
370
- try {
371
- step(generator.next(value));
372
- } catch (e) {
373
- reject(e);
374
- }
375
- };
376
- var rejected = (value) => {
377
- try {
378
- step(generator.throw(value));
379
- } catch (e) {
380
- reject(e);
381
- }
382
- };
383
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
384
- step((generator = generator.apply(__this, __arguments)).next());
385
- });
386
- };
387
290
  const customMessages$1 = {
388
291
  403: "Key is missing, invalid or restricted"
389
292
  };
390
- function search(_0) {
391
- return __async$1(this, arguments, function* (query, options = {}) {
392
- var _a;
393
- if (typeof query !== "string" || query.trim().length === 0) {
394
- throw new Error("The query must be a non-empty string");
395
- }
396
- const endpoint = new URL(
397
- `coordinates/search/${query}.json`,
398
- defaults.maptilerApiURL
293
+ async function search(query, options = {}) {
294
+ if (typeof query !== "string" || query.trim().length === 0) {
295
+ throw new Error("The query must be a non-empty string");
296
+ }
297
+ const endpoint = new URL(
298
+ `coordinates/search/${query}.json`,
299
+ defaults.maptilerApiURL
300
+ );
301
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
302
+ if ("limit" in options) {
303
+ endpoint.searchParams.set("limit", options.limit.toString());
304
+ }
305
+ if ("transformations" in options) {
306
+ endpoint.searchParams.set(
307
+ "transformations",
308
+ options.transformations.toString()
399
309
  );
400
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
401
- if ("limit" in options) {
402
- endpoint.searchParams.set("limit", options.limit.toString());
403
- }
404
- if ("transformations" in options) {
405
- endpoint.searchParams.set(
406
- "transformations",
407
- options.transformations.toString()
408
- );
409
- }
410
- if ("exports" in options) {
411
- endpoint.searchParams.set("exports", options.exports.toString());
412
- }
413
- const urlWithParams = endpoint.toString();
414
- const res = yield callFetch(urlWithParams);
415
- if (!res.ok) {
416
- throw new ServiceError(
417
- res,
418
- res.status in customMessages$1 ? customMessages$1[res.status] : ""
419
- );
420
- }
421
- const obj = yield res.json();
422
- return obj;
423
- });
310
+ }
311
+ if ("exports" in options) {
312
+ endpoint.searchParams.set("exports", options.exports.toString());
313
+ }
314
+ const urlWithParams = endpoint.toString();
315
+ const res = await callFetch(urlWithParams);
316
+ if (!res.ok) {
317
+ throw new ServiceError(
318
+ res,
319
+ res.status in customMessages$1 ? customMessages$1[res.status] : ""
320
+ );
321
+ }
322
+ const obj = await res.json();
323
+ return obj;
424
324
  }
425
- function transform(_0) {
426
- return __async$1(this, arguments, function* (positions, options = {}) {
427
- var _a;
428
- const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
429
- const endpoint = new URL(
430
- `coordinates/transform/${coordinatesStr}.json`,
431
- defaults.maptilerApiURL
325
+ async function transform(positions, options = {}) {
326
+ const coordinatesStr = (Array.isArray(positions[0]) ? positions : [positions]).map((coord) => `${coord[0]},${coord[1]}`).join(";");
327
+ const endpoint = new URL(
328
+ `coordinates/transform/${coordinatesStr}.json`,
329
+ defaults.maptilerApiURL
330
+ );
331
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
332
+ if ("sourceCrs" in options) {
333
+ endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
334
+ }
335
+ if ("targetCrs" in options) {
336
+ endpoint.searchParams.set("t_srs", options.targetCrs.toString());
337
+ }
338
+ if ("operations" in options) {
339
+ endpoint.searchParams.set(
340
+ "ops",
341
+ (Array.isArray(options.operations) ? options.operations : [options.operations]).join("|")
432
342
  );
433
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
434
- if ("sourceCrs" in options) {
435
- endpoint.searchParams.set("s_srs", options.sourceCrs.toString());
436
- }
437
- if ("targetCrs" in options) {
438
- endpoint.searchParams.set("t_srs", options.targetCrs.toString());
439
- }
440
- if ("operations" in options) {
441
- endpoint.searchParams.set(
442
- "ops",
443
- (Array.isArray(options.operations) ? options.operations : [options.operations]).join("|")
444
- );
445
- }
446
- const urlWithParams = endpoint.toString();
447
- const res = yield callFetch(urlWithParams);
448
- if (!res.ok) {
449
- throw new ServiceError(
450
- res,
451
- res.status in customMessages$1 ? customMessages$1[res.status] : ""
452
- );
453
- }
454
- const obj = yield res.json();
455
- return obj;
456
- });
343
+ }
344
+ const urlWithParams = endpoint.toString();
345
+ const res = await callFetch(urlWithParams);
346
+ if (!res.ok) {
347
+ throw new ServiceError(
348
+ res,
349
+ res.status in customMessages$1 ? customMessages$1[res.status] : ""
350
+ );
351
+ }
352
+ const obj = await res.json();
353
+ return obj;
457
354
  }
458
355
  const coordinates = {
459
356
  search,
460
357
  transform
461
358
  };
462
359
 
463
- var __async = (__this, __arguments, generator) => {
464
- return new Promise((resolve, reject) => {
465
- var fulfilled = (value) => {
466
- try {
467
- step(generator.next(value));
468
- } catch (e) {
469
- reject(e);
470
- }
471
- };
472
- var rejected = (value) => {
473
- try {
474
- step(generator.throw(value));
475
- } catch (e) {
476
- reject(e);
477
- }
478
- };
479
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
480
- step((generator = generator.apply(__this, __arguments)).next());
481
- });
482
- };
483
360
  const customMessages = {
484
361
  403: "Key is missing, invalid or restricted"
485
362
  };
486
- function get(_0) {
487
- return __async(this, arguments, function* (dataId, options = {}) {
488
- var _a;
489
- if (typeof dataId !== "string" || dataId.trim().length === 0) {
490
- throw new Error("The data ID must be a non-empty string");
491
- }
492
- const endpoint = new URL(
493
- `data/${encodeURIComponent(dataId)}/features.json`,
494
- defaults.maptilerApiURL
363
+ async function get(dataId, options = {}) {
364
+ if (typeof dataId !== "string" || dataId.trim().length === 0) {
365
+ throw new Error("The data ID must be a non-empty string");
366
+ }
367
+ const endpoint = new URL(
368
+ `data/${encodeURIComponent(dataId)}/features.json`,
369
+ defaults.maptilerApiURL
370
+ );
371
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
372
+ const urlWithParams = endpoint.toString();
373
+ const res = await callFetch(urlWithParams);
374
+ if (!res.ok) {
375
+ throw new ServiceError(
376
+ res,
377
+ res.status in customMessages ? customMessages[res.status] : ""
495
378
  );
496
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
497
- const urlWithParams = endpoint.toString();
498
- const res = yield callFetch(urlWithParams);
499
- if (!res.ok) {
500
- throw new ServiceError(
501
- res,
502
- res.status in customMessages ? customMessages[res.status] : ""
503
- );
504
- }
505
- const obj = yield res.json();
506
- return obj;
507
- });
379
+ }
380
+ const obj = await res.json();
381
+ return obj;
508
382
  }
509
383
  const data = {
510
384
  get
@@ -1177,12 +1051,11 @@ function simplifyAndStringify(path, maxNbChar = 3e3) {
1177
1051
  return str;
1178
1052
  }
1179
1053
  function centered(center, zoom, options = {}) {
1180
- var _a, _b, _c, _d, _e;
1181
1054
  const style = styleToStyle(options.style);
1182
1055
  const scale = options.hiDPI ? "@2x" : "";
1183
- const format = (_a = options.format) != null ? _a : "png";
1184
- let width = ~~((_b = options.width) != null ? _b : 1024);
1185
- let height = ~~((_c = options.height) != null ? _c : 1024);
1056
+ const format = options.format ?? "png";
1057
+ let width = ~~(options.width ?? 1024);
1058
+ let height = ~~(options.height ?? 1024);
1186
1059
  if (options.hiDPI) {
1187
1060
  width = ~~(width / 2);
1188
1061
  height = ~~(height / 2);
@@ -1212,7 +1085,7 @@ function centered(center, zoom, options = {}) {
1212
1085
  }
1213
1086
  if ("path" in options) {
1214
1087
  let pathStr = "";
1215
- pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
1088
+ pathStr += `fill:${options.pathFillColor ?? "none"}|`;
1216
1089
  if ("pathStrokeColor" in options) {
1217
1090
  pathStr += `stroke:${options.pathStrokeColor}|`;
1218
1091
  }
@@ -1223,16 +1096,15 @@ function centered(center, zoom, options = {}) {
1223
1096
  pathStr += simplifyAndStringify(options.path);
1224
1097
  endpoint.searchParams.set("path", pathStr);
1225
1098
  }
1226
- endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
1099
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
1227
1100
  return endpoint.toString();
1228
1101
  }
1229
1102
  function bounded(boundingBox, options = {}) {
1230
- var _a, _b, _c, _d, _e;
1231
1103
  const style = styleToStyle(options.style);
1232
1104
  const scale = options.hiDPI ? "@2x" : "";
1233
- const format = (_a = options.format) != null ? _a : "png";
1234
- let width = ~~((_b = options.width) != null ? _b : 1024);
1235
- let height = ~~((_c = options.height) != null ? _c : 1024);
1105
+ const format = options.format ?? "png";
1106
+ let width = ~~(options.width ?? 1024);
1107
+ let height = ~~(options.height ?? 1024);
1236
1108
  if (options.hiDPI) {
1237
1109
  width = ~~(width / 2);
1238
1110
  height = ~~(height / 2);
@@ -1265,7 +1137,7 @@ function bounded(boundingBox, options = {}) {
1265
1137
  }
1266
1138
  if ("path" in options) {
1267
1139
  let pathStr = "";
1268
- pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
1140
+ pathStr += `fill:${options.pathFillColor ?? "none"}|`;
1269
1141
  if ("pathStrokeColor" in options) {
1270
1142
  pathStr += `stroke:${options.pathStrokeColor}|`;
1271
1143
  }
@@ -1276,11 +1148,10 @@ function bounded(boundingBox, options = {}) {
1276
1148
  pathStr += simplifyAndStringify(options.path);
1277
1149
  endpoint.searchParams.set("path", pathStr);
1278
1150
  }
1279
- endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
1151
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
1280
1152
  return endpoint.toString();
1281
1153
  }
1282
1154
  function automatic(options = {}) {
1283
- var _a, _b, _c, _d, _e;
1284
1155
  if (!("markers" in options) && !("path" in options)) {
1285
1156
  throw new Error(
1286
1157
  "Automatic static maps require markers and/or path to be created."
@@ -1288,9 +1159,9 @@ function automatic(options = {}) {
1288
1159
  }
1289
1160
  const style = styleToStyle(options.style);
1290
1161
  const scale = options.hiDPI ? "@2x" : "";
1291
- const format = (_a = options.format) != null ? _a : "png";
1292
- let width = ~~((_b = options.width) != null ? _b : 1024);
1293
- let height = ~~((_c = options.height) != null ? _c : 1024);
1162
+ const format = options.format ?? "png";
1163
+ let width = ~~(options.width ?? 1024);
1164
+ let height = ~~(options.height ?? 1024);
1294
1165
  if (options.hiDPI) {
1295
1166
  width = ~~(width / 2);
1296
1167
  height = ~~(height / 2);
@@ -1325,7 +1196,7 @@ function automatic(options = {}) {
1325
1196
  }
1326
1197
  if ("path" in options) {
1327
1198
  let pathStr = "";
1328
- pathStr += `fill:${(_d = options.pathFillColor) != null ? _d : "none"}|`;
1199
+ pathStr += `fill:${options.pathFillColor ?? "none"}|`;
1329
1200
  if ("pathStrokeColor" in options) {
1330
1201
  pathStr += `stroke:${options.pathStrokeColor}|`;
1331
1202
  }
@@ -1336,7 +1207,7 @@ function automatic(options = {}) {
1336
1207
  pathStr += simplifyAndStringify(options.path);
1337
1208
  endpoint.searchParams.set("path", pathStr);
1338
1209
  }
1339
- endpoint.searchParams.set("key", (_e = options.apiKey) != null ? _e : config.apiKey);
1210
+ endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
1340
1211
  return endpoint.toString();
1341
1212
  }
1342
1213
  const staticMaps = {
@@ -1345,18 +1216,320 @@ const staticMaps = {
1345
1216
  automatic
1346
1217
  };
1347
1218
 
1219
+ const earthRadius = 63710088e-1;
1220
+ function mToFt(m) {
1221
+ return m * 3.28084;
1222
+ }
1223
+ function degToRad(degrees) {
1224
+ return degrees % 360 * Math.PI / 180;
1225
+ }
1226
+ function radToDeg(radians) {
1227
+ return radians * 180 / Math.PI;
1228
+ }
1229
+ function getZoomLevelResolution(latitude, zoom, tileSize = 512) {
1230
+ return Math.cos(latitude * Math.PI / 180) * 2 * Math.PI * 6378137 / (tileSize * 2 ** zoom) * 3;
1231
+ }
1232
+ function xyzToTileID(x, y, zoom) {
1233
+ return ((1 << zoom) * y + x) * 32 + zoom;
1234
+ }
1235
+
1236
+ function area(area2) {
1237
+ const geometry = "geometry" in area2 ? area2.geometry : area2;
1238
+ const type = geometry.type;
1239
+ if (type === "MultiPolygon") {
1240
+ return multiPolygonArea(geometry.coordinates);
1241
+ }
1242
+ return polygonArea(geometry.coordinates);
1243
+ }
1244
+ function multiPolygonArea(multiPoly) {
1245
+ const coords = "coordinates" in multiPoly ? multiPoly.coordinates : multiPoly;
1246
+ let total = 0;
1247
+ for (const polygon of coords) {
1248
+ total += polygonArea(polygon);
1249
+ }
1250
+ return total;
1251
+ }
1252
+ function polygonArea(poly) {
1253
+ const coords = "coordinates" in poly ? poly.coordinates : poly;
1254
+ let total = 0;
1255
+ for (const ring of coords) {
1256
+ total += ringArea(ring);
1257
+ }
1258
+ return total;
1259
+ }
1260
+ function ringArea(coords) {
1261
+ let p1;
1262
+ let p2;
1263
+ let p3;
1264
+ let lowerIndex;
1265
+ let middleIndex;
1266
+ let upperIndex;
1267
+ let i;
1268
+ let total = 0;
1269
+ const coordsLength = coords.length;
1270
+ if (coordsLength > 2) {
1271
+ for (i = 0; i < coordsLength; i++) {
1272
+ if (i === coordsLength - 2) {
1273
+ lowerIndex = coordsLength - 2;
1274
+ middleIndex = coordsLength - 1;
1275
+ upperIndex = 0;
1276
+ } else if (i === coordsLength - 1) {
1277
+ lowerIndex = coordsLength - 1;
1278
+ middleIndex = 0;
1279
+ upperIndex = 1;
1280
+ } else {
1281
+ lowerIndex = i;
1282
+ middleIndex = i + 1;
1283
+ upperIndex = i + 2;
1284
+ }
1285
+ p1 = coords[lowerIndex];
1286
+ p2 = coords[middleIndex];
1287
+ p3 = coords[upperIndex];
1288
+ total += (degToRad(p3[0]) - degToRad(p1[0])) * Math.sin(degToRad(p2[1]));
1289
+ }
1290
+ total = total * earthRadius * earthRadius / 2;
1291
+ }
1292
+ return Math.abs(total);
1293
+ }
1294
+
1295
+ function lineDistance(line) {
1296
+ const coordinates = "geometry" in line ? line.geometry.coordinates : "coordinates" in line ? line.coordinates : line;
1297
+ let distance = 0;
1298
+ let prevCoord;
1299
+ for (const coordinate of coordinates) {
1300
+ if (prevCoord !== void 0) {
1301
+ distance += pointDistance(prevCoord, coordinate);
1302
+ }
1303
+ prevCoord = coordinate;
1304
+ }
1305
+ return distance;
1306
+ }
1307
+ function pointDistance(from, to) {
1308
+ const { pow, sin, cos, sqrt, atan2 } = Math;
1309
+ const dLat = degToRad(to[1] - from[1]);
1310
+ const dLon = degToRad(to[0] - from[0]);
1311
+ const lat1 = degToRad(from[1]);
1312
+ const lat2 = degToRad(to[1]);
1313
+ const a = pow(sin(dLat / 2), 2) + pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);
1314
+ return 2 * atan2(sqrt(a), sqrt(1 - a)) * earthRadius;
1315
+ }
1316
+
1317
+ function tileCover(coordinates, zoom, tileSize) {
1318
+ const tileHash = /* @__PURE__ */ new Map();
1319
+ const tiles = [];
1320
+ const coords = [];
1321
+ const resolution = getZoomLevelResolution(coordinates[0][1], zoom, tileSize);
1322
+ const samples = sampleProfileLine(coordinates, resolution);
1323
+ for (const sample of samples) {
1324
+ const coordinate = sample;
1325
+ const [tileX, tileY] = webMercProjection.llToTile(coordinate, zoom, tileSize);
1326
+ const id = xyzToTileID(tileX, tileY, zoom);
1327
+ const tile = { id, x: tileX, y: tileY, z: zoom };
1328
+ tileHash.set(id, tile);
1329
+ coords.push({ coordinate, tile });
1330
+ }
1331
+ for (const tile of tileHash.values())
1332
+ tiles.push(tile);
1333
+ return { coords, tiles };
1334
+ }
1335
+ function sampleProfileLine(coordinates, resolution) {
1336
+ const samples = [];
1337
+ let prevCoord;
1338
+ for (const coord of coordinates) {
1339
+ if (prevCoord !== void 0) {
1340
+ const dist = pointDistance(
1341
+ prevCoord,
1342
+ coord
1343
+ );
1344
+ const numSamples = Math.ceil(dist / resolution);
1345
+ for (let i = 0; i <= numSamples - 1; i++) {
1346
+ const sample = [
1347
+ prevCoord[0] + (coord[0] - prevCoord[0]) * (i / numSamples),
1348
+ prevCoord[1] + (coord[1] - prevCoord[1]) * (i / numSamples)
1349
+ ];
1350
+ samples.push(sample);
1351
+ }
1352
+ } else {
1353
+ samples.push(coord);
1354
+ }
1355
+ prevCoord = coord;
1356
+ }
1357
+ return samples;
1358
+ }
1359
+
1360
+ function getElevation(coord, tile, tileSize, tileImage, elevationParser = defaultElevationParser) {
1361
+ const { channels, image } = tileImage;
1362
+ let [x, y] = webMercProjection.llToTilePx(coord, tile, tileSize);
1363
+ x = clampPixel(x, tileSize);
1364
+ y = clampPixel(y, tileSize);
1365
+ const index = (y * tileSize + x) * channels;
1366
+ return elevationParser(
1367
+ image[index],
1368
+ image[index + 1],
1369
+ image[index + 2],
1370
+ channels === 4 ? image[index + 3] : 0
1371
+ );
1372
+ }
1373
+ function clampPixel(n, tileSize) {
1374
+ return Math.max(0, Math.min(tileSize, Math.floor(n * tileSize)));
1375
+ }
1376
+ function defaultElevationParser(r, g, b) {
1377
+ return -1e4 + (r * 256 * 256 + g * 256 + b) * 0.1;
1378
+ }
1379
+
1380
+ async function profileLineString(path, options) {
1381
+ const coordinates = "geometry" in path ? path.geometry.coordinates : path.coordinates;
1382
+ const { coords, tiles } = tileCover(
1383
+ coordinates,
1384
+ options.zoom ?? 13,
1385
+ options.tileSize ?? 512
1386
+ );
1387
+ const tileCache = await getTiles(tiles, options.tileRequest);
1388
+ let points = getElevations(
1389
+ coords,
1390
+ tileCache,
1391
+ options.tileSize ?? 512,
1392
+ options.elevationParser
1393
+ );
1394
+ if (options.smooth === true)
1395
+ points = smoothElevation(points);
1396
+ let output = buildOutput(points);
1397
+ if (options.metric === "ft")
1398
+ output = toFeet(output);
1399
+ return output;
1400
+ }
1401
+ async function getTiles(tiles, tileRequest) {
1402
+ const tileCache = /* @__PURE__ */ new Map();
1403
+ const requests = [];
1404
+ for (const tile of tiles) {
1405
+ requests.push(
1406
+ tileRequest(tile.x, tile.y, tile.z).then((res) => {
1407
+ tileCache.set(tile.id, res);
1408
+ return res;
1409
+ }).catch((err) => {
1410
+ console.error(err);
1411
+ return void 0;
1412
+ })
1413
+ );
1414
+ }
1415
+ await Promise.allSettled(requests);
1416
+ return tileCache;
1417
+ }
1418
+ function getElevations(coords, tileCache, tileSize, elevationParser) {
1419
+ const points = [];
1420
+ let curDistance = 0;
1421
+ let prevCoord;
1422
+ for (const { tile, coordinate } of coords) {
1423
+ const cTile = tileCache.get(tile.id);
1424
+ if (cTile === void 0)
1425
+ throw new Error(
1426
+ `Missing tile ${tile.id} (${tile.x}-${tile.y}-${tile.z})`
1427
+ );
1428
+ const elevation = getElevation(
1429
+ coordinate,
1430
+ [tile.z, tile.x, tile.y],
1431
+ tileSize,
1432
+ cTile,
1433
+ elevationParser
1434
+ );
1435
+ points.push({
1436
+ distance: curDistance,
1437
+ elevation,
1438
+ coordinate,
1439
+ tile
1440
+ });
1441
+ if (prevCoord !== void 0) {
1442
+ curDistance += pointDistance(prevCoord, coordinate);
1443
+ }
1444
+ prevCoord = coordinate;
1445
+ }
1446
+ return points;
1447
+ }
1448
+ function buildOutput(points) {
1449
+ let minElevation = Infinity;
1450
+ let maxElevation = -Infinity;
1451
+ let totalElevation = 0;
1452
+ for (const point of points) {
1453
+ if (point.elevation < minElevation)
1454
+ minElevation = point.elevation;
1455
+ if (point.elevation > maxElevation)
1456
+ maxElevation = point.elevation;
1457
+ totalElevation += point.elevation;
1458
+ }
1459
+ return {
1460
+ distance: points[points.length - 1].distance,
1461
+ minElevation,
1462
+ maxElevation,
1463
+ avgElevation: totalElevation / points.length,
1464
+ startElevation: points[0].elevation,
1465
+ endElevation: points[points.length - 1].elevation,
1466
+ points
1467
+ };
1468
+ }
1469
+ function smoothElevation(points) {
1470
+ const newPoints = [];
1471
+ let prevPoint;
1472
+ for (let i = 0; i < points.length; i++) {
1473
+ const point = points[i];
1474
+ const nextPoint = points[i + 1] ?? points[i];
1475
+ if (prevPoint === void 0) {
1476
+ newPoints.push(point);
1477
+ } else {
1478
+ const newPoint = {
1479
+ distance: point.distance,
1480
+ elevation: (prevPoint.elevation + point.elevation + nextPoint.elevation) / 3,
1481
+ coordinate: point.coordinate,
1482
+ tile: point.tile
1483
+ };
1484
+ newPoints.push(newPoint);
1485
+ }
1486
+ prevPoint = point;
1487
+ }
1488
+ return newPoints;
1489
+ }
1490
+ function toFeet(input) {
1491
+ const output = {
1492
+ distance: mToFt(input.distance),
1493
+ minElevation: mToFt(input.minElevation),
1494
+ maxElevation: mToFt(input.maxElevation),
1495
+ avgElevation: mToFt(input.avgElevation),
1496
+ startElevation: mToFt(input.startElevation),
1497
+ endElevation: mToFt(input.endElevation),
1498
+ points: input.points.map(({ distance, elevation, coordinate, tile }) => ({
1499
+ distance: mToFt(distance),
1500
+ elevation: mToFt(elevation),
1501
+ coordinate,
1502
+ tile
1503
+ }))
1504
+ };
1505
+ return output;
1506
+ }
1507
+
1348
1508
  exports.ClientConfig = ClientConfig;
1349
1509
  exports.LanguageGeocoding = LanguageGeocoding;
1350
1510
  exports.MapStyle = MapStyle;
1351
1511
  exports.MapStyleVariant = MapStyleVariant;
1352
1512
  exports.ReferenceMapStyle = ReferenceMapStyle;
1353
1513
  exports.ServiceError = ServiceError;
1514
+ exports.area = area;
1354
1515
  exports.config = config;
1355
1516
  exports.coordinates = coordinates;
1356
1517
  exports.data = data;
1518
+ exports.defaultElevationParser = defaultElevationParser;
1519
+ exports.degToRad = degToRad;
1520
+ exports.earthRadius = earthRadius;
1357
1521
  exports.expandMapStyle = expandMapStyle;
1358
1522
  exports.geocoding = geocoding;
1359
1523
  exports.geolocation = geolocation;
1524
+ exports.getZoomLevelResolution = getZoomLevelResolution;
1525
+ exports.lineDistance = lineDistance;
1526
+ exports.mToFt = mToFt;
1360
1527
  exports.mapStylePresetList = mapStylePresetList;
1528
+ exports.multiPolygonArea = multiPolygonArea;
1529
+ exports.pointDistance = pointDistance;
1530
+ exports.polygonArea = polygonArea;
1531
+ exports.profileLineString = profileLineString;
1532
+ exports.radToDeg = radToDeg;
1361
1533
  exports.staticMaps = staticMaps;
1534
+ exports.xyzToTileID = xyzToTileID;
1362
1535
  //# sourceMappingURL=maptiler-client.cjs.map