@wemap/routers 11.1.0 → 11.1.1
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 +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- 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/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/routers"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/routers",
|
|
15
|
-
"version": "11.1.
|
|
15
|
+
"version": "11.1.1",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
},
|
|
53
53
|
"./helpers/*": "./helpers/*"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "1fe2ac803a61d5cdb1e3f26185aaeb431bfb482f"
|
|
56
56
|
}
|
|
@@ -439,6 +439,31 @@ describe('OsrmRemoteRouter - createRouterResponseFromJson', () => {
|
|
|
439
439
|
|
|
440
440
|
expect(routerResponse.routerName).equal('osrm');
|
|
441
441
|
expect(routerResponse.itineraries.length).equal(1);
|
|
442
|
+
expect(routerResponse.itineraries[0].mode).equal('WALK');
|
|
443
|
+
expect(routerResponse.from.equals(from)).true;
|
|
444
|
+
expect(routerResponse.to.equals(to)).true;
|
|
445
|
+
|
|
446
|
+
const steps = routerResponse.itineraries[0].steps;
|
|
447
|
+
expect(steps.length).equal(2);
|
|
448
|
+
expect(steps[1].angle).almost.equal(1.575);
|
|
449
|
+
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
it('RouterResponse - 2 - should return CAR itinerary', () => {
|
|
454
|
+
|
|
455
|
+
const filePath = path.resolve(assetsPath, 'itinerary-montpellier-osrm-3.json');
|
|
456
|
+
const fileString = fs.readFileSync(filePath, 'utf8');
|
|
457
|
+
const json = JSON.parse(fileString);
|
|
458
|
+
|
|
459
|
+
const from = new Coordinates(43.605663, 3.887244);
|
|
460
|
+
const to = new Coordinates(43.6054106, 3.8878106);
|
|
461
|
+
const routerResponse = OsrmRemoteRouter.createRouterResponseFromJson(json, from, to, 'driving');
|
|
462
|
+
routerResponse.itineraries.forEach(verifyStepsCoherence);
|
|
463
|
+
|
|
464
|
+
expect(routerResponse.routerName).equal('osrm');
|
|
465
|
+
expect(routerResponse.itineraries.length).equal(1);
|
|
466
|
+
expect(routerResponse.itineraries[0].mode).equal('CAR');
|
|
442
467
|
expect(routerResponse.from.equals(from)).true;
|
|
443
468
|
expect(routerResponse.to.equals(to)).true;
|
|
444
469
|
|
|
@@ -12,17 +12,6 @@ import RoutingModeCorrespondanceNotFound from '../RoutingModeCorrespondanceNotFo
|
|
|
12
12
|
import RemoteRouterServerUnreachable from '../RemoteRouterServerUnreachable.js';
|
|
13
13
|
import { RoutingMode } from '../../model/RoutingMode.js';
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Input mode correspondance
|
|
17
|
-
*/
|
|
18
|
-
const inputModeCorrespondance = new Map();
|
|
19
|
-
inputModeCorrespondance.set('CAR', 'driving');
|
|
20
|
-
inputModeCorrespondance.set('WALK', 'walking');
|
|
21
|
-
inputModeCorrespondance.set('BIKE', 'bike');
|
|
22
|
-
inputModeCorrespondance.set('BUS', 'bus');
|
|
23
|
-
inputModeCorrespondance.set('MULTI', 'walking');
|
|
24
|
-
|
|
25
|
-
|
|
26
15
|
type OsrmCoordinates = Position;
|
|
27
16
|
type OsrmModifier = 'sharp right' | 'sharp left' | 'slight right'
|
|
28
17
|
| 'slight left' | 'right' | 'left' | 'u turn' | 'straight';
|
|
@@ -57,6 +46,18 @@ type OsrmJson = {
|
|
|
57
46
|
waypoints?: []
|
|
58
47
|
};
|
|
59
48
|
|
|
49
|
+
type OsrmMode = 'driving' | 'walking' | 'bike' | 'bus' | 'walking';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Input mode correspondance
|
|
53
|
+
*/
|
|
54
|
+
const inputModeCorrespondance = new Map<RoutingMode, OsrmMode>();
|
|
55
|
+
inputModeCorrespondance.set('CAR', 'driving');
|
|
56
|
+
inputModeCorrespondance.set('WALK', 'walking');
|
|
57
|
+
inputModeCorrespondance.set('BIKE', 'bike');
|
|
58
|
+
inputModeCorrespondance.set('BUS', 'bus');
|
|
59
|
+
inputModeCorrespondance.set('MULTI', 'walking');
|
|
60
|
+
|
|
60
61
|
/**
|
|
61
62
|
* Singleton.
|
|
62
63
|
*/
|
|
@@ -88,7 +89,10 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
88
89
|
|
|
89
90
|
const from = waypoints[0];
|
|
90
91
|
const to = waypoints[waypoints.length - 1];
|
|
91
|
-
|
|
92
|
+
|
|
93
|
+
const osrmMode = inputModeCorrespondance.get(mode);
|
|
94
|
+
|
|
95
|
+
return this.createRouterResponseFromJson(jsonResponse, from, to, osrmMode);
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
/**
|
|
@@ -245,7 +249,7 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
245
249
|
json: OsrmJson,
|
|
246
250
|
from: Coordinates,
|
|
247
251
|
to: Coordinates,
|
|
248
|
-
routingMode = 'walking') {
|
|
252
|
+
routingMode: OsrmMode = 'walking') {
|
|
249
253
|
|
|
250
254
|
const routerResponse = new RouterResponse({ routerName: this.rname, from, to });
|
|
251
255
|
|
|
@@ -71,7 +71,7 @@ describe('OsmRouter - Multi-level itinerary', () => {
|
|
|
71
71
|
expect(steps[0].previousBearing).almost.equals(1.778);
|
|
72
72
|
expect(steps[0].nextBearing).almost.equals(0.207);
|
|
73
73
|
expect(steps[0].distance).almost.equals(2.328);
|
|
74
|
-
expect(steps[0].duration).almost.equals(
|
|
74
|
+
expect(steps[0].duration).almost.equals(2.095);
|
|
75
75
|
expect(steps[0].firstStep).true;
|
|
76
76
|
expect(steps[0].lastStep).false;
|
|
77
77
|
expect(steps[0].levelChange).is.null;
|
|
@@ -171,7 +171,7 @@ describe('OsmRouter - Conveying', () => {
|
|
|
171
171
|
it('do not use oneway conveying', () => {
|
|
172
172
|
|
|
173
173
|
const start = new Coordinates(48.8445715, 2.3718927, null, 0);
|
|
174
|
-
const end = new Coordinates(48.
|
|
174
|
+
const end = new Coordinates(48.8444574, 2.3720728, null, -1);
|
|
175
175
|
|
|
176
176
|
const itinerary = router.getShortestPath(start, end);
|
|
177
177
|
expect(itinerary).is.not.undefined;
|
|
@@ -179,7 +179,7 @@ describe('OsmRouter - Conveying', () => {
|
|
|
179
179
|
|
|
180
180
|
const itineraryOtherWay = router.getShortestPath(end, start);
|
|
181
181
|
expect(itineraryOtherWay).is.not.undefined;
|
|
182
|
-
expect(getNodesNames(itineraryOtherWay)).deep.equals(['proj on null (tmp)', '
|
|
182
|
+
expect(getNodesNames(itineraryOtherWay)).deep.equals(['proj on null (tmp)', 'p7', 'p10', 'p11']);
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -217,7 +217,7 @@ describe('OsmRouter - Instruction stairs same level', () => {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
const expectLevelChangeAtSecondStep = (steps: Step[], direction: 'up' | 'down', difference: number) => {
|
|
220
|
-
expect(steps.length).equals(
|
|
220
|
+
expect(steps.length).equals(3);
|
|
221
221
|
expect(steps[1].levelChange).is.not.null;
|
|
222
222
|
expect(steps[1].levelChange?.direction).equal(direction);
|
|
223
223
|
expect(steps[1].levelChange?.difference).equal(difference);
|
|
@@ -236,8 +236,7 @@ describe('OsmRouter - Instruction stairs same level', () => {
|
|
|
236
236
|
expectLevelChangeAtSecondStep(getItinerary('start7', 'end7').steps, 'up', 1);
|
|
237
237
|
expect(getItinerary('start8', 'end8').steps.length).equal(1);
|
|
238
238
|
expectLevelChangeAtSecondStep(getItinerary('start9', 'end9').steps, 'up', 1);
|
|
239
|
-
//
|
|
240
|
-
expectLevelChangeAtSecondStep(getItinerary('start10', 'end10').steps, 'up', 1);
|
|
239
|
+
expectLevelChangeAtSecondStep(getItinerary('start10', 'end10').steps, 'down', 1); // incline > diff of levels
|
|
241
240
|
});
|
|
242
241
|
});
|
|
243
242
|
|