-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcumulus-map-base.js
More file actions
76 lines (68 loc) · 2.07 KB
/
cumulus-map-base.js
File metadata and controls
76 lines (68 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { useEffect } from 'react';
import { MapContainer, Marker, Popup, TileLayer } from 'react-leaflet';
import { useMap } from 'react-leaflet/hooks';
// Component to handle map invalidation on resize
function MapInvalidator({ mapHeight }) {
const map = useMap();
useEffect(() => {
if (map && mapHeight) {
// Small delay to let DOM update
const timer = setTimeout(() => {
map.invalidateSize();
}, 100);
return () => clearTimeout(timer);
}
}, [map, mapHeight]);
return null;
}
/**
* Base Cumulus Map Container
*
* A reusable Leaflet map component that provides the core map functionality
* for all map modes in the application.
*
* @param {Object} props
* @param {React.ReactNode} props.children - Mode-specific overlays and controls
* @param {number} [props.mapHeight] - Height of the map for resizing
* @param {Array} [props.center=[37.1, -95.7]] - Map center coordinates [lat, lng]
* @param {number} [props.zoom=4] - Initial zoom level
* @param {Array} [props.locations=[]] - Optional markers to display
*/
export default function CumulusMapBase({
children,
mapHeight,
center = [37.1, -95.7],
zoom = 4,
locations = []
}) {
return (
<div className='map-container h-full'>
<MapContainer
center={center}
zoom={zoom}
scrollWheelZoom={false}
>
<TileLayer
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
{/* Handle map invalidation when height changes */}
<MapInvalidator mapHeight={mapHeight} />
{/* Mode-specific overlays and controls */}
{children}
{/* Optional location markers */}
{locations.map((loc, i) => (
<Marker
key={`loc-${i}`}
position={[loc.location.lat, loc.location.lon]}
>
<Popup>
<h2>{loc.name}</h2>
<p>{loc.description}</p>
</Popup>
</Marker>
))}
</MapContainer>
</div>
);
}