-
Notifications
You must be signed in to change notification settings - Fork 6
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
5 changed files
with
138 additions
and
0 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,78 @@ | ||
'use client' | ||
|
||
import L from 'leaflet' | ||
import MarkerIcon from '../node_modules/leaflet/dist/images/marker-icon.png' | ||
import MarkerShadow from '../node_modules/leaflet/dist/images/marker-shadow.png' | ||
import 'leaflet/dist/leaflet.css' | ||
import { MapContainer, TileLayer, Marker, Popup, useMap } from 'react-leaflet' | ||
import { useEffect, useState } from 'react' | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button' | ||
import Stack from '@mui/material/Stack' | ||
|
||
function MyLocationButton({ setPosition }) { | ||
const getMyLocation = () => { | ||
if (navigator.geolocation) { | ||
navigator.geolocation.getCurrentPosition((position) => { | ||
setPosition([position.coords.latitude, position.coords.longitude]) | ||
}) | ||
} else { | ||
console.log("Geolocation is not supported by this browser.") | ||
} | ||
}; | ||
|
||
return ( | ||
<Button variant="contained" onClick={getMyLocation}>Get My Location</Button> | ||
) | ||
} | ||
|
||
function StartMarker({pos}) { | ||
const map = useMap(); | ||
|
||
useEffect(() => { | ||
map.flyTo(pos, map.getZoom()); | ||
}, [map, pos]); | ||
|
||
return (<Marker icon={ | ||
new L.Icon({ | ||
iconUrl: MarkerIcon.src, | ||
iconRetinaUrl: MarkerIcon.src, | ||
iconSize: [25, 41], | ||
iconAnchor: [12.5, 41], | ||
popupAnchor: [0, -41], | ||
shadowUrl: MarkerShadow.src, | ||
shadowSize: [41, 41], | ||
}) | ||
} position={pos}> | ||
<Popup> | ||
You are here. | ||
</Popup> | ||
</Marker>); | ||
} | ||
|
||
const OpenStreetMap = () => { | ||
|
||
const [coord, setCoord] = useState([51.505, -0.09]) | ||
|
||
return ( | ||
<Box> | ||
<Stack spacing={2} direction="row"> | ||
<MyLocationButton setPosition={setCoord} /> | ||
<Button variant="contained">Load GPX</Button> | ||
</Stack> | ||
<MapContainer style={{ | ||
height: '70vh', | ||
width: '70vw' | ||
}} center={coord} zoom={13} scrollWheelZoom={false}> | ||
<TileLayer | ||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
/> | ||
|
||
<StartMarker pos={coord} /> | ||
</MapContainer> | ||
</Box> | ||
) | ||
} | ||
|
||
export default OpenStreetMap |
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
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,26 @@ | ||
import dynamic from 'next/dynamic'; | ||
import Box from '@mui/material/Box'; | ||
import Container from '@mui/material/Container'; | ||
import Grid from '@mui/material/Grid'; | ||
import MyHead from '../../../components/MyHead'; | ||
import Title from '../../../components/Title'; | ||
|
||
const DynamicMap = dynamic(() => import('../../../components/OpenStreetMap'), { | ||
ssr: false | ||
}); | ||
|
||
export default function RideWorkout() { | ||
return ( | ||
<Container maxWidth="md"> | ||
<MyHead title="Map Ride" /> | ||
<Box> | ||
<Title href="/ride">Map Ride</Title> | ||
<p>Plan your ride.</p> | ||
|
||
<DynamicMap /> | ||
|
||
<Grid container direction="row" alignItems="center" spacing={2}></Grid> | ||
</Box> | ||
</Container> | ||
); | ||
} |