@wemap/routers 12.0.0 → 12.2.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/assets/components.osm +146 -0
- package/dist/index.js +64 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -38
- package/dist/index.mjs.map +1 -1
- package/index.ts +0 -2
- package/package.json +2 -2
- package/src/graph/Edge.ts +3 -0
- package/src/graph/Graph.ts +2 -2
- package/src/graph/GraphRouter.ts +3 -1
- package/src/graph/GraphRouterEngine.ts +39 -32
- package/src/graph/Vertex.ts +1 -0
- package/src/model/Itinerary.ts +18 -14
- package/src/types.ts +1 -0
- package/src/wemap-multi/CustomNetworkMap.ts +0 -11
- package/src/wemap-osm/OsmGraphUtils.ts +5 -3
- package/src/wemap-osm/OsmRouter.spec.ts +25 -0
- package/src/wemap-osm/OsmRouterOptions.ts +0 -13
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
|
2
|
+
<osm version='0.6' generator='JOSM'>
|
|
3
|
+
<node id='-161218670596205' action='modify' visible='true' lat='45.19343691244' lon='5.71669745344' />
|
|
4
|
+
<node id='-161218670596206' action='modify' visible='true' lat='45.193278084' lon='5.71670229287' />
|
|
5
|
+
<node id='-161218670596207' action='modify' visible='true' lat='45.19328319976' lon='5.71704036911' />
|
|
6
|
+
<node id='-161218670596208' action='modify' visible='true' lat='45.19344202819' lon='5.71703552968' />
|
|
7
|
+
<node id='-161218670596209' action='modify' visible='true' lat='45.19339744873' lon='5.71676589717'>
|
|
8
|
+
<tag k='name' v='p1' />
|
|
9
|
+
</node>
|
|
10
|
+
<node id='-161218670596210' action='modify' visible='true' lat='45.19339817953' lon='5.71679735347'>
|
|
11
|
+
<tag k='name' v='p2' />
|
|
12
|
+
</node>
|
|
13
|
+
<node id='-161218670596211' action='modify' visible='true' lat='45.19337869139' lon='5.71679873616'>
|
|
14
|
+
<tag k='name' v='p3' />
|
|
15
|
+
</node>
|
|
16
|
+
<node id='-161218670596212' action='modify' visible='true' lat='45.19337747338' lon='5.71675656398'>
|
|
17
|
+
<tag k='name' v='p4' />
|
|
18
|
+
</node>
|
|
19
|
+
<node id='-161218670596215' action='modify' visible='true' lat='45.19340061555' lon='5.71685646366'>
|
|
20
|
+
<tag k='name' v='p21' />
|
|
21
|
+
</node>
|
|
22
|
+
<node id='-161218670596216' action='modify' visible='true' lat='45.19340232076' lon='5.71692594406'>
|
|
23
|
+
<tag k='name' v='p22' />
|
|
24
|
+
</node>
|
|
25
|
+
<node id='-161218670596217' action='modify' visible='true' lat='45.19336456249' lon='5.7169345859'>
|
|
26
|
+
<tag k='name' v='p31' />
|
|
27
|
+
</node>
|
|
28
|
+
<node id='-161218670596218' action='modify' visible='true' lat='45.19332436816' lon='5.71693562293'>
|
|
29
|
+
<tag k='highway' v='elevator' />
|
|
30
|
+
<tag k='name' v='p32' />
|
|
31
|
+
</node>
|
|
32
|
+
<node id='-161218670596219' action='modify' visible='true' lat='45.19332315015' lon='5.71686372281'>
|
|
33
|
+
<tag k='name' v='p33' />
|
|
34
|
+
</node>
|
|
35
|
+
<node id='-161218670596220' action='modify' visible='true' lat='45.19329367429' lon='5.71686441416'>
|
|
36
|
+
<tag k='name' v='p34' />
|
|
37
|
+
</node>
|
|
38
|
+
<node id='-161218670596221' action='modify' visible='true' lat='45.19334458713' lon='5.71673374952'>
|
|
39
|
+
<tag k='name' v='p11' />
|
|
40
|
+
</node>
|
|
41
|
+
<node id='-161218670596222' action='modify' visible='true' lat='45.19334531793' lon='5.71679355106'>
|
|
42
|
+
<tag k='name' v='p12' />
|
|
43
|
+
</node>
|
|
44
|
+
<node id='-161218670596223' action='modify' visible='true' lat='45.19331364967' lon='5.71679493375'>
|
|
45
|
+
<tag k='name' v='p13' />
|
|
46
|
+
</node>
|
|
47
|
+
<node id='-161218670596224' action='modify' visible='true' lat='45.19331145725' lon='5.71674342838'>
|
|
48
|
+
<tag k='name' v='p14' />
|
|
49
|
+
</node>
|
|
50
|
+
<node id='-161218670596225' action='modify' visible='true' lat='45.19340037195' lon='5.71697122731'>
|
|
51
|
+
<tag k='name' v='p41' />
|
|
52
|
+
</node>
|
|
53
|
+
<node id='-161218670596226' action='modify' visible='true' lat='45.19340158996' lon='5.71701478219'>
|
|
54
|
+
<tag k='name' v='p42' />
|
|
55
|
+
</node>
|
|
56
|
+
<node id='-161218670596227' action='modify' visible='true' lat='45.19337747338' lon='5.71701581921'>
|
|
57
|
+
<tag k='name' v='p43' />
|
|
58
|
+
</node>
|
|
59
|
+
<node id='-161218670596228' action='modify' visible='true' lat='45.19337771699' lon='5.71697295568'>
|
|
60
|
+
<tag k='name' v='p44' />
|
|
61
|
+
</node>
|
|
62
|
+
<node id='-161218670596230' action='modify' visible='true' lat='45.19334848476' lon='5.71697986915'>
|
|
63
|
+
<tag k='name' v='p48' />
|
|
64
|
+
</node>
|
|
65
|
+
<node id='-161218670596231' action='modify' visible='true' lat='45.19332241934' lon='5.7169805605'>
|
|
66
|
+
<tag k='name' v='p47' />
|
|
67
|
+
</node>
|
|
68
|
+
<node id='-161218670596232' action='modify' visible='true' lat='45.19332363736' lon='5.71702307836'>
|
|
69
|
+
<tag k='name' v='p46' />
|
|
70
|
+
</node>
|
|
71
|
+
<node id='-161218670596233' action='modify' visible='true' lat='45.19334945917' lon='5.71702065864'>
|
|
72
|
+
<tag k='name' v='p45' />
|
|
73
|
+
</node>
|
|
74
|
+
<way id='-921430905467925' action='modify' visible='true'>
|
|
75
|
+
<nd ref='-161218670596205' />
|
|
76
|
+
<nd ref='-161218670596206' />
|
|
77
|
+
<nd ref='-161218670596207' />
|
|
78
|
+
<nd ref='-161218670596208' />
|
|
79
|
+
<nd ref='-161218670596205' />
|
|
80
|
+
<tag k='wemap:routing-bounds' v='yes' />
|
|
81
|
+
</way>
|
|
82
|
+
<way id='-921430905467948' action='modify' visible='true'>
|
|
83
|
+
<nd ref='-161218670596209' />
|
|
84
|
+
<nd ref='-161218670596210' />
|
|
85
|
+
<nd ref='-161218670596211' />
|
|
86
|
+
<tag k='highway' v='footway' />
|
|
87
|
+
</way>
|
|
88
|
+
<way id='-921430905467953' action='modify' visible='true'>
|
|
89
|
+
<nd ref='-161218670596215' />
|
|
90
|
+
<nd ref='-161218670596216' />
|
|
91
|
+
<tag k='highway' v='footway' />
|
|
92
|
+
</way>
|
|
93
|
+
<way id='-921430905467954' action='modify' visible='true'>
|
|
94
|
+
<nd ref='-161218670596218' />
|
|
95
|
+
<nd ref='-161218670596219' />
|
|
96
|
+
<nd ref='-161218670596220' />
|
|
97
|
+
<tag k='highway' v='footway' />
|
|
98
|
+
<tag k='level' v='0' />
|
|
99
|
+
</way>
|
|
100
|
+
<way id='-921430905467957' action='modify' visible='true'>
|
|
101
|
+
<nd ref='-161218670596217' />
|
|
102
|
+
<nd ref='-161218670596218' />
|
|
103
|
+
<tag k='highway' v='footway' />
|
|
104
|
+
<tag k='level' v='1' />
|
|
105
|
+
</way>
|
|
106
|
+
<way id='-921430905467960' action='modify' visible='true'>
|
|
107
|
+
<nd ref='-161218670596221' />
|
|
108
|
+
<nd ref='-161218670596222' />
|
|
109
|
+
<nd ref='-161218670596223' />
|
|
110
|
+
<tag k='highway' v='footway' />
|
|
111
|
+
<tag k='level' v='0' />
|
|
112
|
+
</way>
|
|
113
|
+
<way id='-921430905467963' action='modify' visible='true'>
|
|
114
|
+
<nd ref='-161218670596225' />
|
|
115
|
+
<nd ref='-161218670596226' />
|
|
116
|
+
<nd ref='-161218670596227' />
|
|
117
|
+
<nd ref='-161218670596228' />
|
|
118
|
+
<nd ref='-161218670596225' />
|
|
119
|
+
<tag k='highway' v='footway' />
|
|
120
|
+
</way>
|
|
121
|
+
<way id='-921430905467967' action='modify' visible='true'>
|
|
122
|
+
<nd ref='-161218670596230' />
|
|
123
|
+
<nd ref='-161218670596231' />
|
|
124
|
+
<nd ref='-161218670596232' />
|
|
125
|
+
<nd ref='-161218670596233' />
|
|
126
|
+
<nd ref='-161218670596230' />
|
|
127
|
+
<tag k='highway' v='footway' />
|
|
128
|
+
</way>
|
|
129
|
+
<way id='-921430905467985' action='modify' visible='true'>
|
|
130
|
+
<nd ref='-161218670596233' />
|
|
131
|
+
<nd ref='-161218670596227' />
|
|
132
|
+
<tag k='highway' v='footway' />
|
|
133
|
+
<tag k='oneway' v='yes' />
|
|
134
|
+
</way>
|
|
135
|
+
<way id='-921430905468123' action='modify' visible='true'>
|
|
136
|
+
<nd ref='-161218670596223' />
|
|
137
|
+
<nd ref='-161218670596224' />
|
|
138
|
+
<tag k='highway' v='footway' />
|
|
139
|
+
<tag k='level' v='1' />
|
|
140
|
+
</way>
|
|
141
|
+
<way id='-921430905468128' action='modify' visible='true'>
|
|
142
|
+
<nd ref='-161218670596211' />
|
|
143
|
+
<nd ref='-161218670596212' />
|
|
144
|
+
<tag k='highway' v='footway' />
|
|
145
|
+
</way>
|
|
146
|
+
</osm>
|
package/dist/index.js
CHANGED
|
@@ -182,6 +182,7 @@ class Graph {
|
|
|
182
182
|
toCompressedJson() {
|
|
183
183
|
return {
|
|
184
184
|
vertices: this.vertices.map((vertex) => vertex.toJson()),
|
|
185
|
+
verticesIds: this.vertices.map((vertex) => vertex.id),
|
|
185
186
|
edges: this.edges.map((edge) => {
|
|
186
187
|
const vertex1Idx = this.vertices.indexOf(edge.vertex1);
|
|
187
188
|
const vertex2Idx = this.vertices.indexOf(edge.vertex2);
|
|
@@ -195,13 +196,11 @@ class Graph {
|
|
|
195
196
|
}
|
|
196
197
|
static fromCompressedJson(json) {
|
|
197
198
|
const vertices = json.vertices.map((vertex) => Vertex.fromJson(vertex));
|
|
198
|
-
const edges = json.edges.map(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
);
|
|
199
|
+
const edges = json.edges.map((jsonEdge) => new Edge(
|
|
200
|
+
vertices[jsonEdge[0]],
|
|
201
|
+
vertices[jsonEdge[1]],
|
|
202
|
+
jsonEdge.length > 2 ? jsonEdge[2] : {}
|
|
203
|
+
));
|
|
205
204
|
return new Graph(vertices, edges);
|
|
206
205
|
}
|
|
207
206
|
static fromCoordinatesSegments(segments) {
|
|
@@ -842,33 +841,37 @@ class Itinerary {
|
|
|
842
841
|
}
|
|
843
842
|
}
|
|
844
843
|
toGeoJson() {
|
|
845
|
-
const transformToPoint = (point, name) => ({
|
|
844
|
+
const transformToPoint = (point, name, type) => ({
|
|
846
845
|
type: "Feature",
|
|
847
|
-
properties: { name, level: point.level },
|
|
846
|
+
properties: { name, level: point.level, ...type && { type } },
|
|
848
847
|
geometry: {
|
|
849
848
|
type: "Point",
|
|
850
849
|
coordinates: [point.lng, point.lat]
|
|
851
850
|
}
|
|
852
851
|
});
|
|
853
|
-
const transformToMultiLineStrings = (segments, level) => {
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
};
|
|
862
|
-
};
|
|
852
|
+
const transformToMultiLineStrings = (segments, level) => ({
|
|
853
|
+
type: "Feature",
|
|
854
|
+
properties: { level, name: level == null ? void 0 : level.toString() },
|
|
855
|
+
geometry: {
|
|
856
|
+
type: "MultiLineString",
|
|
857
|
+
coordinates: segments.map((s) => s.map(({ lat, lng }) => [lng, lat]))
|
|
858
|
+
}
|
|
859
|
+
});
|
|
863
860
|
const levelsOfItinerary = [...new Set(this.coords.map((c) => geo.Level.toString(c.level)))].map(geo.Level.fromString);
|
|
864
861
|
const segmentsSplitted = levelsOfItinerary.map((loi) => [loi, geo.Utils.createSegmentsAtLevel(this.coords, loi, true)]);
|
|
865
862
|
const multiLineStrings = segmentsSplitted.map(([loi, segments]) => transformToMultiLineStrings(segments, loi));
|
|
863
|
+
const legsStarts = this.legs.map((leg, idx) => transformToPoint(leg.start.coords, `Leg ${idx} start`, "leg-start"));
|
|
864
|
+
const legsEnds = this.legs.map((leg, idx) => transformToPoint(leg.end.coords, `Leg ${idx} end`, "leg-end"));
|
|
865
|
+
const steps = this.steps.map((step) => transformToPoint(step.coords, `Step ${step.number}`, "step"));
|
|
866
866
|
return {
|
|
867
867
|
type: "FeatureCollection",
|
|
868
868
|
features: [
|
|
869
|
-
transformToPoint(this.origin, "origin"),
|
|
870
|
-
transformToPoint(this.destination, "destination"),
|
|
871
|
-
...multiLineStrings
|
|
869
|
+
transformToPoint(this.origin, "origin", "origin"),
|
|
870
|
+
transformToPoint(this.destination, "destination", "destination"),
|
|
871
|
+
...multiLineStrings,
|
|
872
|
+
...legsStarts,
|
|
873
|
+
...legsEnds,
|
|
874
|
+
...steps
|
|
872
875
|
]
|
|
873
876
|
};
|
|
874
877
|
}
|
|
@@ -1126,6 +1129,36 @@ class GraphRouterEngine {
|
|
|
1126
1129
|
calculateShortestPathByVertex(source, target, options = GraphRouterOptionsBuilder.DEFAULT, inputVertices = this.graph.vertices, inputEdges = this.graph.edges) {
|
|
1127
1130
|
return this.calculateShortestPathToMultipleDestinationsByVertex(source, [target], options, inputVertices, inputEdges);
|
|
1128
1131
|
}
|
|
1132
|
+
// https://en.wikipedia.org/wiki/Component_(graph_theory)
|
|
1133
|
+
calculateComponents() {
|
|
1134
|
+
function shiftSet(set) {
|
|
1135
|
+
const firstValue = set.values().next().value;
|
|
1136
|
+
set.delete(firstValue);
|
|
1137
|
+
return firstValue;
|
|
1138
|
+
}
|
|
1139
|
+
const verticesToTest = new Set(this.graph.vertices);
|
|
1140
|
+
let components = [];
|
|
1141
|
+
while (verticesToTest.size > 0) {
|
|
1142
|
+
const vertexToTest = shiftSet(verticesToTest);
|
|
1143
|
+
const otherVertices = this.graph.vertices.filter((v) => v.id !== vertexToTest.id);
|
|
1144
|
+
const result = this.calculateShortestPathToMultipleDestinationsByVertex(vertexToTest, otherVertices);
|
|
1145
|
+
const reachedVertices = otherVertices.filter((ov) => result.weightedDistance(ov) !== null);
|
|
1146
|
+
components.push([vertexToTest, ...reachedVertices]);
|
|
1147
|
+
reachedVertices.forEach((rv) => verticesToTest.delete(rv));
|
|
1148
|
+
}
|
|
1149
|
+
for (let i = 0; i < components.length - 1; i++) {
|
|
1150
|
+
const component1 = components[i];
|
|
1151
|
+
for (let j = i + 1; j < components.length; j++) {
|
|
1152
|
+
const component2 = components[j];
|
|
1153
|
+
const componentsIntersect = component2.some((v) => component1.includes(v));
|
|
1154
|
+
if (componentsIntersect) {
|
|
1155
|
+
component1.push(...component2);
|
|
1156
|
+
components = components.filter((component) => component !== component2);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return components.map((c) => [...new Set(c)]);
|
|
1161
|
+
}
|
|
1129
1162
|
}
|
|
1130
1163
|
class GraphRouterResults extends GraphRouterEngineResults {
|
|
1131
1164
|
constructor(engineResults, sourceProjection, targetsProjections) {
|
|
@@ -1205,12 +1238,14 @@ class GraphRouter extends GraphRouterEngine {
|
|
|
1205
1238
|
if (projection.nearestElement instanceof Edge) {
|
|
1206
1239
|
const edge = projection.nearestElement;
|
|
1207
1240
|
const newVertex = new Vertex(projection.coords, {
|
|
1208
|
-
name: `proj on ${edge.properties.name || null} (tmp)
|
|
1241
|
+
name: `proj on ${edge.properties.name || null} (tmp)`,
|
|
1242
|
+
...typeof edge.properties.externalId !== "undefined" && { externalId: edge.properties.externalId }
|
|
1209
1243
|
});
|
|
1210
1244
|
newVertex.id = this.graph.vertices.length + createdVertices.size;
|
|
1211
1245
|
const newEdgesOptions = {
|
|
1212
1246
|
...edge.properties,
|
|
1213
|
-
name: `splitted ${edge.properties.name || null} (tmp)
|
|
1247
|
+
name: `splitted ${edge.properties.name || null} (tmp)`,
|
|
1248
|
+
...typeof edge.properties.externalId !== "undefined" && { externalId: edge.properties.externalId }
|
|
1214
1249
|
};
|
|
1215
1250
|
const newEdge1 = new Edge(edge.vertex1, newVertex, newEdgesOptions);
|
|
1216
1251
|
const newEdge2 = new Edge(newVertex, edge.vertex2, newEdgesOptions);
|
|
@@ -1334,6 +1369,7 @@ const _OsmGraphUtils = class _OsmGraphUtils {
|
|
|
1334
1369
|
static parseNodeProperties(osmNode) {
|
|
1335
1370
|
return {
|
|
1336
1371
|
...osmNode.name && { name: osmNode.name },
|
|
1372
|
+
...osmNode.id && { externalId: osmNode.id },
|
|
1337
1373
|
...osmNode.isGate && { isGate: osmNode.isGate },
|
|
1338
1374
|
...osmNode.isSubwayEntrance && { isSubwayEntrance: osmNode.isSubwayEntrance },
|
|
1339
1375
|
...osmNode.subwayEntranceRef && { subwayEntrsanceRef: osmNode.subwayEntranceRef }
|
|
@@ -1342,6 +1378,7 @@ const _OsmGraphUtils = class _OsmGraphUtils {
|
|
|
1342
1378
|
static parseWayProperties(osmWay) {
|
|
1343
1379
|
return {
|
|
1344
1380
|
...osmWay.name && { name: osmWay.name },
|
|
1381
|
+
...osmWay.id && { externalId: osmWay.id },
|
|
1345
1382
|
...osmWay.isOneway && { isOneway: osmWay.isOneway },
|
|
1346
1383
|
...osmWay.areStairs && { areStairs: osmWay.areStairs },
|
|
1347
1384
|
...osmWay.isElevator && { isElevator: osmWay.isElevator },
|
|
@@ -1415,11 +1452,11 @@ const _OsmGraphUtils = class _OsmGraphUtils {
|
|
|
1415
1452
|
const elevatorCenterFakeOsmNode = new osm.OsmNode(fakeOsmNodeId--, elevatorCenterCoords, { highway: "elevator" });
|
|
1416
1453
|
entryVertices.forEach((entryVertex) => {
|
|
1417
1454
|
const vertexCenter = getOrCreateVertex(elevatorCenterFakeOsmNode, entryVertex.coords.level);
|
|
1418
|
-
edges.push(new Edge(vertexCenter, entryVertex));
|
|
1455
|
+
edges.push(new Edge(vertexCenter, entryVertex, { externalId: way.id }));
|
|
1419
1456
|
});
|
|
1420
1457
|
});
|
|
1421
|
-
elevatorVertices.forEach(([, name, verticesOfEachLevel]) => {
|
|
1422
|
-
const elevatorEdgeProps = { name, isElevator: true };
|
|
1458
|
+
elevatorVertices.forEach(([id, name, verticesOfEachLevel]) => {
|
|
1459
|
+
const elevatorEdgeProps = { name, isElevator: true, externalId: id };
|
|
1423
1460
|
for (let i = 0; i < verticesOfEachLevel.length; i++) {
|
|
1424
1461
|
for (let j = i + 1; j < verticesOfEachLevel.length; j++) {
|
|
1425
1462
|
edges.push(new Edge(verticesOfEachLevel[i], verticesOfEachLevel[j], elevatorEdgeProps));
|
|
@@ -2784,17 +2821,6 @@ class CustomNetworkMap {
|
|
|
2784
2821
|
getRoutesMultipleDestinationsInsideMap(start, ends, options) {
|
|
2785
2822
|
return this.router.calculateShortestPathToMultipleDestinations(start, ends, options);
|
|
2786
2823
|
}
|
|
2787
|
-
get disabledEdges() {
|
|
2788
|
-
return this.router.disabledEdges;
|
|
2789
|
-
}
|
|
2790
|
-
enableEdge(edgeId) {
|
|
2791
|
-
const edge = this.graph.edges.find((e) => e.id === edgeId);
|
|
2792
|
-
return Boolean(edge && this.router.disabledEdges.delete(edge));
|
|
2793
|
-
}
|
|
2794
|
-
disableEdge(edgeId) {
|
|
2795
|
-
const edge = this.graph.edges.find((e) => e.id === edgeId);
|
|
2796
|
-
return Boolean(edge && this.router.disabledEdges.add(edge));
|
|
2797
|
-
}
|
|
2798
2824
|
}
|
|
2799
2825
|
class ItineraryInfoManager {
|
|
2800
2826
|
constructor(itinerary = null) {
|