mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
3238fbc517
The PDF export routed the whole trip under an 8 s deadline while the router is asked one leg at a time, a second apart. A cold month-long trip got about seven legs routed per export; the rest printed as straight lines at "0 m" under a total that looked final, and every further export routed a few more days from the device cache. The export now waits for every leg, bounded by the request pacing, the rate-limit retries and a per-leg timeout. The export dialog and the phone sheet count the legs while they route and offer to print without the rest. Any leg left without a road is marked in the document: the day reads "not routed" or "at least ...", the total says it is a floor, and a note names how many legs are missing. The planner overview shares the same wording. The PDF also routes what the planner map routes now: the road trip's vias, the multi-day tour stages and the reader's distance unit. Closes #2876
19 lines
936 B
TypeScript
19 lines
936 B
TypeScript
import type { DistanceUnit } from '../../types';
|
|
import { formatDistance } from '../../utils/units';
|
|
|
|
type Translate = (key: string, params?: Record<string, string | number>) => string;
|
|
|
|
/**
|
|
* A day's or the trip's distance as the overview panel and the PDF print it.
|
|
*
|
|
* A leg the router gave no road for is drawn straight and adds nothing to the sum, so a
|
|
* figure with such legs in it is a floor, and a figure made of nothing but such legs is
|
|
* no figure at all. "0 m" for a day of driving read as a measurement (#2876). One wording
|
|
* for the screen and the document, so the two cannot drift apart again.
|
|
*/
|
|
export function routeDistanceLabel(meters: number, unroutedLegs: number, unit: DistanceUnit, t: Translate): string {
|
|
const distance = formatDistance(meters / 1000, unit);
|
|
if (unroutedLegs <= 0) return distance;
|
|
return meters > 0 ? t('map.overview.distanceAtLeast', { distance }) : t('map.overview.notRouted');
|
|
}
|