@wemap/routers 11.2.3 → 11.3.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/assets/itinerary-step-not-on-path-osrm.json +457 -0
- package/dist/index.js +147 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -90
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -0
- package/package.json +4 -4
- package/src/model/LevelChange.spec.ts +1 -0
- package/src/model/LevelChange.ts +2 -1
- package/src/remote/osrm/OsrmRemoteRouter.spec.ts +16 -0
- package/src/remote/osrm/OsrmRemoteRouter.ts +2 -3
- package/src/wemap-multi/CustomNetworkMap.ts +5 -5
- package/src/wemap-multi/WemapMultiRouter.ts +5 -8
- package/src/wemap-multi/WemapMultiRouterOptions.ts +2 -7
- package/src/wemap-osm/OsmGraph.ts +120 -61
- package/src/wemap-osm/OsmRouter.elevators.spec.ts +105 -0
- package/src/wemap-osm/OsmRouter.ts +61 -33
- package/src/wemap-osm/OsmRouterOptions.ts +12 -0
package/dist/index.mjs
CHANGED
|
@@ -582,53 +582,91 @@ const _OsmGraph = class extends GeoGraph {
|
|
|
582
582
|
return super.getEdgeByName(name);
|
|
583
583
|
}
|
|
584
584
|
static fromOsmModel(osmModel, waySelectionFilter = DEFAULT_WAY_SELECTOR) {
|
|
585
|
-
const
|
|
585
|
+
const vertices = [];
|
|
586
586
|
const edges = [];
|
|
587
|
-
const
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
587
|
+
const elevatorVertices = [];
|
|
588
|
+
const getOrCreateVertex = (osmNode, forceLevel = null) => {
|
|
589
|
+
let vertex = vertices.find(
|
|
590
|
+
(vertex2) => vertex2.data.id === osmNode.id && (forceLevel !== null ? Level.intersect(vertex2.coords.level, forceLevel) : true)
|
|
591
|
+
) || null;
|
|
592
|
+
if (vertex) {
|
|
593
|
+
return vertex;
|
|
594
|
+
}
|
|
595
|
+
if (vertices.find((v) => v.data.id === osmNode.id)) {
|
|
596
|
+
throw `An error occured because repeat_on as not been set on node ${osmNode.coords} for level ${forceLevel}`;
|
|
597
|
+
}
|
|
598
|
+
let levelsToGenerate = [null];
|
|
599
|
+
if ("level" in osmNode.tags) {
|
|
600
|
+
levelsToGenerate = [osmNode.coords.level];
|
|
601
|
+
if ("repeat_on" in osmNode.tags) {
|
|
602
|
+
levelsToGenerate.push(...osmNode.tags.repeat_on.split(";").map(Level.fromString));
|
|
603
|
+
}
|
|
604
|
+
} else if (forceLevel !== null) {
|
|
605
|
+
levelsToGenerate = [forceLevel];
|
|
606
|
+
}
|
|
607
|
+
levelsToGenerate.forEach((level) => {
|
|
608
|
+
const newVertex = new GeoGraphVertex(osmNode.coords.clone(), { data: osmNode, name: osmNode.tags.name });
|
|
609
|
+
newVertex.coords.level = level;
|
|
610
|
+
vertices.push(newVertex);
|
|
611
|
+
if (Level.intersect(newVertex.coords.level, forceLevel) || forceLevel === null && "level" in osmNode.tags) {
|
|
612
|
+
vertex = newVertex;
|
|
597
613
|
}
|
|
614
|
+
});
|
|
615
|
+
if (osmNode.tags.highway === "elevator" && vertex) {
|
|
616
|
+
elevatorVertices.push(vertex);
|
|
598
617
|
}
|
|
599
|
-
return
|
|
618
|
+
return vertex;
|
|
600
619
|
};
|
|
601
620
|
osmModel.ways.forEach((way) => {
|
|
602
621
|
if (!waySelectionFilter(way)) {
|
|
603
622
|
return;
|
|
604
623
|
}
|
|
605
|
-
let
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
{ data: way, name: way.tags.name, level: way.level }
|
|
612
|
-
);
|
|
613
|
-
_OsmGraph.manageOneWay(edge, way);
|
|
614
|
-
edges.push(edge);
|
|
615
|
-
firstNode = secondNode;
|
|
624
|
+
let levelsToGenerate = [null];
|
|
625
|
+
if ("level" in way.tags) {
|
|
626
|
+
levelsToGenerate = [way.level];
|
|
627
|
+
if ("repeat_on" in way.tags) {
|
|
628
|
+
levelsToGenerate.push(...way.tags.repeat_on.split(";").map(Level.fromString));
|
|
629
|
+
}
|
|
616
630
|
}
|
|
631
|
+
levelsToGenerate.forEach((level) => {
|
|
632
|
+
let firstVertex = getOrCreateVertex(way.nodes[0], level);
|
|
633
|
+
for (let i = 1; i < way.nodes.length; i++) {
|
|
634
|
+
const secondVertex = getOrCreateVertex(way.nodes[i], level);
|
|
635
|
+
const edge = new GeoGraphEdge(
|
|
636
|
+
firstVertex,
|
|
637
|
+
secondVertex,
|
|
638
|
+
{ data: way, name: way.tags.name, level }
|
|
639
|
+
);
|
|
640
|
+
_OsmGraph.manageOneWay(edge, way);
|
|
641
|
+
edges.push(edge);
|
|
642
|
+
firstVertex = secondVertex;
|
|
643
|
+
}
|
|
644
|
+
});
|
|
617
645
|
});
|
|
618
646
|
osmModel.ways.filter((way) => way.isElevator).forEach((way) => {
|
|
619
|
-
way.nodes.
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
647
|
+
const entryVertices = way.nodes.map((node) => vertices.filter((v) => v.data.id === node.id)).flat();
|
|
648
|
+
const elevatorLevel = entryVertices.reduce((acc, v) => Level.union(acc, v.coords.level), null);
|
|
649
|
+
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);
|
|
650
|
+
const elevatorCenterCoords = new Coordinates(elevatorCenter[0], elevatorCenter[1], null, elevatorLevel);
|
|
651
|
+
const elevatorCenterVertex = new GeoGraphVertex(elevatorCenterCoords, { data: way, name: way.tags.name });
|
|
652
|
+
vertices.push(elevatorCenterVertex);
|
|
653
|
+
entryVertices.forEach((entryVertex) => {
|
|
654
|
+
const newEdge = new GeoGraphEdge(
|
|
655
|
+
elevatorCenterVertex,
|
|
656
|
+
entryVertex,
|
|
657
|
+
{
|
|
658
|
+
level: Level.intersection(elevatorCenterVertex.coords.level, entryVertex.coords.level),
|
|
659
|
+
data: way
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
edges.push(newEdge);
|
|
626
663
|
});
|
|
664
|
+
elevatorVertices.push(elevatorCenterVertex);
|
|
627
665
|
});
|
|
628
|
-
|
|
629
|
-
_OsmGraph.createNodesAndEdgesFromElevator(
|
|
666
|
+
elevatorVertices.forEach((node) => {
|
|
667
|
+
_OsmGraph.createNodesAndEdgesFromElevator(vertices, edges, node);
|
|
630
668
|
});
|
|
631
|
-
return new _OsmGraph(
|
|
669
|
+
return new _OsmGraph(vertices, edges, true);
|
|
632
670
|
}
|
|
633
671
|
static manageOneWay(edge, way) {
|
|
634
672
|
const { highway, oneway, conveying } = way.tags;
|
|
@@ -639,81 +677,58 @@ const _OsmGraph = class extends GeoGraph {
|
|
|
639
677
|
edge.vertex2 = tmpNode;
|
|
640
678
|
}
|
|
641
679
|
}
|
|
642
|
-
static createNodesAndEdgesFromElevator(
|
|
643
|
-
const
|
|
680
|
+
static createNodesAndEdgesFromElevator(vertices, edges, elevatorVertex) {
|
|
681
|
+
const createdVertices = [];
|
|
644
682
|
const getOrCreateLevelVertex = (level) => {
|
|
645
|
-
let levelVertex =
|
|
683
|
+
let levelVertex = createdVertices.find(({ coords }) => Level.equals(level, coords.level));
|
|
646
684
|
if (!levelVertex) {
|
|
647
|
-
levelVertex = new GeoGraphVertex(
|
|
648
|
-
data:
|
|
649
|
-
name: `${
|
|
685
|
+
levelVertex = new GeoGraphVertex(elevatorVertex.coords.clone(), {
|
|
686
|
+
data: elevatorVertex.data,
|
|
687
|
+
name: `${elevatorVertex.name} (elevator lvl: ${level})`
|
|
650
688
|
});
|
|
651
689
|
levelVertex.coords.level = level;
|
|
652
|
-
|
|
653
|
-
|
|
690
|
+
createdVertices.push(levelVertex);
|
|
691
|
+
vertices.push(levelVertex);
|
|
654
692
|
}
|
|
655
693
|
return levelVertex;
|
|
656
694
|
};
|
|
657
|
-
|
|
695
|
+
elevatorVertex.edges.forEach((edge) => {
|
|
658
696
|
if (Level.isRange(edge.level)) {
|
|
659
697
|
throw new Error("Cannot handle this elevator edge due to ambiguity");
|
|
660
698
|
}
|
|
661
699
|
const levelVertex = getOrCreateLevelVertex(edge.level);
|
|
662
|
-
if (edge.vertex1 ===
|
|
700
|
+
if (edge.vertex1 === elevatorVertex) {
|
|
663
701
|
edge.vertex1 = levelVertex;
|
|
664
702
|
} else {
|
|
665
703
|
edge.vertex2 = levelVertex;
|
|
666
704
|
}
|
|
667
|
-
levelVertex.edges.push(edge);
|
|
668
705
|
});
|
|
669
|
-
for (let i = 0; i <
|
|
670
|
-
for (let j = i + 1; j <
|
|
671
|
-
const
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
706
|
+
for (let i = 0; i < createdVertices.length; i++) {
|
|
707
|
+
for (let j = i + 1; j < createdVertices.length; j++) {
|
|
708
|
+
const createdVertex1 = createdVertices[i];
|
|
709
|
+
const createdVertex2 = createdVertices[j];
|
|
710
|
+
if (createdVertex1.coords.level === null || createdVertex2.coords.level === null) {
|
|
674
711
|
continue;
|
|
675
712
|
}
|
|
676
|
-
const minLevel = Math.min(
|
|
677
|
-
const maxLevel = Math.max(
|
|
713
|
+
const minLevel = Math.min(createdVertex1.coords.level, createdVertex2.coords.level);
|
|
714
|
+
const maxLevel = Math.max(createdVertex1.coords.level, createdVertex2.coords.level);
|
|
678
715
|
const newEdge = new GeoGraphEdge(
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
{ data:
|
|
716
|
+
createdVertex1,
|
|
717
|
+
createdVertex2,
|
|
718
|
+
{ data: elevatorVertex.data, name: elevatorVertex.name, level: [minLevel, maxLevel] }
|
|
682
719
|
);
|
|
683
720
|
edges.push(newEdge);
|
|
684
721
|
}
|
|
685
722
|
}
|
|
686
|
-
const elevatorNodeIndex =
|
|
723
|
+
const elevatorNodeIndex = vertices.indexOf(elevatorVertex);
|
|
687
724
|
if (elevatorNodeIndex > -1) {
|
|
688
|
-
|
|
725
|
+
vertices.splice(elevatorNodeIndex, 1);
|
|
689
726
|
}
|
|
690
727
|
}
|
|
691
728
|
};
|
|
692
729
|
let OsmGraph = _OsmGraph;
|
|
693
730
|
__publicField(OsmGraph, "HIGHWAYS_PEDESTRIANS", HIGHWAYS_PEDESTRIANS);
|
|
694
731
|
__publicField(OsmGraph, "DEFAULT_WAY_SELECTOR", DEFAULT_WAY_SELECTOR);
|
|
695
|
-
const DEFAULT_OPTIONS = Object.assign({}, GeoGraphRouter.DEFAULT_OPTIONS, {
|
|
696
|
-
weightEdgeFn: (edge) => {
|
|
697
|
-
if (edge.data.isElevator) {
|
|
698
|
-
return 90;
|
|
699
|
-
}
|
|
700
|
-
let duration = getDurationFromLength(edge.length, 4);
|
|
701
|
-
if (edge.data instanceof OsmWay && edge.data.areStairs) {
|
|
702
|
-
duration *= 3;
|
|
703
|
-
}
|
|
704
|
-
return duration;
|
|
705
|
-
},
|
|
706
|
-
acceptEdgeFn: (edge) => {
|
|
707
|
-
const accessTag = edge.data.tags.access;
|
|
708
|
-
return typeof accessTag === "undefined" || accessTag === "yes";
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
const WITHOUT_STAIRS_OPTIONS = Object.assign({}, DEFAULT_OPTIONS, {
|
|
712
|
-
acceptEdgeFn: (edge) => edge.data.tags.highway !== "steps"
|
|
713
|
-
});
|
|
714
|
-
const DEFAULT_TRIP_OPTIONS = Object.assign({}, {
|
|
715
|
-
tspTempCoeff: 0.99
|
|
716
|
-
}, GeoGraphRouter.DEFAULT_OPTIONS);
|
|
717
732
|
const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previousStep) => {
|
|
718
733
|
var _a, _b, _c, _d, _e;
|
|
719
734
|
const edges = graphItinerary.edges;
|
|
@@ -731,10 +746,12 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
|
|
|
731
746
|
let levelChangeType = null;
|
|
732
747
|
if (edge.data.isElevator) {
|
|
733
748
|
levelChangeType = "elevator";
|
|
734
|
-
} else if (edge.data.isConveying) {
|
|
749
|
+
} else if (edge.data instanceof OsmWay && edge.data.isConveying && edge.data.areStairs) {
|
|
735
750
|
levelChangeType = "conveyor";
|
|
736
751
|
} else if (edge.data instanceof OsmWay && edge.data.areStairs) {
|
|
737
752
|
levelChangeType = "stairs";
|
|
753
|
+
} else if (edge.data instanceof OsmWay && edge.data.isConveying) {
|
|
754
|
+
levelChangeType = "moving walkway";
|
|
738
755
|
}
|
|
739
756
|
let forceLevelChange;
|
|
740
757
|
const edgeTags = edge.data.tags || {};
|
|
@@ -774,17 +791,17 @@ const buildStepsRules = (graphItinerary) => (currentCoords, nextCoords, previous
|
|
|
774
791
|
...forceEndOfLevelChange && { forceEndOfLevelChange }
|
|
775
792
|
};
|
|
776
793
|
};
|
|
777
|
-
class
|
|
794
|
+
const _WemapOsmRouter = class extends GeoGraphRouter {
|
|
778
795
|
constructor(graph) {
|
|
779
796
|
super(graph);
|
|
780
797
|
}
|
|
781
798
|
static get rname() {
|
|
782
799
|
return "wemap-osm";
|
|
783
800
|
}
|
|
784
|
-
getShortestPath(start, end, options = DEFAULT_OPTIONS) {
|
|
801
|
+
getShortestPath(start, end, options = _WemapOsmRouter.DEFAULT_OPTIONS) {
|
|
785
802
|
return super.getShortestPath(start, end, options);
|
|
786
803
|
}
|
|
787
|
-
getItinerary(start, end, options = DEFAULT_OPTIONS) {
|
|
804
|
+
getItinerary(start, end, options = _WemapOsmRouter.DEFAULT_OPTIONS) {
|
|
788
805
|
const graphItinerary = this.getShortestPath(start, end, options);
|
|
789
806
|
return Itinerary.fromGraphItinerary(graphItinerary, "WALK", buildStepsRules(graphItinerary));
|
|
790
807
|
}
|
|
@@ -804,7 +821,7 @@ class WemapOsmRouter extends GeoGraphRouter {
|
|
|
804
821
|
}
|
|
805
822
|
return { direction, directionExtra };
|
|
806
823
|
}
|
|
807
|
-
getShortestTrip(waypoints, options = DEFAULT_TRIP_OPTIONS) {
|
|
824
|
+
getShortestTrip(waypoints, options = _WemapOsmRouter.DEFAULT_TRIP_OPTIONS) {
|
|
808
825
|
const points = waypoints.map((waypoint) => {
|
|
809
826
|
const point = new salesman.Point(0, 0);
|
|
810
827
|
point.coords = waypoint;
|
|
@@ -838,7 +855,7 @@ class WemapOsmRouter extends GeoGraphRouter {
|
|
|
838
855
|
}
|
|
839
856
|
return orderedItineraries;
|
|
840
857
|
}
|
|
841
|
-
getTripItinerary(waypoints, options = DEFAULT_TRIP_OPTIONS) {
|
|
858
|
+
getTripItinerary(waypoints, options = _WemapOsmRouter.DEFAULT_TRIP_OPTIONS) {
|
|
842
859
|
const shortestTrip = this.getShortestTrip(waypoints, options);
|
|
843
860
|
return new Itinerary({
|
|
844
861
|
from: shortestTrip[0].start,
|
|
@@ -846,9 +863,49 @@ class WemapOsmRouter extends GeoGraphRouter {
|
|
|
846
863
|
legs: shortestTrip.map((graphItinerary) => Leg.fromGraphItinerary(graphItinerary))
|
|
847
864
|
});
|
|
848
865
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
866
|
+
static buildOptions(options) {
|
|
867
|
+
const weightEdgeFn = (edge) => {
|
|
868
|
+
var _a;
|
|
869
|
+
if ((_a = edge.data) == null ? void 0 : _a.isElevator) {
|
|
870
|
+
return 90;
|
|
871
|
+
}
|
|
872
|
+
let duration = getDurationFromLength(edge.length, 4);
|
|
873
|
+
if (edge.data instanceof OsmWay && edge.data.areStairs) {
|
|
874
|
+
duration *= 3;
|
|
875
|
+
}
|
|
876
|
+
return duration;
|
|
877
|
+
};
|
|
878
|
+
const acceptEdgeFn = (edge) => {
|
|
879
|
+
var _a, _b, _c;
|
|
880
|
+
const accessTag = (_b = (_a = edge.data) == null ? void 0 : _a.tags) == null ? void 0 : _b.access;
|
|
881
|
+
if (typeof accessTag !== "undefined" && accessTag !== "yes")
|
|
882
|
+
return false;
|
|
883
|
+
if (typeof (options == null ? void 0 : options.useStairs) !== "undefined" && !(options == null ? void 0 : options.useStairs) && edge.data instanceof OsmWay && edge.data.areStairs && !edge.data.isConveying)
|
|
884
|
+
return false;
|
|
885
|
+
if (typeof (options == null ? void 0 : options.useEscalator) !== "undefined" && !(options == null ? void 0 : options.useEscalator) && edge.data instanceof OsmWay && edge.data.areStairs && edge.data.isConveying)
|
|
886
|
+
return false;
|
|
887
|
+
if (typeof (options == null ? void 0 : options.useElevator) !== "undefined" && !(options == null ? void 0 : options.useElevator) && ((_c = edge.data) == null ? void 0 : _c.isElevator))
|
|
888
|
+
return false;
|
|
889
|
+
return true;
|
|
890
|
+
};
|
|
891
|
+
return {
|
|
892
|
+
weightEdgeFn,
|
|
893
|
+
acceptEdgeFn,
|
|
894
|
+
projectionMaxDistance: GeoGraphRouter.DEFAULT_OPTIONS.projectionMaxDistance
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
static buildTripOptions(options) {
|
|
898
|
+
return Object.assign(
|
|
899
|
+
{},
|
|
900
|
+
_WemapOsmRouter.buildOptions(options),
|
|
901
|
+
{ tspTempCoeff: 0.99 }
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
let WemapOsmRouter = _WemapOsmRouter;
|
|
906
|
+
__publicField(WemapOsmRouter, "DEFAULT_OPTIONS", _WemapOsmRouter.buildOptions());
|
|
907
|
+
__publicField(WemapOsmRouter, "WITHOUT_STAIRS_OPTIONS", _WemapOsmRouter.buildOptions({ useStairs: false }));
|
|
908
|
+
__publicField(WemapOsmRouter, "DEFAULT_TRIP_OPTIONS", _WemapOsmRouter.buildTripOptions());
|
|
852
909
|
class RemoteRouter {
|
|
853
910
|
}
|
|
854
911
|
class RemoteRouterServerUnreachable extends Error {
|
|
@@ -1592,7 +1649,7 @@ class OsrmRemoteRouter extends RemoteRouter {
|
|
|
1592
1649
|
throw new Error("Osrm Parser: Cannot find step coords in leg coordinates");
|
|
1593
1650
|
}
|
|
1594
1651
|
return {
|
|
1595
|
-
coords:
|
|
1652
|
+
coords: legCoords[idStepCoordsInLeg],
|
|
1596
1653
|
name,
|
|
1597
1654
|
distance,
|
|
1598
1655
|
duration
|
|
@@ -1850,8 +1907,8 @@ class WemapMultiRouter {
|
|
|
1850
1907
|
}
|
|
1851
1908
|
return ioMapsToTest;
|
|
1852
1909
|
}
|
|
1853
|
-
convertOptionsToWemapOsmOptions(options) {
|
|
1854
|
-
const outputOptions =
|
|
1910
|
+
convertOptionsToWemapOsmOptions(options = null) {
|
|
1911
|
+
const outputOptions = WemapOsmRouter.buildOptions(options ? options : {});
|
|
1855
1912
|
if (typeof (options == null ? void 0 : options.tspTempCoeff) !== "undefined") {
|
|
1856
1913
|
outputOptions.tspTempCoeff = options.tspTempCoeff;
|
|
1857
1914
|
}
|