import L from 'leaflet'; import { useEffect, useRef } from 'react'; import 'leaflet/dist/leaflet.css'; interface LocationMapProps { latitude: number; longitude: number; height?: string; zoom?: number; } export function LocationMap({ latitude, longitude, height = '250px', zoom = 15, }: LocationMapProps) { const mapRef = useRef(null); const mapInstanceRef = useRef(null); useEffect(() => { if (!mapRef.current || mapInstanceRef.current) { return; } const map = L.map(mapRef.current, { center: [latitude, longitude], zoom, zoomControl: false, attributionControl: true, }); L.control.zoom({ position: 'topright' }).addTo(map); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap', }).addTo(map); const icon = L.divIcon({ html: `
`, className: '', iconSize: [24, 24], iconAnchor: [12, 12], }); L.marker([latitude, longitude], { icon }).addTo(map); mapInstanceRef.current = map; return () => { map.remove(); mapInstanceRef.current = null; }; }, [latitude, longitude, zoom]); return (
); }