Snap route-inserted waypoints to nearby POIs

When clicking on the route to insert a waypoint, the new point now
snaps to a nearby POI (within 50m) just like click-to-add and drag.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-04-11 02:06:40 +02:00
parent 246806cf1a
commit 14a2bd82fc
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -380,14 +380,18 @@ export function PlannerMap({ yjs, onRouteRequest, highlightPosition, highlighted
const insertWaypointAtSegment = useCallback(
(segmentIndex: number, lat: number, lon: number) => {
const snap = snapToPoi(lat, lon, poiState.pois);
yjs.doc.transact(() => {
const yMap = new Y.Map();
yMap.set("lat", lat);
yMap.set("lon", lon);
yMap.set("lat", snap.lat);
yMap.set("lon", snap.snapped ? snap.lon : lon);
if (snap.name) yMap.set("name", snap.name);
if (snap.osmId) yMap.set("osmId", snap.osmId);
if (snap.poiTags) yMap.set("poiTags", snap.poiTags);
yjs.waypoints.insert(segmentIndex + 1, [yMap]);
}, "local");
},
[yjs.doc, yjs.waypoints],
[yjs.doc, yjs.waypoints, poiState.pois],
);
const handleRouteInsert = useCallback(