@wemap/routers 12.6.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.
- package/dist/index.js +36 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/graph/Graph.ts +30 -6
- package/src/graph/Vertex.spec.ts +2 -1
- package/src/graph/Vertex.ts +11 -2
- package/src/model/StepsBuilder.ts +2 -8
- package/src/types.ts +20 -1
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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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;
|