Stops, tracks and time windows: interpolation, honest ETA ranges, window status, deviation.
$ npx shadcn@latest add @highcommand/route-coreCopies the source into your project and pulls in what it needs (1 other item). First time? Add the registry to components.json.
measure(points: (LngLat | TrackPoint)[]): number[]Cumulative meters from the first point to each point.
bearing(a: LngLat, b: LngLat): numberInitial bearing from a to b, degrees clockwise from north in [0, 360).
positionAt(track: TrackPoint[], t: number, cumulative?: number[]): TrackPosition | nullPosition, heading and progress at time `t`, linearly interpolated between fixes. Clamps before the first and after the last fix. Pass a memoized `cumulative` (from `measure`) when calling every frame.
etaRange(eta: number, now: number, { spread, minSpreadMs, roundMs }?: EtaRangeOptions): TimeRangeAn honest ETA: a range that widens with distance-in-time and skews late (traffic delays more than it speeds up). Never starts before `now`; an overdue ETA is treated as "any minute now".
windowStatus(eta: TimeRange, window: TimeRange): WindowStatusHow an ETA range sits against a promised window. Late only when even the earliest arrival misses; at risk when the range straddles the window end.
delayMinutes(eta: number, promised: number): numberWhole minutes late (negative = early).
formatDelay(minutes: number): string"+12 min", "−3 min", "+1 h 05 min". Zero is "+0 min".
formatTimeRange(start: number, end: number, locale?: string | undefined): string"2:10 – 2:25 PM": shared AM/PM is written once (Intl formatRange).
formatDistance(meters: number, units?: "imperial" | "metric"): string"350 ft" / "1.2 mi" (imperial) or "420 m" / "1.2 km" (metric).
distanceToLine(p: LngLat, line: LngLat[]): numberShortest distance in meters from a point to a polyline.
deviation(planned: LngLat[], actual: LngLat[], thresholdMeters?: number): DeviationCompare the driven path with the planned one.
routeColor(i: number): stringColor for the i-th route from ROUTE_COLORS, wrapping around after 12.
Install this free piece now; the Pro pieces drop in on top of it, in the same app. Pro is $79 once.