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.
Merge pull request #13 from hack4impact-calpoly/1-create-map-leaflet
1 create map leaflet
- Loading branch information
Showing
11 changed files
with
150 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# create local copy of this file and rename to .env.local | ||
# make sure to add .env.local to .gitignore!! | ||
MONGO_URI={mongo-uri-here} |
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 |
---|---|---|
|
@@ -33,3 +33,5 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
prettier.config.js |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
const nextConfig = {}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,45 @@ | ||
"use client"; | ||
import { useRef, useEffect } from "react"; | ||
import { Tree, treeData } from "./tree_data"; | ||
import styles from "@/styles/map.module.css"; | ||
import dynamic from "next/dynamic"; | ||
//import leaflet in client | ||
const L = dynamic(() => import("leaflet") as any, { | ||
ssr: false, | ||
}); | ||
export default function Map() { | ||
return <div>Will probably be made into a component later and not a page, but go to /map to develop!</div>; | ||
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> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//temp class tree | ||
export interface Tree { | ||
collectorName: string; | ||
gpsCoords: number[]; | ||
dateCollected: Date; | ||
photo?: string; | ||
dbh: number; | ||
canopyBreadth: number; | ||
species: string; | ||
treeCond: string[]; | ||
notes?: string; | ||
} | ||
//Dummy data | ||
export const treeData: Tree[] = [ | ||
{ | ||
collectorName: "John Doe", | ||
gpsCoords: [35.267763, -120.675414], | ||
dateCollected: new Date("2025-01-25"), | ||
dbh: 15.2, | ||
canopyBreadth: 8.5, | ||
species: "Quercus agrifolia", | ||
treeCond: ["Healthy", "Mature"], | ||
}, | ||
{ | ||
collectorName: "Jane Smith", | ||
gpsCoords: [35.273266, -120.680012], | ||
dateCollected: new Date("2025-01-26"), | ||
dbh: 10.4, | ||
canopyBreadth: 6.3, | ||
species: "Pinus ponderosa", | ||
treeCond: ["Healthy", "Young"], | ||
}, | ||
{ | ||
collectorName: "Michael Brown", | ||
gpsCoords: [35.276883, -120.673991], | ||
dateCollected: new Date("2025-01-27"), | ||
dbh: 20.8, | ||
canopyBreadth: 12.4, | ||
species: "Sequoia sempervirens", | ||
treeCond: ["Healthy", "Mature", "Thriving"], | ||
}, | ||
{ | ||
collectorName: "Sarah Johnson", | ||
gpsCoords: [35.276889, -120.686529], | ||
dateCollected: new Date("2025-01-27"), | ||
dbh: 5.9, | ||
canopyBreadth: 3.2, | ||
species: "Acer macrophyllum", | ||
treeCond: ["Healthy", "Young"], | ||
}, | ||
{ | ||
collectorName: "Emily Davis", | ||
gpsCoords: [35.270783, -120.674544], | ||
dateCollected: new Date("2025-01-28"), | ||
dbh: 25.6, | ||
canopyBreadth: 15.7, | ||
species: "Platanus racemosa", | ||
treeCond: ["Healthy", "Old Growth"], | ||
}, | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.MapContainer { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-direction: column; | ||
height: 100vh; | ||
} |