@maptiler/client 1.3.0 → 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.
- package/dist/maptiler-client.cjs +42 -16
- package/dist/maptiler-client.cjs.map +1 -1
- package/dist/maptiler-client.d.ts +10 -0
- package/dist/maptiler-client.min.mjs +1 -1
- package/dist/maptiler-client.mjs +42 -16
- package/dist/maptiler-client.mjs.map +1 -1
- package/dist/maptiler-client.umd.js +42 -16
- package/dist/maptiler-client.umd.js.map +1 -1
- package/dist/maptiler-client.umd.min.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/config.ClientConfig.html +9 -9
- package/docs/classes/services_ServiceError.ServiceError.html +7 -7
- package/docs/functions/language.getAutoLanguageGeocoding.html +5 -5
- package/docs/functions/services_simplify.default.html +5 -5
- package/docs/index.html +4 -4
- package/docs/modules/config.html +5 -5
- package/docs/modules/language.html +5 -5
- package/docs/modules/services_ServiceError.html +5 -5
- package/docs/modules/services_coordinates.html +5 -5
- package/docs/modules/services_data.html +5 -5
- package/docs/modules/services_geocoding.html +5 -5
- package/docs/modules/services_geolocation.html +5 -5
- package/docs/modules/services_simplify.html +5 -5
- package/docs/modules/services_staticMaps.html +5 -5
- package/docs/modules.html +4 -4
- package/docs/types/config.FetchFunction.html +5 -5
- package/docs/types/language.LanguageGeocodingString.html +5 -5
- package/docs/types/services_coordinates.CoordinateExport.html +5 -5
- package/docs/types/services_coordinates.CoordinateGrid.html +5 -5
- package/docs/types/services_coordinates.CoordinateId.html +5 -5
- package/docs/types/services_coordinates.CoordinateSearch.html +5 -5
- package/docs/types/services_coordinates.CoordinateSearchResult.html +5 -5
- package/docs/types/services_coordinates.CoordinateTransformResult.html +5 -5
- package/docs/types/services_coordinates.CoordinateTransformation.html +5 -5
- package/docs/types/services_coordinates.CoordinatesSearchOptions.html +5 -5
- package/docs/types/services_coordinates.CoordinatesTransformOptions.html +5 -5
- package/docs/types/services_coordinates.XYZ.html +5 -5
- package/docs/types/services_data.GetDataOptions.html +5 -5
- package/docs/types/services_geocoding.ByIdGeocodingOptions.html +5 -5
- package/docs/types/services_geocoding.CommonForwardAndReverseGeocodingOptions.html +5 -5
- package/docs/types/services_geocoding.Coordinates.html +5 -5
- package/docs/types/services_geocoding.FeatureHierarchy.html +5 -5
- package/docs/types/services_geocoding.GeocodingFeature.html +5 -5
- package/docs/types/services_geocoding.GeocodingOptions.html +5 -5
- package/docs/types/services_geocoding.GeocodingSearchResult.html +5 -5
- package/docs/types/services_geocoding.LanguageGeocodingOptions.html +5 -5
- package/docs/types/services_geocoding.ReverseGeocodingOptions.html +5 -5
- package/docs/types/services_geolocation.GeolocationInfoOptions.html +5 -5
- package/docs/types/services_geolocation.GeolocationResult.html +5 -5
- package/docs/types/services_staticMaps.AutomaticStaticMapOptions.html +5 -5
- package/docs/types/services_staticMaps.BoundedStaticMapOptions.html +5 -5
- package/docs/types/services_staticMaps.CenteredStaticMapOptions.html +5 -5
- package/docs/types/services_staticMaps.StaticMapBaseOptions.html +5 -5
- package/docs/types/services_staticMaps.StaticMapMarker.html +5 -5
- package/docs/variables/config.config.html +5 -5
- package/docs/variables/language.LanguageGeocoding.html +5 -5
- package/docs/variables/services_coordinates.coordinates.html +5 -5
- package/docs/variables/services_data.data.html +5 -5
- package/docs/variables/services_geocoding.geocoding.html +29 -9
- package/docs/variables/services_geolocation.geolocation.html +5 -5
- package/docs/variables/services_staticMaps.staticMaps.html +5 -5
- package/docsmd/README.md +43 -42
- package/docsmd/classes/ClientConfig.md +5 -5
- package/docsmd/classes/MapStyleVariant.md +13 -13
- package/docsmd/classes/ReferenceMapStyle.md +9 -9
- package/docsmd/classes/ServiceError.md +3 -3
- package/package.json +3 -1
- package/src/services/geocoding.ts +71 -21
|
@@ -190,6 +190,33 @@ function addCommonForwardAndReverseGeocodingOptions(
|
|
|
190
190
|
addLanguageGeocodingOptions(searchParams, options);
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
function addForwardGeocodingOptions(
|
|
194
|
+
searchParams: URLSearchParams,
|
|
195
|
+
options: GeocodingOptions
|
|
196
|
+
) {
|
|
197
|
+
addCommonForwardAndReverseGeocodingOptions(searchParams, options);
|
|
198
|
+
|
|
199
|
+
if (options.bbox != undefined) {
|
|
200
|
+
searchParams.set("bbox", options.bbox.join(","));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (options.proximity != undefined) {
|
|
204
|
+
searchParams.set("proximity", options.proximity.join(","));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (options.country != undefined) {
|
|
208
|
+
searchParams.set("country", options.country.join(","));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (options.fuzzyMatch != undefined) {
|
|
212
|
+
searchParams.set("fuzzyMatch", options.fuzzyMatch ? "true" : "false");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (options.autocomplete != undefined) {
|
|
216
|
+
searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
193
220
|
/**
|
|
194
221
|
* Performs a forward geocoding query to MapTiler API.
|
|
195
222
|
* Providing a human readable place name (of a city, country, street, etc.), the function returns
|
|
@@ -214,27 +241,7 @@ async function forward(
|
|
|
214
241
|
|
|
215
242
|
const { searchParams } = endpoint;
|
|
216
243
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (options.bbox != undefined) {
|
|
220
|
-
searchParams.set("bbox", options.bbox.join(","));
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (options.proximity != undefined) {
|
|
224
|
-
searchParams.set("proximity", options.proximity.join(","));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (options.country != undefined) {
|
|
228
|
-
searchParams.set("country", options.country.join(","));
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (options.fuzzyMatch != undefined) {
|
|
232
|
-
searchParams.set("fuzzyMatch", options.fuzzyMatch ? "true" : "false");
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (options.autocomplete != undefined) {
|
|
236
|
-
searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
|
|
237
|
-
}
|
|
244
|
+
addForwardGeocodingOptions(searchParams, options);
|
|
238
245
|
|
|
239
246
|
const urlWithParams = endpoint.toString();
|
|
240
247
|
|
|
@@ -315,6 +322,48 @@ async function byId(
|
|
|
315
322
|
return obj;
|
|
316
323
|
}
|
|
317
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Perform a batch geocoding query to MapTiler API.
|
|
327
|
+
* Provide multiple queries in the array. Each query can be forward, reverse or by feature ID.
|
|
328
|
+
* Learn more on the MapTiler API reference page: https://docs.maptiler.com/cloud/api/geocoding/#batch-geocoding
|
|
329
|
+
* @param queries
|
|
330
|
+
* @param options
|
|
331
|
+
* @returns
|
|
332
|
+
*/
|
|
333
|
+
async function batch(
|
|
334
|
+
queries: string[],
|
|
335
|
+
options: GeocodingOptions = {}
|
|
336
|
+
): Promise<GeocodingSearchResult[]> {
|
|
337
|
+
if (!queries.length) {
|
|
338
|
+
return [];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const joinedQuery = queries
|
|
342
|
+
.map((query) => encodeURIComponent(query))
|
|
343
|
+
.join(";");
|
|
344
|
+
|
|
345
|
+
const endpoint = new URL(
|
|
346
|
+
`geocoding/${joinedQuery}.json`,
|
|
347
|
+
defaults.maptilerApiURL
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
const { searchParams } = endpoint;
|
|
351
|
+
|
|
352
|
+
addForwardGeocodingOptions(searchParams, options);
|
|
353
|
+
|
|
354
|
+
const urlWithParams = endpoint.toString();
|
|
355
|
+
|
|
356
|
+
const res = await callFetch(urlWithParams);
|
|
357
|
+
|
|
358
|
+
if (!res.ok) {
|
|
359
|
+
throw new ServiceError(res, customMessages[res.status] ?? "");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const obj = await res.json();
|
|
363
|
+
|
|
364
|
+
return queries.length === 1 ? [obj] : obj;
|
|
365
|
+
}
|
|
366
|
+
|
|
318
367
|
/**
|
|
319
368
|
* The **geocoding** namespace contains asynchronous functions to call the [MapTiler Geocoding API](https://docs.maptiler.com/cloud/api/geocoding/).
|
|
320
369
|
* The **Geocoding API** provides ways to get geographic coordinates from a human-readable search query of a place (forward geocoding)
|
|
@@ -324,6 +373,7 @@ const geocoding = {
|
|
|
324
373
|
forward,
|
|
325
374
|
reverse,
|
|
326
375
|
byId,
|
|
376
|
+
batch,
|
|
327
377
|
language: LanguageGeocoding,
|
|
328
378
|
};
|
|
329
379
|
|