@wemap/routers 12.8.10 → 12.9.2

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.
@@ -0,0 +1,12 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <osm version='0.6' generator='JOSM'>
3
+ <node id='-161218670344274' action='modify' visible='true' lat='48.84835435445' lon='2.39650479554' />
4
+ <node id='-161218670344470' action='modify' visible='true' lat='48.84826992031' lon='2.39687830076' />
5
+ <way id='-921430905723165' action='modify' visible='true'>
6
+ <nd ref='-161218670344470' />
7
+ <nd ref='-161218670344274' />
8
+ <tag k='highway' v='elevator' />
9
+ <tag k='incline' v='up' />
10
+ <tag k='level' v='-3' />
11
+ </way>
12
+ </osm>
@@ -1,32 +1,38 @@
1
1
  <?xml version='1.0' encoding='UTF-8'?>
2
2
  <osm version='0.6' generator='JOSM'>
3
- <node id='-441589' action='modify' visible='true' lat='43.60917006758' lon='3.88425549985'>
3
+ <node id='-1617378013972158' action='modify' visible='true' lat='43.60917006758' lon='3.88425549985'>
4
4
  <tag k='name' v='position 1' />
5
5
  </node>
6
- <node id='-441590' action='modify' visible='true' lat='43.60911942643' lon='3.88422017836'>
6
+ <node id='-1617378013972159' action='modify' visible='true' lat='43.60911942643' lon='3.88422017836'>
7
7
  <tag k='name' v='n2' />
8
8
  </node>
9
- <node id='-441591' action='modify' visible='true' lat='43.609172167' lon='3.88423552813'>
9
+ <node id='-1617378013972160' action='modify' visible='true' lat='43.609172167' lon='3.88423552813'>
10
10
  <tag k='name' v='n1' />
11
11
  </node>
12
- <node id='-441592' action='modify' visible='true' lat='43.60915386783' lon='3.88424424839'>
12
+ <node id='-1617378013972161' action='modify' visible='true' lat='43.60915386783' lon='3.88424424839'>
13
13
  <tag k='name' v='position 2' />
14
14
  </node>
15
- <node id='-441593' action='modify' visible='true' lat='43.60911497818' lon='3.88423496726'>
15
+ <node id='-1617378013972162' action='modify' visible='true' lat='43.60911497818' lon='3.88423496726'>
16
16
  <tag k='name' v='position 3' />
17
17
  </node>
18
- <node id='-441615' action='modify' visible='true' lat='43.60916653365' lon='3.88424386215'>
19
- <tag k='name' v='start' />
18
+ <node id='-1617378013972163' action='modify' visible='true' lat='43.60916653365' lon='3.88424386215'>
19
+ <tag k='name' v='origin' />
20
20
  </node>
21
- <node id='-441628' action='modify' visible='true' lat='43.60912432623' lon='3.88423287343'>
22
- <tag k='name' v='end' />
21
+ <node id='-1617378013972164' action='modify' visible='true' lat='43.60912432623' lon='3.88423287343'>
22
+ <tag k='name' v='destination' />
23
23
  </node>
24
- <node id='-441829' action='modify' visible='true' lat='43.60916799079' lon='3.88423431239' />
25
- <node id='-441831' action='modify' visible='true' lat='43.60912597253' lon='3.88422208376' />
26
- <node id='-442015' action='modify' visible='true' lat='43.6091464' lon='3.884228' />
27
- <way id='-441481' action='modify' visible='true'>
28
- <nd ref='-441591' />
29
- <nd ref='-441590' />
24
+ <node id='-1617378013972165' action='modify' visible='true' lat='43.60916799079' lon='3.88423431239'>
25
+ <tag k='name' v='porigin' />
26
+ </node>
27
+ <node id='-1617378013972166' action='modify' visible='true' lat='43.60912597256' lon='3.88422208356'>
28
+ <tag k='name' v='pdest' />
29
+ </node>
30
+ <node id='-1617378013972169' action='modify' visible='true' lat='43.60915590092' lon='3.884230794'>
31
+ <tag k='name' v='p2' />
32
+ </node>
33
+ <way id='-1617378013259620' action='modify' visible='true'>
34
+ <nd ref='-1617378013972160' />
35
+ <nd ref='-1617378013972159' />
30
36
  <tag k='highway' v='footway' />
31
37
  <tag k='name' v='w1' />
32
38
  </way>
@@ -4,10 +4,10 @@
4
4
  <tag k='name' v='position 1' />
5
5
  </node>
6
6
  <node id='-441312' action='modify' visible='true' lat='43.60911942643' lon='3.88422017836'>
7
- <tag k='name' v='end' />
7
+ <tag k='name' v='destination' />
8
8
  </node>
9
9
  <node id='-441313' action='modify' visible='true' lat='43.609172167' lon='3.88423552813'>
10
- <tag k='name' v='start' />
10
+ <tag k='name' v='origin' />
11
11
  </node>
12
12
  <node id='-441374' action='modify' visible='true' lat='43.6091434056' lon='3.88424362043'>
13
13
  <tag k='name' v='position 2' />
package/dist/index.js CHANGED
@@ -379,7 +379,7 @@ class GraphRoute extends Graph {
379
379
  return new GraphRoute(start, end, graph.vertices, graph.edges, edgesWeights);
380
380
  }
381
381
  get hasRoute() {
382
- return Boolean(this.edges.length);
382
+ return Boolean(this.vertices.length);
383
383
  }
384
384
  }
385
385
  const SKIP_STEP_ANGLE_MAX = maths.deg2rad(20);
@@ -710,7 +710,16 @@ class Itinerary {
710
710
  this.origin = origin;
711
711
  this.destination = destination;
712
712
  this.legs = legs;
713
- this.duration = typeof duration === "number" ? duration : this.legs.reduce((dur, leg) => dur + leg.duration, 0);
713
+ if (typeof duration === "number") {
714
+ this.duration = duration;
715
+ } else {
716
+ const firstCoords = this.legs[0].coords[0];
717
+ const lastLeg = this.legs[this.legs.length - 1];
718
+ const lastCoords = lastLeg.coords[lastLeg.coords.length - 1];
719
+ const originProjectionDuration = getDurationFromLength(this.origin.distanceTo(firstCoords));
720
+ const destinationProjectionDuration = getDurationFromLength(this.destination.distanceTo(lastCoords));
721
+ this.duration = this.legs.reduce((dur, leg) => dur + leg.duration, originProjectionDuration + destinationProjectionDuration);
722
+ }
714
723
  this.startTime = typeof startTime === "number" ? startTime : null;
715
724
  this.endTime = typeof endTime === "number" ? endTime : null;
716
725
  this.updateStepsFromLegs();
@@ -757,7 +766,7 @@ class Itinerary {
757
766
  }
758
767
  get distance() {
759
768
  if (this._distance === null) {
760
- this._distance = geo.Utils.calcDistance(this.coords);
769
+ this._distance = geo.Utils.calcDistance([this.origin, ...this.coords, this.destination]);
761
770
  }
762
771
  return this._distance;
763
772
  }
@@ -765,17 +774,10 @@ class Itinerary {
765
774
  return Graph.fromCoordinatesSegments([this.coords]);
766
775
  }
767
776
  static fromItineraries(...itineraries) {
768
- let duration = 0;
769
- const legs = [];
770
- itineraries.forEach((_itinerary) => {
771
- duration += _itinerary.duration;
772
- legs.push(..._itinerary.legs);
773
- });
774
777
  return new Itinerary({
775
778
  origin: itineraries[0].origin,
776
779
  destination: itineraries[itineraries.length - 1].destination,
777
- duration,
778
- legs
780
+ legs: itineraries.map((itinerary) => itinerary.legs).flat()
779
781
  });
780
782
  }
781
783
  /**
@@ -845,7 +847,6 @@ class Itinerary {
845
847
  return new Itinerary({
846
848
  origin: graphRoute.start,
847
849
  destination: graphRoute.end,
848
- duration: leg.duration,
849
850
  legs: [leg]
850
851
  });
851
852
  }
@@ -2832,7 +2833,7 @@ const _OsmGraphUtils = class _OsmGraphUtils {
2832
2833
  }
2833
2834
  });
2834
2835
  let fakeOsmNodeId = -1;
2835
- osmModel.ways.filter((way) => way.isElevator).forEach((way) => {
2836
+ osmModel.ways.filter((way) => way.isElevator && way.isGeometryClosed).forEach((way) => {
2836
2837
  const entryVertices = way.nodes.map((node) => verticesMapping.filter(([osmId]) => osmId === node.id).map((vm) => vm[1])).flat();
2837
2838
  const elevatorCenter = way.nodes.reduce((acc, node) => [acc[0] + node.coords.lat, acc[1] + node.coords.lng], [0, 0]).map((val) => val / way.nodes.length);
2838
2839
  const elevatorLevel = entryVertices.reduce((acc, v) => geo.Level.union(acc, v.coords.level), null);
@@ -2899,7 +2900,7 @@ class WemapMultiRoutingError extends RoutingError {
2899
2900
  this.mapName = mapName;
2900
2901
  }
2901
2902
  static notFound(mapName, details) {
2902
- return new WemapMultiRoutingError(StatusCode.NOT_FOUND, mapName, `Cannot found an itinerary in map ${mapName}. Details: ${details}`);
2903
+ return new WemapMultiRoutingError(StatusCode.NOT_FOUND, mapName, `Cannot found an itinerary in map ${mapName}. Details: ${details || "No details"}`);
2903
2904
  }
2904
2905
  }
2905
2906
  class RemoteRoutingError extends RoutingError {
@@ -2910,7 +2911,7 @@ class RemoteRoutingError extends RoutingError {
2910
2911
  this.routerName = routerName;
2911
2912
  }
2912
2913
  static notFound(routerName, details) {
2913
- return new RemoteRoutingError(StatusCode.NOT_FOUND, routerName, `Cannot found an itinerary with ${routerName}. Details: ${details}`);
2914
+ return new RemoteRoutingError(StatusCode.NOT_FOUND, routerName, `Cannot found an itinerary with ${routerName}. Details: ${details || "No details"}`);
2914
2915
  }
2915
2916
  static missingApiKey(routerName, details) {
2916
2917
  return new RemoteRoutingError(StatusCode.UNAUTHENTICATED, routerName, `API key is missing for ${routerName}. Details: ${details}`);
@@ -4755,7 +4756,8 @@ class CustomGraphMap {
4755
4756
  return null;
4756
4757
  }
4757
4758
  getRouteInsideMap(start, end, options) {
4758
- return this.router.calculateShortestPath(start, end, options).route();
4759
+ const route = this.router.calculateShortestPath(start, end, options).route();
4760
+ return route.hasRoute ? route : null;
4759
4761
  }
4760
4762
  getTripInsideMap(waypoints, options) {
4761
4763
  return this.router.getShortestTrip(waypoints, options);
@@ -4822,6 +4824,7 @@ class ItineraryInfoManager {
4822
4824
  __publicField(this, "_coordsPreviousStep", []);
4823
4825
  __publicField(this, "_coordsDistanceTraveled", []);
4824
4826
  __publicField(this, "_coordsLeg", []);
4827
+ __publicField(this, "_itineraryDistanceWithoutProjections", 0);
4825
4828
  this.itinerary = itinerary;
4826
4829
  }
4827
4830
  get itinerary() {
@@ -4839,6 +4842,9 @@ class ItineraryInfoManager {
4839
4842
  this._coordsPreviousStep = new Array(itinerary.coords.length);
4840
4843
  this._coordsDistanceTraveled = new Array(itinerary.coords.length);
4841
4844
  this._coordsLeg = new Array(itinerary.coords.length);
4845
+ const originProjectionDistance = this._itinerary.origin.distanceTo(this._itinerary.coords[0]);
4846
+ const destinationProjectionDistance = this._itinerary.destination.distanceTo(this._itinerary.coords[this._itinerary.coords.length - 1]);
4847
+ this._itineraryDistanceWithoutProjections = itinerary.distance - originProjectionDistance - destinationProjectionDistance;
4842
4848
  let stepId = 0;
4843
4849
  let previousStep = null;
4844
4850
  let nextStep = this._steps[0];
@@ -4874,17 +4880,22 @@ class ItineraryInfoManager {
4874
4880
  if (idx === -1) {
4875
4881
  throw new Error("ItineraryInfoManager: could not find projection in itinerary (Node)");
4876
4882
  }
4877
- const traveledDistance = this._coordsDistanceTraveled[idx];
4878
- const remainingDistance = this._itinerary.distance - traveledDistance;
4883
+ const traveledDistanceOnItinerary = this._coordsDistanceTraveled[idx];
4884
+ const traveledDistance = traveledDistanceOnItinerary;
4885
+ const remainingDistanceOnItinerary = this._itineraryDistanceWithoutProjections - traveledDistanceOnItinerary;
4886
+ const remainingDistance = projection.distanceFromNearestElement + remainingDistanceOnItinerary;
4887
+ const distanceForPercentage = traveledDistance + remainingDistance;
4888
+ const traveledPercentage = traveledDistance / distanceForPercentage;
4889
+ const remainingPercentage = 1 - traveledPercentage;
4879
4890
  itineraryInfo = {
4880
4891
  nextStep: this._coordsNextStep[idx],
4881
4892
  previousStep: this._coordsPreviousStep[idx],
4882
4893
  projection,
4883
4894
  leg: this._coordsLeg[idx],
4884
- traveledDistance,
4895
+ traveledDistance: traveledDistanceOnItinerary,
4885
4896
  remainingDistance,
4886
- traveledPercentage: traveledDistance / this._itinerary.distance,
4887
- remainingPercentage: remainingDistance / this._itinerary.distance
4897
+ traveledPercentage,
4898
+ remainingPercentage
4888
4899
  };
4889
4900
  } else if (projection.nearestElement instanceof Edge) {
4890
4901
  let firstNode = projection.nearestElement.vertex1.coords;
@@ -4896,8 +4907,13 @@ class ItineraryInfoManager {
4896
4907
  firstNode = projection.nearestElement.vertex2.coords;
4897
4908
  idx--;
4898
4909
  }
4899
- const traveledDistance = this._coordsDistanceTraveled[idx] + projection.coords.distanceTo(firstNode);
4900
- const remainingDistance = this._itinerary.distance - traveledDistance;
4910
+ const traveledDistanceOnItinerary = this._coordsDistanceTraveled[idx] + projection.coords.distanceTo(firstNode);
4911
+ const traveledDistance = traveledDistanceOnItinerary;
4912
+ const remainingDistanceOnItinerary = this._itineraryDistanceWithoutProjections - traveledDistanceOnItinerary;
4913
+ const remainingDistance = projection.distanceFromNearestElement + remainingDistanceOnItinerary;
4914
+ const distanceForPercentage = traveledDistance + remainingDistance;
4915
+ const traveledPercentage = traveledDistance / distanceForPercentage;
4916
+ const remainingPercentage = 1 - traveledPercentage;
4901
4917
  itineraryInfo = {
4902
4918
  nextStep: this._coordsNextStep[idx + 1],
4903
4919
  previousStep: this._coordsPreviousStep[idx + 1],
@@ -4905,8 +4921,8 @@ class ItineraryInfoManager {
4905
4921
  leg: this._coordsLeg[idx + 1],
4906
4922
  traveledDistance,
4907
4923
  remainingDistance,
4908
- traveledPercentage: traveledDistance / this._itinerary.distance,
4909
- remainingPercentage: remainingDistance / this._itinerary.distance
4924
+ traveledPercentage,
4925
+ remainingPercentage
4910
4926
  };
4911
4927
  }
4912
4928
  return itineraryInfo;