@wemap/routers 11.0.3 → 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 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
- const splitStepCondition = splitByAngle || splitByLevel || (customRules == null ? void 0 : customRules.createNewStep);
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 || (customRules == null ? void 0 : customRules.levelChangeType)) {
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 (difference === 0 && (customRules == null ? void 0 : customRules.levelChangeDirection)) {
51
- direction = customRules.levelChangeDirection;
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
  }
@@ -701,7 +702,7 @@ __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
704
  weightEdgeFn: (edge) => {
704
- if (edge.data instanceof osm.OsmNode && edge.data.isElevator) {
705
+ if (edge.data.isElevator) {
705
706
  return 90;
706
707
  }
707
708
  let duration = getDurationFromLength(edge.length, 4);
@@ -739,10 +740,10 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
739
740
  } else if (edge.data instanceof osm.OsmWay && edge.data.areStairs) {
740
741
  levelChangeType = "stairs";
741
742
  }
743
+ let forceLevelChange;
742
744
  const edgeTags = edge.data.tags || {};
743
- let levelChangeDirection = null;
744
745
  if (edge.data instanceof osm.OsmWay && edge.data.areStairs && ["up", "down"].includes(edgeTags.incline) && !(previousStep == null ? void 0 : previousStep.levelChange)) {
745
- levelChangeDirection = edgeTags.incline;
746
+ forceLevelChange = edgeTags.incline;
746
747
  for (const n of edge.data.nodes) {
747
748
  if (n !== vertex.data)
748
749
  continue;
@@ -754,10 +755,15 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
754
755
  return acc;
755
756
  }, null);
756
757
  if (isReversed) {
757
- levelChangeDirection = levelChangeDirection === "up" ? "down" : "up";
758
+ forceLevelChange = forceLevelChange === "up" ? "down" : "up";
758
759
  }
759
760
  }
760
- const createNewStep = isSubwayEntrance || levelChangeDirection;
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;
761
767
  return {
762
768
  createNewStep,
763
769
  stepName: (_d = edge.data) == null ? void 0 : _d.tags.name,
@@ -768,7 +774,8 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
768
774
  ...isGate && { isGate: true }
769
775
  },
770
776
  ...levelChangeType && { levelChangeType },
771
- ...levelChangeDirection && { levelChangeDirection }
777
+ ...forceLevelChange && { forceLevelChange },
778
+ ...forceEndOfLevelChange && { forceEndOfLevelChange }
772
779
  };
773
780
  };
774
781
  class WemapOsmRouter extends geo.GeoGraphRouter {