@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 +43 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/remote/idfm/IdfmRemoteRouter.ts +53 -22
package/dist/index.mjs
CHANGED
|
@@ -1225,8 +1225,8 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
1225
1225
|
get rname() {
|
|
1226
1226
|
return "idfm";
|
|
1227
1227
|
}
|
|
1228
|
-
async getItineraries(endpointUrl, mode, waypoints) {
|
|
1229
|
-
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
1228
|
+
async getItineraries(endpointUrl, mode, waypoints, options = {}) {
|
|
1229
|
+
const url = this.getURL(endpointUrl, mode, waypoints, options);
|
|
1230
1230
|
const res = await fetch(url, {
|
|
1231
1231
|
method: "GET",
|
|
1232
1232
|
headers: { apiKey }
|
|
@@ -1246,43 +1246,65 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
1246
1246
|
}
|
|
1247
1247
|
return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
1248
1248
|
}
|
|
1249
|
-
getURL(endpointUrl, mode, waypoints) {
|
|
1249
|
+
getURL(endpointUrl, mode, waypoints, options) {
|
|
1250
1250
|
if (waypoints.length > 2) {
|
|
1251
1251
|
Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints.length})`);
|
|
1252
1252
|
}
|
|
1253
|
-
const fromPlace = `from=${waypoints[0].longitude};${waypoints[0].latitude}`;
|
|
1254
|
-
const toPlace = `to=${waypoints[1].longitude};${waypoints[1].latitude}`;
|
|
1255
1253
|
const url = new URL(endpointUrl);
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1254
|
+
const coreParams = new URLSearchParams();
|
|
1255
|
+
coreParams.set("from", `${waypoints[0].longitude};${waypoints[0].latitude}`);
|
|
1256
|
+
coreParams.set("to", `${waypoints[1].longitude};${waypoints[1].latitude}`);
|
|
1257
|
+
if ("useStairs" in options && !options.useStairs) {
|
|
1258
|
+
coreParams.set("wheelchair", "true");
|
|
1259
|
+
}
|
|
1260
|
+
let queryParams = new URLSearchParams();
|
|
1259
1261
|
switch (mode) {
|
|
1260
1262
|
case "WALK":
|
|
1261
|
-
|
|
1263
|
+
queryParams = this.getWalkingQuery();
|
|
1262
1264
|
break;
|
|
1263
1265
|
case "BIKE":
|
|
1264
|
-
|
|
1266
|
+
queryParams = this.getBikeQuery();
|
|
1265
1267
|
break;
|
|
1266
1268
|
case "CAR":
|
|
1267
|
-
|
|
1269
|
+
queryParams = this.getCarQuery();
|
|
1268
1270
|
break;
|
|
1269
1271
|
}
|
|
1270
|
-
|
|
1272
|
+
[coreParams, queryParams].map((params) => {
|
|
1273
|
+
for (const pair of params.entries()) {
|
|
1274
|
+
console.log(pair[0], pair[1]);
|
|
1275
|
+
url.searchParams.append(pair[0], pair[1]);
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
return url.toString();
|
|
1271
1279
|
}
|
|
1272
1280
|
getCarQuery() {
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
|
|
1281
|
+
const urlSearchParams = new URLSearchParams();
|
|
1282
|
+
TRANSPORT_IDS.forEach((id) => {
|
|
1283
|
+
urlSearchParams.append("forbidden_uris[]", id);
|
|
1284
|
+
});
|
|
1285
|
+
urlSearchParams.append("first_section_mode[]", "walking");
|
|
1286
|
+
urlSearchParams.append("first_section_mode[]", "car");
|
|
1287
|
+
urlSearchParams.append("last_section_mode[]", "walking");
|
|
1288
|
+
urlSearchParams.append("last_section_mode[]", "car");
|
|
1289
|
+
return urlSearchParams;
|
|
1276
1290
|
}
|
|
1277
1291
|
getWalkingQuery() {
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1280
|
-
|
|
1292
|
+
const urlSearchParams = new URLSearchParams();
|
|
1293
|
+
TRANSPORT_IDS.forEach((id) => {
|
|
1294
|
+
urlSearchParams.append("forbidden_uris[]", id);
|
|
1295
|
+
});
|
|
1296
|
+
urlSearchParams.append("first_section_mode[]", "walking");
|
|
1297
|
+
urlSearchParams.append("last_section_mode[]", "walking");
|
|
1298
|
+
return urlSearchParams;
|
|
1281
1299
|
}
|
|
1282
1300
|
getBikeQuery() {
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
|
|
1301
|
+
const urlSearchParams = new URLSearchParams();
|
|
1302
|
+
TRANSPORT_IDS.forEach((id) => {
|
|
1303
|
+
urlSearchParams.append("forbidden_uris[]", id);
|
|
1304
|
+
});
|
|
1305
|
+
urlSearchParams.append("first_section_mode[]", "bike");
|
|
1306
|
+
urlSearchParams.append("last_section_mode[]", "bike");
|
|
1307
|
+
return urlSearchParams;
|
|
1286
1308
|
}
|
|
1287
1309
|
getSectionCoords(section) {
|
|
1288
1310
|
const from = section.from.stop_point ? jsonToCoordinates$1(section.from.stop_point.coord) : jsonToCoordinates$1(section.from.address.coord);
|