Controls and Mapbox Config Update

This commit is contained in:
2025-09-27 09:56:23 -04:00
parent ca5913678c
commit 775b1719f0
5 changed files with 99 additions and 31 deletions

View File

@@ -0,0 +1,32 @@
"use client";
import React, { useEffect } from 'react';
import mapboxgl from 'mapbox-gl';
type Position = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
interface Props {
mapRef: React.MutableRefObject<mapboxgl.Map | null>;
position?: Position;
showCompass?: boolean;
showZoom?: boolean;
visualizePitch?: boolean;
style?: React.CSSProperties;
}
export default function MapNavigationControl({ mapRef, position = 'top-right', showCompass = true, showZoom = true, visualizePitch = false, style }: Props) {
useEffect(() => {
const map = mapRef.current;
if (!map) return;
const nav = new mapboxgl.NavigationControl({ showCompass, showZoom, visualizePitch });
map.addControl(nav, position);
return () => {
try { map.removeControl(nav); } catch (e) {}
};
}, [mapRef, position, showCompass, showZoom, visualizePitch]);
// the control is rendered by mapbox, so this component itself renders nothing
return null;
}