"use client"; import { MapContainer, TileLayer, Marker, Popup, LayersControl } from 'react-leaflet'; import 'leaflet/dist/leaflet.css'; import { useEffect } from 'react'; import { mapLayers } from './mapLayers'; // Fix for default markers in react-leaflet const fixLeafletIcons = () => { if (typeof window !== 'undefined') { const L = require('leaflet'); delete L.Icon.Default.prototype._getIconUrl; L.Icon.Default.mergeOptions({ iconRetinaUrl: '/leaflet/marker-icon-2x.png', iconUrl: '/leaflet/marker-icon.png', shadowUrl: '/leaflet/marker-shadow.png', }); } }; export default function EnhancedLeafletMap({ center, zoom = 13, markers = [], showLayerControl = true, defaultLayer = 'OpenStreetMap' }) { useEffect(() => { fixLeafletIcons(); }, []); const { BaseLayer } = LayersControl; return ( {showLayerControl ? ( {mapLayers.base.map((layer, index) => ( ))} ) : ( // Default layer when no layer control )} {markers.map((marker, index) => ( {marker.popup && {marker.popup}} ))} ); }