@wemap/routers 11.0.2 → 11.1.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 +29 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/model/generateSteps.ts +13 -11
- package/src/wemap-osm/OsmRouter.ts +26 -14
package/dist/index.js
CHANGED
|
@@ -36,19 +36,20 @@ function generateSteps(leg, rules) {
|
|
|
36
36
|
const edgeLevel = geo.Level.union(currentCoords.level, nextCoords.level);
|
|
37
37
|
const nextBearing = currentCoords.bearingTo(nextCoords);
|
|
38
38
|
const angle = maths.diffAngle(previousBearing, nextBearing + Math.PI);
|
|
39
|
-
let splitByAngle = Math.abs(maths.diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
|
|
40
|
-
const splitByLevel = geo.Level.isRange(edgeLevel) && !geo.Level.isRange(currentCoords.level);
|
|
41
|
-
splitByAngle = splitByAngle && !(currentCoords.level && geo.Level.isRange(currentCoords.level));
|
|
42
39
|
const previousStep = steps.length ? steps[steps.length - 1] : null;
|
|
43
40
|
const customRules = rules == null ? void 0 : rules(currentCoords, nextCoords, previousStep);
|
|
44
|
-
|
|
41
|
+
let splitByAngle = Math.abs(maths.diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
|
|
42
|
+
const splitByLevel = geo.Level.isRange(edgeLevel) && !geo.Level.isRange(currentCoords.level) || (customRules == null ? void 0 : customRules.forceLevelChange);
|
|
43
|
+
splitByAngle = splitByAngle && !(currentCoords.level && geo.Level.isRange(currentCoords.level));
|
|
44
|
+
const splitByEndOfLevelChange = (previousStep == null ? void 0 : previousStep.levelChange) && !geo.Level.isRange(currentCoords.level) || (customRules == null ? void 0 : customRules.forceEndOfLevelChange);
|
|
45
|
+
const splitStepCondition = splitByAngle || splitByLevel || splitByEndOfLevelChange || (customRules == null ? void 0 : customRules.createNewStep);
|
|
45
46
|
if (isFirstStep || splitStepCondition) {
|
|
46
47
|
let levelChange;
|
|
47
|
-
if (splitByLevel
|
|
48
|
+
if (splitByLevel) {
|
|
48
49
|
const difference = geo.Level.diff(currentCoords.level, nextCoords.level) || 0;
|
|
49
50
|
let direction = difference > 0 ? "up" : "down";
|
|
50
|
-
if (
|
|
51
|
-
direction = customRules.
|
|
51
|
+
if (customRules == null ? void 0 : customRules.forceLevelChange) {
|
|
52
|
+
direction = customRules == null ? void 0 : customRules.forceLevelChange;
|
|
52
53
|
}
|
|
53
54
|
levelChange = { difference, direction, type: customRules == null ? void 0 : customRules.levelChangeType };
|
|
54
55
|
}
|
|
@@ -700,7 +701,16 @@ let OsmGraph = _OsmGraph;
|
|
|
700
701
|
__publicField(OsmGraph, "HIGHWAYS_PEDESTRIANS", HIGHWAYS_PEDESTRIANS);
|
|
701
702
|
__publicField(OsmGraph, "DEFAULT_WAY_SELECTOR", DEFAULT_WAY_SELECTOR);
|
|
702
703
|
const DEFAULT_OPTIONS = Object.assign({}, geo.GeoGraphRouter.DEFAULT_OPTIONS, {
|
|
703
|
-
weightEdgeFn: (edge) =>
|
|
704
|
+
weightEdgeFn: (edge) => {
|
|
705
|
+
if (edge.data.isElevator) {
|
|
706
|
+
return 90;
|
|
707
|
+
}
|
|
708
|
+
let duration = getDurationFromLength(edge.length, 4);
|
|
709
|
+
if (edge.data instanceof osm.OsmWay && edge.data.areStairs) {
|
|
710
|
+
duration *= 3;
|
|
711
|
+
}
|
|
712
|
+
return duration;
|
|
713
|
+
}
|
|
704
714
|
});
|
|
705
715
|
const WITHOUT_STAIRS_OPTIONS = Object.assign({}, DEFAULT_OPTIONS, {
|
|
706
716
|
acceptEdgeFn: (edge) => edge.data.tags.highway !== "steps"
|
|
@@ -730,10 +740,10 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
|
|
|
730
740
|
} else if (edge.data instanceof osm.OsmWay && edge.data.areStairs) {
|
|
731
741
|
levelChangeType = "stairs";
|
|
732
742
|
}
|
|
743
|
+
let forceLevelChange;
|
|
733
744
|
const edgeTags = edge.data.tags || {};
|
|
734
|
-
let levelChangeDirection = null;
|
|
735
745
|
if (edge.data instanceof osm.OsmWay && edge.data.areStairs && ["up", "down"].includes(edgeTags.incline) && !(previousStep == null ? void 0 : previousStep.levelChange)) {
|
|
736
|
-
|
|
746
|
+
forceLevelChange = edgeTags.incline;
|
|
737
747
|
for (const n of edge.data.nodes) {
|
|
738
748
|
if (n !== vertex.data)
|
|
739
749
|
continue;
|
|
@@ -745,10 +755,15 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
|
|
|
745
755
|
return acc;
|
|
746
756
|
}, null);
|
|
747
757
|
if (isReversed) {
|
|
748
|
-
|
|
758
|
+
forceLevelChange = forceLevelChange === "up" ? "down" : "up";
|
|
749
759
|
}
|
|
750
760
|
}
|
|
751
|
-
const
|
|
761
|
+
const previousEdge = edgeId > 0 && edges.length ? edges[edgeId - 1] : null;
|
|
762
|
+
const previousEdgeTags = (previousEdge == null ? void 0 : previousEdge.data.tags) || {};
|
|
763
|
+
const forceEndOfLevelChange = Boolean(
|
|
764
|
+
previousEdge && previousEdge.data instanceof osm.OsmWay && ["up", "down"].includes(previousEdgeTags.incline) && previousEdge.data.areStairs && edge.data instanceof osm.OsmWay && (!["up", "down"].includes(edgeTags.incline) || !edge.data.areStairs)
|
|
765
|
+
);
|
|
766
|
+
const createNewStep = isSubwayEntrance;
|
|
752
767
|
return {
|
|
753
768
|
createNewStep,
|
|
754
769
|
stepName: (_d = edge.data) == null ? void 0 : _d.tags.name,
|
|
@@ -759,7 +774,8 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
|
|
|
759
774
|
...isGate && { isGate: true }
|
|
760
775
|
},
|
|
761
776
|
...levelChangeType && { levelChangeType },
|
|
762
|
-
...
|
|
777
|
+
...forceLevelChange && { forceLevelChange },
|
|
778
|
+
...forceEndOfLevelChange && { forceEndOfLevelChange }
|
|
763
779
|
};
|
|
764
780
|
};
|
|
765
781
|
class WemapOsmRouter extends geo.GeoGraphRouter {
|