Update routing to new navigation format
This commit is contained in:
parent
e696761f8e
commit
05d7faa725
|
@ -37,6 +37,11 @@ const parseTime = (time, reference) => {
|
|||
return result;
|
||||
};
|
||||
|
||||
/** List of OSM nodes that are stops. */
|
||||
const stopsSet = new Set(
|
||||
Object.values(network.stops).map(stop => stop.properties.node)
|
||||
);
|
||||
|
||||
/** Guess whether a stop comes directly before another one. */
|
||||
const isPenultimateStop = (stop, finalStop) => {
|
||||
// If there is a standard segment linking both stops, it’s certainly
|
||||
|
@ -53,8 +58,8 @@ const isPenultimateStop = (stop, finalStop) => {
|
|||
}
|
||||
|
||||
// If there is another stop in the way, it can’t be either
|
||||
for (const node of route.slice(1, -1)) {
|
||||
if (node in network.stops) {
|
||||
for (const nodeId of route.slice(1, -1)) {
|
||||
if (stopsSet.has(nodeId)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,14 +16,23 @@ for (const [beginId, begin] of Object.entries(network.navigation)) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Find the shortest path of nodes linking two nodes or stops.
|
||||
* @param {string} from ID of the starting stop or node.
|
||||
* @param {string} to ID of the ending stop or node.
|
||||
* @return {Array.<string>} If possible, list of nodes joining `from` to `to`.
|
||||
* Get the OSM ID of a stop.
|
||||
* @param {string} stopId Network ID of the stop.
|
||||
* @return {string} OSM ID of the stop.
|
||||
*/
|
||||
export const findPath = (from, to) => {
|
||||
export const stopToOSM = stopId => network.stops[stopId].properties.node;
|
||||
|
||||
/**
|
||||
* Find the shortest path of nodes linking two stops.
|
||||
* @param {string} fromStop Network ID of the starting stop.
|
||||
* @param {string} toStop Network ID of the ending stop.
|
||||
* @return {Array.<string>} If it exists, a path of nodes joining the two stops.
|
||||
*/
|
||||
export const findPath = (fromStop, toStop) => {
|
||||
try {
|
||||
return dijkstra.find_path(graph, from, to);
|
||||
return dijkstra.find_path(
|
||||
graph, stopToOSM(fromStop), stopToOSM(toStop)
|
||||
);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
|
@ -31,12 +40,12 @@ export const findPath = (from, to) => {
|
|||
|
||||
/**
|
||||
* Find the shortest segment linking two nodes or stops.
|
||||
* @param {string} from ID of the starting stop or node.
|
||||
* @param {string} to ID of the ending stop or node.
|
||||
* @return {LineString?} If it exists, a segment linking the two nodes.
|
||||
* @param {string} fromStop Network ID of the starting stop.
|
||||
* @param {string} toStop Network ID of the ending stop.
|
||||
* @return {LineString?} If it exists, a segment joining the two stops.
|
||||
*/
|
||||
export const findSegment = (from, to) => {
|
||||
const path = findPath(from, to);
|
||||
export const findSegment = (fromStop, toStop) => {
|
||||
const path = findPath(fromStop, toStop);
|
||||
|
||||
if (path === null) {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue