@wemap/routers 11.1.1 → 11.2.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/index.js CHANGED
@@ -1233,8 +1233,8 @@ class IdfmRemoteRouter extends RemoteRouter {
1233
1233
  get rname() {
1234
1234
  return "idfm";
1235
1235
  }
1236
- async getItineraries(endpointUrl, mode, waypoints) {
1237
- const url = this.getURL(endpointUrl, mode, waypoints);
1236
+ async getItineraries(endpointUrl, mode, waypoints, options = {}) {
1237
+ const url = this.getURL(endpointUrl, mode, waypoints, options);
1238
1238
  const res = await fetch(url, {
1239
1239
  method: "GET",
1240
1240
  headers: { apiKey }
@@ -1254,43 +1254,65 @@ class IdfmRemoteRouter extends RemoteRouter {
1254
1254
  }
1255
1255
  return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
1256
1256
  }
1257
- getURL(endpointUrl, mode, waypoints) {
1257
+ getURL(endpointUrl, mode, waypoints, options) {
1258
1258
  if (waypoints.length > 2) {
1259
1259
  Logger__default.default.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints.length})`);
1260
1260
  }
1261
- const fromPlace = `from=${waypoints[0].longitude};${waypoints[0].latitude}`;
1262
- const toPlace = `to=${waypoints[1].longitude};${waypoints[1].latitude}`;
1263
1261
  const url = new URL(endpointUrl);
1264
- let { search } = url;
1265
- search = (search ? `${search}&` : "?") + `${fromPlace}&${toPlace}`;
1266
- let query = "";
1262
+ const coreParams = new URLSearchParams();
1263
+ coreParams.set("from", `${waypoints[0].longitude};${waypoints[0].latitude}`);
1264
+ coreParams.set("to", `${waypoints[1].longitude};${waypoints[1].latitude}`);
1265
+ if ("useStairs" in options && !options.useStairs) {
1266
+ coreParams.set("wheelchair", "true");
1267
+ }
1268
+ let queryParams = new URLSearchParams();
1267
1269
  switch (mode) {
1268
1270
  case "WALK":
1269
- query = this.getWalkingQuery();
1271
+ queryParams = this.getWalkingQuery();
1270
1272
  break;
1271
1273
  case "BIKE":
1272
- query = this.getBikeQuery();
1274
+ queryParams = this.getBikeQuery();
1273
1275
  break;
1274
1276
  case "CAR":
1275
- query = this.getCarQuery();
1277
+ queryParams = this.getCarQuery();
1276
1278
  break;
1277
1279
  }
1278
- return `${url.origin}${url.pathname}${search}${query}`;
1280
+ [coreParams, queryParams].map((params) => {
1281
+ for (const pair of params.entries()) {
1282
+ console.log(pair[0], pair[1]);
1283
+ url.searchParams.append(pair[0], pair[1]);
1284
+ }
1285
+ });
1286
+ return url.toString();
1279
1287
  }
1280
1288
  getCarQuery() {
1281
- const forbiddenTransport = TRANSPORT_IDS.map((id) => `forbidden_uris[]=${id}`).join("&");
1282
- const allowCar = "first_section_mode[]=walking&first_section_mode[]=car&last_section_mode[]=walking&last_section_mode[]=car";
1283
- return `&${forbiddenTransport}&${allowCar}`;
1289
+ const urlSearchParams = new URLSearchParams();
1290
+ TRANSPORT_IDS.forEach((id) => {
1291
+ urlSearchParams.append("forbidden_uris[]", id);
1292
+ });
1293
+ urlSearchParams.append("first_section_mode[]", "walking");
1294
+ urlSearchParams.append("first_section_mode[]", "car");
1295
+ urlSearchParams.append("last_section_mode[]", "walking");
1296
+ urlSearchParams.append("last_section_mode[]", "car");
1297
+ return urlSearchParams;
1284
1298
  }
1285
1299
  getWalkingQuery() {
1286
- const forbiddenTransport = TRANSPORT_IDS.map((id) => `forbidden_uris[]=${id}`).join("&");
1287
- const allowWalking = "first_section_mode[]=walking&last_section_mode[]=walking";
1288
- return `&${forbiddenTransport}&${allowWalking}`;
1300
+ const urlSearchParams = new URLSearchParams();
1301
+ TRANSPORT_IDS.forEach((id) => {
1302
+ urlSearchParams.append("forbidden_uris[]", id);
1303
+ });
1304
+ urlSearchParams.append("first_section_mode[]", "walking");
1305
+ urlSearchParams.append("last_section_mode[]", "walking");
1306
+ return urlSearchParams;
1289
1307
  }
1290
1308
  getBikeQuery() {
1291
- const forbiddenTransport = TRANSPORT_IDS.map((id) => `forbidden_uris[]=${id}`).join("&");
1292
- const allowBike = "first_section_mode[]=bike&last_section_mode[]=bike";
1293
- return `&${forbiddenTransport}&${allowBike}`;
1309
+ const urlSearchParams = new URLSearchParams();
1310
+ TRANSPORT_IDS.forEach((id) => {
1311
+ urlSearchParams.append("forbidden_uris[]", id);
1312
+ });
1313
+ urlSearchParams.append("first_section_mode[]", "bike");
1314
+ urlSearchParams.append("last_section_mode[]", "bike");
1315
+ return urlSearchParams;
1294
1316
  }
1295
1317
  getSectionCoords(section) {
1296
1318
  const from = section.from.stop_point ? jsonToCoordinates$1(section.from.stop_point.coord) : jsonToCoordinates$1(section.from.address.coord);