mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
fix(maps): say which engine drew a day and keep Valhalla days found while the relay rests
The route cache key followed the relay's rest, so after one failed relay request (always the case offline) every day the device held only from Valhalla missed the cache for ten minutes. The key now follows the configured provider, and a resting relay only stops the question from going out. A route now names the engine that drew it. A day OSRM drew because Valhalla could not answer is OSRM's on the rail, and its other ways are asked of OSRM, instead of being labelled Valhalla's and compared with Valhalla offers. An own Valhalla gets the relay's twelve second deadline, and a day that runs it out goes to OSRM without a second wait. A day that avoids something keeps its old cache key, so the days a device already holds stay found. The leg segment and the offer types move to modules both engines import.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useSettingsStore } from '../../store/settingsStore';
|
||||
import type { DistanceUnit } from '../../types';
|
||||
import type { DistanceUnit, RouteSegment, Waypoint } from '../../types';
|
||||
import { formatDistance } from '../../utils/units';
|
||||
|
||||
/** The unit a route's texts are written in, which is why it is part of the route cache key. */
|
||||
@@ -25,3 +25,28 @@ export function formatDuration(seconds: number): string {
|
||||
}
|
||||
return `${m} min`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The connector data for leg i of a routed chain, which runs from waypoint i to waypoint
|
||||
* i + 1: both ends, the midpoint the label sits on, and the walking time at 5 km/h next to
|
||||
* the time the engine measured. The same for every engine, so a day reads alike whichever
|
||||
* of them drew it.
|
||||
*/
|
||||
export function legSegment(
|
||||
leg: { distance: number; duration: number },
|
||||
i: number,
|
||||
waypoints: Waypoint[]
|
||||
): RouteSegment {
|
||||
const from: [number, number] = [waypoints[i].lat, waypoints[i].lng];
|
||||
const to: [number, number] = [waypoints[i + 1].lat, waypoints[i + 1].lng];
|
||||
return {
|
||||
mid: [(from[0] + to[0]) / 2, (from[1] + to[1]) / 2],
|
||||
from,
|
||||
to,
|
||||
distance: leg.distance,
|
||||
duration: leg.duration,
|
||||
walkingText: formatDuration(leg.distance / (5000 / 3600)),
|
||||
drivingText: formatDuration(leg.duration),
|
||||
distanceText: formatRouteDistance(leg.distance),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user