@wemap/routers 11.0.3 → 11.1.1

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.mjs CHANGED
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  import { Level, Coordinates, Utils, GeoGraph, GeoGraphEdge, GeoGraphVertex, GeoGraphRouter, GeoGraphItinerary, NoRouteFoundError, GeoGraphProjectionHandler } from "@wemap/geo";
8
8
  import { deg2rad, diffAngle, rad2deg, positiveMod } from "@wemap/maths";
9
9
  import salesman from "@wemap/salesman.js";
10
- import { OsmNode, OsmWay, OsmParser } from "@wemap/osm";
10
+ import { OsmWay, OsmParser } from "@wemap/osm";
11
11
  import Logger from "@wemap/logger";
12
12
  import Polyline from "@mapbox/polyline";
13
13
  import pointInPolygon from "@turf/boolean-point-in-polygon";
@@ -28,19 +28,20 @@ function generateSteps(leg, rules) {
28
28
  const edgeLevel = Level.union(currentCoords.level, nextCoords.level);
29
29
  const nextBearing = currentCoords.bearingTo(nextCoords);
30
30
  const angle = diffAngle(previousBearing, nextBearing + Math.PI);
31
- let splitByAngle = Math.abs(diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
32
- const splitByLevel = Level.isRange(edgeLevel) && !Level.isRange(currentCoords.level);
33
- splitByAngle = splitByAngle && !(currentCoords.level && Level.isRange(currentCoords.level));
34
31
  const previousStep = steps.length ? steps[steps.length - 1] : null;
35
32
  const customRules = rules == null ? void 0 : rules(currentCoords, nextCoords, previousStep);
36
- const splitStepCondition = splitByAngle || splitByLevel || (customRules == null ? void 0 : customRules.createNewStep);
33
+ let splitByAngle = Math.abs(diffAngle(Math.PI, angle)) >= SKIP_STEP_ANGLE_MAX;
34
+ const splitByLevel = Level.isRange(edgeLevel) && !Level.isRange(currentCoords.level) || (customRules == null ? void 0 : customRules.forceLevelChange);
35
+ splitByAngle = splitByAngle && !(currentCoords.level && Level.isRange(currentCoords.level));
36
+ const splitByEndOfLevelChange = (previousStep == null ? void 0 : previousStep.levelChange) && !Level.isRange(currentCoords.level) || (customRules == null ? void 0 : customRules.forceEndOfLevelChange);
37
+ const splitStepCondition = splitByAngle || splitByLevel || splitByEndOfLevelChange || (customRules == null ? void 0 : customRules.createNewStep);
37
38
  if (isFirstStep || splitStepCondition) {
38
39
  let levelChange;
39
- if (splitByLevel || (customRules == null ? void 0 : customRules.levelChangeType)) {
40
+ if (splitByLevel) {
40
41
  const difference = Level.diff(currentCoords.level, nextCoords.level) || 0;
41
42
  let direction = difference > 0 ? "up" : "down";
42
- if (difference === 0 && (customRules == null ? void 0 : customRules.levelChangeDirection)) {
43
- direction = customRules.levelChangeDirection;
43
+ if (customRules == null ? void 0 : customRules.forceLevelChange) {
44
+ direction = customRules == null ? void 0 : customRules.forceLevelChange;
44
45
  }
45
46
  levelChange = { difference, direction, type: customRules == null ? void 0 : customRules.levelChangeType };
46
47
  }
@@ -693,7 +694,7 @@ __publicField(OsmGraph, "HIGHWAYS_PEDESTRIANS", HIGHWAYS_PEDESTRIANS);
693
694
  __publicField(OsmGraph, "DEFAULT_WAY_SELECTOR", DEFAULT_WAY_SELECTOR);
694
695
  const DEFAULT_OPTIONS = Object.assign({}, GeoGraphRouter.DEFAULT_OPTIONS, {
695
696
  weightEdgeFn: (edge) => {
696
- if (edge.data instanceof OsmNode && edge.data.isElevator) {
697
+ if (edge.data.isElevator) {
697
698
  return 90;
698
699
  }
699
700
  let duration = getDurationFromLength(edge.length, 4);
@@ -731,10 +732,10 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
731
732
  } else if (edge.data instanceof OsmWay && edge.data.areStairs) {
732
733
  levelChangeType = "stairs";
733
734
  }
735
+ let forceLevelChange;
734
736
  const edgeTags = edge.data.tags || {};
735
- let levelChangeDirection = null;
736
737
  if (edge.data instanceof OsmWay && edge.data.areStairs && ["up", "down"].includes(edgeTags.incline) && !(previousStep == null ? void 0 : previousStep.levelChange)) {
737
- levelChangeDirection = edgeTags.incline;
738
+ forceLevelChange = edgeTags.incline;
738
739
  for (const n of edge.data.nodes) {
739
740
  if (n !== vertex.data)
740
741
  continue;
@@ -746,10 +747,15 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
746
747
  return acc;
747
748
  }, null);
748
749
  if (isReversed) {
749
- levelChangeDirection = levelChangeDirection === "up" ? "down" : "up";
750
+ forceLevelChange = forceLevelChange === "up" ? "down" : "up";
750
751
  }
751
752
  }
752
- const createNewStep = isSubwayEntrance || levelChangeDirection;
753
+ const previousEdge = edgeId > 0 && edges.length ? edges[edgeId - 1] : null;
754
+ const previousEdgeTags = (previousEdge == null ? void 0 : previousEdge.data.tags) || {};
755
+ const forceEndOfLevelChange = Boolean(
756
+ previousEdge && previousEdge.data instanceof OsmWay && ["up", "down"].includes(previousEdgeTags.incline) && previousEdge.data.areStairs && edge.data instanceof OsmWay && (!["up", "down"].includes(edgeTags.incline) || !edge.data.areStairs)
757
+ );
758
+ const createNewStep = isSubwayEntrance;
753
759
  return {
754
760
  createNewStep,
755
761
  stepName: (_d = edge.data) == null ? void 0 : _d.tags.name,
@@ -760,7 +766,8 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
760
766
  ...isGate && { isGate: true }
761
767
  },
762
768
  ...levelChangeType && { levelChangeType },
763
- ...levelChangeDirection && { levelChangeDirection }
769
+ ...forceLevelChange && { forceLevelChange },
770
+ ...forceEndOfLevelChange && { forceEndOfLevelChange }
764
771
  };
765
772
  };
766
773
  class WemapOsmRouter extends GeoGraphRouter {
@@ -1423,7 +1430,8 @@ class OsrmRemoteRouter extends RemoteRouter {
1423
1430
  });
1424
1431
  const from = waypoints[0];
1425
1432
  const to = waypoints[waypoints.length - 1];
1426
- return this.createRouterResponseFromJson(jsonResponse, from, to);
1433
+ const osrmMode = inputModeCorrespondance$1.get(mode);
1434
+ return this.createRouterResponseFromJson(jsonResponse, from, to, osrmMode);
1427
1435
  }
1428
1436
  getURL(endpointUrl, mode, waypoints) {
1429
1437
  const osrmMode = inputModeCorrespondance$1.get(mode);