@maptiler/client 3.0.2 → 3.1.0-rc.1

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.
@@ -1189,6 +1189,101 @@ const geolocation = {
1189
1189
  info
1190
1190
  };
1191
1191
 
1192
+ function addLocations(search, locations) {
1193
+ for (const loc of locations) {
1194
+ search.append("location", `${loc.lat},${loc.lon}`);
1195
+ }
1196
+ }
1197
+ function addResponseOptions(search, response) {
1198
+ if (!response) return;
1199
+ if (response.units) search.set("response.units", response.units);
1200
+ if (response.language) search.set("response.language", response.language);
1201
+ if (response.alternates !== void 0)
1202
+ search.set("alternates", String(response.alternates));
1203
+ if (response.additionalData?.detailLevel)
1204
+ search.set(
1205
+ "response.additionalData.detailLevel",
1206
+ response.additionalData.detailLevel
1207
+ );
1208
+ }
1209
+ function addProfileOptions(search, profile, opts) {
1210
+ if (!opts) return;
1211
+ if (profile === "car") {
1212
+ const o = opts;
1213
+ if (o.mode) search.set("car.mode", o.mode);
1214
+ if (o.topSpeed) search.set("topSpeed", String(o.topSpeed));
1215
+ if (o.avoidances?.tolls !== void 0)
1216
+ search.set("avoidances.tolls", String(o.avoidances.tolls));
1217
+ if (o.avoidances?.ferry !== void 0)
1218
+ search.set("avoidances.ferry", String(o.avoidances.ferry));
1219
+ if (o.avoidances?.highway !== void 0)
1220
+ search.set("avoidances.highway", String(o.avoidances.highway));
1221
+ }
1222
+ if (profile === "truck") {
1223
+ const o = opts;
1224
+ if (o.height) search.set("truck.height", String(o.height));
1225
+ if (o.weight) search.set("truck.weight", String(o.weight));
1226
+ if (o.axleLoad) search.set("truck.axleLoad", String(o.axleLoad));
1227
+ if (o.hazmat !== void 0) search.set("truck.hazmat", String(o.hazmat));
1228
+ if (o.topSpeed) search.set("topSpeed", String(o.topSpeed));
1229
+ if (o.avoidances?.tolls !== void 0)
1230
+ search.set("avoidances.tolls", String(o.avoidances.tolls));
1231
+ }
1232
+ if (profile === "bicycle") {
1233
+ const o = opts;
1234
+ if (o.type) search.set("bicycle.type", o.type);
1235
+ if (o.cyclingSpeed)
1236
+ search.set("bicycle.cyclingSpeed", String(o.cyclingSpeed));
1237
+ }
1238
+ if (profile === "pedestrian") {
1239
+ const o = opts;
1240
+ if (o.walkingSpeed)
1241
+ search.set("pedestrian.walkingSpeed", String(o.walkingSpeed));
1242
+ }
1243
+ }
1244
+ async function directionsPost(body) {
1245
+ const url = new URL("routing/directions", defaults.maptilerApiURL);
1246
+ url.searchParams.set("key", config.apiKey);
1247
+ const res = await callFetch(url.toString(), {
1248
+ method: "POST",
1249
+ headers: { "content-type": "application/json" },
1250
+ body: JSON.stringify(body)
1251
+ });
1252
+ if (!res.ok) {
1253
+ throw new ServiceError(res);
1254
+ }
1255
+ return await res.json();
1256
+ }
1257
+ async function directionsGet(req) {
1258
+ const url = new URL("routing/directions", defaults.maptilerApiURL);
1259
+ const search = url.searchParams;
1260
+ search.set("key", config.apiKey);
1261
+ search.set("profile", req.profile);
1262
+ if (req.id) search.set("id", req.id);
1263
+ if (req.departureTime) search.set("departureTime", req.departureTime);
1264
+ if (req.arrivalTime) search.set("arrivalTime", req.arrivalTime);
1265
+ addLocations(search, req.locations);
1266
+ addResponseOptions(search, req.response);
1267
+ addProfileOptions(search, req.profile, req.profileOptions);
1268
+ const res = await callFetch(url.toString());
1269
+ if (!res.ok) {
1270
+ throw new ServiceError(res);
1271
+ }
1272
+ return await res.json();
1273
+ }
1274
+ const routing = {
1275
+ /**
1276
+ * Get directions using POST request
1277
+ * @experimental This API is experimental and can change anytime!
1278
+ */
1279
+ directionsPost,
1280
+ /**
1281
+ * Get directions using GET request
1282
+ * @experimental This API is experimental and can change anytime!
1283
+ */
1284
+ directionsGet
1285
+ };
1286
+
1192
1287
  const customMessages$2 = {
1193
1288
  403: "Key is missing, invalid or restricted"
1194
1289
  };
@@ -3336,6 +3431,7 @@ exports.isLanguageInfo = isLanguageInfo;
3336
3431
  exports.mapStylePresetList = mapStylePresetList;
3337
3432
  exports.math = math;
3338
3433
  exports.misc = misc;
3434
+ exports.routing = routing;
3339
3435
  exports.staticMaps = staticMaps;
3340
3436
  exports.styleToStyle = styleToStyle;
3341
3437
  exports.toLanguageInfo = toLanguageInfo;