From f1938509d7c8b27b79d0d71d6f1f1e787e305626 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 17 Aug 2025 18:43:32 +0000 Subject: [PATCH] feat: Add 'Show points' checkbox to display polyline points Co-authored-by: aider (gemini/gemini-2.5-pro) --- mapper/src/App.js | 50 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/mapper/src/App.js b/mapper/src/App.js index 4450a42..d1c32c8 100644 --- a/mapper/src/App.js +++ b/mapper/src/App.js @@ -144,10 +144,11 @@ function MapViewManager({ coords, mapState, setMapState, loading, setSubmenu }) return null; } -function PolylineWithArrows({ coords, showDirection }) { +function PolylineWithArrows({ coords, showDirection, showPoints }) { const map = useMap(); const polylineRef = useRef(null); const decoratorRef = useRef(null); + const pointsLayerRef = useRef(null); useEffect(() => { if (polylineRef.current) { @@ -156,6 +157,9 @@ function PolylineWithArrows({ coords, showDirection }) { if (decoratorRef.current) { map.removeLayer(decoratorRef.current); } + if (pointsLayerRef.current) { + map.removeLayer(pointsLayerRef.current); + } if (coords && coords.length > 1) { const polyline = leaflet.polyline(coords, { color: 'blue' }); @@ -185,6 +189,21 @@ function PolylineWithArrows({ coords, showDirection }) { } else { decoratorRef.current = null; } + + if (showPoints) { + const points = coords.map(coord => leaflet.circleMarker(coord, { + color: 'red', + radius: 3, + weight: 1, + fillColor: 'red', + fillOpacity: 1 + })); + const pointsLayer = leaflet.layerGroup(points); + pointsLayerRef.current = pointsLayer; + map.addLayer(pointsLayer); + } else { + pointsLayerRef.current = null; + } } return () => { @@ -194,13 +213,16 @@ function PolylineWithArrows({ coords, showDirection }) { if (decoratorRef.current) { map.removeLayer(decoratorRef.current); } + if (pointsLayerRef.current) { + map.removeLayer(pointsLayerRef.current); + } }; - }, [coords, map, showDirection]); + }, [coords, map, showDirection, showPoints]); return null; } -function Map({data, loading, end, duration, slider, mapState, setMapState, setSubmenu, showDirection, setDrawnItems}) { +function Map({data, loading, end, duration, slider, mapState, setMapState, setSubmenu, showDirection, showPoints, setDrawnItems}) { const range = useMemo(() => parseSlider(end, duration, slider), [end, duration, slider]); const coords = useMemo(() => { @@ -296,7 +318,7 @@ function Map({data, loading, end, duration, slider, mapState, setMapState, setSu attribution='© OpenStreetMap contributors' url='https://maptiles.p.rapidapi.com/en/map/v1/{z}/{x}/{y}.png?rapidapi-key=4375b0b1d8msh0c9e7fa3efb9adfp1769dfjsnd603a0387fea' /> - + Show direction +