@wemap/routers 12.5.0 → 12.7.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.
@@ -0,0 +1,47 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <osm version='0.6' generator='JOSM'>
3
+ <node id='-1610618489058234' action='modify' visible='true' lat='48.87601173273' lon='2.32555037119'>
4
+ <tag k='name' v='p1' />
5
+ </node>
6
+ <node id='-1610618489058235' action='modify' visible='true' lat='48.87597991746' lon='2.3253223214'>
7
+ <tag k='name' v='p2' />
8
+ </node>
9
+ <node id='-1610618489058236' action='modify' visible='true' lat='48.87573599972' lon='2.32538912386'>
10
+ <tag k='name' v='p3' />
11
+ </node>
12
+ <node id='-1610618489058237' action='modify' visible='true' lat='48.87575872503' lon='2.32561026305'>
13
+ <tag k='name' v='p4' />
14
+ </node>
15
+ <node id='-1610618489058238' action='modify' visible='true' lat='48.87619959391' lon='2.32495145256' />
16
+ <node id='-1610618489058239' action='modify' visible='true' lat='48.87625261911' lon='2.32559874539' />
17
+ <node id='-1610618489058240' action='modify' visible='true' lat='48.87542996461' lon='2.32583140224' />
18
+ <node id='-1610618489058241' action='modify' visible='true' lat='48.87539057382' lon='2.32522557301' />
19
+ <way id='-921430905799056' action='modify' visible='true'>
20
+ <nd ref='-1610618489058234' />
21
+ <nd ref='-1610618489058235' />
22
+ <tag k='highway' v='steps' />
23
+ <tag k='level' v='0;1' />
24
+ <tag k='name' v='e1' />
25
+ </way>
26
+ <way id='-921430905799057' action='modify' visible='true'>
27
+ <nd ref='-1610618489058236' />
28
+ <nd ref='-1610618489058237' />
29
+ <tag k='highway' v='footway' />
30
+ <tag k='name' v='e3' />
31
+ </way>
32
+ <way id='-921430905799058' action='modify' visible='true'>
33
+ <nd ref='-1610618489058238' />
34
+ <nd ref='-1610618489058239' />
35
+ <nd ref='-1610618489058240' />
36
+ <nd ref='-1610618489058241' />
37
+ <nd ref='-1610618489058238' />
38
+ <tag k='wemap:routing-bounds' v='yes' />
39
+ </way>
40
+ <way id='-921430905799059' action='modify' visible='true'>
41
+ <nd ref='-1610618489058235' />
42
+ <nd ref='-1610618489058236' />
43
+ <tag k='highway' v='footway' />
44
+ <tag k='level' v='0' />
45
+ <tag k='name' v='e2' />
46
+ </way>
47
+ </osm>
package/dist/index.js CHANGED
@@ -75,10 +75,19 @@ class Vertex {
75
75
  return this.coords.bearingTo(other.coords);
76
76
  }
77
77
  toJson() {
78
- return this.coords.toCompressedJson();
78
+ return {
79
+ id: this.id,
80
+ coords: this.coords.toCompressedJson(),
81
+ ...Object.keys(this.properties).length > 0 && { properties: this.properties }
82
+ };
79
83
  }
80
84
  static fromJson(json) {
81
- return new Vertex(geo.Coordinates.fromCompressedJson(json));
85
+ const v = new Vertex(
86
+ geo.Coordinates.fromCompressedJson(json.coords),
87
+ json.properties
88
+ );
89
+ v.id = json.id;
90
+ return v;
82
91
  }
83
92
  }
84
93
  class Graph {
@@ -179,9 +188,30 @@ class Graph {
179
188
  });
180
189
  return bestProjection;
181
190
  }
182
- toCompressedJson() {
191
+ toJson() {
183
192
  return {
184
193
  vertices: this.vertices.map((vertex) => vertex.toJson()),
194
+ edges: this.edges.map((edge) => ({
195
+ id: edge.id,
196
+ vertex1Idx: this.vertices.indexOf(edge.vertex1),
197
+ vertex2Idx: this.vertices.indexOf(edge.vertex2),
198
+ ...Object.keys(edge.properties).length > 0 && { properties: edge.properties }
199
+ }))
200
+ };
201
+ }
202
+ static fromJson(json) {
203
+ const vertices = json.vertices.map((vertex) => Vertex.fromJson(vertex));
204
+ const edges = json.edges.map((jsonEdge) => new Edge(
205
+ vertices[jsonEdge.vertex1Idx],
206
+ vertices[jsonEdge.vertex2Idx],
207
+ jsonEdge.properties
208
+ ));
209
+ return new Graph(vertices, edges);
210
+ }
211
+ /** @deprecated */
212
+ toCompressedJson() {
213
+ return {
214
+ vertices: this.vertices.map((vertex) => vertex.coords.toCompressedJson()),
185
215
  verticesIds: this.vertices.map((vertex) => vertex.id),
186
216
  edges: this.edges.map((edge) => {
187
217
  const vertex1Idx = this.vertices.indexOf(edge.vertex1);
@@ -194,8 +224,9 @@ class Graph {
194
224
  })
195
225
  };
196
226
  }
227
+ /** @deprecated */
197
228
  static fromCompressedJson(json) {
198
- const vertices = json.vertices.map((vertex) => Vertex.fromJson(vertex));
229
+ const vertices = json.vertices.map((vertex) => new Vertex(geo.Coordinates.fromCompressedJson(vertex)));
199
230
  const edges = json.edges.map((jsonEdge) => new Edge(
200
231
  vertices[jsonEdge[0]],
201
232
  vertices[jsonEdge[1]],
@@ -429,9 +460,6 @@ class StepsBuilder {
429
460
  ...levelChangeType && { type: levelChangeType }
430
461
  };
431
462
  }
432
- if (currentStep && currentStep.duration === 0) {
433
- delete currentStep.duration;
434
- }
435
463
  currentStep = {
436
464
  coords: currentCoords,
437
465
  ...stepName && { name: stepName },
@@ -443,9 +471,7 @@ class StepsBuilder {
443
471
  stepsInfo.push(currentStep);
444
472
  }
445
473
  currentStep.distance += currentCoords.distanceTo(nextCoords);
446
- if (duration) {
447
- currentStep.duration += duration;
448
- }
474
+ currentStep.duration += duration;
449
475
  previousBearing = nextBearing;
450
476
  }
451
477
  const lastCoords = graphRoute.vertices[graphRoute.vertices.length - 1].coords;
@@ -2271,6 +2297,10 @@ const _GraphRouterOptionsBuilder = class _GraphRouterOptionsBuilder {
2271
2297
  let duration = getDurationFromLength(edge.length, 4);
2272
2298
  if (edge.properties.areStairs) {
2273
2299
  duration *= 3;
2300
+ } else if (edge.properties.areEscalators) {
2301
+ duration *= 1.5;
2302
+ } else if (edge.properties.isMovingWalkway) {
2303
+ duration *= 0.8;
2274
2304
  }
2275
2305
  return duration;
2276
2306
  };
@@ -2746,7 +2776,7 @@ const _OsmGraphUtils = class _OsmGraphUtils {
2746
2776
  })) == null ? void 0 : _a[1]) || null;
2747
2777
  if (vertex) {
2748
2778
  if (!geo.Level.equals(vertex.coords.level, nodeLevel)) {
2749
- vertex.coords.level = geo.Level.intersection(vertex.coords.level, nodeLevel);
2779
+ vertex.coords.level = geo.Level.intersection(vertex.coords.level, nodeLevel) || nodeLevel;
2750
2780
  }
2751
2781
  return vertex;
2752
2782
  }