mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
11f4c740e1
A router snaps every waypoint to the nearest road before it starts, and OSRM does it with no distance limit at all. A viewpoint above a valley, a farmhouse down a track, a marina at the end of a pier: the drive to it really begins somewhere else, and the line said nothing about that. It either stopped short for no visible reason or appeared to cut across open ground. OSRM reports the snap position and its distance in every single answer, and this client has thrown both away since the first route was drawn. Reading them costs no request and no key. The gap is drawn as a dashed spur in the route's own blue, over the route rather than under it, because it is the one piece of the line that is not driving. Thirty metres is the floor, which is about a dual carriageway and its verge, so a place pinned off an aerial photo does not earn a dash. From a quarter of a kilometre the rail prints the distance too, because that is where "the car park is over there" turns into luggage, a gate, or a track a hire car should not be on. Vias are deliberately left out: a via is a shape handle, not a destination, and a dash hanging off one reads as a fault.
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
import type { SnappedWaypoint } from '../../types'
|
|
|
|
/**
|
|
* The gap between a place and the road the drive actually reaches it from.
|
|
*
|
|
* A router snaps every waypoint to the nearest road before it starts, and OSRM does it
|
|
* with no distance limit. A place set back from the road is therefore driven to from
|
|
* somewhere else, and the line drawn for that drive begins at the somewhere else without
|
|
* saying so — which is what a viewpoint above a valley, a farmhouse down a track or a
|
|
* marina at the end of a pier all look like today: a route that stops short for no
|
|
* visible reason, or worse, one that appears to cut across open ground.
|
|
*
|
|
* Drawn as a dashed spur rather than hidden or silently absorbed, which is the same
|
|
* answer Google gives: the drive ends at the road, the rest is not driving, and the
|
|
* picture should say which is which.
|
|
*/
|
|
|
|
/**
|
|
* Below this, the gap is map precision rather than missing road.
|
|
*
|
|
* Thirty metres is roughly the width of a dual carriageway plus its verge, and a place
|
|
* pinned from an aerial photo lands that far from the centreline it belongs to all the
|
|
* time. Drawing those would put a dash on almost every stop and teach people to ignore
|
|
* the mark entirely.
|
|
*/
|
|
export const ACCESS_SPUR_MIN_M = 30
|
|
|
|
/**
|
|
* Above this, the spur is worth a number as well as a line.
|
|
*
|
|
* A quarter of a kilometre is where "the car park is over there" turns into something
|
|
* that changes the plan: a walk with luggage, a locked gate, a track a hire car should
|
|
* not be on. Below it the dash alone says enough.
|
|
*/
|
|
export const ACCESS_LABEL_MIN_M = 250
|
|
|
|
/** The two-point line from a place to the road it was routed from, or null if there is none worth drawing. */
|
|
export function spurFor(snapped: SnappedWaypoint | undefined | null): [[number, number], [number, number]] | null {
|
|
if (!snapped) return null
|
|
if (!(snapped.meters >= ACCESS_SPUR_MIN_M)) return null
|
|
return [snapped.asked, snapped.at]
|
|
}
|
|
|
|
/** Whether this gap is far enough that the rail should print the distance beside it. */
|
|
export function spurWorthLabelling(meters: number | null | undefined): boolean {
|
|
return typeof meters === 'number' && meters >= ACCESS_LABEL_MIN_M
|
|
}
|