@maptiler/client 1.1.3 → 1.4.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 (75) hide show
  1. package/dist/maptiler-client.cjs +113 -36
  2. package/dist/maptiler-client.cjs.map +1 -1
  3. package/dist/maptiler-client.d.ts +79 -28
  4. package/dist/maptiler-client.min.mjs +1 -1
  5. package/dist/maptiler-client.mjs +113 -36
  6. package/dist/maptiler-client.mjs.map +1 -1
  7. package/dist/maptiler-client.umd.js +113 -36
  8. package/dist/maptiler-client.umd.js.map +1 -1
  9. package/dist/maptiler-client.umd.min.js +1 -1
  10. package/docs/assets/search.js +1 -1
  11. package/docs/classes/config.ClientConfig.html +9 -9
  12. package/docs/classes/services_ServiceError.ServiceError.html +7 -7
  13. package/docs/functions/language.getAutoLanguageGeocoding.html +5 -5
  14. package/docs/functions/services_simplify.default.html +5 -5
  15. package/docs/index.html +4 -4
  16. package/docs/modules/config.html +5 -5
  17. package/docs/modules/language.html +5 -5
  18. package/docs/modules/services_ServiceError.html +5 -5
  19. package/docs/modules/services_coordinates.html +5 -5
  20. package/docs/modules/services_data.html +5 -5
  21. package/docs/modules/services_geocoding.html +12 -6
  22. package/docs/modules/services_geolocation.html +5 -5
  23. package/docs/modules/services_simplify.html +5 -5
  24. package/docs/modules/services_staticMaps.html +5 -5
  25. package/docs/modules.html +4 -4
  26. package/docs/types/config.FetchFunction.html +5 -5
  27. package/docs/types/language.LanguageGeocodingString.html +5 -5
  28. package/docs/types/services_coordinates.CoordinateExport.html +5 -5
  29. package/docs/types/services_coordinates.CoordinateGrid.html +5 -5
  30. package/docs/types/services_coordinates.CoordinateId.html +5 -5
  31. package/docs/types/services_coordinates.CoordinateSearch.html +5 -5
  32. package/docs/types/services_coordinates.CoordinateSearchResult.html +5 -5
  33. package/docs/types/services_coordinates.CoordinateTransformResult.html +5 -5
  34. package/docs/types/services_coordinates.CoordinateTransformation.html +5 -5
  35. package/docs/types/services_coordinates.CoordinatesSearchOptions.html +6 -6
  36. package/docs/types/services_coordinates.CoordinatesTransformOptions.html +6 -6
  37. package/docs/types/services_coordinates.XYZ.html +5 -5
  38. package/docs/types/services_data.GetDataOptions.html +6 -6
  39. package/docs/types/services_geocoding.ByIdGeocodingOptions.html +63 -0
  40. package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +63 -0
  41. package/docs/types/services_geocoding.Coordinates.html +9 -6
  42. package/docs/types/services_geocoding.FeatureHierarchy.html +9 -6
  43. package/docs/types/services_geocoding.GeocodingFeature.html +9 -6
  44. package/docs/types/services_geocoding.GeocodingOptions.html +10 -26
  45. package/docs/types/services_geocoding.GeocodingSearchResult.html +9 -6
  46. package/docs/types/services_geocoding.LanguageGeocodingOptions.html +70 -0
  47. package/docs/types/services_geocoding.ReverseGeocodingOptions.html +10 -18
  48. package/docs/types/services_geolocation.GeolocationInfoOptions.html +6 -6
  49. package/docs/types/services_geolocation.GeolocationResult.html +5 -5
  50. package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +5 -5
  51. package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +5 -5
  52. package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +5 -5
  53. package/docs/types/services_staticMaps.StaticMapBaseOptions.html +6 -6
  54. package/docs/types/services_staticMaps.StaticMapMarker.html +5 -5
  55. package/docs/variables/config.config.html +5 -5
  56. package/docs/variables/language.LanguageGeocoding.html +5 -5
  57. package/docs/variables/services_coordinates.coordinates.html +5 -5
  58. package/docs/variables/services_data.data.html +5 -5
  59. package/docs/variables/services_geocoding.geocoding.html +56 -12
  60. package/docs/variables/services_geolocation.geolocation.html +5 -5
  61. package/docs/variables/services_staticMaps.staticMaps.html +5 -5
  62. package/docsmd/README.md +82 -68
  63. package/docsmd/classes/ClientConfig.md +5 -5
  64. package/docsmd/classes/MapStyleVariant.md +13 -13
  65. package/docsmd/classes/ReferenceMapStyle.md +9 -9
  66. package/docsmd/classes/ServiceError.md +3 -3
  67. package/examples/test-browser-umd.html +6 -6
  68. package/package.json +3 -1
  69. package/src/index.ts +4 -0
  70. package/src/mapstyle.ts +46 -1
  71. package/src/services/coordinates.ts +2 -2
  72. package/src/services/data.ts +1 -1
  73. package/src/services/geocoding.ts +206 -65
  74. package/src/services/geolocation.ts +1 -1
  75. package/src/services/staticMaps.ts +1 -1
@@ -195,6 +195,48 @@
195
195
  400: "Query too long / Invalid parameters",
196
196
  403: "Key is missing, invalid or restricted"
197
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
+ }
198
240
  function forward(_0) {
199
241
  return __async$3(this, arguments, function* (query, options = {}) {
200
242
  var _a;
@@ -205,30 +247,12 @@
205
247
  `geocoding/${encodeURIComponent(query)}.json`,
206
248
  defaults.maptilerApiURL
207
249
  );
208
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
209
- if ("bbox" in options) {
210
- endpoint.searchParams.set("bbox", options.bbox.join(","));
211
- }
212
- if ("proximity" in options) {
213
- endpoint.searchParams.set("proximity", options.proximity.join(","));
214
- }
215
- if ("language" in options) {
216
- const languages = Array.from(
217
- new Set(
218
- (Array.isArray(options.language) ? options.language : [options.language]).map(
219
- (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
220
- )
221
- )
222
- ).join(",");
223
- endpoint.searchParams.set("language", languages);
224
- }
250
+ const { searchParams } = endpoint;
251
+ addForwardGeocodingOptions(searchParams, options);
225
252
  const urlWithParams = endpoint.toString();
226
253
  const res = yield callFetch(urlWithParams);
227
254
  if (!res.ok) {
228
- throw new ServiceError(
229
- res,
230
- res.status in customMessages$3 ? customMessages$3[res.status] : ""
231
- );
255
+ throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
232
256
  }
233
257
  const obj = yield res.json();
234
258
  return obj;
@@ -244,32 +268,57 @@
244
268
  `geocoding/${position[0]},${position[1]}.json`,
245
269
  defaults.maptilerApiURL
246
270
  );
247
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config.apiKey);
248
- if ("language" in options) {
249
- const languages = Array.from(
250
- new Set(
251
- (Array.isArray(options.language) ? options.language : [options.language]).map(
252
- (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
253
- )
254
- )
255
- ).join(",");
256
- endpoint.searchParams.set("language", languages);
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 : "");
257
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);
258
286
  const urlWithParams = endpoint.toString();
259
287
  const res = yield callFetch(urlWithParams);
260
288
  if (!res.ok) {
261
- throw new ServiceError(
262
- res,
263
- res.status in customMessages$3 ? customMessages$3[res.status] : ""
264
- );
289
+ throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
265
290
  }
266
291
  const obj = yield res.json();
267
292
  return obj;
268
293
  });
269
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
+ }
270
317
  const geocoding = {
271
318
  forward,
272
319
  reverse,
320
+ byId,
321
+ batch,
273
322
  language: LanguageGeocoding
274
323
  };
275
324
 
@@ -657,6 +706,13 @@
657
706
  description: "",
658
707
  imageURL: ""
659
708
  },
709
+ {
710
+ id: "streets-v2-night",
711
+ name: "Night",
712
+ variantType: "NIGHT",
713
+ description: "",
714
+ imageURL: ""
715
+ },
660
716
  {
661
717
  id: "streets-v2-pastel",
662
718
  name: "Pastel",
@@ -677,6 +733,13 @@
677
733
  variantType: "DEFAULT",
678
734
  description: "",
679
735
  imageURL: ""
736
+ },
737
+ {
738
+ id: "outdoor-v2-dark",
739
+ name: "Dark",
740
+ variantType: "DARK",
741
+ description: "",
742
+ imageURL: ""
680
743
  }
681
744
  ]
682
745
  },
@@ -687,10 +750,17 @@
687
750
  variants: [
688
751
  {
689
752
  id: "winter-v2",
690
- name: "Winter",
753
+ name: "Default",
691
754
  variantType: "DEFAULT",
692
755
  description: "",
693
756
  imageURL: ""
757
+ },
758
+ {
759
+ id: "winter-v2-dark",
760
+ name: "Dark",
761
+ variantType: "DARK",
762
+ description: "",
763
+ imageURL: ""
694
764
  }
695
765
  ]
696
766
  },
@@ -811,6 +881,13 @@
811
881
  description: "",
812
882
  imageURL: ""
813
883
  },
884
+ {
885
+ id: "topo-v2-dark",
886
+ name: "Dark",
887
+ variantType: "DARK",
888
+ description: "",
889
+ imageURL: ""
890
+ },
814
891
  {
815
892
  id: "topo-v2-shiny",
816
893
  name: "Shiny",