@wemap/routers 12.0.0-alpha.5 → 12.0.0-alpha.7
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 +166 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -211
- package/dist/index.mjs.map +1 -1
- package/index.ts +3 -5
- package/package.json +2 -2
- package/src/graph/GraphRouterOptions.ts +5 -5
- package/src/graph/GraphRouterOptionsBuilder.ts +26 -26
- package/src/model/RouterRequest.ts +23 -0
- package/src/remote/RemoteRouter.ts +2 -11
- package/src/remote/RemoteRouterManager.ts +11 -25
- package/src/remote/cityway/CitywayRemoteRouter.ts +16 -16
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.ts +6 -10
- package/src/remote/idfm/IdfmRemoteRouter.ts +17 -23
- package/src/remote/osrm/OsrmRemoteRouter.ts +17 -35
- package/src/remote/otp/OtpRemoteRouter.ts +13 -16
- package/src/remote/wemap-multi/WemapMultiRemoteRouter.spec.ts +35 -25
- package/src/remote/wemap-multi/WemapMultiRemoteRouter.ts +17 -15
- package/src/wemap-multi/WemapMultiRouter.spec.ts +39 -27
- package/src/wemap-multi/WemapMultiRouter.ts +77 -116
- package/src/remote/RemoteRouterOptions.ts +0 -3
- package/src/remote/wemap-multi/WemapMultiRemoteRouterOptions.ts +0 -4
- package/src/remote/wemap-multi/WemapMultiRemoteRouterPayload.ts +0 -37
- package/src/wemap-multi/WemapMultiRouterOptions.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -944,31 +944,31 @@ class RouterResponse {
|
|
|
944
944
|
}
|
|
945
945
|
const _GraphRouterOptionsBuilder = class _GraphRouterOptionsBuilder {
|
|
946
946
|
constructor() {
|
|
947
|
-
__publicField(this, "
|
|
948
|
-
__publicField(this, "
|
|
949
|
-
__publicField(this, "
|
|
950
|
-
__publicField(this, "
|
|
951
|
-
__publicField(this, "
|
|
947
|
+
__publicField(this, "avoidStairs", false);
|
|
948
|
+
__publicField(this, "avoidEscalators", false);
|
|
949
|
+
__publicField(this, "avoidElevators", false);
|
|
950
|
+
__publicField(this, "avoidMovingWalkway", false);
|
|
951
|
+
__publicField(this, "avoidTicketRestrictedAreas", false);
|
|
952
952
|
__publicField(this, "projectionMaxDistance");
|
|
953
953
|
}
|
|
954
|
-
|
|
955
|
-
this.
|
|
954
|
+
setAvoidStairs(avoidStairs) {
|
|
955
|
+
this.avoidStairs = avoidStairs;
|
|
956
956
|
return this;
|
|
957
957
|
}
|
|
958
|
-
|
|
959
|
-
this.
|
|
958
|
+
setAvoidEscalators(avoidEscalators) {
|
|
959
|
+
this.avoidEscalators = avoidEscalators;
|
|
960
960
|
return this;
|
|
961
961
|
}
|
|
962
|
-
|
|
963
|
-
this.
|
|
962
|
+
setAvoidElevators(avoidElevators) {
|
|
963
|
+
this.avoidElevators = avoidElevators;
|
|
964
964
|
return this;
|
|
965
965
|
}
|
|
966
|
-
|
|
967
|
-
this.
|
|
966
|
+
setAvoidMovingWalkway(avoidMovingWalkway) {
|
|
967
|
+
this.avoidMovingWalkway = avoidMovingWalkway;
|
|
968
968
|
return this;
|
|
969
969
|
}
|
|
970
|
-
|
|
971
|
-
this.
|
|
970
|
+
setAvoidTicketRestrictedAreas(avoidTicketRestrictedAreas) {
|
|
971
|
+
this.avoidTicketRestrictedAreas = avoidTicketRestrictedAreas;
|
|
972
972
|
return this;
|
|
973
973
|
}
|
|
974
974
|
static fromJson(options) {
|
|
@@ -988,25 +988,25 @@ const _GraphRouterOptionsBuilder = class _GraphRouterOptionsBuilder {
|
|
|
988
988
|
return duration;
|
|
989
989
|
};
|
|
990
990
|
const acceptEdgeFn = (edge) => {
|
|
991
|
-
if (
|
|
991
|
+
if (this.avoidStairs && edge.properties.areStairs)
|
|
992
992
|
return false;
|
|
993
|
-
if (
|
|
993
|
+
if (this.avoidEscalators && edge.properties.areEscalators)
|
|
994
994
|
return false;
|
|
995
|
-
if (
|
|
995
|
+
if (this.avoidElevators && edge.properties.isElevator)
|
|
996
996
|
return false;
|
|
997
|
-
if (
|
|
997
|
+
if (this.avoidMovingWalkway && edge.properties.isMovingWalkway)
|
|
998
998
|
return false;
|
|
999
|
-
if (
|
|
999
|
+
if (this.avoidTicketRestrictedAreas && edge.properties.needTicket)
|
|
1000
1000
|
return false;
|
|
1001
1001
|
return true;
|
|
1002
1002
|
};
|
|
1003
1003
|
return {
|
|
1004
1004
|
input: {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1005
|
+
avoidStairs: this.avoidStairs,
|
|
1006
|
+
avoidEscalators: this.avoidEscalators,
|
|
1007
|
+
avoidElevators: this.avoidElevators,
|
|
1008
|
+
avoidMovingWalkway: this.avoidMovingWalkway,
|
|
1009
|
+
avoidTicketRestrictedAreas: this.avoidTicketRestrictedAreas,
|
|
1010
1010
|
projectionMaxDistance: this.projectionMaxDistance
|
|
1011
1011
|
},
|
|
1012
1012
|
weightEdgeFn,
|
|
@@ -1016,7 +1016,7 @@ const _GraphRouterOptionsBuilder = class _GraphRouterOptionsBuilder {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
};
|
|
1018
1018
|
__publicField(_GraphRouterOptionsBuilder, "DEFAULT", new _GraphRouterOptionsBuilder().build());
|
|
1019
|
-
__publicField(_GraphRouterOptionsBuilder, "WITHOUT_STAIRS", new _GraphRouterOptionsBuilder().
|
|
1019
|
+
__publicField(_GraphRouterOptionsBuilder, "WITHOUT_STAIRS", new _GraphRouterOptionsBuilder().setAvoidStairs(true).build());
|
|
1020
1020
|
let GraphRouterOptionsBuilder = _GraphRouterOptionsBuilder;
|
|
1021
1021
|
class GraphRouterEngineResults {
|
|
1022
1022
|
constructor(prev, dist, source, targets, edges) {
|
|
@@ -1528,29 +1528,30 @@ 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, routerRequest) {
|
|
1532
|
+
const url = this.getURL(endpointUrl, routerRequest);
|
|
1533
1533
|
const res = await fetch(url).catch(() => {
|
|
1534
1534
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1535
1535
|
});
|
|
1536
1536
|
const jsonResponse = await res.json().catch(() => {
|
|
1537
1537
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1538
1538
|
});
|
|
1539
|
-
return this.createRouterResponseFromJson(jsonResponse,
|
|
1539
|
+
return this.createRouterResponseFromJson(jsonResponse, routerRequest.origin, routerRequest.destination);
|
|
1540
1540
|
}
|
|
1541
1541
|
/**
|
|
1542
1542
|
* @throws {transitModeCorrespondanceNotFound}
|
|
1543
1543
|
*/
|
|
1544
|
-
getURL(endpointUrl,
|
|
1545
|
-
const
|
|
1544
|
+
getURL(endpointUrl, routerRequest) {
|
|
1545
|
+
const { origin, destination, travelMode, waypoints } = routerRequest;
|
|
1546
|
+
const citywayMode = inputModeCorrespondance$2.get(travelMode);
|
|
1546
1547
|
if (!citywayMode) {
|
|
1547
|
-
throw new TransitModeCorrespondanceNotFound(this.rname,
|
|
1548
|
+
throw new TransitModeCorrespondanceNotFound(this.rname, travelMode);
|
|
1548
1549
|
}
|
|
1549
|
-
if (waypoints.length >
|
|
1550
|
-
Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints.length})`);
|
|
1550
|
+
if ((waypoints || []).length > 0) {
|
|
1551
|
+
Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints == null ? void 0 : waypoints.length})`);
|
|
1551
1552
|
}
|
|
1552
|
-
const fromPlace = `DepartureLatitude=${
|
|
1553
|
-
const toPlace = `ArrivalLatitude=${
|
|
1553
|
+
const fromPlace = `DepartureLatitude=${origin.latitude}&DepartureLongitude=${origin.longitude}`;
|
|
1554
|
+
const toPlace = `ArrivalLatitude=${destination.latitude}&ArrivalLongitude=${destination.longitude}`;
|
|
1554
1555
|
const queryMode = `TripModes=${citywayMode}`;
|
|
1555
1556
|
const url = new URL(endpointUrl);
|
|
1556
1557
|
let { search } = url;
|
|
@@ -1714,18 +1715,19 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
1714
1715
|
* @override
|
|
1715
1716
|
* @throws {RemoteRouterServerUnreachable}
|
|
1716
1717
|
*/
|
|
1717
|
-
async getItineraries(endpointUrl,
|
|
1718
|
-
const url = this.getURL(endpointUrl,
|
|
1718
|
+
async getItineraries(endpointUrl, routerRequest) {
|
|
1719
|
+
const url = this.getURL(endpointUrl, routerRequest);
|
|
1719
1720
|
const res = await fetch(url).catch(() => {
|
|
1720
1721
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1721
1722
|
});
|
|
1722
1723
|
const jsonResponse = await res.json().catch(() => {
|
|
1723
1724
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1724
1725
|
});
|
|
1725
|
-
return this.createRouterResponseFromJson(jsonResponse,
|
|
1726
|
+
return this.createRouterResponseFromJson(jsonResponse, routerRequest.origin, routerRequest.destination);
|
|
1726
1727
|
}
|
|
1727
|
-
getURL(endpointUrl,
|
|
1728
|
+
getURL(endpointUrl, routerRequest) {
|
|
1728
1729
|
let url = endpointUrl + "/route/v1/walking/";
|
|
1730
|
+
const waypoints = [routerRequest.origin, ...routerRequest.waypoints || [], routerRequest.destination];
|
|
1729
1731
|
url += waypoints.map((waypoint) => {
|
|
1730
1732
|
if (waypoint.level !== null) {
|
|
1731
1733
|
const altitude = geo.Level.isRange(waypoint.level) ? waypoint.level[0] : waypoint.level;
|
|
@@ -1834,8 +1836,8 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
1834
1836
|
* @throws {IdfmRemoteRouterTokenError}
|
|
1835
1837
|
* @throws {RemoteRouterServerUnreachable}
|
|
1836
1838
|
*/
|
|
1837
|
-
async getItineraries(endpointUrl,
|
|
1838
|
-
const url = this.getURL(endpointUrl,
|
|
1839
|
+
async getItineraries(endpointUrl, routerRequest) {
|
|
1840
|
+
const url = this.getURL(endpointUrl, routerRequest);
|
|
1839
1841
|
const res = await fetch(url, {
|
|
1840
1842
|
method: "GET",
|
|
1841
1843
|
headers: { apiKey }
|
|
@@ -1848,36 +1850,38 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
1848
1850
|
if (jsonResponse && jsonResponse.error) {
|
|
1849
1851
|
return new RouterResponse({
|
|
1850
1852
|
routerName: this.rname,
|
|
1851
|
-
from:
|
|
1852
|
-
to:
|
|
1853
|
+
from: routerRequest.origin,
|
|
1854
|
+
to: routerRequest.destination,
|
|
1853
1855
|
error: jsonResponse.error.message || "no details."
|
|
1854
1856
|
});
|
|
1855
1857
|
}
|
|
1856
|
-
const routerResponse = this.createRouterResponseFromJson(jsonResponse,
|
|
1857
|
-
const sameModeFound = routerResponse.itineraries.some((itinerary) => itinerary.mode === travelMode);
|
|
1858
|
+
const routerResponse = this.createRouterResponseFromJson(jsonResponse, routerRequest.origin, routerRequest.destination);
|
|
1859
|
+
const sameModeFound = routerResponse.itineraries.some((itinerary) => itinerary.mode === routerRequest.travelMode);
|
|
1858
1860
|
if (!sameModeFound) {
|
|
1859
1861
|
return new RouterResponse({
|
|
1860
1862
|
routerName: this.rname,
|
|
1861
|
-
from:
|
|
1862
|
-
to:
|
|
1863
|
+
from: routerRequest.origin,
|
|
1864
|
+
to: routerRequest.destination,
|
|
1863
1865
|
error: "Selected mode of transport was not found for this itinerary."
|
|
1864
1866
|
});
|
|
1865
1867
|
}
|
|
1866
1868
|
return routerResponse;
|
|
1867
1869
|
}
|
|
1868
|
-
getURL(endpointUrl,
|
|
1869
|
-
|
|
1870
|
-
|
|
1870
|
+
getURL(endpointUrl, routerRequest) {
|
|
1871
|
+
var _a;
|
|
1872
|
+
const { origin, destination, waypoints, travelMode } = routerRequest;
|
|
1873
|
+
if ((waypoints || []).length > 0) {
|
|
1874
|
+
Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints == null ? void 0 : waypoints.length})`);
|
|
1871
1875
|
}
|
|
1872
1876
|
const url = new URL(endpointUrl);
|
|
1873
1877
|
const coreParams = new URLSearchParams();
|
|
1874
|
-
coreParams.set("from", `${
|
|
1875
|
-
coreParams.set("to", `${
|
|
1876
|
-
if (
|
|
1878
|
+
coreParams.set("from", `${origin.longitude};${origin.latitude}`);
|
|
1879
|
+
coreParams.set("to", `${destination.longitude};${destination.latitude}`);
|
|
1880
|
+
if ((_a = routerRequest.itineraryModifiers) == null ? void 0 : _a.avoidStairs) {
|
|
1877
1881
|
coreParams.set("wheelchair", "true");
|
|
1878
1882
|
}
|
|
1879
1883
|
let queryParams = new URLSearchParams();
|
|
1880
|
-
switch (
|
|
1884
|
+
switch (travelMode) {
|
|
1881
1885
|
case "WALK":
|
|
1882
1886
|
queryParams = this.getWalkingQuery();
|
|
1883
1887
|
break;
|
|
@@ -2062,7 +2066,11 @@ class TravelModeCorrespondanceNotFound extends Error {
|
|
|
2062
2066
|
this.transitMode = transitMode;
|
|
2063
2067
|
}
|
|
2064
2068
|
}
|
|
2065
|
-
const inputModeCorrespondance$1 = (
|
|
2069
|
+
const inputModeCorrespondance$1 = (routerRequest) => {
|
|
2070
|
+
var _a;
|
|
2071
|
+
const { travelMode, travelModePreference: preference } = routerRequest;
|
|
2072
|
+
if (travelMode === "WALK" && ((_a = routerRequest.itineraryModifiers) == null ? void 0 : _a.avoidStairs))
|
|
2073
|
+
return "pmr";
|
|
2066
2074
|
if (travelMode === "WALK")
|
|
2067
2075
|
return "walking";
|
|
2068
2076
|
if (travelMode === "BIKE") {
|
|
@@ -2093,27 +2101,23 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
2093
2101
|
* @throws {RemoteRouterServerUnreachable}
|
|
2094
2102
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2095
2103
|
*/
|
|
2096
|
-
async getItineraries(endpointUrl,
|
|
2097
|
-
const url = this.getURL(endpointUrl,
|
|
2104
|
+
async getItineraries(endpointUrl, routerRequest) {
|
|
2105
|
+
const url = this.getURL(endpointUrl, routerRequest);
|
|
2098
2106
|
const res = await fetch(url).catch(() => {
|
|
2099
2107
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2100
2108
|
});
|
|
2101
2109
|
const jsonResponse = await res.json().catch(() => {
|
|
2102
2110
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2103
2111
|
});
|
|
2104
|
-
|
|
2105
|
-
const to = waypoints[waypoints.length - 1];
|
|
2106
|
-
inputModeCorrespondance$1(travelMode, travelModePreference);
|
|
2107
|
-
return this.createRouterResponseFromJson(jsonResponse, from, to, outputModeCorrespondance.get(travelMode));
|
|
2112
|
+
return this.createRouterResponseFromJson(jsonResponse, routerRequest.origin, routerRequest.destination, routerRequest.travelMode);
|
|
2108
2113
|
}
|
|
2109
2114
|
/**
|
|
2110
2115
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2111
2116
|
*/
|
|
2112
|
-
getURL(endpointUrl,
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
}
|
|
2117
|
+
getURL(endpointUrl, routerRequest) {
|
|
2118
|
+
const { origin, destination } = routerRequest;
|
|
2119
|
+
const osrmMode = inputModeCorrespondance$1(routerRequest);
|
|
2120
|
+
const waypoints = [origin, ...routerRequest.waypoints || [], destination];
|
|
2117
2121
|
let url = endpointUrl + "/route/v1/" + osrmMode + "/";
|
|
2118
2122
|
url += waypoints.map((waypoint) => [waypoint.longitude + "," + waypoint.latitude]).join(";");
|
|
2119
2123
|
url += "?geometries=geojson&overview=full&steps=true";
|
|
@@ -2227,7 +2231,8 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
2227
2231
|
"waypoints": []
|
|
2228
2232
|
};
|
|
2229
2233
|
}
|
|
2230
|
-
createRouterResponseFromJson(json, from, to,
|
|
2234
|
+
createRouterResponseFromJson(json, from, to, travelMode) {
|
|
2235
|
+
const transitMode = outputModeCorrespondance.get(travelMode);
|
|
2231
2236
|
const routerResponse = new RouterResponse({ routerName: this.rname, from, to });
|
|
2232
2237
|
const { routes: jsonRoutes } = json;
|
|
2233
2238
|
if (!jsonRoutes) {
|
|
@@ -2297,29 +2302,30 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
2297
2302
|
* @throws {RemoteRouterServerUnreachable}
|
|
2298
2303
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2299
2304
|
*/
|
|
2300
|
-
async getItineraries(endpointUrl,
|
|
2301
|
-
const url = this.getURL(endpointUrl,
|
|
2305
|
+
async getItineraries(endpointUrl, routerRequest) {
|
|
2306
|
+
const url = this.getURL(endpointUrl, routerRequest);
|
|
2302
2307
|
const res = await fetch(url).catch(() => {
|
|
2303
2308
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2304
2309
|
});
|
|
2305
2310
|
const jsonResponse = await res.json().catch(() => {
|
|
2306
2311
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2307
2312
|
});
|
|
2308
|
-
return this.createRouterResponseFromJson(jsonResponse,
|
|
2313
|
+
return this.createRouterResponseFromJson(jsonResponse, routerRequest.origin, routerRequest.destination);
|
|
2309
2314
|
}
|
|
2310
2315
|
/**
|
|
2311
2316
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2312
2317
|
*/
|
|
2313
|
-
getURL(endpointUrl,
|
|
2314
|
-
const
|
|
2318
|
+
getURL(endpointUrl, routerRequest) {
|
|
2319
|
+
const { origin, destination, waypoints, travelMode } = routerRequest;
|
|
2320
|
+
const otpMode = inputModeCorrespondance.get(travelMode);
|
|
2315
2321
|
if (!otpMode) {
|
|
2316
|
-
throw new TravelModeCorrespondanceNotFound(this.rname,
|
|
2322
|
+
throw new TravelModeCorrespondanceNotFound(this.rname, travelMode);
|
|
2317
2323
|
}
|
|
2318
|
-
if (waypoints.length >
|
|
2319
|
-
Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints.length})`);
|
|
2324
|
+
if ((waypoints || []).length > 0) {
|
|
2325
|
+
Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints == null ? void 0 : waypoints.length})`);
|
|
2320
2326
|
}
|
|
2321
|
-
const fromPlace = `fromPlace=${
|
|
2322
|
-
const toPlace = `toPlace=${
|
|
2327
|
+
const fromPlace = `fromPlace=${origin.latitude},${origin.longitude}`;
|
|
2328
|
+
const toPlace = `toPlace=${destination.latitude},${destination.longitude}`;
|
|
2323
2329
|
const queryMode = `mode=${otpMode}`;
|
|
2324
2330
|
const url = new URL(endpointUrl);
|
|
2325
2331
|
let { search } = url;
|
|
@@ -2402,44 +2408,25 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
2402
2408
|
}
|
|
2403
2409
|
}
|
|
2404
2410
|
const OtpRemoteRouter$1 = new OtpRemoteRouter();
|
|
2405
|
-
class WemapMultiRemoteRouterPayload {
|
|
2406
|
-
constructor(waypoints, mode, options = null) {
|
|
2407
|
-
this.waypoints = waypoints;
|
|
2408
|
-
this.mode = mode;
|
|
2409
|
-
this.options = options;
|
|
2410
|
-
}
|
|
2411
|
-
toJson() {
|
|
2412
|
-
return {
|
|
2413
|
-
waypoints: this.waypoints.map((coords) => coords.toCompressedJson()),
|
|
2414
|
-
mode: this.mode,
|
|
2415
|
-
...this.options && { options: this.options }
|
|
2416
|
-
};
|
|
2417
|
-
}
|
|
2418
|
-
static fromJson(json) {
|
|
2419
|
-
return new WemapMultiRemoteRouterPayload(
|
|
2420
|
-
json.waypoints.map(geo.Coordinates.fromCompressedJson),
|
|
2421
|
-
json.mode,
|
|
2422
|
-
json.options
|
|
2423
|
-
);
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
2411
|
class WemapMultiRemoteRouter extends RemoteRouter {
|
|
2427
2412
|
get rname() {
|
|
2428
2413
|
return "wemap-multi";
|
|
2429
2414
|
}
|
|
2430
|
-
async getItineraries(endpointUrl,
|
|
2431
|
-
const
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2415
|
+
async getItineraries(endpointUrl, routerRequest) {
|
|
2416
|
+
const { origin, destination, waypoints } = routerRequest;
|
|
2417
|
+
const payload = {
|
|
2418
|
+
...routerRequest,
|
|
2419
|
+
origin: origin instanceof geo.Coordinates ? origin.toJson() : origin,
|
|
2420
|
+
destination: destination instanceof geo.Coordinates ? destination.toJson() : destination,
|
|
2421
|
+
...waypoints && { waypoints: waypoints.map((w) => w instanceof geo.Coordinates ? w.toJson() : w) }
|
|
2422
|
+
};
|
|
2436
2423
|
const res = await fetch(endpointUrl, {
|
|
2437
2424
|
method: "POST",
|
|
2438
2425
|
headers: {
|
|
2439
2426
|
"Accept": "application/json",
|
|
2440
2427
|
"Content-Type": "application/json"
|
|
2441
2428
|
},
|
|
2442
|
-
body: JSON.stringify(payload
|
|
2429
|
+
body: JSON.stringify(payload)
|
|
2443
2430
|
}).catch(() => {
|
|
2444
2431
|
throw new RemoteRouterServerUnreachable(this.rname, endpointUrl);
|
|
2445
2432
|
});
|
|
@@ -2467,31 +2454,31 @@ class RemoteRouterManager {
|
|
|
2467
2454
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2468
2455
|
* @throws {IdfmRemoteRouterTokenError}
|
|
2469
2456
|
*/
|
|
2470
|
-
async getItineraries(name, endpointUrl,
|
|
2457
|
+
async getItineraries(name, endpointUrl, routerRequest) {
|
|
2471
2458
|
const router = this.getRouterByName(name);
|
|
2472
2459
|
if (!router) {
|
|
2473
2460
|
throw new Error(`Unknown "${name}" remote router`);
|
|
2474
2461
|
}
|
|
2475
|
-
return router.getItineraries(endpointUrl,
|
|
2462
|
+
return router.getItineraries(endpointUrl, routerRequest);
|
|
2476
2463
|
}
|
|
2477
2464
|
/**
|
|
2478
2465
|
* @throws {RemoteRouterServerUnreachable}
|
|
2479
2466
|
* @throws {TravelModeCorrespondanceNotFound}
|
|
2480
2467
|
* @throws {IdfmRemoteRouterTokenError}
|
|
2481
2468
|
*/
|
|
2482
|
-
async getItinerariesWithFallback(
|
|
2469
|
+
async getItinerariesWithFallback(routerRequest, fallbackStrategy) {
|
|
2483
2470
|
let routerResponse;
|
|
2484
|
-
for (const { name, endpointUrl } of
|
|
2485
|
-
routerResponse = await this.getItineraries(name, endpointUrl,
|
|
2471
|
+
for (const { name, endpointUrl } of fallbackStrategy) {
|
|
2472
|
+
routerResponse = await this.getItineraries(name, endpointUrl, routerRequest);
|
|
2486
2473
|
if (routerResponse.itineraries.length) {
|
|
2487
2474
|
return routerResponse;
|
|
2488
2475
|
}
|
|
2489
2476
|
}
|
|
2490
2477
|
if (!routerResponse) {
|
|
2491
2478
|
routerResponse = new RouterResponse({
|
|
2492
|
-
routerName:
|
|
2493
|
-
from:
|
|
2494
|
-
to:
|
|
2479
|
+
routerName: fallbackStrategy.map((rr) => rr.name),
|
|
2480
|
+
from: routerRequest.origin,
|
|
2481
|
+
to: routerRequest.destination
|
|
2495
2482
|
});
|
|
2496
2483
|
}
|
|
2497
2484
|
return routerResponse;
|
|
@@ -2518,86 +2505,51 @@ class WemapMultiRouter {
|
|
|
2518
2505
|
getMapByName(mapId) {
|
|
2519
2506
|
return this.maps.find((map) => map.name === mapId);
|
|
2520
2507
|
}
|
|
2521
|
-
getIoMapsFromOptions(options) {
|
|
2522
|
-
let ioMapsToTest = this.maps;
|
|
2523
|
-
const targetMaps = options == null ? void 0 : options.targetMaps;
|
|
2524
|
-
if (targetMaps) {
|
|
2525
|
-
ioMapsToTest = this.maps.filter((map) => map.name && targetMaps.includes(map.name));
|
|
2526
|
-
if (ioMapsToTest.length !== targetMaps.length) {
|
|
2527
|
-
ioMapsToTest.forEach((map) => {
|
|
2528
|
-
if (map.name && !targetMaps.includes(map.name)) {
|
|
2529
|
-
Logger.warn(`CustomNetworkMap "${map.name}" not found in WemapMultiRouter`);
|
|
2530
|
-
}
|
|
2531
|
-
});
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
return ioMapsToTest;
|
|
2535
|
-
}
|
|
2536
2508
|
// TODO: Move it away
|
|
2537
|
-
async getTrip(mode, waypoints, options = null) {
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
}
|
|
2572
|
-
return mapOfThisWaypoint || map;
|
|
2573
|
-
}, null);
|
|
2574
|
-
if (mapOfWaypoints === null) {
|
|
2575
|
-
throw Error(`No map found for this itineraries.`);
|
|
2576
|
-
}
|
|
2577
|
-
const routerOptions = GraphRouterOptionsBuilder.fromJson(options || {});
|
|
2578
|
-
const routes = mapOfWaypoints.getRoutesMultipleDestinationsInsideMap(start, ends, routerOptions);
|
|
2579
|
-
return {
|
|
2580
|
-
routerName: this.rname,
|
|
2581
|
-
itineraries: ends.map((end) => Itinerary.fromGraphRoute(routes.route(end)))
|
|
2582
|
-
};
|
|
2583
|
-
}
|
|
2584
|
-
async getItineraries(travelMode, travelModePreference, waypoints, options = null) {
|
|
2585
|
-
var _a;
|
|
2586
|
-
if (waypoints.length > 2) {
|
|
2587
|
-
Logger.warn(`WemapMultiRouter uses only the first 2 waypoints (asked ${waypoints.length})`);
|
|
2588
|
-
}
|
|
2589
|
-
const start = waypoints[0];
|
|
2590
|
-
const end = waypoints[1];
|
|
2509
|
+
// async getTrip(mode: TravelMode, waypoints: Coordinates[], options: WemapMultiRouterOptions | null = null) {
|
|
2510
|
+
// const ioMapsToTest = this.getIoMapsFromOptions(options);
|
|
2511
|
+
// if (waypoints.length < 2) {
|
|
2512
|
+
// throw Error(`Cannot retrieve a trip itinerary. Two points or more are necessary`);
|
|
2513
|
+
// }
|
|
2514
|
+
// if (mode !== 'WALK') {
|
|
2515
|
+
// throw Error(`Cannot calculate trip itinerary for mode "${mode}". Only "WALK" is implemented.`);
|
|
2516
|
+
// }
|
|
2517
|
+
// // Retrieve the map which embed all the waypoints
|
|
2518
|
+
// const mapOfWaypoints = waypoints.reduce((map, waypoint) => {
|
|
2519
|
+
// const mapOfThisWaypoint = ioMapsToTest.find(map => map.isPointInside(waypoint));
|
|
2520
|
+
// if (!mapOfThisWaypoint) {
|
|
2521
|
+
// throw Error(`Cannot find a network for this trip waypoint (${waypoint.toString()}). Outdoor trips are not implemented.`)
|
|
2522
|
+
// }
|
|
2523
|
+
// if (map && mapOfThisWaypoint !== map) {
|
|
2524
|
+
// throw Error(`Cannot handle this trip, because two waypoints are on different maps (${mapOfThisWaypoint} and ${mapOfWaypoints}). ` +
|
|
2525
|
+
// `Multi-map trips are not implemented.`)
|
|
2526
|
+
// }
|
|
2527
|
+
// return mapOfThisWaypoint
|
|
2528
|
+
// }, null as CustomNetworkMap | null);
|
|
2529
|
+
// // Create GraphRouterOptions from WemapMultiRouterOptions
|
|
2530
|
+
// const routerOptions = GraphRouterOptionsBuilder.fromJson(options || {});
|
|
2531
|
+
// const tripRoutes = mapOfWaypoints!.getTripInsideMap(waypoints, routerOptions);
|
|
2532
|
+
// const tripItineraries = tripRoutes.map(tripRoute => Itinerary.fromGraphRoute(tripRoute));
|
|
2533
|
+
// return new RouterResponse({
|
|
2534
|
+
// routerName: this.rname,
|
|
2535
|
+
// from: tripItineraries[0].from,
|
|
2536
|
+
// to: tripItineraries[tripItineraries.length - 1].to,
|
|
2537
|
+
// itineraries: tripItineraries
|
|
2538
|
+
// });
|
|
2539
|
+
// }
|
|
2540
|
+
async getItineraries(routerRequest, fallbackStrategy = [], targetMaps = this.maps) {
|
|
2541
|
+
const start = routerRequest.origin;
|
|
2542
|
+
const end = routerRequest.destination;
|
|
2591
2543
|
const routerResponse = new RouterResponse({
|
|
2592
2544
|
routerName: this.rname,
|
|
2593
2545
|
from: start,
|
|
2594
2546
|
to: end
|
|
2595
2547
|
});
|
|
2596
|
-
|
|
2597
|
-
const ioMapsToTest =
|
|
2548
|
+
fallbackStrategy = fallbackStrategy.filter(({ name }) => name !== WemapMultiRemoteRouter$1.rname) || [];
|
|
2549
|
+
const ioMapsToTest = targetMaps;
|
|
2598
2550
|
if (!ioMapsToTest.length) {
|
|
2599
2551
|
try {
|
|
2600
|
-
return await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
2552
|
+
return await RemoteRouterManager$1.getItinerariesWithFallback(routerRequest, fallbackStrategy);
|
|
2601
2553
|
} catch (e) {
|
|
2602
2554
|
if (!isRoutingError(e)) {
|
|
2603
2555
|
throw e;
|
|
@@ -2609,7 +2561,7 @@ class WemapMultiRouter {
|
|
|
2609
2561
|
let ioMapRoute;
|
|
2610
2562
|
let ioMapItinerary;
|
|
2611
2563
|
const mapWithStart = ioMapsToTest.find((map) => map.isPointInside(start));
|
|
2612
|
-
const routerOptions = GraphRouterOptionsBuilder.fromJson(
|
|
2564
|
+
const routerOptions = GraphRouterOptionsBuilder.fromJson(routerRequest.itineraryModifiers || {});
|
|
2613
2565
|
if (mapWithStart && mapWithStart.isPointInside(end)) {
|
|
2614
2566
|
try {
|
|
2615
2567
|
ioMapRoute = mapWithStart.getRouteInsideMap(start, end, routerOptions);
|
|
@@ -2628,7 +2580,7 @@ class WemapMultiRouter {
|
|
|
2628
2580
|
let remoteRouterResponse;
|
|
2629
2581
|
if (!mapWithStart && !mapWithEnd) {
|
|
2630
2582
|
try {
|
|
2631
|
-
return await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
2583
|
+
return await RemoteRouterManager$1.getItinerariesWithFallback(routerRequest, fallbackStrategy);
|
|
2632
2584
|
} catch (e) {
|
|
2633
2585
|
if (!isRoutingError(e)) {
|
|
2634
2586
|
throw e;
|
|
@@ -2645,13 +2597,13 @@ class WemapMultiRouter {
|
|
|
2645
2597
|
}
|
|
2646
2598
|
try {
|
|
2647
2599
|
ioMapRoute = mapWithStart.getBestRouteFromStartToEntryPoints(start, end, routerOptions);
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
[
|
|
2653
|
-
|
|
2654
|
-
);
|
|
2600
|
+
const newRouterRequest = {
|
|
2601
|
+
...routerRequest,
|
|
2602
|
+
origin: ioMapRoute.end,
|
|
2603
|
+
destination: end,
|
|
2604
|
+
waypoints: []
|
|
2605
|
+
};
|
|
2606
|
+
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(newRouterRequest, fallbackStrategy);
|
|
2655
2607
|
if (!remoteRouterResponse.itineraries.length) {
|
|
2656
2608
|
throw new NoRouteFoundError(ioMapRoute.end, end, remoteRouterResponse.error);
|
|
2657
2609
|
}
|
|
@@ -2659,7 +2611,7 @@ class WemapMultiRouter {
|
|
|
2659
2611
|
if (!isRoutingError(e)) {
|
|
2660
2612
|
throw e;
|
|
2661
2613
|
}
|
|
2662
|
-
routerResponse.error = `Tried to calculate an itinerary from "start" to "entrypoints" using wemap router on local map "${mapWithStart.name}" and an itinerary from "entrypoints" to "end" using remote routers (${
|
|
2614
|
+
routerResponse.error = `Tried to calculate an itinerary from "start" to "entrypoints" using wemap router on local map "${mapWithStart.name}" and an itinerary from "entrypoints" to "end" using remote routers (${fallbackStrategy.map((r) => r.name).join(", ")}), but failed. Details: ${e.message}.`;
|
|
2663
2615
|
return routerResponse;
|
|
2664
2616
|
}
|
|
2665
2617
|
ioMapItinerary = Itinerary.fromGraphRoute(ioMapRoute);
|
|
@@ -2677,13 +2629,13 @@ class WemapMultiRouter {
|
|
|
2677
2629
|
}
|
|
2678
2630
|
try {
|
|
2679
2631
|
ioMapRoute = mapWithEnd.getBestRouteFromEntryPointsToEnd(start, end, routerOptions);
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
[
|
|
2685
|
-
|
|
2686
|
-
);
|
|
2632
|
+
const newRouterRequest = {
|
|
2633
|
+
...routerRequest,
|
|
2634
|
+
origin: start,
|
|
2635
|
+
destination: ioMapRoute.start,
|
|
2636
|
+
waypoints: []
|
|
2637
|
+
};
|
|
2638
|
+
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(newRouterRequest, fallbackStrategy);
|
|
2687
2639
|
if (!remoteRouterResponse.itineraries.length) {
|
|
2688
2640
|
throw new NoRouteFoundError(start, ioMapRoute.start, remoteRouterResponse.error);
|
|
2689
2641
|
}
|
|
@@ -2691,7 +2643,7 @@ class WemapMultiRouter {
|
|
|
2691
2643
|
if (!isRoutingError(e)) {
|
|
2692
2644
|
throw e;
|
|
2693
2645
|
}
|
|
2694
|
-
routerResponse.error = `Tried to calculate an itinerary from "start" to "entrypoints" using remote routers (${
|
|
2646
|
+
routerResponse.error = `Tried to calculate an itinerary from "start" to "entrypoints" using remote routers (${fallbackStrategy.map((r) => r.name).join(", ")}) and an itinerary from "entrypoints" to "end" using wemap router on local map "${mapWithEnd.name}", but failed. Details: ${e.message}.`;
|
|
2695
2647
|
return routerResponse;
|
|
2696
2648
|
}
|
|
2697
2649
|
ioMapItinerary = Itinerary.fromGraphRoute(ioMapRoute);
|
|
@@ -2718,12 +2670,15 @@ class WemapMultiRouter {
|
|
|
2718
2670
|
try {
|
|
2719
2671
|
ioMapRoute1 = mapWithStart.getBestRouteFromStartToEntryPoints(start, end, routerOptions);
|
|
2720
2672
|
ioMapRoute2 = mapWithEnd.getBestRouteFromEntryPointsToEnd(start, end, routerOptions);
|
|
2673
|
+
const newRouterRequest = {
|
|
2674
|
+
...routerRequest,
|
|
2675
|
+
origin: ioMapRoute1.end,
|
|
2676
|
+
destination: ioMapRoute2.start,
|
|
2677
|
+
waypoints: []
|
|
2678
|
+
};
|
|
2721
2679
|
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
travelModePreference,
|
|
2725
|
-
[ioMapRoute1.end, ioMapRoute2.start],
|
|
2726
|
-
options || void 0
|
|
2680
|
+
newRouterRequest,
|
|
2681
|
+
fallbackStrategy
|
|
2727
2682
|
);
|
|
2728
2683
|
if (!remoteRouterResponse.itineraries.length) {
|
|
2729
2684
|
throw new NoRouteFoundError(ioMapRoute1.end, ioMapRoute2.start, remoteRouterResponse.error);
|
|
@@ -2732,7 +2687,7 @@ class WemapMultiRouter {
|
|
|
2732
2687
|
if (!isRoutingError(e)) {
|
|
2733
2688
|
throw e;
|
|
2734
2689
|
}
|
|
2735
|
-
routerResponse.error = `Tried to calculate an itinerary from "start" to "entrypoints1" using wemap router on local map "${mapWithStart.name}", an itinerary from "entrypoints1" to "entrypoints2" using remote routers (${
|
|
2690
|
+
routerResponse.error = `Tried to calculate an itinerary from "start" to "entrypoints1" using wemap router on local map "${mapWithStart.name}", an itinerary from "entrypoints1" to "entrypoints2" using remote routers (${fallbackStrategy.map((r) => r.name).join(", ")}) and an itinerary from "entrypoints2" to "end" using wemap router on local map "${mapWithEnd.name}", but failed. Details: ${e.message}.`;
|
|
2736
2691
|
return routerResponse;
|
|
2737
2692
|
}
|
|
2738
2693
|
routerResponse.itineraries = remoteRouterResponse.itineraries.map(
|
|
@@ -3013,6 +2968,7 @@ exports.Graph = Graph;
|
|
|
3013
2968
|
exports.GraphProjection = GraphProjection;
|
|
3014
2969
|
exports.GraphRoute = GraphRoute;
|
|
3015
2970
|
exports.GraphRouter = GraphRouter;
|
|
2971
|
+
exports.GraphRouterOptionsBuilder = GraphRouterOptionsBuilder;
|
|
3016
2972
|
exports.IdfmRemoteRouter = IdfmRemoteRouter$1;
|
|
3017
2973
|
exports.Itinerary = Itinerary;
|
|
3018
2974
|
exports.ItineraryInfoManager = ItineraryInfoManager;
|
|
@@ -3026,7 +2982,6 @@ exports.RemoteRouterServerUnreachable = RemoteRouterServerUnreachable;
|
|
|
3026
2982
|
exports.RouterResponse = RouterResponse;
|
|
3027
2983
|
exports.Vertex = Vertex;
|
|
3028
2984
|
exports.WemapMultiRemoteRouter = WemapMultiRemoteRouter$1;
|
|
3029
|
-
exports.WemapMultiRemoteRouterPayload = WemapMultiRemoteRouterPayload;
|
|
3030
2985
|
exports.WemapMultiRouter = WemapMultiRouter;
|
|
3031
2986
|
exports.getDurationFromLength = getDurationFromLength;
|
|
3032
2987
|
//# sourceMappingURL=index.js.map
|