From 6983e2655bf3cb662dd99ee6470e8296ae58b85a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 20 Apr 2026 18:43:36 +0000 Subject: [PATCH] feat: switch to NA tileset + browser geolocation Swap tile source from idaho.pmtiles (427 MB, Idaho-only) to na.pmtiles (31 GB, CONUS + Canada + Mexico + Alaska). Replace MapLibre GeolocateControl with browser geolocation API that flies to user location on load and stores coordinates in Zustand for future use. Co-Authored-By: Claude Opus 4.6 --- src/components/MapView.jsx | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/components/MapView.jsx b/src/components/MapView.jsx index fc09269..52efb65 100644 --- a/src/components/MapView.jsx +++ b/src/components/MapView.jsx @@ -36,6 +36,10 @@ const MapView = forwardRef(function MapView({ onMapClick }, ref) { const protocol = new Protocol() maplibregl.addProtocol('pmtiles', protocol.tile) + // Default center: Matt's home (Filer, ID) — updated by geolocation if permitted + const DEFAULT_CENTER = [-114.6066, 42.5736] + const DEFAULT_ZOOM = 10 + const map = new maplibregl.Map({ container: mapRef.current, style: { @@ -45,25 +49,37 @@ const MapView = forwardRef(function MapView({ onMapClick }, ref) { sources: { protomaps: { type: 'vector', - url: 'pmtiles:///tiles/idaho.pmtiles', + url: 'pmtiles:///tiles/na.pmtiles', attribution: 'Protomaps | OSM', }, }, layers: layers('protomaps', namedTheme('dark'), { lang: 'en' }), }, - center: [-114.5, 44.0], - zoom: 6, + center: DEFAULT_CENTER, + zoom: DEFAULT_ZOOM, }) map.addControl(new maplibregl.NavigationControl(), 'top-right') - map.addControl( - new maplibregl.GeolocateControl({ - positionOptions: { enableHighAccuracy: true }, - trackUserLocation: false, - }), - 'top-right' - ) + + // Request geolocation for initial view (not for routing — that's separate) + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + (pos) => { + const { latitude, longitude } = pos.coords + // Only fly to user location if no stops have been added yet + if (useStore.getState().stops.length === 0) { + map.flyTo({ center: [longitude, latitude], zoom: 12, duration: 1500 }) + } + useStore.getState().setUserLocation({ lat: latitude, lon: longitude }) + useStore.getState().setGeoPermission('granted') + }, + () => { + useStore.getState().setGeoPermission('denied') + }, + { enableHighAccuracy: false, timeout: 8000, maximumAge: 300000 } + ) + } map.on('click', () => { // Mobile: collapse sheet when map is tapped