@wemap/routers 11.1.0 → 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 +45 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/remote/idfm/IdfmRemoteRouter.ts +53 -22
- package/src/remote/osrm/OsrmRemoteRouter.spec.ts +25 -0
- package/src/remote/osrm/OsrmRemoteRouter.ts +17 -13
- package/src/wemap-osm/OsmRouter.spec.ts +5 -6
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
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
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
|
-
|
|
1271
|
+
queryParams = this.getWalkingQuery();
|
|
1270
1272
|
break;
|
|
1271
1273
|
case "BIKE":
|
|
1272
|
-
|
|
1274
|
+
queryParams = this.getBikeQuery();
|
|
1273
1275
|
break;
|
|
1274
1276
|
case "CAR":
|
|
1275
|
-
|
|
1277
|
+
queryParams = this.getCarQuery();
|
|
1276
1278
|
break;
|
|
1277
1279
|
}
|
|
1278
|
-
|
|
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
|
|
1282
|
-
|
|
1283
|
-
|
|
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
|
|
1287
|
-
|
|
1288
|
-
|
|
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
|
|
1292
|
-
|
|
1293
|
-
|
|
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);
|
|
@@ -1438,7 +1460,8 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
1438
1460
|
});
|
|
1439
1461
|
const from = waypoints[0];
|
|
1440
1462
|
const to = waypoints[waypoints.length - 1];
|
|
1441
|
-
|
|
1463
|
+
const osrmMode = inputModeCorrespondance$1.get(mode);
|
|
1464
|
+
return this.createRouterResponseFromJson(jsonResponse, from, to, osrmMode);
|
|
1442
1465
|
}
|
|
1443
1466
|
getURL(endpointUrl, mode, waypoints) {
|
|
1444
1467
|
const osrmMode = inputModeCorrespondance$1.get(mode);
|