From 502ae2b982bbb147f9a0be51e7c405f01e7feb2f Mon Sep 17 00:00:00 2001 From: "Tanner Collin (aider)" Date: Thu, 14 Aug 2025 23:01:02 +0000 Subject: [PATCH] feat: add checkbox to toggle direction arrows --- mapper/src/App.js | 72 +++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/mapper/src/App.js b/mapper/src/App.js index b2d18f7..b129cd8 100644 --- a/mapper/src/App.js +++ b/mapper/src/App.js @@ -130,7 +130,7 @@ function MapViewManager({ coords, mapState, setMapState, loading, setSubmenu }) return null; } -function PolylineWithArrows({ coords }) { +function PolylineWithArrows({ coords, showDirection }) { const map = useMap(); const polylineRef = useRef(null); const decoratorRef = useRef(null); @@ -148,25 +148,29 @@ function PolylineWithArrows({ coords }) { polylineRef.current = polyline; map.addLayer(polyline); - const decorator = leaflet.polylineDecorator(polyline, { - patterns: [ - { - offset: 25, - repeat: 100, - symbol: leaflet.Symbol.arrowHead({ - pixelSize: 15, - polygon: false, - pathOptions: { - stroke: true, - color: 'blue', - weight: 3 - } - }) - } - ] - }); - decoratorRef.current = decorator; - map.addLayer(decorator); + if (showDirection) { + const decorator = leaflet.polylineDecorator(polyline, { + patterns: [ + { + offset: 25, + repeat: 100, + symbol: leaflet.Symbol.arrowHead({ + pixelSize: 15, + polygon: false, + pathOptions: { + stroke: true, + color: 'blue', + weight: 3 + } + }) + } + ] + }); + decoratorRef.current = decorator; + map.addLayer(decorator); + } else { + decoratorRef.current = null; + } } return () => { @@ -177,12 +181,12 @@ function PolylineWithArrows({ coords }) { map.removeLayer(decoratorRef.current); } }; - }, [coords, map]); + }, [coords, map, showDirection]); return null; } -function Map({end, duration, slider, mapState, setMapState, setSubmenu}) { +function Map({end, duration, slider, mapState, setMapState, setSubmenu, showDirection}) { const [data, loading] = useSensor('owntracks', 'OwnTracks', end, duration); const range = useMemo(() => parseSlider(end, duration, slider), [end, duration, slider]); @@ -242,7 +246,7 @@ function Map({end, duration, slider, mapState, setMapState, setSubmenu}) { attribution='© OpenStreetMap contributors' url='https://maptiles.p.rapidapi.com/en/map/v1/{z}/{x}/{y}.png?rapidapi-key=4375b0b1d8msh0c9e7fa3efb9adfp1769dfjsnd603a0387fea' /> - + ) : @@ -259,7 +263,7 @@ function Map({end, duration, slider, mapState, setMapState, setSubmenu}) { ); } -function Menu({duration, setDuration, end, setEnd, slider, setSlider, submenu, setSubmenu}) { +function Menu({duration, setDuration, end, setEnd, slider, setSlider, submenu, setSubmenu, showDirection, setShowDirection}) { const [showRange, setShowRange] = useState(false); const chooseDuration = (x) => { @@ -427,6 +431,16 @@ function Menu({duration, setDuration, end, setEnd, slider, setSlider, submenu, s

Misc

+
+ +
} @@ -471,6 +485,7 @@ function App() { const initialLat = params.get('lat'); const initialLng = params.get('lng'); const initialZoom = params.get('zoom'); + const initialShowDirection = params.get('showDirection') === 'true'; const initialDuration = (initialDurationId && durations[parseInt(initialDurationId, 10)]) ? durations[parseInt(initialDurationId, 10)] : durations[0]; const initialEnd = initialEndTimestamp ? moment.unix(initialEndTimestamp) : moment(); @@ -484,6 +499,7 @@ function App() { zoom: initialZoom ? parseInt(initialZoom, 10) : 13, }); const [submenu, setSubmenu] = useState(false); + const [showDirection, setShowDirection] = useState(initialShowDirection); const isInitialMount = useRef(true); useEffect(() => { @@ -501,6 +517,9 @@ function App() { params.set('duration', duration.id); params.set('end', end.unix()); params.set('slider', slider.join(',')); + if (showDirection) { + params.set('showDirection', 'true'); + } if (mapState.center) { params.set('lat', mapState.center[0].toFixed(5)); params.set('lng', mapState.center[1].toFixed(5)); @@ -512,7 +531,7 @@ function App() { return () => { clearTimeout(handler); }; - }, [duration, end, slider, mapState]); + }, [duration, end, slider, mapState, showDirection]); return (
@@ -525,6 +544,8 @@ function App() { setSlider={setSlider} submenu={submenu} setSubmenu={setSubmenu} + showDirection={showDirection} + setShowDirection={setShowDirection} />
);