Fit map to NZ bounds on load
This commit is contained in:
parent
096c534536
commit
19b2b00750
1 changed files with 14 additions and 7 deletions
|
@ -1,18 +1,25 @@
|
||||||
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet'
|
import { MapContainer, TileLayer, useMap } from 'react-leaflet'
|
||||||
|
|
||||||
|
const NZ_BOUNDS = [
|
||||||
|
[-47.204642, 165.344238],
|
||||||
|
[-34.307144, 179.824219]
|
||||||
|
]
|
||||||
|
|
||||||
|
function FitNewZealandBounds() {
|
||||||
|
const map = useMap()
|
||||||
|
map.fitBounds(NZ_BOUNDS)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export default function Map() {
|
export default function Map() {
|
||||||
return (
|
return (
|
||||||
<div className="map-container">
|
<div className="map-container">
|
||||||
<MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
|
<MapContainer scrollWheelZoom={true}>
|
||||||
<TileLayer
|
<TileLayer
|
||||||
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
/>
|
/>
|
||||||
<Marker position={[51.505, -0.09]}>
|
<FitNewZealandBounds />
|
||||||
<Popup>
|
|
||||||
A pretty CSS3 popup. <br /> Easily customizable.
|
|
||||||
</Popup>
|
|
||||||
</Marker>
|
|
||||||
</MapContainer>
|
</MapContainer>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue