@wemap/routers 7.5.0 → 7.5.2
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/wemap-routers.es.js +379 -237
- package/dist/wemap-routers.es.js.map +1 -1
- package/package.json +2 -2
- package/src/ItineraryInfoManager.spec.js +3 -1
- package/src/remote/cityway/CitywayRemoteRouter.js +10 -10
- package/src/remote/cityway/CitywayRemoteRouter.spec.js +9 -5
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.js +8 -10
- package/src/remote/idfm/IdfmRemoteRouter.js +15 -14
- package/src/remote/idfm/IdfmRemoteRouter.spec.js +5 -3
- package/src/remote/osrm/OsrmRemoteRouter.js +10 -9
- package/src/remote/otp/OtpRemoteRouter.js +15 -12
- package/src/remote/otp/OtpRemoteRouter.spec.js +10 -6
package/dist/wemap-routers.es.js
CHANGED
|
@@ -435,6 +435,58 @@ function getDurationFromLength(length, speed = 5) {
|
|
|
435
435
|
return length / (speed * 1000 / 3600);
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
+
/* eslint-disable max-statements */
|
|
439
|
+
/* eslint-disable max-depth */
|
|
440
|
+
/**
|
|
441
|
+
* @param {RouterResponse} routerResponse
|
|
442
|
+
* @param {Number} levelFactor
|
|
443
|
+
*/
|
|
444
|
+
function multiplyRouterResponseLevel(routerResponse, levelFactor) {
|
|
445
|
+
if (routerResponse.from.level) {
|
|
446
|
+
routerResponse.from.level.multiplyBy(levelFactor);
|
|
447
|
+
}
|
|
448
|
+
if (routerResponse.to.level) {
|
|
449
|
+
routerResponse.to.level.multiplyBy(levelFactor);
|
|
450
|
+
}
|
|
451
|
+
for (const itinerary of routerResponse.itineraries) {
|
|
452
|
+
if (itinerary.from.level) {
|
|
453
|
+
itinerary.from.level.multiplyBy(levelFactor);
|
|
454
|
+
}
|
|
455
|
+
if (itinerary.to.level) {
|
|
456
|
+
itinerary.to.level.multiplyBy(levelFactor);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
for (const leg of itinerary.legs) {
|
|
460
|
+
if (leg.from.coords.level) {
|
|
461
|
+
leg.from.coords.level.multiplyBy(levelFactor);
|
|
462
|
+
}
|
|
463
|
+
if (leg.to.coords.level) {
|
|
464
|
+
leg.to.coords.level.multiplyBy(levelFactor);
|
|
465
|
+
}
|
|
466
|
+
for (const coords of leg.coords) {
|
|
467
|
+
if (coords.level) {
|
|
468
|
+
coords.level.multiplyBy(levelFactor);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (leg.steps) {
|
|
472
|
+
for (const step of leg.steps) {
|
|
473
|
+
if (step.coords.level) {
|
|
474
|
+
step.coords.level.multiplyBy(levelFactor);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (itinerary._coords) {
|
|
481
|
+
for (const coords of itinerary._coords) {
|
|
482
|
+
if (coords.level) {
|
|
483
|
+
coords.level.multiplyBy(levelFactor);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
438
490
|
/* eslint-disable max-statements */
|
|
439
491
|
|
|
440
492
|
/**
|
|
@@ -1355,6 +1407,7 @@ class IOMap {
|
|
|
1355
1407
|
* @param {Coordinates} end Then end coordinates (which is inside the network)
|
|
1356
1408
|
* @param {WemapRouterOptions} options
|
|
1357
1409
|
* @returns {Itinerary}
|
|
1410
|
+
* @throws {NoRouteFoundError}
|
|
1358
1411
|
*/
|
|
1359
1412
|
getBestItineraryFromEntryPointsToEnd(start, end, options) {
|
|
1360
1413
|
|
|
@@ -1386,6 +1439,7 @@ class IOMap {
|
|
|
1386
1439
|
* @param {Coordinates} end Then end coordinates (which is outside the network)
|
|
1387
1440
|
* @param {WemapRouterOptions} options
|
|
1388
1441
|
* @returns {Itinerary}
|
|
1442
|
+
* @throws {NoRouteFoundError}
|
|
1389
1443
|
*/
|
|
1390
1444
|
getBestItineraryFromStartToEntryPoints(start, end, options) {
|
|
1391
1445
|
|
|
@@ -1407,6 +1461,7 @@ class IOMap {
|
|
|
1407
1461
|
* @param {Coordinates} end the end coordinates
|
|
1408
1462
|
* @param {WemapRouterOptions} options
|
|
1409
1463
|
* @returns {?Itinerary}
|
|
1464
|
+
* @throws {NoRouteFoundError}
|
|
1410
1465
|
*/
|
|
1411
1466
|
getItineraryInsideMap(start, end, options) {
|
|
1412
1467
|
|
|
@@ -1440,7 +1495,7 @@ class WemapMetaRouterOptions {
|
|
|
1440
1495
|
|
|
1441
1496
|
class RemoteRouterOptions {
|
|
1442
1497
|
|
|
1443
|
-
/** @type {boolean} */
|
|
1498
|
+
/** @type {!boolean} */
|
|
1444
1499
|
useStairs = true;
|
|
1445
1500
|
|
|
1446
1501
|
/**
|
|
@@ -1456,7 +1511,9 @@ class RemoteRouterOptions {
|
|
|
1456
1511
|
*/
|
|
1457
1512
|
static fromJson(json) {
|
|
1458
1513
|
const obj = new RemoteRouterOptions();
|
|
1459
|
-
|
|
1514
|
+
if ('useStairs' in json) {
|
|
1515
|
+
obj.useStairs = json.useStairs;
|
|
1516
|
+
}
|
|
1460
1517
|
return obj;
|
|
1461
1518
|
}
|
|
1462
1519
|
|
|
@@ -1487,6 +1544,43 @@ class RemoteRouter {
|
|
|
1487
1544
|
|
|
1488
1545
|
}
|
|
1489
1546
|
|
|
1547
|
+
class IdfmRemoteRouterTokenError extends Error {
|
|
1548
|
+
|
|
1549
|
+
constructor() {
|
|
1550
|
+
super('An error occured with IDFM token request');
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
class RemoteRouterServerUnreachable extends Error {
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* @param {!string} name
|
|
1558
|
+
* @param {!string} endpointUrl
|
|
1559
|
+
*/
|
|
1560
|
+
constructor(name, endpointUrl) {
|
|
1561
|
+
super(`Remote router server ${name} is unreachable. URL: ${endpointUrl}`);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
class RoutingModeCorrespondanceNotFound extends Error {
|
|
1566
|
+
|
|
1567
|
+
/** @type {!string} */
|
|
1568
|
+
routerName;
|
|
1569
|
+
|
|
1570
|
+
/** @type {!string} */
|
|
1571
|
+
routingMode;
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
* @param {!string} routerName
|
|
1575
|
+
* @param {!string} routingMode
|
|
1576
|
+
*/
|
|
1577
|
+
constructor(routerName, routingMode) {
|
|
1578
|
+
this.routerName = routerName;
|
|
1579
|
+
this.routingMode = routingMode;
|
|
1580
|
+
super(`routing mode "${routingMode}" correspondance not found for router "${routerName}"`);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1490
1584
|
/**
|
|
1491
1585
|
* @param {Itinerary} itinerary
|
|
1492
1586
|
*/
|
|
@@ -1561,34 +1655,11 @@ function dateWithTimeZone(year, month, day, hour, minute, second, timeZone = 'Eu
|
|
|
1561
1655
|
return date;
|
|
1562
1656
|
}
|
|
1563
1657
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
*/
|
|
1570
|
-
constructor(name, endpointUrl) {
|
|
1571
|
-
super(`Remote router server ${name} is unreachable. URL: ${endpointUrl}`);
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
class RoutingModeCorrespondanceNotFound extends Error {
|
|
1576
|
-
|
|
1577
|
-
/** @type {!string} */
|
|
1578
|
-
routerName;
|
|
1579
|
-
|
|
1580
|
-
/** @type {!string} */
|
|
1581
|
-
routingMode;
|
|
1582
|
-
|
|
1583
|
-
/**
|
|
1584
|
-
* @param {!string} routerName
|
|
1585
|
-
* @param {!string} routingMode
|
|
1586
|
-
*/
|
|
1587
|
-
constructor(routerName, routingMode) {
|
|
1588
|
-
this.routerName = routerName;
|
|
1589
|
-
this.routingMode = routingMode;
|
|
1590
|
-
super(`routing mode "${routingMode}" correspondance not found for router "${routerName}"`);
|
|
1591
|
-
}
|
|
1658
|
+
function isRoutingError(e) {
|
|
1659
|
+
return e instanceof RemoteRouterServerUnreachable
|
|
1660
|
+
|| e instanceof RoutingModeCorrespondanceNotFound
|
|
1661
|
+
|| e instanceof IdfmRemoteRouterTokenError
|
|
1662
|
+
|| e instanceof NoRouteFoundError;
|
|
1592
1663
|
}
|
|
1593
1664
|
|
|
1594
1665
|
/* eslint-disable max-depth */
|
|
@@ -1673,12 +1744,14 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
1673
1744
|
*/
|
|
1674
1745
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
1675
1746
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
1676
|
-
const res = await fetch(url)
|
|
1677
|
-
if (res.status !== 200) {
|
|
1747
|
+
const res = await (fetch(url).catch(() => {
|
|
1678
1748
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1749
|
+
}));
|
|
1750
|
+
|
|
1751
|
+
const jsonResponse = await res.json().catch(() => {
|
|
1752
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1753
|
+
});
|
|
1754
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
1682
1755
|
}
|
|
1683
1756
|
|
|
1684
1757
|
|
|
@@ -1985,12 +2058,14 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
1985
2058
|
*/
|
|
1986
2059
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
1987
2060
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
1988
|
-
const res = await fetch(url)
|
|
1989
|
-
if (res.status !== 200) {
|
|
2061
|
+
const res = await (fetch(url).catch(() => {
|
|
1990
2062
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
|
|
2063
|
+
}));
|
|
2064
|
+
|
|
2065
|
+
const jsonResponse = await res.json().catch(() => {
|
|
2066
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2067
|
+
});
|
|
2068
|
+
return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
1994
2069
|
}
|
|
1995
2070
|
|
|
1996
2071
|
/**
|
|
@@ -2099,13 +2174,6 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
2099
2174
|
|
|
2100
2175
|
var DeutscheBahnRemoteRouter$1 = new DeutscheBahnRemoteRouter();
|
|
2101
2176
|
|
|
2102
|
-
class IdfmRemoteRouterTokenError extends Error {
|
|
2103
|
-
|
|
2104
|
-
constructor() {
|
|
2105
|
-
super('An error occured with IDFM token request');
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
2177
|
/* eslint-disable max-statements */
|
|
2110
2178
|
|
|
2111
2179
|
/**
|
|
@@ -2199,16 +2267,31 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
2199
2267
|
|
|
2200
2268
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
2201
2269
|
|
|
2202
|
-
const res = await fetch(url, {
|
|
2270
|
+
const res = await (fetch(url, {
|
|
2203
2271
|
method: 'GET',
|
|
2204
2272
|
headers: { Authorization: 'Bearer ' + this.token }
|
|
2205
|
-
})
|
|
2206
|
-
|
|
2273
|
+
}).catch(() => {
|
|
2274
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2275
|
+
}));
|
|
2276
|
+
|
|
2277
|
+
|
|
2278
|
+
const jsonResponse = await res.json().catch(() => {
|
|
2207
2279
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2280
|
+
});
|
|
2281
|
+
|
|
2282
|
+
// When IDFM failed to calculate an itinerary (ie. start or end
|
|
2283
|
+
// point is far from network), it respond a 404 with an error message
|
|
2284
|
+
// or a 200 with an error message
|
|
2285
|
+
if (jsonResponse && jsonResponse.error) {
|
|
2286
|
+
const routerResponse = new RouterResponse();
|
|
2287
|
+
routerResponse.routerName = this.rname;
|
|
2288
|
+
routerResponse.from = waypoints[0];
|
|
2289
|
+
routerResponse.to = waypoints[1];
|
|
2290
|
+
routerResponse.error = jsonResponse.error.message || 'no details.';
|
|
2291
|
+
return routerResponse;
|
|
2208
2292
|
}
|
|
2209
|
-
const response = await res.json();
|
|
2210
2293
|
|
|
2211
|
-
return this.createRouterResponseFromJson(
|
|
2294
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
2212
2295
|
}
|
|
2213
2296
|
|
|
2214
2297
|
/**
|
|
@@ -2557,12 +2640,16 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
2557
2640
|
*/
|
|
2558
2641
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
2559
2642
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
2560
|
-
|
|
2561
|
-
|
|
2643
|
+
|
|
2644
|
+
const res = await (fetch(url).catch(() => {
|
|
2562
2645
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2646
|
+
}));
|
|
2647
|
+
|
|
2648
|
+
const jsonResponse = await res.json().catch(() => {
|
|
2649
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2650
|
+
});
|
|
2651
|
+
|
|
2652
|
+
return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
2566
2653
|
}
|
|
2567
2654
|
|
|
2568
2655
|
/**
|
|
@@ -2874,12 +2961,14 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
2874
2961
|
*/
|
|
2875
2962
|
async getItineraries(endpointUrl, mode, waypoints) {
|
|
2876
2963
|
const url = this.getURL(endpointUrl, mode, waypoints);
|
|
2877
|
-
const res = await fetch(url)
|
|
2878
|
-
if (res.status !== 200) {
|
|
2964
|
+
const res = await (fetch(url).catch(() => {
|
|
2879
2965
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
|
|
2966
|
+
}));
|
|
2967
|
+
|
|
2968
|
+
const jsonResponse = await res.json().catch(() => {
|
|
2969
|
+
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
2970
|
+
});
|
|
2971
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
2883
2972
|
}
|
|
2884
2973
|
|
|
2885
2974
|
/**
|
|
@@ -3051,6 +3140,135 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
3051
3140
|
|
|
3052
3141
|
var OtpRemoteRouter$1 = new OtpRemoteRouter();
|
|
3053
3142
|
|
|
3143
|
+
// Also extends properties of WemapMetaRouterOptions
|
|
3144
|
+
class WemapMetaRemoteRouterOptions extends RemoteRouterOptions {
|
|
3145
|
+
|
|
3146
|
+
constructor() {
|
|
3147
|
+
super();
|
|
3148
|
+
// Ugly multiple inheritance trick
|
|
3149
|
+
Object.assign(this, new WemapMetaRouterOptions());
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
/**
|
|
3153
|
+
* @returns {object}
|
|
3154
|
+
*/
|
|
3155
|
+
toJson() {
|
|
3156
|
+
const json = super.toJson();
|
|
3157
|
+
json.remoteRouters = this.remoteRouters;
|
|
3158
|
+
if (this.targetMaps) {
|
|
3159
|
+
json.targetMaps = this.targetMaps;
|
|
3160
|
+
}
|
|
3161
|
+
return json;
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
/**
|
|
3165
|
+
* @param {object}
|
|
3166
|
+
* @returns {WemapMetaRemoteRouterOptions}
|
|
3167
|
+
*/
|
|
3168
|
+
static fromJson(json) {
|
|
3169
|
+
const obj = new WemapMetaRemoteRouterOptions();
|
|
3170
|
+
if ('useStairs' in json) {
|
|
3171
|
+
obj.useStairs = json.useStairs;
|
|
3172
|
+
}
|
|
3173
|
+
obj.remoteRouters = json.remoteRouters ? json.remoteRouters : [];
|
|
3174
|
+
obj.targetMaps = json.targetMaps ? json.targetMaps : null;
|
|
3175
|
+
return obj;
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
class WemapMetaRemoteRouterPayload {
|
|
3180
|
+
|
|
3181
|
+
/** @type {!(Coordinates[])} */
|
|
3182
|
+
waypoints;
|
|
3183
|
+
|
|
3184
|
+
/** @type {!string} */
|
|
3185
|
+
mode;
|
|
3186
|
+
|
|
3187
|
+
/** @type {!WemapMetaRemoteRouterOptions} */
|
|
3188
|
+
options = null;
|
|
3189
|
+
|
|
3190
|
+
/**
|
|
3191
|
+
* @returns {object}
|
|
3192
|
+
*/
|
|
3193
|
+
toJson() {
|
|
3194
|
+
const json = {
|
|
3195
|
+
waypoints: this.waypoints.map(coords => coords.toCompressedJson()),
|
|
3196
|
+
mode: this.mode
|
|
3197
|
+
};
|
|
3198
|
+
if (this.options) {
|
|
3199
|
+
json.options = this.options.toJson();
|
|
3200
|
+
}
|
|
3201
|
+
return json;
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
/**
|
|
3205
|
+
* @param {object}
|
|
3206
|
+
* @returns {WemapMetaRemoteRouterPayload}
|
|
3207
|
+
*/
|
|
3208
|
+
static fromJson(json) {
|
|
3209
|
+
const obj = new WemapMetaRemoteRouterPayload();
|
|
3210
|
+
obj.waypoints = json.waypoints.map(coords => Coordinates.fromCompressedJson(coords));
|
|
3211
|
+
obj.mode = json.mode;
|
|
3212
|
+
if (json.options) {
|
|
3213
|
+
obj.options = WemapMetaRemoteRouterOptions.fromJson(json.options);
|
|
3214
|
+
}
|
|
3215
|
+
return obj;
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
/* eslint-disable max-statements */
|
|
3220
|
+
|
|
3221
|
+
|
|
3222
|
+
/**
|
|
3223
|
+
* Singleton.
|
|
3224
|
+
*/
|
|
3225
|
+
class WemapMetaRemoteRouter extends RemoteRouter {
|
|
3226
|
+
|
|
3227
|
+
/**
|
|
3228
|
+
* @override
|
|
3229
|
+
*/
|
|
3230
|
+
get rname() {
|
|
3231
|
+
return 'wemap-meta';
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3234
|
+
/**
|
|
3235
|
+
* @param {!string} endpointUrl
|
|
3236
|
+
* @param {!string} mode see Constants.ROUTING_MODE
|
|
3237
|
+
* @param {Array<Coordinates>} waypoints
|
|
3238
|
+
* @param {?WemapMetaRemoteRouterOptions} options
|
|
3239
|
+
* @returns {!RouterResponse}
|
|
3240
|
+
* @throws {RemoteRouterServerUnreachable}
|
|
3241
|
+
*/
|
|
3242
|
+
async getItineraries(endpointUrl, mode, waypoints,
|
|
3243
|
+
options = new WemapMetaRemoteRouterOptions()) {
|
|
3244
|
+
|
|
3245
|
+
const payload = new WemapMetaRemoteRouterPayload();
|
|
3246
|
+
payload.waypoints = waypoints;
|
|
3247
|
+
payload.mode = mode;
|
|
3248
|
+
payload.options = options;
|
|
3249
|
+
|
|
3250
|
+
const res = await (fetch(endpointUrl, {
|
|
3251
|
+
method: 'POST',
|
|
3252
|
+
headers: {
|
|
3253
|
+
'Accept': 'application/json',
|
|
3254
|
+
'Content-Type': 'application/json'
|
|
3255
|
+
},
|
|
3256
|
+
body: JSON.stringify(payload.toJson())
|
|
3257
|
+
}).catch(() => {
|
|
3258
|
+
throw new RemoteRouterServerUnreachable(this.rname, endpointUrl);
|
|
3259
|
+
}));
|
|
3260
|
+
|
|
3261
|
+
const jsonResponse = await res.json().catch(() => {
|
|
3262
|
+
throw new RemoteRouterServerUnreachable(this.rname, endpointUrl);
|
|
3263
|
+
});
|
|
3264
|
+
|
|
3265
|
+
return RouterResponse.fromJson(jsonResponse);
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
var WemapMetaRemoteRouter$1 = new WemapMetaRemoteRouter();
|
|
3271
|
+
|
|
3054
3272
|
/**
|
|
3055
3273
|
* Singleton
|
|
3056
3274
|
*/
|
|
@@ -3062,7 +3280,8 @@ class RemoteRouterManager {
|
|
|
3062
3280
|
DeutscheBahnRemoteRouter$1,
|
|
3063
3281
|
IdfmRemoteRouter$1,
|
|
3064
3282
|
OsrmRemoteRouter$1,
|
|
3065
|
-
OtpRemoteRouter$1
|
|
3283
|
+
OtpRemoteRouter$1,
|
|
3284
|
+
WemapMetaRemoteRouter$1
|
|
3066
3285
|
];
|
|
3067
3286
|
|
|
3068
3287
|
/**
|
|
@@ -3122,40 +3341,6 @@ class RemoteRouterManager {
|
|
|
3122
3341
|
|
|
3123
3342
|
var RemoteRouterManager$1 = new RemoteRouterManager();
|
|
3124
3343
|
|
|
3125
|
-
// Also extends properties of WemapMetaRouterOptions
|
|
3126
|
-
class WemapMetaRemoteRouterOptions extends RemoteRouterOptions {
|
|
3127
|
-
|
|
3128
|
-
constructor() {
|
|
3129
|
-
super();
|
|
3130
|
-
// Ugly multiple inheritance trick
|
|
3131
|
-
Object.assign(this, new WemapMetaRouterOptions());
|
|
3132
|
-
}
|
|
3133
|
-
|
|
3134
|
-
/**
|
|
3135
|
-
* @returns {object}
|
|
3136
|
-
*/
|
|
3137
|
-
toJson() {
|
|
3138
|
-
const json = super.toJson();
|
|
3139
|
-
json.remoteRouters = this.remoteRouters;
|
|
3140
|
-
if (this.targetMaps) {
|
|
3141
|
-
json.targetMaps = this.targetMaps;
|
|
3142
|
-
}
|
|
3143
|
-
return json;
|
|
3144
|
-
}
|
|
3145
|
-
|
|
3146
|
-
/**
|
|
3147
|
-
* @param {object}
|
|
3148
|
-
* @returns {WemapMetaRemoteRouterOptions}
|
|
3149
|
-
*/
|
|
3150
|
-
static fromJson(json) {
|
|
3151
|
-
const obj = new WemapMetaRemoteRouterOptions();
|
|
3152
|
-
obj.useStairs = json.useStairs;
|
|
3153
|
-
obj.remoteRouters = json.remoteRouters;
|
|
3154
|
-
obj.targetMaps = json.targetMaps ? json.targetMaps : null;
|
|
3155
|
-
return obj;
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3158
|
-
|
|
3159
3344
|
/* eslint-disable complexity */
|
|
3160
3345
|
|
|
3161
3346
|
|
|
@@ -3208,6 +3393,12 @@ class WemapMetaRouter {
|
|
|
3208
3393
|
const start = waypoints[0];
|
|
3209
3394
|
const end = waypoints[1];
|
|
3210
3395
|
|
|
3396
|
+
const routerResponse = new RouterResponse();
|
|
3397
|
+
routerResponse.routerName = this.rname;
|
|
3398
|
+
routerResponse.from = start;
|
|
3399
|
+
routerResponse.to = end;
|
|
3400
|
+
|
|
3401
|
+
|
|
3211
3402
|
// Avoid cycles on remoteRouters
|
|
3212
3403
|
const remoteRouters = options.remoteRouters.filter(
|
|
3213
3404
|
({ name }) => name !== WemapMetaRemoteRouterOptions.rname
|
|
@@ -3230,8 +3421,8 @@ class WemapMetaRouter {
|
|
|
3230
3421
|
|
|
3231
3422
|
// Send a warning if one of the request ioMap (from targetMaps) is not present in this.maps
|
|
3232
3423
|
if (ioMapsToTest.length !== targetMaps.length) {
|
|
3233
|
-
|
|
3234
|
-
if (!
|
|
3424
|
+
ioMapsToTest.forEach(map => {
|
|
3425
|
+
if (!targetMaps.includes(map.name)) {
|
|
3235
3426
|
Logger.warn(`IOMap "${map.name}" not found in WemapMetaRouter`);
|
|
3236
3427
|
}
|
|
3237
3428
|
});
|
|
@@ -3246,7 +3437,15 @@ class WemapMetaRouter {
|
|
|
3246
3437
|
* 3 - intersection of this.maps and options.targetMaps is empty
|
|
3247
3438
|
*/
|
|
3248
3439
|
if (!ioMapsToTest.length) {
|
|
3249
|
-
|
|
3440
|
+
try {
|
|
3441
|
+
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters, mode, waypoints);
|
|
3442
|
+
} catch (e) {
|
|
3443
|
+
if (!isRoutingError(e)) {
|
|
3444
|
+
throw e;
|
|
3445
|
+
}
|
|
3446
|
+
routerResponse.error = e.message;
|
|
3447
|
+
return routerResponse;
|
|
3448
|
+
}
|
|
3250
3449
|
}
|
|
3251
3450
|
|
|
3252
3451
|
|
|
@@ -3259,10 +3458,8 @@ class WemapMetaRouter {
|
|
|
3259
3458
|
*
|
|
3260
3459
|
*/
|
|
3261
3460
|
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
routerResponse.to = end;
|
|
3265
|
-
|
|
3461
|
+
/** @type {Itinerary} */
|
|
3462
|
+
let ioMapItinerary;
|
|
3266
3463
|
|
|
3267
3464
|
// Find the first map where the "start" is inside.
|
|
3268
3465
|
const mapWithStart = ioMapsToTest.find(map => map.isPointInside(start));
|
|
@@ -3279,9 +3476,17 @@ class WemapMetaRouter {
|
|
|
3279
3476
|
*/
|
|
3280
3477
|
if (mapWithStart && mapWithStart.isPointInside(end)) {
|
|
3281
3478
|
|
|
3282
|
-
|
|
3479
|
+
try {
|
|
3480
|
+
ioMapItinerary = mapWithStart.getItineraryInsideMap(start, end, wemapRouterOptions);
|
|
3481
|
+
} catch (e) {
|
|
3482
|
+
if (!isRoutingError(e)) {
|
|
3483
|
+
throw e;
|
|
3484
|
+
}
|
|
3485
|
+
routerResponse.error = `${e.message} - on map ${mapWithStart.name}.`;
|
|
3486
|
+
return routerResponse;
|
|
3487
|
+
}
|
|
3283
3488
|
|
|
3284
|
-
routerResponse.itineraries.push(
|
|
3489
|
+
routerResponse.itineraries.push(ioMapItinerary);
|
|
3285
3490
|
routerResponse.routerName = [this.rname, WemapRouter.rname];
|
|
3286
3491
|
|
|
3287
3492
|
return routerResponse;
|
|
@@ -3291,21 +3496,27 @@ class WemapMetaRouter {
|
|
|
3291
3496
|
// Note: At this step, mapWithEnd is necessarily different from mapWithStart
|
|
3292
3497
|
const mapWithEnd = ioMapsToTest.find(map => map.isPointInside(end));
|
|
3293
3498
|
|
|
3499
|
+
|
|
3500
|
+
/** @type {RouterResponse} */
|
|
3501
|
+
let remoteRouterResponse;
|
|
3502
|
+
|
|
3294
3503
|
/*
|
|
3295
3504
|
* Case 2
|
|
3296
3505
|
*
|
|
3297
3506
|
* If no io map have been found for "start" and "end", therefore use remote router.
|
|
3298
3507
|
*/
|
|
3299
3508
|
if (!mapWithStart && !mapWithEnd) {
|
|
3300
|
-
|
|
3509
|
+
try {
|
|
3510
|
+
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters, mode, waypoints);
|
|
3511
|
+
} catch (e) {
|
|
3512
|
+
if (!isRoutingError(e)) {
|
|
3513
|
+
throw e;
|
|
3514
|
+
}
|
|
3515
|
+
routerResponse.error = e.message;
|
|
3516
|
+
return routerResponse;
|
|
3517
|
+
}
|
|
3301
3518
|
}
|
|
3302
3519
|
|
|
3303
|
-
/** @type {RouterResponse} */
|
|
3304
|
-
let remoteRouterResponse;
|
|
3305
|
-
|
|
3306
|
-
/** @type {Itinerary} */
|
|
3307
|
-
let ioMapItinerary;
|
|
3308
|
-
|
|
3309
3520
|
/**
|
|
3310
3521
|
* Case 3
|
|
3311
3522
|
*
|
|
@@ -3327,17 +3538,23 @@ class WemapMetaRouter {
|
|
|
3327
3538
|
return routerResponse;
|
|
3328
3539
|
}
|
|
3329
3540
|
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3541
|
+
try {
|
|
3542
|
+
ioMapItinerary = mapWithStart.getBestItineraryFromStartToEntryPoints(start, end, wemapRouterOptions);
|
|
3543
|
+
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
3544
|
+
remoteRouters, mode, [ioMapItinerary.to, end]
|
|
3545
|
+
);
|
|
3546
|
+
if (!remoteRouterResponse.itineraries.length) {
|
|
3547
|
+
throw new NoRouteFoundError(ioMapItinerary.to, end, remoteRouterResponse.error);
|
|
3548
|
+
}
|
|
3549
|
+
} catch (e) {
|
|
3550
|
+
if (!isRoutingError(e)) {
|
|
3551
|
+
throw e;
|
|
3552
|
+
}
|
|
3553
|
+
routerResponse.error = 'Tried to calculate an itinerary from "start" '
|
|
3554
|
+
+ `to "entrypoints" using wemap router on local map "${mapWithStart.name}" and `
|
|
3555
|
+
+ 'an itinerary from "entrypoints" to "end" using remote routers '
|
|
3556
|
+
+ `(${remoteRouters.map(r => r.name).join(', ')}), but failed. `
|
|
3557
|
+
+ `Details: ${e.message}.`;
|
|
3341
3558
|
return routerResponse;
|
|
3342
3559
|
}
|
|
3343
3560
|
|
|
@@ -3375,16 +3592,23 @@ class WemapMetaRouter {
|
|
|
3375
3592
|
* calculate all the routes to entrypoints using local router than all the routes with the
|
|
3376
3593
|
* remote router.
|
|
3377
3594
|
*/
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3595
|
+
try {
|
|
3596
|
+
ioMapItinerary = mapWithEnd.getBestItineraryFromEntryPointsToEnd(start, end, wemapRouterOptions);
|
|
3597
|
+
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
3598
|
+
remoteRouters, mode, [start, ioMapItinerary.from]
|
|
3599
|
+
);
|
|
3600
|
+
if (!remoteRouterResponse.itineraries.length) {
|
|
3601
|
+
throw new NoRouteFoundError(start, ioMapItinerary.from, remoteRouterResponse.error);
|
|
3602
|
+
}
|
|
3603
|
+
} catch (e) {
|
|
3604
|
+
if (!isRoutingError(e)) {
|
|
3605
|
+
throw e;
|
|
3606
|
+
}
|
|
3607
|
+
routerResponse.error = 'Tried to calculate an itinerary from "start" to "entrypoints" '
|
|
3608
|
+
+ `using remote routers (${remoteRouters.map(r => r.name).join(', ')}) and an `
|
|
3609
|
+
+ 'itinerary from "entrypoints" to "end" using wemap router on local map '
|
|
3610
|
+
+ `"${mapWithEnd.name}", but failed. `
|
|
3611
|
+
+ `Details: ${e.message}.`;
|
|
3388
3612
|
return routerResponse;
|
|
3389
3613
|
}
|
|
3390
3614
|
|
|
@@ -3424,18 +3648,26 @@ class WemapMetaRouter {
|
|
|
3424
3648
|
return routerResponse;
|
|
3425
3649
|
}
|
|
3426
3650
|
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3651
|
+
let ioMapItinerary1, ioMapItinerary2;
|
|
3652
|
+
try {
|
|
3653
|
+
ioMapItinerary1 = mapWithStart.getBestItineraryFromStartToEntryPoints(start, end, wemapRouterOptions);
|
|
3654
|
+
ioMapItinerary2 = mapWithEnd.getBestItineraryFromEntryPointsToEnd(start, end, wemapRouterOptions);
|
|
3655
|
+
remoteRouterResponse = await RemoteRouterManager$1.getItinerariesWithFallback(
|
|
3656
|
+
remoteRouters, mode, [ioMapItinerary1.to, ioMapItinerary2.from]
|
|
3657
|
+
);
|
|
3658
|
+
if (!remoteRouterResponse.itineraries.length) {
|
|
3659
|
+
throw new NoRouteFoundError(ioMapItinerary1.to, ioMapItinerary2.from, remoteRouterResponse.error);
|
|
3660
|
+
}
|
|
3661
|
+
} catch (e) {
|
|
3662
|
+
if (!isRoutingError(e)) {
|
|
3663
|
+
throw e;
|
|
3664
|
+
}
|
|
3665
|
+
routerResponse.error = 'Tried to calculate an itinerary from "start" to "entrypoints1" '
|
|
3666
|
+
+ `using wemap router on local map "${mapWithStart.name}", an itinerary from `
|
|
3667
|
+
+ '"entrypoints1" to "entrypoints2" using remote routers '
|
|
3668
|
+
+ `(${remoteRouters.map(r => r.name).join(', ')}) and an itinerary from "entrypoints2" `
|
|
3669
|
+
+ `to "end" using wemap router on local map "${mapWithEnd.name}", but failed. `
|
|
3670
|
+
+ `Details: ${e.message}.`;
|
|
3439
3671
|
return routerResponse;
|
|
3440
3672
|
}
|
|
3441
3673
|
|
|
@@ -3456,96 +3688,6 @@ class WemapMetaRouter {
|
|
|
3456
3688
|
|
|
3457
3689
|
}
|
|
3458
3690
|
|
|
3459
|
-
class WemapMetaRemoteRouterPayload {
|
|
3460
|
-
|
|
3461
|
-
/** @type {!(Coordinates[])} */
|
|
3462
|
-
waypoints;
|
|
3463
|
-
|
|
3464
|
-
/** @type {!string} */
|
|
3465
|
-
mode;
|
|
3466
|
-
|
|
3467
|
-
/** @type {!WemapMetaRemoteRouterOptions} */
|
|
3468
|
-
options = null;
|
|
3469
|
-
|
|
3470
|
-
/**
|
|
3471
|
-
* @returns {object}
|
|
3472
|
-
*/
|
|
3473
|
-
toJson() {
|
|
3474
|
-
const json = {
|
|
3475
|
-
waypoints: this.waypoints.map(coords => coords.toCompressedJson()),
|
|
3476
|
-
mode: this.mode
|
|
3477
|
-
};
|
|
3478
|
-
if (this.options) {
|
|
3479
|
-
json.options = this.options.toJson();
|
|
3480
|
-
}
|
|
3481
|
-
return json;
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3484
|
-
/**
|
|
3485
|
-
* @param {object}
|
|
3486
|
-
* @returns {WemapMetaRemoteRouterPayload}
|
|
3487
|
-
*/
|
|
3488
|
-
static fromJson(json) {
|
|
3489
|
-
const obj = new WemapMetaRemoteRouterPayload();
|
|
3490
|
-
obj.waypoints = json.waypoints.map(coords => Coordinates.fromCompressedJson(coords));
|
|
3491
|
-
obj.mode = json.mode;
|
|
3492
|
-
if (json.options) {
|
|
3493
|
-
obj.options = WemapMetaRemoteRouterOptions.fromJson(json.options);
|
|
3494
|
-
}
|
|
3495
|
-
return obj;
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
|
|
3499
|
-
/* eslint-disable max-statements */
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
/**
|
|
3503
|
-
* Singleton.
|
|
3504
|
-
*/
|
|
3505
|
-
class WemapMetaRemoteRouter extends RemoteRouter {
|
|
3506
|
-
|
|
3507
|
-
/**
|
|
3508
|
-
* @override
|
|
3509
|
-
*/
|
|
3510
|
-
get rname() {
|
|
3511
|
-
return 'wemap-meta';
|
|
3512
|
-
}
|
|
3513
|
-
|
|
3514
|
-
/**
|
|
3515
|
-
* @param {!string} endpointUrl
|
|
3516
|
-
* @param {!string} mode see Constants.ROUTING_MODE
|
|
3517
|
-
* @param {Array<Coordinates>} waypoints
|
|
3518
|
-
* @param {?WemapMetaRemoteRouterOptions} options
|
|
3519
|
-
* @returns {!RouterResponse}
|
|
3520
|
-
* @throws {RemoteRouterServerUnreachable}
|
|
3521
|
-
*/
|
|
3522
|
-
async getItineraries(endpointUrl, mode, waypoints, options) {
|
|
3523
|
-
|
|
3524
|
-
const payload = new WemapMetaRemoteRouterPayload();
|
|
3525
|
-
payload.waypoints = waypoints;
|
|
3526
|
-
payload.mode = mode;
|
|
3527
|
-
payload.options = options;
|
|
3528
|
-
|
|
3529
|
-
const res = await fetch(endpointUrl, {
|
|
3530
|
-
method: 'POST',
|
|
3531
|
-
headers: {
|
|
3532
|
-
'Accept': 'application/json',
|
|
3533
|
-
'Content-Type': 'application/json'
|
|
3534
|
-
},
|
|
3535
|
-
body: JSON.stringify(payload.toJson())
|
|
3536
|
-
});
|
|
3537
|
-
|
|
3538
|
-
if (res.status !== 200) {
|
|
3539
|
-
throw new RemoteRouterServerUnreachable(this.rname, endpointUrl);
|
|
3540
|
-
}
|
|
3541
|
-
const response = await res.json();
|
|
3542
|
-
return RouterResponse.fromJson(response);
|
|
3543
|
-
}
|
|
3544
|
-
|
|
3545
|
-
}
|
|
3546
|
-
|
|
3547
|
-
var WemapMetaRemoteRouter$1 = new WemapMetaRemoteRouter();
|
|
3548
|
-
|
|
3549
3691
|
/* eslint-disable max-statements */
|
|
3550
3692
|
|
|
3551
3693
|
class ItineraryInfoManager {
|
|
@@ -3687,5 +3829,5 @@ class ItineraryInfoManager {
|
|
|
3687
3829
|
|
|
3688
3830
|
}
|
|
3689
3831
|
|
|
3690
|
-
export { CitywayRemoteRouter$1 as CitywayRemoteRouter, Constants, DeutscheBahnRemoteRouter$1 as DeutscheBahnRemoteRouter, IdfmRemoteRouter$1 as IdfmRemoteRouter, Itinerary, ItineraryInfo, ItineraryInfoManager, Leg, LevelChange, OsrmRemoteRouter$1 as OsrmRemoteRouter, OtpRemoteRouter$1 as OtpRemoteRouter, RouterResponse, Step, WemapMetaRemoteRouter$1 as WemapMetaRemoteRouter, WemapMetaRemoteRouterOptions, WemapMetaRemoteRouterPayload, WemapMetaRouter, IOMap as WemapMetaRouterIOMap, WemapMetaRouterOptions, WemapNetworkUtils, WemapRouter, WemapRouterOptions, WemapRouterUtils, getDurationFromLength };
|
|
3832
|
+
export { CitywayRemoteRouter$1 as CitywayRemoteRouter, Constants, DeutscheBahnRemoteRouter$1 as DeutscheBahnRemoteRouter, IdfmRemoteRouter$1 as IdfmRemoteRouter, Itinerary, ItineraryInfo, ItineraryInfoManager, Leg, LevelChange, OsrmRemoteRouter$1 as OsrmRemoteRouter, OtpRemoteRouter$1 as OtpRemoteRouter, RemoteRouterManager$1 as RemoteRouterManager, RouterResponse, Step, WemapMetaRemoteRouter$1 as WemapMetaRemoteRouter, WemapMetaRemoteRouterOptions, WemapMetaRemoteRouterPayload, WemapMetaRouter, IOMap as WemapMetaRouterIOMap, WemapMetaRouterOptions, WemapNetworkUtils, WemapRouter, WemapRouterOptions, WemapRouterUtils, getDurationFromLength, multiplyRouterResponseLevel };
|
|
3691
3833
|
//# sourceMappingURL=wemap-routers.es.js.map
|