-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventMapPage.js
More file actions
47 lines (41 loc) · 1.36 KB
/
EventMapPage.js
File metadata and controls
47 lines (41 loc) · 1.36 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
function EventMapPage() {
const mapRef = React.useRef(null);
const userId = localStorage.getItem("user_id");
React.useEffect(() => {
const map = L.map(mapRef.current).setView([39.9545, -75.1994], 16);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Add default markers
defaultLocations.forEach(loc => {
L.marker([loc.lat, loc.lng])
.addTo(map)
.bindTooltip(loc.name, { permanent: false, direction: "top" })
.on("click", () => {
window.location.hash = `#location/${loc.id}`;
});
});
// Add event locations from DB
fetch(`http://localhost:3001/api/users/${userId}/events`)
.then(res => res.json())
.then(events => {
events.forEach(event => {
L.marker([event.latitude, event.longitude])
.addTo(map)
.bindTooltip(event.location, { permanent: false, direction: "top" })
.on("click", () => {
window.location.hash = `#event/${event.id}`;
});
});
});
}, []);
return (
<div className="flex flex-col h-screen overflow-hidden">
<div ref={mapRef} className="flex-grow w-full z-0" />
<div className="z-10">
<Navigation />
</div>
</div>
);
}
window.EventMapPage = EventMapPage;