Fit map to NZ bounds on load

This commit is contained in:
Dana Lambert 2021-10-18 17:09:56 +13:00
parent 096c534536
commit 19b2b00750

View file

@ -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='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' attribution='&copy; <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>
) )