@wemap/osm 2.7.11 → 2.7.14
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 +2 -2
- package/src/network/OsmRouter.spec.js +3 -2
- package/src/osrm/OsrmUtils.js +37 -12
- package/src/osrm/OsrmUtils.spec.js +21 -0
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/osm"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/osm",
|
|
14
|
-
"version": "2.7.
|
|
14
|
+
"version": "2.7.14",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"lodash.isnumber": "^3.0.3",
|
|
33
33
|
"sax": "^1.2.4"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a196bbcae92e89add1caa2d532c9ae8bf583e42e"
|
|
36
36
|
}
|
|
@@ -87,8 +87,9 @@ describe('OsmRouter - Multi-level itinerary', () => {
|
|
|
87
87
|
it('do not use stairs', () => {
|
|
88
88
|
const itineraryWithoutStairs = router.getShortestPath(itineraryStart, itineraryEnd, { useStairs: false });
|
|
89
89
|
expect(itineraryWithoutStairs.nodes.length).equal(11);
|
|
90
|
-
expect(itineraryWithoutStairs.nodes[6].data.
|
|
91
|
-
expect(itineraryWithoutStairs.nodes[7].data.
|
|
90
|
+
expect(itineraryWithoutStairs.nodes[6].data.isElevator).is.true;
|
|
91
|
+
expect(itineraryWithoutStairs.nodes[7].data.isElevator).is.true;
|
|
92
|
+
expect(itineraryWithoutStairs.edges[6].data.isElevator).is.true;
|
|
92
93
|
});
|
|
93
94
|
|
|
94
95
|
});
|
package/src/osrm/OsrmUtils.js
CHANGED
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
rad2deg, Utils as MathUtils, diffAngle, deg2rad
|
|
10
10
|
} from '@wemap/maths';
|
|
11
11
|
|
|
12
|
+
import OsmNode from '../model/OsmNode';
|
|
13
|
+
import OsmWay from '../model/OsmWay';
|
|
14
|
+
|
|
12
15
|
|
|
13
16
|
class OsrmUtils {
|
|
14
17
|
|
|
@@ -22,7 +25,7 @@ class OsrmUtils {
|
|
|
22
25
|
|
|
23
26
|
const {
|
|
24
27
|
nodes, length, nextEdgeData, nextBearing, previousBearing, angle, node,
|
|
25
|
-
duration, levelChange
|
|
28
|
+
duration, levelChange, edges
|
|
26
29
|
} = itinerarySteps[i];
|
|
27
30
|
|
|
28
31
|
const edgeData = i !== lastStepId ? nextEdgeData : itinerary.edges[lastStepId];
|
|
@@ -56,11 +59,24 @@ class OsrmUtils {
|
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
if (node.data && node.data.tags) {
|
|
59
|
-
osrmStep.wemap.
|
|
62
|
+
osrmStep.wemap.node = {
|
|
63
|
+
id: node.data.id,
|
|
64
|
+
tags: node.data.tags
|
|
65
|
+
};
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
if (i !== lastStepId) {
|
|
63
|
-
osrmStep.wemap.
|
|
69
|
+
osrmStep.wemap.nextEdgeData = {
|
|
70
|
+
id: nextEdgeData.id,
|
|
71
|
+
tags: nextEdgeData.tags
|
|
72
|
+
};
|
|
73
|
+
if (edges[0].data instanceof OsmNode) {
|
|
74
|
+
osrmStep.wemap.nextEdgeData.type = 'node';
|
|
75
|
+
osrmStep.wemap.nextEdgeData.coords = OsrmUtils.wgs84ToJson(edges[0].data.coords);
|
|
76
|
+
}
|
|
77
|
+
if (edges[0].data instanceof OsmWay) {
|
|
78
|
+
osrmStep.wemap.nextEdgeData.type = 'way';
|
|
79
|
+
}
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
// The first modifier is not mandatory by OSRM.
|
|
@@ -170,7 +186,7 @@ class OsrmUtils {
|
|
|
170
186
|
const node = itinerary.getNodeByCoords(wgs84);
|
|
171
187
|
if (!node) {
|
|
172
188
|
throw new Error('Cannot parse these step coordinates, '
|
|
173
|
-
|
|
189
|
+
+ 'they are not found in main itinerary: ' + wgs84.toString());
|
|
174
190
|
}
|
|
175
191
|
step.nodes.push(node);
|
|
176
192
|
|
|
@@ -208,17 +224,26 @@ class OsrmUtils {
|
|
|
208
224
|
*/
|
|
209
225
|
if (jsonStep.wemap) {
|
|
210
226
|
const firstNode = step.nodes[0];
|
|
211
|
-
if (jsonStep.wemap.
|
|
212
|
-
|
|
227
|
+
if (jsonStep.wemap.node && firstNode) {
|
|
228
|
+
const {
|
|
229
|
+
id, tags
|
|
230
|
+
} = jsonStep.wemap.node;
|
|
231
|
+
firstNode.data = new OsmNode(id, step.nodes[0].coords, tags);
|
|
213
232
|
}
|
|
214
233
|
|
|
215
234
|
const firstEdge = step.edges[0];
|
|
216
|
-
if (jsonStep.wemap.
|
|
217
|
-
|
|
218
|
-
tags
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
235
|
+
if (jsonStep.wemap.nextEdgeData && firstEdge) {
|
|
236
|
+
const {
|
|
237
|
+
coords, id, tags, type
|
|
238
|
+
} = jsonStep.wemap.nextEdgeData;
|
|
239
|
+
if (type === 'node') {
|
|
240
|
+
firstEdge.data = new OsmNode(id, OsrmUtils.jsonToWgs84(coords), tags);
|
|
241
|
+
} else if (type === 'way') {
|
|
242
|
+
firstEdge.data = new OsmWay(id, tags);
|
|
243
|
+
}
|
|
244
|
+
if (firstEdge.data) {
|
|
245
|
+
firstEdge.data.level = firstEdge.level;
|
|
246
|
+
}
|
|
222
247
|
}
|
|
223
248
|
}
|
|
224
249
|
|
|
@@ -11,6 +11,7 @@ import OsmParser from '../model/OsmParser';
|
|
|
11
11
|
import OsmRouter from '../network/OsmRouter';
|
|
12
12
|
import OsmNetwork from '../network/OsmNetwork';
|
|
13
13
|
import OsrmUtils from './OsrmUtils';
|
|
14
|
+
import OsmNode from '../model/OsmNode';
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
const load = fileName => {
|
|
@@ -297,6 +298,26 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
297
298
|
|
|
298
299
|
});
|
|
299
300
|
|
|
301
|
+
describe('OsrmUtils - itineraryToOsrmJson - createItineraryFromJson - elevator', () => {
|
|
302
|
+
|
|
303
|
+
it('With levels (Bureaux Wemap)', () => {
|
|
304
|
+
|
|
305
|
+
const { router } = load('bureaux-wemap-montpellier-network.osm');
|
|
306
|
+
|
|
307
|
+
const start = new WGS84(43.6092754, 3.8842306, null, new Level(2));
|
|
308
|
+
const end = new WGS84(43.60949854, 3.88452048, null, new Level(0));
|
|
309
|
+
const itinerary = router.getShortestPath(start, end);
|
|
310
|
+
|
|
311
|
+
const osrmJson = OsrmUtils.itineraryToOsrmJson(itinerary);
|
|
312
|
+
const jsonSteps = osrmJson.routes[0].legs[0].steps;
|
|
313
|
+
|
|
314
|
+
expect(jsonSteps[4].wemap.nextEdgeData.type).equals('node');
|
|
315
|
+
|
|
316
|
+
const itineraryBis = OsrmUtils.createItineraryFromJson(osrmJson, start, end);
|
|
317
|
+
expect(itineraryBis.steps[4].edges[0].data).instanceOf(OsmNode);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
300
321
|
describe('OsrmUtils - Output JSON', () => {
|
|
301
322
|
|
|
302
323
|
it('noRouteFoundJson', () => {
|