generated from hack4impact-calpoly/nextjs-app-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,43 +3,16 @@ import { useRef, useEffect } from "react"; | |
import { Tree, treeData } from "./tree_data"; | ||
import styles from "@/styles/map.module.css"; | ||
import dynamic from "next/dynamic"; | ||
import MapComponent from "@/components/Map"; | ||
import { Box } from "@chakra-ui/react"; | ||
//import leaflet in client | ||
const L = dynamic(() => import("leaflet") as any, { | ||
ssr: false, | ||
}); | ||
export default function Map() { | ||
const mapRef = useRef(null); | ||
useEffect(() => { | ||
require("leaflet/dist/leaflet.css"); | ||
const L = require("leaflet"); | ||
const DefaultIcon = L.icon({ | ||
iconUrl: "https://unpkg.com/[email protected]/dist/images/marker-icon.png", | ||
shadowUrl: "https://unpkg.com/[email protected]/dist/images/marker-shadow.png", | ||
}); | ||
L.Marker.prototype.options.icon = DefaultIcon; | ||
//initilize the map | ||
if (!mapRef.current) { | ||
mapRef.current = L.map("map").setView([35.270378, -120.680656], 14.5); | ||
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(mapRef.current); | ||
//add marker to map | ||
treeData.map((tree: Tree) => { | ||
const marker = L.marker([tree.gpsCoords[0], tree.gpsCoords[1]]).addTo(mapRef.current); | ||
marker.bindPopup(` | ||
<strong>${tree.species}</strong><br/> | ||
Collected by: ${tree.collectorName}<br/> | ||
Date Collected: ${tree.dateCollected.toISOString().split("T")[0]}<br/> | ||
Notes: ${tree.notes || "No additional notes"} | ||
`); | ||
}); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<div className={styles.MapContainer}> | ||
Map with 5 points | ||
<div id="map" style={{ height: "50vh", width: "75%" }}></div> | ||
</div> | ||
</div> | ||
<Box width="100%" height="90vh" p={{ base: "20px", md: "50px" }}> | ||
<MapComponent /> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.