@wemap/routers 7.5.1 → 8.0.0-alpha.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/package.json +5 -5
- package/src/model/RouterResponse.js +1 -1
- package/src/remote/cityway/CitywayRemoteRouter.js +10 -10
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.js +11 -10
- package/src/remote/idfm/IdfmRemoteRouter.js +8 -9
- package/src/remote/osrm/OsrmRemoteRouter.js +15 -13
- package/src/remote/otp/OtpRemoteRouter.js +9 -8
- package/src/wemap-meta/WemapMetaRouter.js +1 -1
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/routers"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/routers",
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "8.0.0-alpha.0",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@turf/boolean-point-in-polygon": "^6.5.0",
|
|
30
30
|
"@turf/convex": "^6.5.0",
|
|
31
31
|
"@turf/helpers": "^6.5.0",
|
|
32
|
-
"@wemap/geo": "^
|
|
32
|
+
"@wemap/geo": "^8.0.0-alpha.0",
|
|
33
33
|
"@wemap/logger": "^7.0.0",
|
|
34
|
-
"@wemap/maths": "^
|
|
35
|
-
"@wemap/osm": "^
|
|
34
|
+
"@wemap/maths": "^8.0.0-alpha.0",
|
|
35
|
+
"@wemap/osm": "^8.0.0-alpha.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "b5cfa73ad766f0763ab980127281a561ecb9ddac"
|
|
38
38
|
}
|
|
@@ -100,7 +100,7 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
100
100
|
const jsonResponse = await res.json().catch(() => {
|
|
101
101
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
102
102
|
});
|
|
103
|
-
return this.createRouterResponseFromJson(jsonResponse
|
|
103
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
|
|
@@ -132,21 +132,18 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
132
132
|
/**
|
|
133
133
|
* Generate multi itineraries from Cityway JSON
|
|
134
134
|
* @param {object} json JSON file provided by Cityway.
|
|
135
|
-
* @
|
|
136
|
-
* @returns {!RouterResponse}
|
|
135
|
+
* @returns {?RouterResponse}
|
|
137
136
|
* @example https://preprod.api.lia2.cityway.fr/journeyplanner/api/opt/PlanTrips/json?DepartureLatitude=49.51509388236216&DepartureLongitude=0.09341749619366316&ArrivalLatitude=49.5067090188444&ArrivalLongitude=0.1694842115417831&DepartureType=COORDINATES&ArrivalType=COORDINATES
|
|
138
137
|
*/
|
|
139
|
-
createRouterResponseFromJson(json
|
|
140
|
-
|
|
141
|
-
const routerResponse = new RouterResponse();
|
|
142
|
-
routerResponse.routerName = this.rname;
|
|
143
|
-
routerResponse.from = waypoints[0];
|
|
144
|
-
routerResponse.to = waypoints[1];
|
|
138
|
+
createRouterResponseFromJson(json) {
|
|
145
139
|
|
|
146
140
|
if (json.StatusCode !== 200 || !json.Data || !json.Data.length) {
|
|
147
|
-
return
|
|
141
|
+
return null;
|
|
148
142
|
}
|
|
149
143
|
|
|
144
|
+
const routerResponse = new RouterResponse();
|
|
145
|
+
routerResponse.routerName = this.rname;
|
|
146
|
+
|
|
150
147
|
|
|
151
148
|
// Do not know if it the best approach, but it works...
|
|
152
149
|
const allJsonTrips = json.Data.reduce((acc, dataObj) => {
|
|
@@ -305,6 +302,9 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
305
302
|
generateStepsMetadata(itinerary);
|
|
306
303
|
}
|
|
307
304
|
|
|
305
|
+
routerResponse.from = routerResponse.itineraries[0].from;
|
|
306
|
+
routerResponse.to = routerResponse.itineraries[routerResponse.itineraries.length - 1].to;
|
|
307
|
+
|
|
308
308
|
return routerResponse;
|
|
309
309
|
}
|
|
310
310
|
|
|
@@ -64,22 +64,23 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
64
64
|
/**
|
|
65
65
|
* Generate multi itineraries from the DB JSON
|
|
66
66
|
* @param {object} json JSON file provided by the DB.
|
|
67
|
-
* @param {Coordinates
|
|
68
|
-
* @
|
|
67
|
+
* @param {Coordinates} from itinerary start
|
|
68
|
+
* @param {Coordinates} to itinerary end
|
|
69
|
+
* @returns {?RouterResponse}
|
|
69
70
|
*/
|
|
70
|
-
createRouterResponseFromJson(json,
|
|
71
|
-
|
|
72
|
-
const routerResponse = new RouterResponse();
|
|
73
|
-
routerResponse.routerName = this.rname;
|
|
74
|
-
routerResponse.from = waypoints[0];
|
|
75
|
-
routerResponse.to = waypoints[1];
|
|
71
|
+
createRouterResponseFromJson(json, from, to) {
|
|
76
72
|
|
|
77
73
|
const { segments: jsonSegments } = json;
|
|
78
74
|
|
|
79
75
|
if (!jsonSegments) {
|
|
80
|
-
return
|
|
76
|
+
return null;
|
|
81
77
|
}
|
|
82
78
|
|
|
79
|
+
const routerResponse = new RouterResponse();
|
|
80
|
+
routerResponse.routerName = this.rname;
|
|
81
|
+
|
|
82
|
+
routerResponse.from = from;
|
|
83
|
+
routerResponse.to = to;
|
|
83
84
|
|
|
84
85
|
/** @type {GraphEdge<OsmElement>[]} */
|
|
85
86
|
const edges = [];
|
|
@@ -128,7 +129,7 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
128
129
|
graphItinerary.end = nodes[nodes.length - 1].coords;
|
|
129
130
|
|
|
130
131
|
const points = nodes.map(node => node.coords);
|
|
131
|
-
const itinerary = Itinerary.fromOrderedCoordinates(points,
|
|
132
|
+
const itinerary = Itinerary.fromOrderedCoordinates(points, from, to);
|
|
132
133
|
itinerary.legs[0].steps = StepsGeneration.fromGraphItinerary(graphItinerary);
|
|
133
134
|
itinerary.legs[0].steps.map((step, idx) => (step._idCoordsInLeg = idx));
|
|
134
135
|
|
|
@@ -127,7 +127,7 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
127
127
|
return routerResponse;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
return this.createRouterResponseFromJson(jsonResponse
|
|
130
|
+
return this.createRouterResponseFromJson(jsonResponse);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
@@ -327,20 +327,19 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
327
327
|
/**
|
|
328
328
|
* Generate multi itineraries from OTP JSON
|
|
329
329
|
* @param {object} json JSON file provided by OTP.
|
|
330
|
-
* @param {Coordinates[]} waypoints
|
|
331
330
|
* @returns {?RouterResponse}
|
|
332
331
|
*/
|
|
333
|
-
createRouterResponseFromJson(json
|
|
334
|
-
|
|
335
|
-
const routerResponse = new RouterResponse();
|
|
336
|
-
routerResponse.routerName = this.rname;
|
|
337
|
-
routerResponse.from = waypoints[0];
|
|
338
|
-
routerResponse.to = waypoints[1];
|
|
332
|
+
createRouterResponseFromJson(json) {
|
|
339
333
|
|
|
340
334
|
if (!json || !json.journeys) {
|
|
341
|
-
return
|
|
335
|
+
return null;
|
|
342
336
|
}
|
|
343
337
|
|
|
338
|
+
const routerResponse = new RouterResponse();
|
|
339
|
+
routerResponse.routerName = this.rname;
|
|
340
|
+
|
|
341
|
+
routerResponse.from = this.getSectionCoords(json.journeys[0].sections[0]).from;
|
|
342
|
+
routerResponse.to = this.getSectionCoords(last(json.journeys[0].sections)).to;
|
|
344
343
|
|
|
345
344
|
const timeZone = json.context.timezone;
|
|
346
345
|
|
|
@@ -53,7 +53,7 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
53
53
|
throw new RemoteRouterServerUnreachable(this.rname, url);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
return this.createRouterResponseFromJson(jsonResponse, waypoints);
|
|
56
|
+
return this.createRouterResponseFromJson(jsonResponse, waypoints[0], waypoints[1]);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -259,20 +259,16 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
259
259
|
/**
|
|
260
260
|
* Generate multi itineraries from OSRM JSON
|
|
261
261
|
* @param {object} json JSON file provided by OSRM.
|
|
262
|
-
* @param {Coordinates
|
|
262
|
+
* @param {Coordinates} from itinerary start
|
|
263
|
+
* @param {Coordinates} to itinerary end
|
|
263
264
|
* @param {?string} routingMode [walking|driving|bicycle]
|
|
264
|
-
* @returns {
|
|
265
|
+
* @returns {?RouterResponse}
|
|
265
266
|
*/
|
|
266
|
-
createRouterResponseFromJson(json,
|
|
267
|
-
|
|
268
|
-
const routerResponse = new RouterResponse();
|
|
269
|
-
routerResponse.routerName = this.rname;
|
|
270
|
-
routerResponse.from = waypoints[0];
|
|
271
|
-
routerResponse.to = waypoints[1];
|
|
272
|
-
|
|
267
|
+
createRouterResponseFromJson(json, from, to, routingMode = 'walking') {
|
|
273
268
|
const { routes: jsonRoutes } = json;
|
|
269
|
+
|
|
274
270
|
if (!jsonRoutes) {
|
|
275
|
-
return
|
|
271
|
+
return null;
|
|
276
272
|
}
|
|
277
273
|
|
|
278
274
|
const routingModeCorrespondance = new Map();
|
|
@@ -281,6 +277,12 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
281
277
|
routingModeCorrespondance.set('bicycle', 'BIKE');
|
|
282
278
|
const mode = routingModeCorrespondance.get(routingMode) || null;
|
|
283
279
|
|
|
280
|
+
const routerResponse = new RouterResponse();
|
|
281
|
+
routerResponse.routerName = this.rname;
|
|
282
|
+
|
|
283
|
+
routerResponse.from = from;
|
|
284
|
+
routerResponse.to = to;
|
|
285
|
+
|
|
284
286
|
for (const jsonItinerary of jsonRoutes) {
|
|
285
287
|
|
|
286
288
|
const itinerary = new Itinerary();
|
|
@@ -288,8 +290,8 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
288
290
|
// itinerary.coords = jsonItinerary.geometry.coordinates.map(jsonToCoordinates);
|
|
289
291
|
itinerary.distance = jsonItinerary.distance;
|
|
290
292
|
itinerary.duration = jsonItinerary.duration;
|
|
291
|
-
itinerary.from =
|
|
292
|
-
itinerary.to =
|
|
293
|
+
itinerary.from = from;
|
|
294
|
+
itinerary.to = to;
|
|
293
295
|
|
|
294
296
|
routerResponse.itineraries.push(itinerary);
|
|
295
297
|
|
|
@@ -127,21 +127,22 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
127
127
|
/**
|
|
128
128
|
* Generate multi itineraries from OTP JSON
|
|
129
129
|
* @param {object} json JSON file provided by OTP.
|
|
130
|
-
* @param {Coordinates[]} waypoints
|
|
131
130
|
* @returns {?RouterResponse}
|
|
132
131
|
*/
|
|
133
|
-
createRouterResponseFromJson(json
|
|
134
|
-
|
|
135
|
-
const routerResponse = new RouterResponse();
|
|
136
|
-
routerResponse.routerName = this.rname;
|
|
137
|
-
routerResponse.from = waypoints[0];
|
|
138
|
-
routerResponse.to = waypoints[1];
|
|
132
|
+
createRouterResponseFromJson(json) {
|
|
139
133
|
|
|
140
134
|
const { plan: jsonPlan } = json;
|
|
135
|
+
|
|
141
136
|
if (!jsonPlan) {
|
|
142
|
-
return
|
|
137
|
+
return null;
|
|
143
138
|
}
|
|
144
139
|
|
|
140
|
+
const routerResponse = new RouterResponse();
|
|
141
|
+
routerResponse.routerName = this.rname;
|
|
142
|
+
|
|
143
|
+
routerResponse.from = this.jsonToCoordinates(jsonPlan.from);
|
|
144
|
+
routerResponse.to = this.jsonToCoordinates(jsonPlan.to);
|
|
145
|
+
|
|
145
146
|
for (const jsonItinerary of jsonPlan.itineraries) {
|
|
146
147
|
|
|
147
148
|
const itinerary = new Itinerary();
|
|
@@ -44,7 +44,7 @@ class WemapMetaRouter {
|
|
|
44
44
|
* @param {string} mode see Constants.ROUTING_MODE
|
|
45
45
|
* @param {Coordinates[]} waypoints
|
|
46
46
|
* @param {WemapMetaRouterOptions} options
|
|
47
|
-
* @returns {
|
|
47
|
+
* @returns {RouterResponse}
|
|
48
48
|
*/
|
|
49
49
|
async getItineraries(mode, waypoints, options) {
|
|
50
50
|
|