@wemap/osm 2.7.14 → 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": "2.7.14",
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": "^2.7.9",
30
- "@wemap/graph": "^2.7.9",
31
- "@wemap/logger": "^2.7.7",
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": "a196bbcae92e89add1caa2d532c9ae8bf583e42e"
35
+ "gitHead": "2bbb4840a99b90eaae989291cb728ac87cebade8"
36
36
  }
@@ -1,6 +1,6 @@
1
1
  import { expect } from 'chai';
2
2
 
3
- import { WGS84 } from '@wemap/geo';
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 WGS84(45, 5), {name: 'p1'}),
16
- new OsmNode(2, new WGS84(46, 5.5), {name: 'p2'}),
17
- new OsmNode(3, new WGS84(46.1, 5.3), {name: 'p3'}),
18
- new OsmNode(4, new WGS84(46, 5.6), {name: 'p4'})
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 { WGS84 } from '@wemap/geo';
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 WGS84(0, 0))).not.throw(Error);
11
+ expect(() => new OsmNode(0, new Coordinates(0, 0))).not.throw(Error);
12
12
  });
13
13
 
14
14
  it('getters', () => {
@@ -2,7 +2,7 @@
2
2
  import sax from 'sax';
3
3
 
4
4
  import {
5
- Level, WGS84
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 WGS84(Number(attr.lat), Number(attr.lon)));
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, WGS84
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 WGS84(43.6092754, 3.8842306, null, new Level(2));
16
- const itineraryEnd = new WGS84(43.6092602, 3.8842669, null, new Level(1));
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 WGS84(43.609219, 3.8841743, null, new Level(2));
79
- const end = new WGS84(43.6091722, 3.8842355, null, new Level(2));
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);
@@ -87,9 +87,8 @@ 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.isElevator).is.true;
91
- expect(itineraryWithoutStairs.nodes[7].data.isElevator).is.true;
92
- expect(itineraryWithoutStairs.edges[6].data.isElevator).is.true;
90
+ expect(itineraryWithoutStairs.nodes[6].data.tags.highway).equal('elevator');
91
+ expect(itineraryWithoutStairs.nodes[7].data.tags.highway).equal('elevator');
93
92
  });
94
93
 
95
94
  });
@@ -101,8 +100,8 @@ describe('OsmRouter - One Way itinerary', () => {
101
100
 
102
101
  it('do not use oneway', () => {
103
102
 
104
- const start = new WGS84(43.6094542, 3.8842072);
105
- const end = new WGS84(43.6093792, 3.8841889);
103
+ const start = new Coordinates(43.6094542, 3.8842072);
104
+ const end = new Coordinates(43.6093792, 3.8841889);
106
105
 
107
106
  const itinerary = router.getShortestPath(start, end);
108
107
  expect(itinerary).is.not.undefined;
@@ -122,8 +121,8 @@ describe('OsmRouter - Conveying', () => {
122
121
 
123
122
  it('do not use oneway conveying', () => {
124
123
 
125
- const start = new WGS84(48.8445715, 2.3718927, null, new Level(0));
126
- const end = new WGS84(48.84443728652394, 2.3721685669363524, null, new Level(-1));
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));
127
126
 
128
127
  const itinerary = router.getShortestPath(start, end);
129
128
  expect(itinerary).is.not.undefined;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-statements */
2
2
  import {
3
- Level, WGS84
3
+ Level, Coordinates
4
4
  } from '@wemap/geo';
5
5
  import {
6
6
  Edge, Node, Itinerary, Step, Network
@@ -25,7 +25,7 @@ class OsrmUtils {
25
25
 
26
26
  const {
27
27
  nodes, length, nextEdgeData, nextBearing, previousBearing, angle, node,
28
- duration, levelChange, edges
28
+ duration, levelChange
29
29
  } = itinerarySteps[i];
30
30
 
31
31
  const edgeData = i !== lastStepId ? nextEdgeData : itinerary.edges[lastStepId];
@@ -48,7 +48,7 @@ class OsrmUtils {
48
48
  maneuver: {
49
49
  bearing_before: rad2deg(bearingBefore),
50
50
  bearing_after: rad2deg(bearingAfter),
51
- location: OsrmUtils.wgs84ToJson(node.coords),
51
+ location: OsrmUtils.coordinatesToJson(node.coords),
52
52
  type
53
53
  },
54
54
  wemap: {}
@@ -66,17 +66,10 @@ class OsrmUtils {
66
66
  }
67
67
 
68
68
  if (i !== lastStepId) {
69
- osrmStep.wemap.nextEdgeData = {
69
+ osrmStep.wemap.nextWay = {
70
70
  id: nextEdgeData.id,
71
71
  tags: nextEdgeData.tags
72
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
- }
80
73
  }
81
74
 
82
75
  // The first modifier is not mandatory by OSRM.
@@ -115,8 +108,8 @@ class OsrmUtils {
115
108
  /**
116
109
  * Generate Itinerary from OSRM JSON, start and end.
117
110
  * @param {Object} json JSON file provided by OSRM.
118
- * @param {WGS84} start itinerary start
119
- * @param {WGS84} end itinerary end
111
+ * @param {Coordinates} start itinerary start
112
+ * @param {Coordinates} end itinerary end
120
113
  */
121
114
  static createItineraryFromJson(json, start, end) {
122
115
  const itinerary = new Itinerary();
@@ -134,7 +127,7 @@ class OsrmUtils {
134
127
  let previousNode;
135
128
  const { coordinates } = geometry;
136
129
  for (let i = 0; i < coordinates.length; i++) {
137
- const node = new Node(OsrmUtils.jsonToWgs84(coordinates[i]));
130
+ const node = new Node(OsrmUtils.jsonToCoordinates(coordinates[i]));
138
131
  itinerary.nodes.push(node);
139
132
 
140
133
  if (previousNode) {
@@ -182,7 +175,7 @@ class OsrmUtils {
182
175
  coordinates = [coordinates[0]];
183
176
  }
184
177
  coordinates.forEach(coords => {
185
- const wgs84 = OsrmUtils.jsonToWgs84(coords);
178
+ const wgs84 = OsrmUtils.jsonToCoordinates(coords);
186
179
  const node = itinerary.getNodeByCoords(wgs84);
187
180
  if (!node) {
188
181
  throw new Error('Cannot parse these step coordinates, '
@@ -232,18 +225,12 @@ class OsrmUtils {
232
225
  }
233
226
 
234
227
  const firstEdge = step.edges[0];
235
- if (jsonStep.wemap.nextEdgeData && firstEdge) {
228
+ if (jsonStep.wemap.nextWay && firstEdge) {
236
229
  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
- }
230
+ id, tags
231
+ } = jsonStep.wemap.nextWay;
232
+ firstEdge.data = new OsmWay(id, tags);
233
+ firstEdge.data.level = firstEdge.level;
247
234
  }
248
235
  }
249
236
 
@@ -279,16 +266,16 @@ class OsrmUtils {
279
266
  return 'u turn';
280
267
  }
281
268
 
282
- static wgs84ToJson(wgs84) {
283
- const output = [wgs84.lng, wgs84.lat];
284
- if (wgs84.level) {
285
- output.push(wgs84.level.toString());
269
+ static coordinatesToJson(coordinates) {
270
+ const output = [coordinates.lng, coordinates.lat];
271
+ if (coordinates.level) {
272
+ output.push(coordinates.level.toString());
286
273
  }
287
274
  return output;
288
275
  }
289
276
 
290
- static jsonToWgs84(json) {
291
- const output = new WGS84(json[1], json[0]);
277
+ static jsonToCoordinates(json) {
278
+ const output = new Coordinates(json[1], json[0]);
292
279
  if (json.length > 2) {
293
280
  output.level = Level.fromString(json[2]);
294
281
  }
@@ -296,7 +283,7 @@ class OsrmUtils {
296
283
  }
297
284
 
298
285
  static nodesToJsonCoords(nodes) {
299
- return nodes.map(node => OsrmUtils.wgs84ToJson(node.coords));
286
+ return nodes.map(node => OsrmUtils.coordinatesToJson(node.coords));
300
287
  }
301
288
 
302
289
 
@@ -4,14 +4,13 @@ import fs from 'fs';
4
4
  import path from 'path';
5
5
 
6
6
  import {
7
- Level, WGS84
7
+ Level, Coordinates
8
8
  } from '@wemap/geo';
9
9
 
10
10
  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';
15
14
 
16
15
 
17
16
  const load = fileName => {
@@ -36,8 +35,8 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
36
35
  network, router
37
36
  } = load('bureaux-wemap-montpellier-network.osm');
38
37
 
39
- wemapStart = new WGS84(43.6092754, 3.8842306, null, new Level(2));
40
- wemapEnd = new WGS84(43.6092602, 3.8842669, null, new Level(1));
38
+ wemapStart = new Coordinates(43.6092754, 3.8842306, null, new Level(2));
39
+ wemapEnd = new Coordinates(43.6092602, 3.8842669, null, new Level(1));
41
40
  const itinerary = router.getShortestPath(wemapStart, wemapEnd);
42
41
  wemapItinerary = itinerary;
43
42
 
@@ -57,7 +56,7 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
57
56
  for (let i = 1; i < 11; i++) {
58
57
  expect(
59
58
  network.getNodeByName('p' + (i + 6)).coords.equalsTo(
60
- OsrmUtils.jsonToWgs84(coordinates[i]))
59
+ OsrmUtils.jsonToCoordinates(coordinates[i]))
61
60
  ).true;
62
61
  }
63
62
 
@@ -69,7 +68,7 @@ describe('OsrmUtils - itineraryToOsrmJson', () => {
69
68
  const {
70
69
  location, type
71
70
  } = steps[i].maneuver;
72
- expect(itinerarySteps[i].node.coords.equalsTo(OsrmUtils.jsonToWgs84(location))).true;
71
+ expect(itinerarySteps[i].node.coords.equalsTo(OsrmUtils.jsonToCoordinates(location))).true;
73
72
 
74
73
  let expectedType;
75
74
  switch (i) {
@@ -164,8 +163,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
164
163
 
165
164
  const json = JSON.parse(fileString);
166
165
 
167
- const start = new WGS84(43.6007871, 3.8757218000000004);
168
- const end = new WGS84(43.598877, 3.873866);
166
+ const start = new Coordinates(43.6007871, 3.8757218000000004);
167
+ const end = new Coordinates(43.598877, 3.873866);
169
168
 
170
169
  const itinerary = OsrmUtils.createItineraryFromJson(json, start, end);
171
170
 
@@ -178,7 +177,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
178
177
 
179
178
  let step;
180
179
  step = steps[0];
181
- expect(WGS84.equalsTo(step.location, new WGS84(43.600777, 3.875607))).true;
180
+ expect(Coordinates.equalsTo(step.location, new Coordinates(43.600777, 3.875607))).true;
182
181
  expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
183
182
  expect(step.nodes.length).equals(6);
184
183
  expect(step.edges.length).equals(5);
@@ -187,7 +186,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
187
186
  expect(step.name).equals('');
188
187
 
189
188
  step = steps[1];
190
- expect(WGS84.equalsTo(step.location, new WGS84(43.599881, 3.876396))).true;
189
+ expect(Coordinates.equalsTo(step.location, new Coordinates(43.599881, 3.876396))).true;
191
190
  expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('right');
192
191
  expect(step.nodes.length).equals(12);
193
192
  expect(step.edges.length).equals(11);
@@ -196,7 +195,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
196
195
  expect(step.name).equals('Boulevard Vieussens');
197
196
 
198
197
  step = steps[2];
199
- expect(WGS84.equalsTo(step.location, new WGS84(43.599577, 3.874655))).true;
198
+ expect(Coordinates.equalsTo(step.location, new Coordinates(43.599577, 3.874655))).true;
200
199
  expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
201
200
  expect(step.nodes.length).equals(2);
202
201
  expect(step.edges.length).equals(1);
@@ -205,7 +204,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
205
204
  expect(step.name).equals('Impasse Bizeray');
206
205
 
207
206
  step = steps[3];
208
- expect(WGS84.equalsTo(step.location, new WGS84(43.599063, 3.874623))).true;
207
+ expect(Coordinates.equalsTo(step.location, new Coordinates(43.599063, 3.874623))).true;
209
208
  expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('right');
210
209
  expect(step.nodes.length).equals(2);
211
210
  expect(step.edges.length).equals(1);
@@ -214,7 +213,7 @@ describe('OsrmUtils - createItineraryFromJson', () => {
214
213
  expect(step.name).equals('Rue du Docteur Louis Perrier');
215
214
 
216
215
  step = steps[4];
217
- expect(WGS84.equalsTo(step.location, new WGS84(43.59906, 3.873865))).true;
216
+ expect(Coordinates.equalsTo(step.location, new Coordinates(43.59906, 3.873865))).true;
218
217
  expect(OsrmUtils.getModifierFromAngle(step.angle)).equals('left');
219
218
  expect(step.nodes.length).equals(1);
220
219
  expect(step.edges.length).equals(0);
@@ -243,8 +242,8 @@ describe('OsrmUtils - createItineraryFromJson', () => {
243
242
 
244
243
  const json = JSON.parse(fileString);
245
244
 
246
- const start = new WGS84(43.6007871, 3.8757218000000004);
247
- const end = new WGS84(43.598877, 3.873866);
245
+ const start = new Coordinates(43.6007871, 3.8757218000000004);
246
+ const end = new Coordinates(43.598877, 3.873866);
248
247
 
249
248
  const itinerary = OsrmUtils.createItineraryFromJson(json, start, end);
250
249
 
@@ -290,34 +289,14 @@ describe('OsrmUtils - createItineraryFromJson', () => {
290
289
 
291
290
  const json = JSON.parse(fileString);
292
291
 
293
- const start = new WGS84(43.6007871, 3.8757218000000004);
294
- const end = new WGS84(43.598877, 3.873866);
292
+ const start = new Coordinates(43.6007871, 3.8757218000000004);
293
+ const end = new Coordinates(43.598877, 3.873866);
295
294
 
296
295
  expect(() => OsrmUtils.createItineraryFromJson(json, start, end)).throw(Error);
297
296
  });
298
297
 
299
298
  });
300
299
 
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
-
321
300
  describe('OsrmUtils - Output JSON', () => {
322
301
 
323
302
  it('noRouteFoundJson', () => {