@wemap/routers 11.0.0-alpha.25 → 11.0.0-alpha.26
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 +69 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -23
- package/dist/index.mjs.map +1 -1
- package/helpers/InstructionManager.ts +4 -4
- package/package.json +4 -3
- package/src/wemap-multi/CustomNetworkMap.ts +5 -0
- package/src/wemap-multi/WemapMultiRouter.ts +67 -19
- package/src/wemap-multi/WemapMultiRouterOptions.ts +2 -0
- package/src/wemap-osm/OsmGraph.ts +8 -3
- package/src/wemap-osm/OsmRouter.ts +12 -3
package/dist/index.js
CHANGED
|
@@ -576,9 +576,9 @@ class RouterResponse {
|
|
|
576
576
|
const HIGHWAYS_PEDESTRIANS = ["footway", "steps", "pedestrian", "living_street", "path", "track", "sidewalk", "elevator"];
|
|
577
577
|
const DEFAULT_WAY_SELECTOR = (way) => {
|
|
578
578
|
const isElevatorArea = way.tags.highway === "elevator" && way.isArea;
|
|
579
|
-
return HIGHWAYS_PEDESTRIANS.includes(way.tags.highway) && !isElevatorArea || way.tags.footway === "sidewalk" || way.tags.public_transport === "platform" || way.tags.railway === "platform";
|
|
579
|
+
return HIGHWAYS_PEDESTRIANS.includes(way.tags.highway) && !isElevatorArea && !["no", "private"].includes(way.tags.access) || way.tags.footway === "sidewalk" || way.tags.public_transport === "platform" || way.tags.railway === "platform";
|
|
580
580
|
};
|
|
581
|
-
class
|
|
581
|
+
const _OsmGraph = class extends geo.GeoGraph {
|
|
582
582
|
getVertexByCoords(coords) {
|
|
583
583
|
return geo.GeoGraph.getVertexByCoords(this.vertices, coords);
|
|
584
584
|
}
|
|
@@ -617,7 +617,7 @@ class OsmGraph extends geo.GeoGraph {
|
|
|
617
617
|
secondNode,
|
|
618
618
|
{ data: way, name: way.tags.name, level: way.level }
|
|
619
619
|
);
|
|
620
|
-
|
|
620
|
+
_OsmGraph.manageOneWay(edge, way);
|
|
621
621
|
edges.push(edge);
|
|
622
622
|
firstNode = secondNode;
|
|
623
623
|
}
|
|
@@ -633,9 +633,9 @@ class OsmGraph extends geo.GeoGraph {
|
|
|
633
633
|
});
|
|
634
634
|
});
|
|
635
635
|
elevatorNodes.forEach((node) => {
|
|
636
|
-
|
|
636
|
+
_OsmGraph.createNodesAndEdgesFromElevator(nodes, edges, node);
|
|
637
637
|
});
|
|
638
|
-
return new
|
|
638
|
+
return new _OsmGraph(nodes, edges, true);
|
|
639
639
|
}
|
|
640
640
|
static manageOneWay(edge, way) {
|
|
641
641
|
const { highway, oneway, conveying } = way.tags;
|
|
@@ -695,7 +695,10 @@ class OsmGraph extends geo.GeoGraph {
|
|
|
695
695
|
nodes.splice(elevatorNodeIndex, 1);
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
|
-
}
|
|
698
|
+
};
|
|
699
|
+
let OsmGraph = _OsmGraph;
|
|
700
|
+
__publicField(OsmGraph, "HIGHWAYS_PEDESTRIANS", HIGHWAYS_PEDESTRIANS);
|
|
701
|
+
__publicField(OsmGraph, "DEFAULT_WAY_SELECTOR", DEFAULT_WAY_SELECTOR);
|
|
699
702
|
const DEFAULT_OPTIONS = Object.assign({}, geo.GeoGraphRouter.DEFAULT_OPTIONS, {
|
|
700
703
|
weightEdgeFn: (edge) => edge.data instanceof osm.OsmNode && edge.data.isElevator ? 30 : getDurationFromLength(edge.length)
|
|
701
704
|
});
|
|
@@ -807,9 +810,16 @@ class WemapOsmRouter extends geo.GeoGraphRouter {
|
|
|
807
810
|
for (let i = 0; i < orderedPoints.length - 1; i++) {
|
|
808
811
|
const p = orderedPoints[i];
|
|
809
812
|
const q = orderedPoints[i + 1];
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
+
let cachedItinerary = cache.find((itinerary) => itinerary.start === p.coords && itinerary.end === q.coords || itinerary.end === p.coords && itinerary.start === q.coords);
|
|
814
|
+
if (cachedItinerary.end === p.coords) {
|
|
815
|
+
cachedItinerary = geo.GeoGraphItinerary.fromGraphVertices(
|
|
816
|
+
cachedItinerary.end,
|
|
817
|
+
cachedItinerary.start,
|
|
818
|
+
cachedItinerary.vertices.reverse(),
|
|
819
|
+
cachedItinerary.edgesWeights
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
orderedItineraries.push(cachedItinerary);
|
|
813
823
|
}
|
|
814
824
|
return orderedItineraries;
|
|
815
825
|
}
|
|
@@ -1788,6 +1798,51 @@ class WemapMultiRouter {
|
|
|
1788
1798
|
removeIOMap(customNetworkMap) {
|
|
1789
1799
|
this.maps = this.maps.filter((map) => map !== customNetworkMap);
|
|
1790
1800
|
}
|
|
1801
|
+
getIoMapsFromOptions(options) {
|
|
1802
|
+
let ioMapsToTest = this.maps;
|
|
1803
|
+
const targetMaps = options == null ? void 0 : options.targetMaps;
|
|
1804
|
+
if (targetMaps) {
|
|
1805
|
+
ioMapsToTest = this.maps.filter((map) => map.name && targetMaps.includes(map.name));
|
|
1806
|
+
if (ioMapsToTest.length !== targetMaps.length) {
|
|
1807
|
+
ioMapsToTest.forEach((map) => {
|
|
1808
|
+
if (map.name && !targetMaps.includes(map.name)) {
|
|
1809
|
+
Logger__default.default.warn(`CustomNetworkMap "${map.name}" not found in WemapMultiRouter`);
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
return ioMapsToTest;
|
|
1815
|
+
}
|
|
1816
|
+
convertOptionsToWemapOsmOptions(options) {
|
|
1817
|
+
return !options || !("useStairs" in options) || options.useStairs ? WemapOsmRouter.DEFAULT_OPTIONS : WemapOsmRouter.WITHOUT_STAIRS_OPTIONS;
|
|
1818
|
+
}
|
|
1819
|
+
async getTrip(mode, waypoints, options = null) {
|
|
1820
|
+
const ioMapsToTest = this.getIoMapsFromOptions(options);
|
|
1821
|
+
if (waypoints.length < 2) {
|
|
1822
|
+
throw Error(`Cannot retrieve a trip itinerary. Two points or more are necessary`);
|
|
1823
|
+
}
|
|
1824
|
+
if (mode !== "WALK") {
|
|
1825
|
+
throw Error(`Cannot calculate trip itinerary for mode "${mode}". Only "WALK" is implemented.`);
|
|
1826
|
+
}
|
|
1827
|
+
const mapOfWaypoints = waypoints.reduce((map, waypoint) => {
|
|
1828
|
+
const mapOfThisWaypoint = ioMapsToTest.find((map2) => map2.isPointInside(waypoint));
|
|
1829
|
+
if (!mapOfThisWaypoint) {
|
|
1830
|
+
throw Error(`Cannot find a network for this trip waypoint (${waypoint.toString()}). Outdoor trips are not implemented.`);
|
|
1831
|
+
}
|
|
1832
|
+
if (map && mapOfThisWaypoint !== map) {
|
|
1833
|
+
throw Error(`Cannot handle this trip, because two waypoints are on different maps (${mapOfThisWaypoint} and ${mapOfWaypoints}). Multi-map trips are not implemented.`);
|
|
1834
|
+
}
|
|
1835
|
+
return mapOfThisWaypoint;
|
|
1836
|
+
}, null);
|
|
1837
|
+
const wemapOsmRouterOptions = this.convertOptionsToWemapOsmOptions(options);
|
|
1838
|
+
const tripItinerary = mapOfWaypoints.getTripInsideMap(waypoints, wemapOsmRouterOptions);
|
|
1839
|
+
return new RouterResponse({
|
|
1840
|
+
routerName: this.rname,
|
|
1841
|
+
from: tripItinerary.from,
|
|
1842
|
+
to: tripItinerary.to,
|
|
1843
|
+
itineraries: [tripItinerary]
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1791
1846
|
async getItineraries(mode, waypoints, options = null) {
|
|
1792
1847
|
var _a;
|
|
1793
1848
|
if (waypoints.length > 2) {
|
|
@@ -1801,18 +1856,7 @@ class WemapMultiRouter {
|
|
|
1801
1856
|
to: end
|
|
1802
1857
|
});
|
|
1803
1858
|
const remoteRouters2 = ((_a = options == null ? void 0 : options.remoteRouters) == null ? void 0 : _a.filter(({ name }) => name !== WemapMultiRemoteRouter$1.rname)) || [];
|
|
1804
|
-
|
|
1805
|
-
const targetMaps = options == null ? void 0 : options.targetMaps;
|
|
1806
|
-
if (targetMaps) {
|
|
1807
|
-
ioMapsToTest = this.maps.filter((map) => map.name && targetMaps.includes(map.name));
|
|
1808
|
-
if (ioMapsToTest.length !== targetMaps.length) {
|
|
1809
|
-
ioMapsToTest.forEach((map) => {
|
|
1810
|
-
if (map.name && !targetMaps.includes(map.name)) {
|
|
1811
|
-
Logger__default.default.warn(`CustomNetworkMap "${map.name}" not found in WemapMultiRouter`);
|
|
1812
|
-
}
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1859
|
+
const ioMapsToTest = this.getIoMapsFromOptions(options);
|
|
1816
1860
|
if (!ioMapsToTest.length) {
|
|
1817
1861
|
try {
|
|
1818
1862
|
return await RemoteRouterManager$1.getItinerariesWithFallback(remoteRouters2, mode, waypoints);
|
|
@@ -1826,7 +1870,7 @@ class WemapMultiRouter {
|
|
|
1826
1870
|
}
|
|
1827
1871
|
let ioMapItinerary;
|
|
1828
1872
|
const mapWithStart = ioMapsToTest.find((map) => map.isPointInside(start));
|
|
1829
|
-
const wemapOsmRouterOptions =
|
|
1873
|
+
const wemapOsmRouterOptions = this.convertOptionsToWemapOsmOptions(options);
|
|
1830
1874
|
if (mapWithStart && mapWithStart.isPointInside(end)) {
|
|
1831
1875
|
try {
|
|
1832
1876
|
ioMapItinerary = mapWithStart.getItineraryInsideMap(start, end, wemapOsmRouterOptions);
|
|
@@ -2056,6 +2100,9 @@ class CustomNetworkMap {
|
|
|
2056
2100
|
getItineraryInsideMap(start, end, options) {
|
|
2057
2101
|
return this.router.getItinerary(start, end, options);
|
|
2058
2102
|
}
|
|
2103
|
+
getTripInsideMap(waypoints, options) {
|
|
2104
|
+
return this.router.getTripItinerary(waypoints, options);
|
|
2105
|
+
}
|
|
2059
2106
|
enableWay(osmId) {
|
|
2060
2107
|
this.graph.edges.filter((edge) => edge.data.id === osmId).forEach((e) => this.router.disabledEdges.delete(e));
|
|
2061
2108
|
this.disabledWays.delete(osmId);
|