import { useState } from "react" import { MapContainer, TileLayer, Marker, useMapEvents } from 'react-leaflet' const NZ_BOUNDS = [ [-47.204642, 165.344238], [-34.307144, 179.824219] ] function LocationMarker(props) { const [position, setPosition] = useState(null) const map = useMapEvents({ click(e) { const newPosition = e.latlng; setPosition(newPosition); props.updateFilterState({ "coordinates": newPosition }); props.setNextDisabled(false); } }) map.whenReady(() => { const savedCoordinates = props.filters["coordinates"]; if (!position && savedCoordinates) { setPosition(savedCoordinates); props.setNextDisabled(false); map.flyTo(savedCoordinates, 9) } }) return position === null ? null : ( ) } const fitNZBounds = (map) => { map.fitBounds(NZ_BOUNDS); } function CoordinatesDisplay(props) { const savedCoordinates = props.filters["coordinates"]; return savedCoordinates ? (
Latitude: {savedCoordinates.lat}
Longitude: {savedCoordinates.lng}
) : null; } export default function Map(props) { return (
) }