@wemap/routers 6.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/assets/bureaux-wemap-montpellier-network.osm +162 -0
- package/assets/gare-de-lyon-extract.osm +174 -0
- package/assets/itinerary-deutsche-bahn-1.json +368 -0
- package/assets/itinerary-grenoble-otp-1.json +1536 -0
- package/assets/itinerary-grenoble-otp-2.json +1092 -0
- package/assets/itinerary-lehavre-cityway-1.json +6799 -0
- package/assets/itinerary-lehavre-cityway-2.json +2133 -0
- package/assets/itinerary-lehavre-cityway-3.json +12577 -0
- package/assets/itinerary-lehavre-cityway-4.json +1451 -0
- package/assets/itinerary-lehavre-cityway-5.json +5925 -0
- package/assets/itinerary-montpellier-osrm-3.json +1 -0
- package/assets/itinerary-montpellier-outdoor-without-steps.json +110 -0
- package/assets/itinerary-montpellier-outdoor.json +513 -0
- package/assets/itinerary-with-duplicate-nodes.json +110 -0
- package/assets/network-conveying-backward.osm +74 -0
- package/assets/network-elevator.osm +48 -0
- package/assets/network-simple.osm +27 -0
- package/assets/network-with-modifiers.osm +39 -0
- package/assets/one-way.osm +46 -0
- package/dist/wemap-osm.es.js +2012 -0
- package/dist/wemap-osm.es.js.map +1 -0
- package/index.js +24 -0
- package/package.json +35 -0
- package/src/ItineraryInfoManager.js +148 -0
- package/src/ItineraryInfoManager.spec.js +54 -0
- package/src/Utils.js +64 -0
- package/src/cityway/CitywayUtils.js +240 -0
- package/src/cityway/CitywayUtils.spec.js +109 -0
- package/src/deutsche-bahn/DeutscheBahnRouterUtils.js +91 -0
- package/src/deutsche-bahn/DeutscheBahnRouterUtils.spec.js +54 -0
- package/src/model/Itinerary.js +197 -0
- package/src/model/Itinerary.type.spec.js +105 -0
- package/src/model/ItineraryInfo.js +34 -0
- package/src/model/Leg.js +113 -0
- package/src/model/LevelChange.js +65 -0
- package/src/model/RouterResponse.js +19 -0
- package/src/model/RouterResponse.type.spec.js +24 -0
- package/src/model/Step.js +118 -0
- package/src/osrm/OsrmUtils.js +269 -0
- package/src/osrm/OsrmUtils.spec.js +457 -0
- package/src/otp/OtpUtils.js +150 -0
- package/src/otp/OtpUtils.spec.js +97 -0
- package/src/wemap/WemapNetworkUtils.js +195 -0
- package/src/wemap/WemapNetworkUtils.spec.js +109 -0
- package/src/wemap/WemapRouter.js +27 -0
- package/src/wemap/WemapRouter.spec.js +221 -0
- package/src/wemap/WemapRouterOptions.js +32 -0
- package/src/wemap/WemapRouterUtils.js +46 -0
- package/src/wemap/WemapStepsGeneration.js +104 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { GraphItinerary } from '@wemap/geo';
|
|
2
|
+
import { OsmElement } from '@wemap/osm';
|
|
3
|
+
|
|
4
|
+
import Itinerary from '../model/Itinerary.js';
|
|
5
|
+
import Leg from '../model/Leg.js';
|
|
6
|
+
import WemapStepsGeneration from './WemapStepsGeneration.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {GraphItinerary<OsmElement>} graphItinerary
|
|
10
|
+
* @param {string} mode
|
|
11
|
+
* @returns {Leg}
|
|
12
|
+
*/
|
|
13
|
+
export function createLegFromGraphItinerary(graphItinerary, mode = 'WALK') {
|
|
14
|
+
|
|
15
|
+
const leg = new Leg();
|
|
16
|
+
|
|
17
|
+
leg.from = { coords: graphItinerary.start };
|
|
18
|
+
leg.to = { coords: graphItinerary.end };
|
|
19
|
+
leg.coords = graphItinerary.nodes.map(node => node.coords);
|
|
20
|
+
leg.distance = graphItinerary.edges.reduce((acc, edge) => acc + edge.length, 0);
|
|
21
|
+
leg.duration = graphItinerary.edgesWeights.reduce((acc, weight) => acc + weight, 0);
|
|
22
|
+
leg.mode = mode;
|
|
23
|
+
leg.steps = WemapStepsGeneration.fromGraphItinerary(graphItinerary);
|
|
24
|
+
|
|
25
|
+
return leg;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {GraphItinerary<OsmElement>} graphItinerary
|
|
30
|
+
* @param {string} mode
|
|
31
|
+
* @returns {Itinerary}
|
|
32
|
+
*/
|
|
33
|
+
export function createItineraryFromGraphItinerary(graphItinerary, mode = 'WALK') {
|
|
34
|
+
|
|
35
|
+
const leg = createLegFromGraphItinerary(graphItinerary, mode);
|
|
36
|
+
|
|
37
|
+
const itinerary = new Itinerary();
|
|
38
|
+
|
|
39
|
+
itinerary.from = graphItinerary.start;
|
|
40
|
+
itinerary.to = graphItinerary.end;
|
|
41
|
+
itinerary.distance = leg.distance;
|
|
42
|
+
itinerary.duration = leg.duration;
|
|
43
|
+
itinerary.legs.push(leg);
|
|
44
|
+
|
|
45
|
+
return itinerary;
|
|
46
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
/* eslint-disable max-statements */
|
|
3
|
+
import { Coordinates, GraphItinerary } from '@wemap/geo';
|
|
4
|
+
import { diffAngle, deg2rad } from '@wemap/maths';
|
|
5
|
+
import { OsmElement } from '@wemap/osm';
|
|
6
|
+
|
|
7
|
+
import LevelChange from '../model/LevelChange.js';
|
|
8
|
+
import Step from '../model/Step.js';
|
|
9
|
+
|
|
10
|
+
const SKIP_STEP_ANGLE_MAX = deg2rad(20);
|
|
11
|
+
|
|
12
|
+
class WemapStepsGeneration {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {GraphItinerary<OsmElement>} itinerary
|
|
16
|
+
* @returns {Step[]}
|
|
17
|
+
*/
|
|
18
|
+
static fromGraphItinerary(itinerary) {
|
|
19
|
+
|
|
20
|
+
const steps = [];
|
|
21
|
+
|
|
22
|
+
const { start, end, nodes, edges } = itinerary;
|
|
23
|
+
|
|
24
|
+
let currentStep, previousStep;
|
|
25
|
+
let previousBearing = start.bearingTo(nodes[0].coords);
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < nodes.length - 1; i++) {
|
|
28
|
+
|
|
29
|
+
const isFirstStep = !currentStep;
|
|
30
|
+
|
|
31
|
+
const node = nodes[i];
|
|
32
|
+
const nextNode = nodes[i + 1];
|
|
33
|
+
const edge = edges[i];
|
|
34
|
+
|
|
35
|
+
const bearing = edge.bearing;
|
|
36
|
+
const angle = diffAngle(previousBearing, bearing + Math.PI);
|
|
37
|
+
|
|
38
|
+
let splitByAngle = Math.abs(diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
|
|
39
|
+
|
|
40
|
+
const splitByLevel = edge.level && edge.level.isRange
|
|
41
|
+
&& node.coords.level && !node.coords.level.isRange;
|
|
42
|
+
splitByAngle = splitByAngle && !(node.coords.level && node.coords.level.isRange);
|
|
43
|
+
|
|
44
|
+
const splitStepCondition = splitByAngle || splitByLevel;
|
|
45
|
+
|
|
46
|
+
const isSubwayEntrance = node ? node.builtFrom.tags.railway === 'subway_entrance' : false;
|
|
47
|
+
|
|
48
|
+
// New step creation
|
|
49
|
+
if (isFirstStep || splitStepCondition || isSubwayEntrance) {
|
|
50
|
+
|
|
51
|
+
previousStep = currentStep;
|
|
52
|
+
|
|
53
|
+
currentStep = new Step();
|
|
54
|
+
currentStep.coords = node.coords;
|
|
55
|
+
currentStep.number = steps.length + 1;
|
|
56
|
+
currentStep.angle = angle;
|
|
57
|
+
currentStep.previousBearing = previousBearing;
|
|
58
|
+
currentStep.nextBearing = bearing;
|
|
59
|
+
currentStep.name = edge.builtFrom.tags.name || null;
|
|
60
|
+
currentStep.distance = 0;
|
|
61
|
+
currentStep.duration = 0;
|
|
62
|
+
|
|
63
|
+
if (isSubwayEntrance) {
|
|
64
|
+
currentStep.extras.subwayEntrance = true;
|
|
65
|
+
currentStep.name = node.builtFrom.tags.name;
|
|
66
|
+
if (node.builtFrom.tags.ref) {
|
|
67
|
+
currentStep.extras.subwayEntranceRef = node.builtFrom.tags.ref;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (splitByLevel) {
|
|
72
|
+
currentStep.levelChange = LevelChange.fromTwoNodes(node, nextNode);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
steps.push(currentStep);
|
|
76
|
+
|
|
77
|
+
if (!previousStep) {
|
|
78
|
+
currentStep.firstStep = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
currentStep.distance += edge.length;
|
|
83
|
+
currentStep.duration += itinerary.edgesWeights[i];
|
|
84
|
+
previousBearing = bearing;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const lastNode = nodes[nodes.length - 1];
|
|
88
|
+
const lastStep = new Step();
|
|
89
|
+
lastStep.coords = lastNode.coords;
|
|
90
|
+
lastStep.number = steps.length + 1;
|
|
91
|
+
lastStep.previousBearing = previousBearing;
|
|
92
|
+
lastStep.distance = lastNode.coords.distanceTo(end);
|
|
93
|
+
if (!Coordinates.equalsTo(lastNode.coords, end)) {
|
|
94
|
+
lastStep.nextBearing = lastNode.coords.bearingTo(end);
|
|
95
|
+
lastStep.angle = diffAngle(lastStep.previousBearing, lastStep.nextBearing + Math.PI);
|
|
96
|
+
}
|
|
97
|
+
lastStep.lastStep = true;
|
|
98
|
+
steps.push(lastStep);
|
|
99
|
+
|
|
100
|
+
return steps;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
export default WemapStepsGeneration;
|