From 610f36ae9c376cc38f2273f866e34b4598aff697 Mon Sep 17 00:00:00 2001 From: Chris Sherwood Date: Fri, 3 Apr 2026 13:14:33 -0700 Subject: [PATCH] feat(maps): add imperial/metric toggle for scale bar Defaults to metric for global audience. Persists choice in localStorage. Segmented button styled to match MapLibre controls. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../inertia/components/maps/MapComponent.tsx | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/admin/inertia/components/maps/MapComponent.tsx b/admin/inertia/components/maps/MapComponent.tsx index 5b53608..84e8f48 100644 --- a/admin/inertia/components/maps/MapComponent.tsx +++ b/admin/inertia/components/maps/MapComponent.tsx @@ -11,6 +11,9 @@ import maplibregl from 'maplibre-gl' import 'maplibre-gl/dist/maplibre-gl.css' import { Protocol } from 'pmtiles' import { useEffect, useRef, useState, useCallback } from 'react' + +type ScaleUnit = 'imperial' | 'metric' + import { useMapMarkers, PIN_COLORS } from '~/hooks/useMapMarkers' import type { PinColorId } from '~/hooks/useMapMarkers' import MarkerPin from './MarkerPin' @@ -23,6 +26,17 @@ export default function MapComponent() { const [markerName, setMarkerName] = useState('') const [markerColor, setMarkerColor] = useState('orange') const [selectedMarkerId, setSelectedMarkerId] = useState(null) + const [scaleUnit, setScaleUnit] = useState( + () => (localStorage.getItem('nomad:map-scale-unit') as ScaleUnit) || 'metric' + ) + + const toggleScaleUnit = useCallback(() => { + setScaleUnit((prev) => { + const next = prev === 'metric' ? 'imperial' : 'metric' + localStorage.setItem('nomad:map-scale-unit', next) + return next + }) + }, []) // Add the PMTiles protocol to maplibre-gl useEffect(() => { @@ -83,7 +97,45 @@ export default function MapComponent() { > - + +
+
+ + +
+
{/* Existing markers */} {markers.map((marker) => (