@wemap/osm 2.7.14 → 3.1.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
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/osm"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/osm",
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "3.1.0",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
],
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@wemap/geo": "^
|
|
30
|
-
"@wemap/graph": "^
|
|
31
|
-
"@wemap/logger": "^
|
|
29
|
+
"@wemap/geo": "^3.0.0",
|
|
30
|
+
"@wemap/graph": "^3.0.0",
|
|
31
|
+
"@wemap/logger": "^3.0.0",
|
|
32
32
|
"lodash.isnumber": "^3.0.3",
|
|
33
33
|
"sax": "^1.2.4"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "65aa989226647982201e95ecafae68e2e48e85ae"
|
|
36
36
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Coordinates } from '@wemap/geo';
|
|
4
4
|
import Logger from '@wemap/logger';
|
|
5
5
|
|
|
6
6
|
import OsmModel from './OsmModel';
|
|
@@ -12,10 +12,10 @@ Logger.enable(false);
|
|
|
12
12
|
describe('OsmModel', () => {
|
|
13
13
|
|
|
14
14
|
const nodes = [
|
|
15
|
-
new OsmNode(1, new
|
|
16
|
-
new OsmNode(2, new
|
|
17
|
-
new OsmNode(3, new
|
|
18
|
-
new OsmNode(4, new
|
|
15
|
+
new OsmNode(1, new Coordinates(45, 5), {name: 'p1'}),
|
|
16
|
+
new OsmNode(2, new Coordinates(46, 5.5), {name: 'p2'}),
|
|
17
|
+
new OsmNode(3, new Coordinates(46.1, 5.3), {name: 'p3'}),
|
|
18
|
+
new OsmNode(4, new Coordinates(46, 5.6), {name: 'p4'})
|
|
19
19
|
];
|
|
20
20
|
|
|
21
21
|
const ways = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Coordinates } from '@wemap/geo';
|
|
4
4
|
|
|
5
5
|
import OsmNode from './OsmNode';
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ describe('OsmNode', () => {
|
|
|
8
8
|
|
|
9
9
|
it('creation', () => {
|
|
10
10
|
expect(() => new OsmNode(0)).not.throw(Error);
|
|
11
|
-
expect(() => new OsmNode(0, new
|
|
11
|
+
expect(() => new OsmNode(0, new Coordinates(0, 0))).not.throw(Error);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it('getters', () => {
|
package/src/model/OsmParser.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import sax from 'sax';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
Level,
|
|
5
|
+
Level, Coordinates
|
|
6
6
|
} from '@wemap/geo';
|
|
7
7
|
|
|
8
8
|
import OsmModel from './OsmModel';
|
|
@@ -86,7 +86,7 @@ class OsmParser {
|
|
|
86
86
|
static parseNode(attr) {
|
|
87
87
|
return new OsmNode(
|
|
88
88
|
Number(attr.id),
|
|
89
|
-
new
|
|
89
|
+
new Coordinates(Number(attr.lat), Number(attr.lon)));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
static parseWay(attr) {
|
|
@@ -4,7 +4,7 @@ import fs from 'fs';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
Level,
|
|
7
|
+
Level, Coordinates
|
|
8
8
|
} from '@wemap/geo';
|
|
9
9
|
import { Node } from '@wemap/graph';
|
|
10
10
|
|
|
@@ -12,8 +12,8 @@ import OsmParser from '../model/OsmParser';
|
|
|
12
12
|
import OsmRouter from './OsmRouter';
|
|
13
13
|
import OsmNetwork from './OsmNetwork';
|
|
14
14
|
|
|
15
|
-
const itineraryStart = new
|
|
16
|
-
const itineraryEnd = new
|
|
15
|
+
const itineraryStart = new Coordinates(43.6092754, 3.8842306, null, new Level(2));
|
|
16
|
+
const itineraryEnd = new Coordinates(43.6092602, 3.8842669, null, new Level(1));
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
const loadNetwork = fileName => {
|
|
@@ -75,8 +75,8 @@ describe('OsmRouter - Multi-level itinerary', () => {
|
|
|
75
75
|
|
|
76
76
|
it('router returns shortest path 2', () => {
|
|
77
77
|
|
|
78
|
-
const start = new
|
|
79
|
-
const end = new
|
|
78
|
+
const start = new Coordinates(43.609219, 3.8841743, null, new Level(2));
|
|
79
|
+
const end = new Coordinates(43.6091722, 3.8842355, null, new Level(2));
|
|
80
80
|
const itinerary2 = router.getShortestPath(start, end);
|
|
81
81
|
|
|
82
82
|
expect(itinerary2.nodes.length).equal(3);
|
|
@@ -101,8 +101,8 @@ describe('OsmRouter - One Way itinerary', () => {
|
|
|
101
101
|
|
|
102
102
|
it('do not use oneway', () => {
|
|
103
103
|
|
|
104
|
-
const start = new
|
|
105
|
-
const end = new
|
|
104
|
+
const start = new Coordinates(43.6094542, 3.8842072);
|
|
105
|
+
const end = new Coordinates(43.6093792, 3.8841889);
|
|
106
106
|
|
|
107
107
|
const itinerary = router.getShortestPath(start, end);
|
|
108
108
|
expect(itinerary).is.not.undefined;
|
|
@@ -122,8 +122,8 @@ describe('OsmRouter - Conveying', () => {
|
|
|
122
122
|
|
|
123
123
|
it('do not use oneway conveying', () => {
|
|
124
124
|
|
|
125
|
-
const start = new
|
|
126
|
-
const end = new
|
|
125
|
+
const start = new Coordinates(48.8445715, 2.3718927, null, new Level(0));
|
|
126
|
+
const end = new Coordinates(48.84443728652394, 2.3721685669363524, null, new Level(-1));
|
|
127
127
|
|
|
128
128
|
const itinerary = router.getShortestPath(start, end);
|
|
129
129
|
expect(itinerary).is.not.undefined;
|
package/src/osrm/OsrmUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-statements */
|
|
2
2
|
import {
|
|
3
|
-
Level,
|
|
3
|
+
Level, Coordinates
|
|
4
4
|
} from '@wemap/geo';
|
|
5
5
|
import {
|
|
6
6
|
Edge, Node, Itinerary, Step, Network
|
|
@@ -48,7 +48,7 @@ class OsrmUtils {
|
|
|
48
48
|
maneuver: {
|
|
49
49
|
bearing_before: rad2deg(bearingBefore),
|
|
50
50
|
bearing_after: rad2deg(bearingAfter),
|
|
51
|
-
location: OsrmUtils.
|
|
51
|
+
location: OsrmUtils.coordinatesToJson(node.coords),
|
|
52
52
|
type
|
|
53
53
|
},
|
|
54
54
|
wemap: {}
|
|
@@ -72,7 +72,7 @@ class OsrmUtils {
|
|
|
72
72
|
};
|
|
73
73
|
if (edges[0].data instanceof OsmNode) {
|
|
74
74
|
osrmStep.wemap.nextEdgeData.type = 'node';
|
|
75
|
-
osrmStep.wemap.nextEdgeData.coords = OsrmUtils.
|
|
75
|
+
osrmStep.wemap.nextEdgeData.coords = OsrmUtils.coordinatesToJson(edges[0].data.coords);
|
|
76
76
|
}
|
|
77
77
|
if (edges[0].data instanceof OsmWay) {
|
|
78
78
|
osrmStep.wemap.nextEdgeData.type = 'way';
|
|
@@ -115,8 +115,8 @@ class OsrmUtils {
|
|
|
115
115
|
/**
|
|
116
116
|
* Generate Itinerary from OSRM JSON, start and end.
|
|
117
117
|
* @param {Object} json JSON file provided by OSRM.
|
|
118
|
-
* @param {
|
|
119
|
-
* @param {
|
|
118
|
+
* @param {Coordinates} start itinerary start
|
|
119
|
+
* @param {Coordinates} end itinerary end
|
|
120
120
|
*/
|
|
121
121
|
static createItineraryFromJson(json, start, end) {
|
|
122
122
|
const itinerary = new Itinerary();
|
|
@@ -134,7 +134,7 @@ class OsrmUtils {
|
|
|
134
134
|
let previousNode;
|
|
135
135
|
const { coordinates } = geometry;
|
|
136
136
|
for (let i = 0; i < coordinates.length; i++) {
|
|
137
|
-
const node = new Node(OsrmUtils.
|
|
137
|
+
const node = new Node(OsrmUtils.jsonToCoordinates(coordinates[i]));
|
|
138
138
|
itinerary.nodes.push(node);
|
|
139
139
|
|
|
140
140
|
if (previousNode) {
|
|
@@ -182,7 +182,7 @@ class OsrmUtils {
|
|
|
182
182
|
coordinates = [coordinates[0]];
|
|
183
183
|
}
|
|
184
184
|
coordinates.forEach(coords => {
|
|
185
|
-
const wgs84 = OsrmUtils.
|
|
185
|
+
const wgs84 = OsrmUtils.jsonToCoordinates(coords);
|
|
186
186
|
const node = itinerary.getNodeByCoords(wgs84);
|
|
187
187
|
if (!node) {
|
|
188
188
|
throw new Error('Cannot parse these step coordinates, '
|
|
@@ -237,7 +237,7 @@ class OsrmUtils {
|
|
|
237
237
|
coords, id, tags, type
|
|
238
238
|
} = jsonStep.wemap.nextEdgeData;
|
|
239
239
|
if (type === 'node') {
|
|
240
|
-
firstEdge.data = new OsmNode(id, OsrmUtils.
|
|
240
|
+
firstEdge.data = new OsmNode(id, OsrmUtils.jsonToCoordinates(coords), tags);
|
|
241
241
|
} else if (type === 'way') {
|
|
242
242
|
firstEdge.data = new OsmWay(id, tags);
|
|
243
243
|
}
|
|
@@ -279,16 +279,16 @@ class OsrmUtils {
|
|
|
279
279
|
return 'u turn';
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
static
|
|
283
|
-
const output = [
|
|
284
|
-
if (
|
|
285
|
-
output.push(
|
|
282
|
+
static coordinatesToJson(coordinates) {
|
|
283
|
+
const output = [coordinates.lng, coordinates.lat];
|
|
284
|
+
if (coordinates.level) {
|
|
285
|
+
output.push(coordinates.level.toString());
|
|
286
286
|
}
|
|
287
287
|
return output;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
static
|
|
291
|
-
const output = new
|
|
290
|
+
static jsonToCoordinates(json) {
|
|
291
|
+
const output = new Coordinates(json[1], json[0]);
|
|
292
292
|
if (json.length > 2) {
|
|
293
293
|
output.level = Level.fromString(json[2]);
|
|
294
294
|
}
|
|
@@ -296,7 +296,7 @@ class OsrmUtils {
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
static nodesToJsonCoords(nodes) {
|
|
299
|
-
return nodes.map(node => OsrmUtils.
|
|
299
|
+
return nodes.map(node => OsrmUtils.coordinatesToJson(node.coords));
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
|
|
@@ -4,7 +4,7 @@ import fs from 'fs';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
Level,
|
|
7
|
+
Level, Coordinates
|
|
8
8
|
} from '@wemap/geo';
|
|
9
9
|
|
|
10
10
|
import OsmParser from '../model/OsmParser';
|
|
@@ -36,8 +36,8 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
|
|
|
36
36
|
network, router
|
|
37
37
|
} = load('bureaux-wemap-montpellier-network.osm');
|
|
38
38
|
|
|
39
|
-
wemapStart = new
|
|
40
|
-
wemapEnd = new
|
|
39
|
+
wemapStart = new Coordinates(43.6092754, 3.8842306, null, new Level(2));
|
|
40
|
+
wemapEnd = new Coordinates(43.6092602, 3.8842669, null, new Level(1));
|
|
41
41
|
const itinerary = router.getShortestPath(wemapStart, wemapEnd);
|
|
42
42
|
wemapItinerary = itinerary;
|
|
43
43
|
|
|
@@ -57,7 +57,7 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
|
|
|
57
57
|
for (let i = 1; i < 11; i++) {
|
|
58
58
|
expect(
|
|
59
59
|
network.getNodeByName('p' + (i + 6)).coords.equalsTo(
|
|
60
|
-
OsrmUtils.
|
|
60
|
+
OsrmUtils.jsonToCoordinates(coordinates[i]))
|
|
61
61
|
).true;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -69,7 +69,7 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
|
|
|
69
69
|
const {
|
|
70
70
|
location, type
|
|
71
71
|
} = steps[i].maneuver;
|
|
72
|
-
expect(itinerarySteps[i].node.coords.equalsTo(OsrmUtils.
|
|
72
|
+
expect(itinerarySteps[i].node.coords.equalsTo(OsrmUtils.jsonToCoordinates(location))).true;
|
|
73
73
|
|
|
74
74
|
let expectedType;
|
|
75
75
|
switch (i) {
|
|
@@ -164,8 +164,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
164
164
|
|
|
165
165
|
const json = JSON.parse(fileString);
|
|
166
166
|
|
|
167
|
-
const start = new
|
|
168
|
-
const end = new
|
|
167
|
+
const start = new Coordinates(43.6007871, 3.8757218000000004);
|
|
168
|
+
const end = new Coordinates(43.598877, 3.873866);
|
|
169
169
|
|
|
170
170
|
const itinerary = OsrmUtils.createItineraryFromJson(json, start, end);
|
|
171
171
|
|
|
@@ -178,7 +178,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
178
178
|
|
|
179
179
|
let step;
|
|
180
180
|
step = steps[0];
|
|
181
|
-
expect(
|
|
181
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.600777, 3.875607))).true;
|
|
182
182
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
|
|
183
183
|
expect(step.nodes.length).equals(6);
|
|
184
184
|
expect(step.edges.length).equals(5);
|
|
@@ -187,7 +187,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
187
187
|
expect(step.name).equals('');
|
|
188
188
|
|
|
189
189
|
step = steps[1];
|
|
190
|
-
expect(
|
|
190
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.599881, 3.876396))).true;
|
|
191
191
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('right');
|
|
192
192
|
expect(step.nodes.length).equals(12);
|
|
193
193
|
expect(step.edges.length).equals(11);
|
|
@@ -196,7 +196,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
196
196
|
expect(step.name).equals('Boulevard Vieussens');
|
|
197
197
|
|
|
198
198
|
step = steps[2];
|
|
199
|
-
expect(
|
|
199
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.599577, 3.874655))).true;
|
|
200
200
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
|
|
201
201
|
expect(step.nodes.length).equals(2);
|
|
202
202
|
expect(step.edges.length).equals(1);
|
|
@@ -205,7 +205,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
205
205
|
expect(step.name).equals('Impasse Bizeray');
|
|
206
206
|
|
|
207
207
|
step = steps[3];
|
|
208
|
-
expect(
|
|
208
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.599063, 3.874623))).true;
|
|
209
209
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('right');
|
|
210
210
|
expect(step.nodes.length).equals(2);
|
|
211
211
|
expect(step.edges.length).equals(1);
|
|
@@ -214,7 +214,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
214
214
|
expect(step.name).equals('Rue du Docteur Louis Perrier');
|
|
215
215
|
|
|
216
216
|
step = steps[4];
|
|
217
|
-
expect(
|
|
217
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.59906, 3.873865))).true;
|
|
218
218
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
|
|
219
219
|
expect(step.nodes.length).equals(1);
|
|
220
220
|
expect(step.edges.length).equals(0);
|
|
@@ -243,8 +243,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
243
243
|
|
|
244
244
|
const json = JSON.parse(fileString);
|
|
245
245
|
|
|
246
|
-
const start = new
|
|
247
|
-
const end = new
|
|
246
|
+
const start = new Coordinates(43.6007871, 3.8757218000000004);
|
|
247
|
+
const end = new Coordinates(43.598877, 3.873866);
|
|
248
248
|
|
|
249
249
|
const itinerary = OsrmUtils.createItineraryFromJson(json, start, end);
|
|
250
250
|
|
|
@@ -290,8 +290,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
290
290
|
|
|
291
291
|
const json = JSON.parse(fileString);
|
|
292
292
|
|
|
293
|
-
const start = new
|
|
294
|
-
const end = new
|
|
293
|
+
const start = new Coordinates(43.6007871, 3.8757218000000004);
|
|
294
|
+
const end = new Coordinates(43.598877, 3.873866);
|
|
295
295
|
|
|
296
296
|
expect(() => OsrmUtils.createItineraryFromJson(json, start, end)).throw(Error);
|
|
297
297
|
});
|
|
@@ -304,8 +304,8 @@ describe('OsrmUtils - itineraryToOsrmJson - createItineraryFromJson - elevator',
|
|
|
304
304
|
|
|
305
305
|
const { router } = load('bureaux-wemap-montpellier-network.osm');
|
|
306
306
|
|
|
307
|
-
const start = new
|
|
308
|
-
const end = new
|
|
307
|
+
const start = new Coordinates(43.6092754, 3.8842306, null, new Level(2));
|
|
308
|
+
const end = new Coordinates(43.60949854, 3.88452048, null, new Level(0));
|
|
309
309
|
const itinerary = router.getShortestPath(start, end);
|
|
310
310
|
|
|
311
311
|
const osrmJson = OsrmUtils.itineraryToOsrmJson(itinerary);
|