@wemap/routers 12.0.0-alpha.2 → 12.0.0-alpha.3
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 +46 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -38
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -1
- package/package.json +2 -2
- package/src/model/TravelMode.ts +3 -1
- package/src/remote/RemoteRouter.ts +3 -2
- package/src/remote/RemoteRouterManager.ts +7 -5
- package/src/remote/cityway/CitywayRemoteRouter.ts +8 -3
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.ts +9 -4
- package/src/remote/idfm/IdfmRemoteRouter.ts +11 -5
- package/src/remote/osrm/OsrmRemoteRouter.ts +21 -19
- package/src/remote/otp/OtpRemoteRouter.ts +8 -3
- package/src/remote/wemap-multi/WemapMultiRemoteRouter.spec.ts +5 -5
- package/src/remote/wemap-multi/WemapMultiRemoteRouter.ts +6 -3
- package/src/wemap-multi/WemapMultiRouter.spec.ts +5 -5
- package/src/wemap-multi/WemapMultiRouter.ts +7 -7
package/dist/index.js
CHANGED
|
@@ -1528,8 +1528,8 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
1528
1528
|
* @throws {transitModeCorrespondanceNotFound}
|
|
1529
1529
|
* @throws {RemoteRouterServerUnreachable}
|
|
1530
1530
|
*/
|
|
1531
|
-
async getItineraries(endpointUrl,
|
|
1532
|
-
const url = this.getURL(endpointUrl,
|
|
1531
|
+
async getItineraries(endpointUrl, travelMode, travelModePreference, waypoints) {
|
|
1532
|
+
const url = this.getURL(endpointUrl, travelMode, waypoints);
|
|
1533
1533
|
const res = await fetch(url).catch(() => {
|
|
1534
1534
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1535
1535
|
});
|
|
@@ -1714,8 +1714,8 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
1714
1714
|
* @override
|
|
1715
1715
|
* @throws {RemoteRouterServerUnreachable}
|
|
1716
1716
|
*/
|
|
1717
|
-
async getItineraries(endpointUrl,
|
|
1718
|
-
const url = this.getURL(endpointUrl,
|
|
1717
|
+
async getItineraries(endpointUrl, travelMode, travelModePreference, waypoints) {
|
|
1718
|
+
const url = this.getURL(endpointUrl, travelMode, waypoints);
|
|
1719
1719
|
const res = await fetch(url).catch(() => {
|
|
1720
1720
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1721
1721
|
});
|
|
@@ -1834,8 +1834,8 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
1834
1834
|
* @throws {IdfmRemoteRouterTokenError}
|
|
1835
1835
|
* @throws {RemoteRouterServerUnreachable}
|
|
1836
1836
|
*/
|
|
1837
|
-
async getItineraries(endpointUrl,
|
|
1838
|
-
const url = this.getURL(endpointUrl,
|
|
1837
|
+
async getItineraries(endpointUrl, travelMode, travelModePreference, waypoints, options = {}) {
|
|
1838
|
+
const url = this.getURL(endpointUrl, travelMode, waypoints, options);
|
|
1839
1839
|
const res = await fetch(url, {
|
|
1840
1840
|
method: "GET",
|
|
1841
1841
|
headers: { apiKey }
|
|
@@ -1854,7 +1854,7 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
1854
1854
|
});
|
|
1855
1855
|
}
|
|
1856
1856
|
const routerResponse = this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
1857
|
-
const sameModeFound = routerResponse.itineraries.some((itinerary) => itinerary.mode ===
|
|
1857
|
+
const sameModeFound = routerResponse.itineraries.some((itinerary) => itinerary.mode === travelMode);
|
|
1858
1858
|
if (!sameModeFound) {
|
|
1859
1859
|
return new RouterResponse({
|
|
1860
1860
|
routerName: this.rname,
|
|
@@ -2062,18 +2062,26 @@ class TravelModeCorrespondanceNotFound extends Error {
|
|
|
2062
2062
|
this.transitMode = transitMode;
|
|
2063
2063
|
}
|
|
2064
2064
|
}
|
|
2065
|
-
const inputModeCorrespondance$1 =
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2065
|
+
const inputModeCorrespondance$1 = (travelMode, preference) => {
|
|
2066
|
+
if (travelMode === "WALK")
|
|
2067
|
+
return "walking";
|
|
2068
|
+
if (travelMode === "BIKE") {
|
|
2069
|
+
if (preference === "FASTEST")
|
|
2070
|
+
return "bike-fastest";
|
|
2071
|
+
if (preference === "SAFEST")
|
|
2072
|
+
return "bike-safest";
|
|
2073
|
+
if (preference === "TOURISM")
|
|
2074
|
+
return "bike-safest";
|
|
2075
|
+
return "bike-safest";
|
|
2076
|
+
}
|
|
2077
|
+
if (travelMode === "CAR")
|
|
2078
|
+
return "driving";
|
|
2079
|
+
throw new TravelModeCorrespondanceNotFound("osrm", travelMode);
|
|
2080
|
+
};
|
|
2071
2081
|
const outputModeCorrespondance = /* @__PURE__ */ new Map();
|
|
2072
2082
|
outputModeCorrespondance.set("driving", "CAR");
|
|
2073
2083
|
outputModeCorrespondance.set("walking", "WALK");
|
|
2074
|
-
outputModeCorrespondance.set("bike
|
|
2075
|
-
outputModeCorrespondance.set("bike-safest", "BIKE");
|
|
2076
|
-
outputModeCorrespondance.set("bike-fastest", "BIKE");
|
|
2084
|
+
outputModeCorrespondance.set("bike", "BIKE");
|
|
2077
2085
|
class OsrmRemoteRouter extends RemoteRouter {
|
|
2078
2086
|
/**
|
|
2079
2087
|
* @override
|
|
@@ -2085,8 +2093,8 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
2085
2093
|
* @throws {RemoteRouterServerUnreachable}
|
|
2086
2094
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2087
2095
|
*/
|
|
2088
|
-
async getItineraries(endpointUrl,
|
|
2089
|
-
const url = this.getURL(endpointUrl,
|
|
2096
|
+
async getItineraries(endpointUrl, travelMode, travelModePreference, waypoints, options = {}) {
|
|
2097
|
+
const url = this.getURL(endpointUrl, travelMode, travelModePreference, waypoints, options);
|
|
2090
2098
|
const res = await fetch(url).catch(() => {
|
|
2091
2099
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2092
2100
|
});
|
|
@@ -2095,17 +2103,14 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
2095
2103
|
});
|
|
2096
2104
|
const from = waypoints[0];
|
|
2097
2105
|
const to = waypoints[waypoints.length - 1];
|
|
2098
|
-
const osrmMode = inputModeCorrespondance$1
|
|
2106
|
+
const osrmMode = inputModeCorrespondance$1(travelMode, travelModePreference);
|
|
2099
2107
|
return this.createRouterResponseFromJson(jsonResponse, from, to, osrmMode);
|
|
2100
2108
|
}
|
|
2101
2109
|
/**
|
|
2102
2110
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2103
2111
|
*/
|
|
2104
|
-
getURL(endpointUrl,
|
|
2105
|
-
let osrmMode = inputModeCorrespondance$1
|
|
2106
|
-
if (!osrmMode) {
|
|
2107
|
-
throw new TravelModeCorrespondanceNotFound(this.rname, mode);
|
|
2108
|
-
}
|
|
2112
|
+
getURL(endpointUrl, travelMode, travelModePreference, waypoints, options = {}) {
|
|
2113
|
+
let osrmMode = inputModeCorrespondance$1(travelMode, travelModePreference);
|
|
2109
2114
|
if ("useStairs" in options && !options.useStairs) {
|
|
2110
2115
|
osrmMode = "pmr";
|
|
2111
2116
|
}
|
|
@@ -2293,8 +2298,8 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
2293
2298
|
* @throws {RemoteRouterServerUnreachable}
|
|
2294
2299
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2295
2300
|
*/
|
|
2296
|
-
async getItineraries(endpointUrl,
|
|
2297
|
-
const url = this.getURL(endpointUrl,
|
|
2301
|
+
async getItineraries(endpointUrl, travelMode, travelModePreference, waypoints) {
|
|
2302
|
+
const url = this.getURL(endpointUrl, travelMode, waypoints);
|
|
2298
2303
|
const res = await fetch(url).catch(() => {
|
|
2299
2304
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2300
2305
|
});
|
|
@@ -2423,10 +2428,10 @@ class WemapMultiRemoteRouter extends RemoteRouter {
|
|
|
2423
2428
|
get rname() {
|
|
2424
2429
|
return "wemap-multi";
|
|
2425
2430
|
}
|
|
2426
|
-
async getItineraries(endpointUrl,
|
|
2431
|
+
async getItineraries(endpointUrl, travelMode, travelModePreference, waypoints, options) {
|
|
2427
2432
|
const payload = new WemapMultiRemoteRouterPayload(
|
|
2428
2433
|
waypoints,
|
|
2429
|
-
|
|
2434
|
+
travelMode,
|
|
2430
2435
|
options
|
|
2431
2436
|
);
|
|
2432
2437
|
const res = await fetch(endpointUrl, {
|
|
@@ -2463,22 +2468,22 @@ class RemoteRouterManager {
|
|
|
2463
2468
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2464
2469
|
* @throws {IdfmRemoteRouterTokenError}
|
|
2465
2470
|
*/
|
|
2466
|
-
async getItineraries(name, endpointUrl,
|
|
2471
|
+
async getItineraries(name, endpointUrl, travelMode, travelModePreference, waypoints, options) {
|
|
2467
2472
|
const router = this.getRouterByName(name);
|
|
2468
2473
|
if (!router) {
|
|
2469
2474
|
throw new Error(`Unknown "${name}" remote router`);
|
|
2470
2475
|
}
|
|
2471
|
-
return router.getItineraries(endpointUrl,
|
|
2476
|
+
return router.getItineraries(endpointUrl, travelMode, travelModePreference, waypoints, options);
|
|
2472
2477
|
}
|
|
2473
2478
|
/**
|
|
2474
2479
|
* @throws {RemoteRouterServerUnreachable}
|
|
2475
2480
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2476
2481
|
* @throws {IdfmRemoteRouterTokenError}
|
|
2477
2482
|
*/
|
|
2478
|
-
async getItinerariesWithFallback(remoteRouters2,
|
|
2483
|
+
async getItinerariesWithFallback(remoteRouters2, travelMode, travelModePreference, waypoints, options) {
|
|
2479
2484
|
let routerResponse;
|
|
2480
2485
|
for (const { name, endpointUrl } of remoteRouters2) {
|
|
2481
|
-
routerResponse = await this.getItineraries(name, endpointUrl,
|
|
2486
|
+
routerResponse = await this.getItineraries(name, endpointUrl, travelMode, travelModePreference, waypoints, options);
|
|
2482
2487
|
if (routerResponse.itineraries.length) {
|
|
2483
2488
|
return routerResponse;
|
|
2484
2489
|
}
|
|
@@ -2577,7 +2582,7 @@ class WemapMultiRouter {
|
|
|
2577
2582
|
itineraries: ends.map((end) => Itinerary.fromGraphRoute(routes.route(end)))
|
|
2578
2583
|
};
|
|
2579
2584
|
}
|
|
2580
|
-
async getItineraries(
|
|
2585
|
+
async getItineraries(travelMode, travelModePreference, waypoints, options = null) {
|
|
2581
2586
|
var _a;
|
|
2582
2587
|
if (waypoints.length > 2) {
|
|
2583
2588
|
Logger.warn(`WemapMultiRouter uses only the first 2 waypoints (asked ${waypoints.length})`);
|
|
@@ -2593,7 +2598,7 @@ class WemapMultiRouter {
|
|
|
2593
2598
|
const ioMapsToTest = this.getIoMapsFromOptions(options);
|
|
2594
2599
|
if (!ioMapsToTest.length) {
|
|
2595
2600
|
try {
|
|
2596
|
-
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters2,
|
|
2601
|
+
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters2, travelMode, travelModePreference, waypoints, options || void 0);
|
|
2597
2602
|
} catch (e) {
|
|
2598
2603
|
if (!isRoutingError(e)) {
|
|
2599
2604
|
throw e;
|
|
@@ -2624,7 +2629,7 @@ class WemapMultiRouter {
|
|
|
2624
2629
|
let remoteRouterResponse;
|
|
2625
2630
|
if (!mapWithStart && !mapWithEnd) {
|
|
2626
2631
|
try {
|
|
2627
|
-
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters2,
|
|
2632
|
+
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters2, travelMode, travelModePreference, waypoints, options || void 0);
|
|
2628
2633
|
} catch (e) {
|
|
2629
2634
|
if (!isRoutingError(e)) {
|
|
2630
2635
|
throw e;
|
|
@@ -2643,7 +2648,8 @@ class WemapMultiRouter {
|
|
|
2643
2648
|
ioMapRoute = mapWithStart.getBestRouteFromStartToEntryPoints(start, end, routerOptions);
|
|
2644
2649
|
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
2645
2650
|
remoteRouters2,
|
|
2646
|
-
|
|
2651
|
+
travelMode,
|
|
2652
|
+
travelModePreference,
|
|
2647
2653
|
[ioMapRoute.end, end],
|
|
2648
2654
|
options || void 0
|
|
2649
2655
|
);
|
|
@@ -2674,7 +2680,8 @@ class WemapMultiRouter {
|
|
|
2674
2680
|
ioMapRoute = mapWithEnd.getBestRouteFromEntryPointsToEnd(start, end, routerOptions);
|
|
2675
2681
|
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
2676
2682
|
remoteRouters2,
|
|
2677
|
-
|
|
2683
|
+
travelMode,
|
|
2684
|
+
travelModePreference,
|
|
2678
2685
|
[start, ioMapRoute.start],
|
|
2679
2686
|
options || void 0
|
|
2680
2687
|
);
|
|
@@ -2714,7 +2721,8 @@ class WemapMultiRouter {
|
|
|
2714
2721
|
ioMapRoute2 = mapWithEnd.getBestRouteFromEntryPointsToEnd(start, end, routerOptions);
|
|
2715
2722
|
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
2716
2723
|
remoteRouters2,
|
|
2717
|
-
|
|
2724
|
+
travelMode,
|
|
2725
|
+
travelModePreference,
|
|
2718
2726
|
[ioMapRoute1.end, ioMapRoute2.start],
|
|
2719
2727
|
options || void 0
|
|
2720
2728
|
);
|