-
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
4 changed files
with
122 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use client'; | ||
import L from 'leaflet'; | ||
import { Marker, Popup } from 'react-leaflet'; | ||
import { useEffect } from 'react'; | ||
import MarkerIcon from '../node_modules/leaflet/dist/images/marker-icon.png'; | ||
import MarkerShadow from '../node_modules/leaflet/dist/images/marker-shadow.png'; | ||
|
||
export default function MapMarker({ map, position }) { | ||
useEffect(() => { | ||
if (map) { | ||
console.log('fly to ', position); | ||
map.flyTo(position, map.getZoom()); | ||
} | ||
}, [map, position]); | ||
|
||
return ( | ||
<Marker | ||
position={position} | ||
// @ts-ignore | ||
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], | ||
}) | ||
} | ||
> | ||
<Popup> | ||
You are here. | ||
{`${position}`} | ||
</Popup> | ||
</Marker> | ||
); | ||
} |
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,78 +1,33 @@ | ||
'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' | ||
'use client'; | ||
import 'leaflet/dist/leaflet.css'; | ||
import { MapContainer, TileLayer } from 'react-leaflet'; | ||
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 | ||
import { ReactNode } from 'react'; | ||
|
||
const OpenStreetMap = ({ children, center, setMap }: { children?: ReactNode; center: number[]; setMap: any }) => { | ||
return ( | ||
<Box> | ||
<MapContainer | ||
style={{ | ||
height: '70vh', | ||
width: '70vw', | ||
}} | ||
// @ts-ignore | ||
center={center} | ||
zoom={13} | ||
scrollWheelZoom={false} | ||
ref={setMap} | ||
> | ||
<TileLayer | ||
// @ts-ignore | ||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
/> | ||
|
||
{children} | ||
</MapContainer> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default OpenStreetMap; |
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
8860b40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
bfree – ./
bfree-git-master-olliv.vercel.app
bfree.vercel.app
bfree-olliv.vercel.app