@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.
- package/assets/horizontal-elevator.osm +12 -0
- package/assets/itinerary-info-two-points-proj.osm +21 -15
- package/assets/itinerary-info-two-points.osm +2 -2
- package/dist/index.js +41 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/ItineraryInfoManager.spec.ts +30 -27
- package/src/ItineraryInfoManager.ts +43 -9
- package/src/RoutingError.ts +2 -2
- package/src/graph/GraphRoute.ts +1 -1
- package/src/model/Itinerary.ts +13 -15
- package/src/remote/cityway/CitywayRemoteRouter.spec.ts +1 -1
- package/src/remote/deutsche-bahn/DeutscheBahnRemoteRouter.spec.ts +2 -2
- package/src/remote/geovelo/GeoveloRemoteRouter.spec.ts +1 -1
- package/src/remote/osrm/OsrmRemoteRouter.spec.ts +1 -1
- package/src/wemap-multi/CustomGraphMap.ts +2 -1
- package/src/wemap-osm/OsmGraphUtils.spec.ts +12 -0
- package/src/wemap-osm/OsmGraphUtils.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -377,7 +377,7 @@ class GraphRoute extends Graph {
|
|
|
377
377
|
return new GraphRoute(start, end, graph.vertices, graph.edges, edgesWeights);
|
|
378
378
|
}
|
|
379
379
|
get hasRoute() {
|
|
380
|
-
return Boolean(this.
|
|
380
|
+
return Boolean(this.vertices.length);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
const SKIP_STEP_ANGLE_MAX = deg2rad(20);
|
|
@@ -708,7 +708,16 @@ class Itinerary {
|
|
|
708
708
|
this.origin = origin;
|
|
709
709
|
this.destination = destination;
|
|
710
710
|
this.legs = legs;
|
|
711
|
-
|
|
711
|
+
if (typeof duration === "number") {
|
|
712
|
+
this.duration = duration;
|
|
713
|
+
} else {
|
|
714
|
+
const firstCoords = this.legs[0].coords[0];
|
|
715
|
+
const lastLeg = this.legs[this.legs.length - 1];
|
|
716
|
+
const lastCoords = lastLeg.coords[lastLeg.coords.length - 1];
|
|
717
|
+
const originProjectionDuration = getDurationFromLength(this.origin.distanceTo(firstCoords));
|
|
718
|
+
const destinationProjectionDuration = getDurationFromLength(this.destination.distanceTo(lastCoords));
|
|
719
|
+
this.duration = this.legs.reduce((dur, leg) => dur + leg.duration, originProjectionDuration + destinationProjectionDuration);
|
|
720
|
+
}
|
|
712
721
|
this.startTime = typeof startTime === "number" ? startTime : null;
|
|
713
722
|
this.endTime = typeof endTime === "number" ? endTime : null;
|
|
714
723
|
this.updateStepsFromLegs();
|
|
@@ -755,7 +764,7 @@ class Itinerary {
|
|
|
755
764
|
}
|
|
756
765
|
get distance() {
|
|
757
766
|
if (this._distance === null) {
|
|
758
|
-
this._distance = Utils.calcDistance(this.coords);
|
|
767
|
+
this._distance = Utils.calcDistance([this.origin, ...this.coords, this.destination]);
|
|
759
768
|
}
|
|
760
769
|
return this._distance;
|
|
761
770
|
}
|
|
@@ -763,17 +772,10 @@ class Itinerary {
|
|
|
763
772
|
return Graph.fromCoordinatesSegments([this.coords]);
|
|
764
773
|
}
|
|
765
774
|
static fromItineraries(...itineraries) {
|
|
766
|
-
let duration = 0;
|
|
767
|
-
const legs = [];
|
|
768
|
-
itineraries.forEach((_itinerary) => {
|
|
769
|
-
duration += _itinerary.duration;
|
|
770
|
-
legs.push(..._itinerary.legs);
|
|
771
|
-
});
|
|
772
775
|
return new Itinerary({
|
|
773
776
|
origin: itineraries[0].origin,
|
|
774
777
|
destination: itineraries[itineraries.length - 1].destination,
|
|
775
|
-
|
|
776
|
-
legs
|
|
778
|
+
legs: itineraries.map((itinerary) => itinerary.legs).flat()
|
|
777
779
|
});
|
|
778
780
|
}
|
|
779
781
|
/**
|
|
@@ -843,7 +845,6 @@ class Itinerary {
|
|
|
843
845
|
return new Itinerary({
|
|
844
846
|
origin: graphRoute.start,
|
|
845
847
|
destination: graphRoute.end,
|
|
846
|
-
duration: leg.duration,
|
|
847
848
|
legs: [leg]
|
|
848
849
|
});
|
|
849
850
|
}
|
|
@@ -2830,7 +2831,7 @@ const _OsmGraphUtils = class _OsmGraphUtils {
|
|
|
2830
2831
|
}
|
|
2831
2832
|
});
|
|
2832
2833
|
let fakeOsmNodeId = -1;
|
|
2833
|
-
osmModel.ways.filter((way) => way.isElevator).forEach((way) => {
|
|
2834
|
+
osmModel.ways.filter((way) => way.isElevator && way.isGeometryClosed).forEach((way) => {
|
|
2834
2835
|
const entryVertices = way.nodes.map((node) => verticesMapping.filter(([osmId]) => osmId === node.id).map((vm) => vm[1])).flat();
|
|
2835
2836
|
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);
|
|
2836
2837
|
const elevatorLevel = entryVertices.reduce((acc, v) => Level.union(acc, v.coords.level), null);
|
|
@@ -2897,7 +2898,7 @@ class WemapMultiRoutingError extends RoutingError {
|
|
|
2897
2898
|
this.mapName = mapName;
|
|
2898
2899
|
}
|
|
2899
2900
|
static notFound(mapName, details) {
|
|
2900
|
-
return new WemapMultiRoutingError(StatusCode.NOT_FOUND, mapName, `Cannot found an itinerary in map ${mapName}. Details: ${details}`);
|
|
2901
|
+
return new WemapMultiRoutingError(StatusCode.NOT_FOUND, mapName, `Cannot found an itinerary in map ${mapName}. Details: ${details || "No details"}`);
|
|
2901
2902
|
}
|
|
2902
2903
|
}
|
|
2903
2904
|
class RemoteRoutingError extends RoutingError {
|
|
@@ -2908,7 +2909,7 @@ class RemoteRoutingError extends RoutingError {
|
|
|
2908
2909
|
this.routerName = routerName;
|
|
2909
2910
|
}
|
|
2910
2911
|
static notFound(routerName, details) {
|
|
2911
|
-
return new RemoteRoutingError(StatusCode.NOT_FOUND, routerName, `Cannot found an itinerary with ${routerName}. Details: ${details}`);
|
|
2912
|
+
return new RemoteRoutingError(StatusCode.NOT_FOUND, routerName, `Cannot found an itinerary with ${routerName}. Details: ${details || "No details"}`);
|
|
2912
2913
|
}
|
|
2913
2914
|
static missingApiKey(routerName, details) {
|
|
2914
2915
|
return new RemoteRoutingError(StatusCode.UNAUTHENTICATED, routerName, `API key is missing for ${routerName}. Details: ${details}`);
|
|
@@ -4753,7 +4754,8 @@ class CustomGraphMap {
|
|
|
4753
4754
|
return null;
|
|
4754
4755
|
}
|
|
4755
4756
|
getRouteInsideMap(start, end, options) {
|
|
4756
|
-
|
|
4757
|
+
const route = this.router.calculateShortestPath(start, end, options).route();
|
|
4758
|
+
return route.hasRoute ? route : null;
|
|
4757
4759
|
}
|
|
4758
4760
|
getTripInsideMap(waypoints, options) {
|
|
4759
4761
|
return this.router.getShortestTrip(waypoints, options);
|
|
@@ -4820,6 +4822,7 @@ class ItineraryInfoManager {
|
|
|
4820
4822
|
__publicField(this, "_coordsPreviousStep", []);
|
|
4821
4823
|
__publicField(this, "_coordsDistanceTraveled", []);
|
|
4822
4824
|
__publicField(this, "_coordsLeg", []);
|
|
4825
|
+
__publicField(this, "_itineraryDistanceWithoutProjections", 0);
|
|
4823
4826
|
this.itinerary = itinerary;
|
|
4824
4827
|
}
|
|
4825
4828
|
get itinerary() {
|
|
@@ -4837,6 +4840,9 @@ class ItineraryInfoManager {
|
|
|
4837
4840
|
this._coordsPreviousStep = new Array(itinerary.coords.length);
|
|
4838
4841
|
this._coordsDistanceTraveled = new Array(itinerary.coords.length);
|
|
4839
4842
|
this._coordsLeg = new Array(itinerary.coords.length);
|
|
4843
|
+
const originProjectionDistance = this._itinerary.origin.distanceTo(this._itinerary.coords[0]);
|
|
4844
|
+
const destinationProjectionDistance = this._itinerary.destination.distanceTo(this._itinerary.coords[this._itinerary.coords.length - 1]);
|
|
4845
|
+
this._itineraryDistanceWithoutProjections = itinerary.distance - originProjectionDistance - destinationProjectionDistance;
|
|
4840
4846
|
let stepId = 0;
|
|
4841
4847
|
let previousStep = null;
|
|
4842
4848
|
let nextStep = this._steps[0];
|
|
@@ -4872,17 +4878,22 @@ class ItineraryInfoManager {
|
|
|
4872
4878
|
if (idx === -1) {
|
|
4873
4879
|
throw new Error("ItineraryInfoManager: could not find projection in itinerary (Node)");
|
|
4874
4880
|
}
|
|
4875
|
-
const
|
|
4876
|
-
const
|
|
4881
|
+
const traveledDistanceOnItinerary = this._coordsDistanceTraveled[idx];
|
|
4882
|
+
const traveledDistance = traveledDistanceOnItinerary;
|
|
4883
|
+
const remainingDistanceOnItinerary = this._itineraryDistanceWithoutProjections - traveledDistanceOnItinerary;
|
|
4884
|
+
const remainingDistance = projection.distanceFromNearestElement + remainingDistanceOnItinerary;
|
|
4885
|
+
const distanceForPercentage = traveledDistance + remainingDistance;
|
|
4886
|
+
const traveledPercentage = traveledDistance / distanceForPercentage;
|
|
4887
|
+
const remainingPercentage = 1 - traveledPercentage;
|
|
4877
4888
|
itineraryInfo = {
|
|
4878
4889
|
nextStep: this._coordsNextStep[idx],
|
|
4879
4890
|
previousStep: this._coordsPreviousStep[idx],
|
|
4880
4891
|
projection,
|
|
4881
4892
|
leg: this._coordsLeg[idx],
|
|
4882
|
-
traveledDistance,
|
|
4893
|
+
traveledDistance: traveledDistanceOnItinerary,
|
|
4883
4894
|
remainingDistance,
|
|
4884
|
-
traveledPercentage
|
|
4885
|
-
remainingPercentage
|
|
4895
|
+
traveledPercentage,
|
|
4896
|
+
remainingPercentage
|
|
4886
4897
|
};
|
|
4887
4898
|
} else if (projection.nearestElement instanceof Edge) {
|
|
4888
4899
|
let firstNode = projection.nearestElement.vertex1.coords;
|
|
@@ -4894,8 +4905,13 @@ class ItineraryInfoManager {
|
|
|
4894
4905
|
firstNode = projection.nearestElement.vertex2.coords;
|
|
4895
4906
|
idx--;
|
|
4896
4907
|
}
|
|
4897
|
-
const
|
|
4898
|
-
const
|
|
4908
|
+
const traveledDistanceOnItinerary = this._coordsDistanceTraveled[idx] + projection.coords.distanceTo(firstNode);
|
|
4909
|
+
const traveledDistance = traveledDistanceOnItinerary;
|
|
4910
|
+
const remainingDistanceOnItinerary = this._itineraryDistanceWithoutProjections - traveledDistanceOnItinerary;
|
|
4911
|
+
const remainingDistance = projection.distanceFromNearestElement + remainingDistanceOnItinerary;
|
|
4912
|
+
const distanceForPercentage = traveledDistance + remainingDistance;
|
|
4913
|
+
const traveledPercentage = traveledDistance / distanceForPercentage;
|
|
4914
|
+
const remainingPercentage = 1 - traveledPercentage;
|
|
4899
4915
|
itineraryInfo = {
|
|
4900
4916
|
nextStep: this._coordsNextStep[idx + 1],
|
|
4901
4917
|
previousStep: this._coordsPreviousStep[idx + 1],
|
|
@@ -4903,8 +4919,8 @@ class ItineraryInfoManager {
|
|
|
4903
4919
|
leg: this._coordsLeg[idx + 1],
|
|
4904
4920
|
traveledDistance,
|
|
4905
4921
|
remainingDistance,
|
|
4906
|
-
traveledPercentage
|
|
4907
|
-
remainingPercentage
|
|
4922
|
+
traveledPercentage,
|
|
4923
|
+
remainingPercentage
|
|
4908
4924
|
};
|
|
4909
4925
|
}
|
|
4910
4926
|
return itineraryInfo;
|