From a81346894947ff825e32261a8597a76c4b7f5caf Mon Sep 17 00:00:00 2001 From: chriscrosstalk <49691103+chriscrosstalk@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:05:48 -0700 Subject: [PATCH] feat(maps): add imperial/metric toggle for scale bar (#641) 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 | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/admin/inertia/components/maps/MapComponent.tsx b/admin/inertia/components/maps/MapComponent.tsx index 5b53608..bac307d 100644 --- a/admin/inertia/components/maps/MapComponent.tsx +++ b/admin/inertia/components/maps/MapComponent.tsx @@ -11,6 +11,8 @@ 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 +25,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 +96,45 @@ export default function MapComponent() { > - + +
+
+ + +
+
{/* Existing markers */} {markers.map((marker) => (