mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
1bc82f97fd
Paddle tours are planned on the water by TREK's own router: a water network per paddle region, built from the same Geofabrik extract as the obstacles and searched in a worker thread of the server (no sidecar). Rivers, canals and lakes (direct or along the shore), portages round weirs, locks by policy, whitewater by boat, gaps marked. Found portages and locks become points of their own; an unplannable leg says why and offers a way out. - Shaping points: a click on the line sets a point that steers the route without being a stop (hikes and paddle tours); recompute a single leg. - Lake style direct/shore, suggested from the wind forecast. - Regions load by themselves where a paddler plans (admin setting: automatic, on request, off; size cap and a daily count), with requests for the admins, a notification, and the load followed on the leg. - Portage from the last point, portages follow footways via the walking router (or stay straight), "put in here" on slipways and put-ins. - MCP plan_paddle_route with the REST route's rules.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { buildRegionGraph, type BuiltWaterGraph, WaterCollector } from '../paddle-routing/water-graph.contract';
|
|
import { extractPaddleFeatures, type ExtractedFeature } from './paddle-extract';
|
|
|
|
export type ImportPhase = 'read' | 'build';
|
|
|
|
export interface ImportOutcome {
|
|
timestamp: number | null;
|
|
features: ExtractedFeature[];
|
|
/** The region's water network for routing (PAD-11); null when the extract holds no water it routes on. */
|
|
graph: BuiltWaterGraph | null;
|
|
}
|
|
|
|
/**
|
|
* One region's read: its paddle obstacles and, from the same passes, the
|
|
* water network the router plans on. Pure work on a file, so it runs in a
|
|
* thread of its own and the server keeps answering meanwhile.
|
|
*/
|
|
export async function importExtract(
|
|
path: string,
|
|
regionId: string,
|
|
onProgress: (phase: ImportPhase, fraction: number | null) => void,
|
|
): Promise<ImportOutcome> {
|
|
let collector: WaterCollector | null = null;
|
|
const { timestamp, features, coordOf } = await extractPaddleFeatures(
|
|
path,
|
|
(fraction) => onProgress('read', fraction),
|
|
(want) => (collector = new WaterCollector(want)),
|
|
);
|
|
onProgress('build', null);
|
|
const sourceTimestamp = timestamp === null ? null : new Date(timestamp * 1000).toISOString();
|
|
const graph = collector ? buildRegionGraph(collector, coordOf, { regionId, sourceTimestamp }) : null;
|
|
return { timestamp, features, graph };
|
|
}
|