mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(maps): stop the day route drawing drives to airports you flew from
A flight leaving overnight contributes only its departure airport on the day it leaves, and the evening hotel bookend was attaching to whatever point sat at the day's edge. So the map drew a straight line from the airport you took off from to the hotel you were checking into. The same blind spot on the run builder produced the long rays: a day's order is a bare wall clock, so an inbound long-haul whose departure clock reads late sorts after the day's local stops, and its far departure airport got appended to that run. OSRM answers such a pair with NoRoute and the fallback straightens the whole chunk, taking the genuine local drive with it. Both now ask whether the pair could be driven at all. A flight, train, ferry, cruise or coach carries you out of the day's geography, so its departure point has no drive back to tonight's hotel and its arrival point had no drive from this morning's. A hire car is the opposite and stays out of that set: you keep driving it, so a multi-day rental's pickup and drop-off points keep their hotel legs. Alongside it, any leg touching a booking endpoint has to be within MAX_DRIVE_KM, which catches the mis-sorted edges the role alone cannot see. The sidebar gets both guards so its hotel connectors stay in step with the drawn route; the mobile map and timeline read the same hook.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Straight-line distance between two coordinates, in kilometres.
|
||||
*
|
||||
* Lifted out of useTransportRoutes so the day-route builder can share the one
|
||||
* implementation instead of adding a fourth copy. The map overlays keep their own
|
||||
* `[lat, lng]`-tuple variants — different call shape, and they only sum arc lengths.
|
||||
*/
|
||||
export function haversineKm(a: { lat: number; lng: number }, b: { lat: number; lng: number }): number {
|
||||
const R = 6371
|
||||
const dLat = (b.lat - a.lat) * Math.PI / 180
|
||||
const dLng = (b.lng - a.lng) * Math.PI / 180
|
||||
const la1 = a.lat * Math.PI / 180
|
||||
const la2 = b.lat * Math.PI / 180
|
||||
const h = Math.sin(dLat / 2) ** 2 + Math.cos(la1) * Math.cos(la2) * Math.sin(dLng / 2) ** 2
|
||||
return 2 * R * Math.asin(Math.sqrt(h))
|
||||
}
|
||||
|
||||
/**
|
||||
* Beyond this straight-line distance a leg of a day's route is not a drive anyone
|
||||
* makes between two stops — it is a booking endpoint that landed next to a local
|
||||
* stop, and the road router answers such a pair with NoRoute (#2133). The same
|
||||
* 2000 km useTransportRoutes has always used for booking geometry.
|
||||
*
|
||||
* Deliberately only ever applied to a leg that touches a TRANSPORT endpoint. Two
|
||||
* real places 2000 km apart are a long drive someone planned; an airport 2000 km
|
||||
* from the stop before it never is.
|
||||
*/
|
||||
export const MAX_DRIVE_KM = 2000
|
||||
|
||||
/** Whether two points are close enough to plausibly be joined by a road leg. */
|
||||
export function withinDriveRange(a: { lat: number; lng: number }, b: { lat: number; lng: number }): boolean {
|
||||
return haversineKm(a, b) <= MAX_DRIVE_KM
|
||||
}
|
||||
Reference in New Issue
Block a user