@wemap/osm 2.7.13 → 3.0.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.0.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": "2bbb4840a99b90eaae989291cb728ac87cebade8"
|
|
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);
|
|
@@ -100,8 +100,8 @@ describe('OsmRouter - One Way itinerary', () => {
|
|
|
100
100
|
|
|
101
101
|
it('do not use oneway', () => {
|
|
102
102
|
|
|
103
|
-
const start = new
|
|
104
|
-
const end = new
|
|
103
|
+
const start = new Coordinates(43.6094542, 3.8842072);
|
|
104
|
+
const end = new Coordinates(43.6093792, 3.8841889);
|
|
105
105
|
|
|
106
106
|
const itinerary = router.getShortestPath(start, end);
|
|
107
107
|
expect(itinerary).is.not.undefined;
|
|
@@ -121,8 +121,8 @@ describe('OsmRouter - Conveying', () => {
|
|
|
121
121
|
|
|
122
122
|
it('do not use oneway conveying', () => {
|
|
123
123
|
|
|
124
|
-
const start = new
|
|
125
|
-
const end = new
|
|
124
|
+
const start = new Coordinates(48.8445715, 2.3718927, null, new Level(0));
|
|
125
|
+
const end = new Coordinates(48.84443728652394, 2.3721685669363524, null, new Level(-1));
|
|
126
126
|
|
|
127
127
|
const itinerary = router.getShortestPath(start, end);
|
|
128
128
|
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: {}
|
|
@@ -108,8 +108,8 @@ class OsrmUtils {
|
|
|
108
108
|
/**
|
|
109
109
|
* Generate Itinerary from OSRM JSON, start and end.
|
|
110
110
|
* @param {Object} json JSON file provided by OSRM.
|
|
111
|
-
* @param {
|
|
112
|
-
* @param {
|
|
111
|
+
* @param {Coordinates} start itinerary start
|
|
112
|
+
* @param {Coordinates} end itinerary end
|
|
113
113
|
*/
|
|
114
114
|
static createItineraryFromJson(json, start, end) {
|
|
115
115
|
const itinerary = new Itinerary();
|
|
@@ -127,7 +127,7 @@ class OsrmUtils {
|
|
|
127
127
|
let previousNode;
|
|
128
128
|
const { coordinates } = geometry;
|
|
129
129
|
for (let i = 0; i < coordinates.length; i++) {
|
|
130
|
-
const node = new Node(OsrmUtils.
|
|
130
|
+
const node = new Node(OsrmUtils.jsonToCoordinates(coordinates[i]));
|
|
131
131
|
itinerary.nodes.push(node);
|
|
132
132
|
|
|
133
133
|
if (previousNode) {
|
|
@@ -175,7 +175,7 @@ class OsrmUtils {
|
|
|
175
175
|
coordinates = [coordinates[0]];
|
|
176
176
|
}
|
|
177
177
|
coordinates.forEach(coords => {
|
|
178
|
-
const wgs84 = OsrmUtils.
|
|
178
|
+
const wgs84 = OsrmUtils.jsonToCoordinates(coords);
|
|
179
179
|
const node = itinerary.getNodeByCoords(wgs84);
|
|
180
180
|
if (!node) {
|
|
181
181
|
throw new Error('Cannot parse these step coordinates, '
|
|
@@ -266,16 +266,16 @@ class OsrmUtils {
|
|
|
266
266
|
return 'u turn';
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
static
|
|
270
|
-
const output = [
|
|
271
|
-
if (
|
|
272
|
-
output.push(
|
|
269
|
+
static coordinatesToJson(coordinates) {
|
|
270
|
+
const output = [coordinates.lng, coordinates.lat];
|
|
271
|
+
if (coordinates.level) {
|
|
272
|
+
output.push(coordinates.level.toString());
|
|
273
273
|
}
|
|
274
274
|
return output;
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
static
|
|
278
|
-
const output = new
|
|
277
|
+
static jsonToCoordinates(json) {
|
|
278
|
+
const output = new Coordinates(json[1], json[0]);
|
|
279
279
|
if (json.length > 2) {
|
|
280
280
|
output.level = Level.fromString(json[2]);
|
|
281
281
|
}
|
|
@@ -283,7 +283,7 @@ class OsrmUtils {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
static nodesToJsonCoords(nodes) {
|
|
286
|
-
return nodes.map(node => OsrmUtils.
|
|
286
|
+
return nodes.map(node => OsrmUtils.coordinatesToJson(node.coords));
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
|
|
@@ -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';
|
|
@@ -35,8 +35,8 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
|
|
|
35
35
|
network, router
|
|
36
36
|
} = load('bureaux-wemap-montpellier-network.osm');
|
|
37
37
|
|
|
38
|
-
wemapStart = new
|
|
39
|
-
wemapEnd = new
|
|
38
|
+
wemapStart = new Coordinates(43.6092754, 3.8842306, null, new Level(2));
|
|
39
|
+
wemapEnd = new Coordinates(43.6092602, 3.8842669, null, new Level(1));
|
|
40
40
|
const itinerary = router.getShortestPath(wemapStart, wemapEnd);
|
|
41
41
|
wemapItinerary = itinerary;
|
|
42
42
|
|
|
@@ -56,7 +56,7 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
|
|
|
56
56
|
for (let i = 1; i < 11; i++) {
|
|
57
57
|
expect(
|
|
58
58
|
network.getNodeByName('p' + (i + 6)).coords.equalsTo(
|
|
59
|
-
OsrmUtils.
|
|
59
|
+
OsrmUtils.jsonToCoordinates(coordinates[i]))
|
|
60
60
|
).true;
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -68,7 +68,7 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
|
|
|
68
68
|
const {
|
|
69
69
|
location, type
|
|
70
70
|
} = steps[i].maneuver;
|
|
71
|
-
expect(itinerarySteps[i].node.coords.equalsTo(OsrmUtils.
|
|
71
|
+
expect(itinerarySteps[i].node.coords.equalsTo(OsrmUtils.jsonToCoordinates(location))).true;
|
|
72
72
|
|
|
73
73
|
let expectedType;
|
|
74
74
|
switch (i) {
|
|
@@ -163,8 +163,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
163
163
|
|
|
164
164
|
const json = JSON.parse(fileString);
|
|
165
165
|
|
|
166
|
-
const start = new
|
|
167
|
-
const end = new
|
|
166
|
+
const start = new Coordinates(43.6007871, 3.8757218000000004);
|
|
167
|
+
const end = new Coordinates(43.598877, 3.873866);
|
|
168
168
|
|
|
169
169
|
const itinerary = OsrmUtils.createItineraryFromJson(json, start, end);
|
|
170
170
|
|
|
@@ -177,7 +177,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
177
177
|
|
|
178
178
|
let step;
|
|
179
179
|
step = steps[0];
|
|
180
|
-
expect(
|
|
180
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.600777, 3.875607))).true;
|
|
181
181
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
|
|
182
182
|
expect(step.nodes.length).equals(6);
|
|
183
183
|
expect(step.edges.length).equals(5);
|
|
@@ -186,7 +186,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
186
186
|
expect(step.name).equals('');
|
|
187
187
|
|
|
188
188
|
step = steps[1];
|
|
189
|
-
expect(
|
|
189
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.599881, 3.876396))).true;
|
|
190
190
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('right');
|
|
191
191
|
expect(step.nodes.length).equals(12);
|
|
192
192
|
expect(step.edges.length).equals(11);
|
|
@@ -195,7 +195,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
195
195
|
expect(step.name).equals('Boulevard Vieussens');
|
|
196
196
|
|
|
197
197
|
step = steps[2];
|
|
198
|
-
expect(
|
|
198
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.599577, 3.874655))).true;
|
|
199
199
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
|
|
200
200
|
expect(step.nodes.length).equals(2);
|
|
201
201
|
expect(step.edges.length).equals(1);
|
|
@@ -204,7 +204,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
204
204
|
expect(step.name).equals('Impasse Bizeray');
|
|
205
205
|
|
|
206
206
|
step = steps[3];
|
|
207
|
-
expect(
|
|
207
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.599063, 3.874623))).true;
|
|
208
208
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('right');
|
|
209
209
|
expect(step.nodes.length).equals(2);
|
|
210
210
|
expect(step.edges.length).equals(1);
|
|
@@ -213,7 +213,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
213
213
|
expect(step.name).equals('Rue du Docteur Louis Perrier');
|
|
214
214
|
|
|
215
215
|
step = steps[4];
|
|
216
|
-
expect(
|
|
216
|
+
expect(Coordinates.equalsTo(step.location, new Coordinates(43.59906, 3.873865))).true;
|
|
217
217
|
expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
|
|
218
218
|
expect(step.nodes.length).equals(1);
|
|
219
219
|
expect(step.edges.length).equals(0);
|
|
@@ -242,8 +242,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
242
242
|
|
|
243
243
|
const json = JSON.parse(fileString);
|
|
244
244
|
|
|
245
|
-
const start = new
|
|
246
|
-
const end = new
|
|
245
|
+
const start = new Coordinates(43.6007871, 3.8757218000000004);
|
|
246
|
+
const end = new Coordinates(43.598877, 3.873866);
|
|
247
247
|
|
|
248
248
|
const itinerary = OsrmUtils.createItineraryFromJson(json, start, end);
|
|
249
249
|
|
|
@@ -289,8 +289,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
|
|
|
289
289
|
|
|
290
290
|
const json = JSON.parse(fileString);
|
|
291
291
|
|
|
292
|
-
const start = new
|
|
293
|
-
const end = new
|
|
292
|
+
const start = new Coordinates(43.6007871, 3.8757218000000004);
|
|
293
|
+
const end = new Coordinates(43.598877, 3.873866);
|
|
294
294
|
|
|
295
295
|
expect(() => OsrmUtils.createItineraryFromJson(json, start, end)).throw(Error);
|
|
296
296
|
});
|