Add map component

This commit is contained in:
2024-02-24 17:59:31 +02:00
parent 508b749903
commit 5c29df8c1a
9 changed files with 655 additions and 150 deletions

53
src/geomap/geomap.tsx Normal file
View File

@@ -0,0 +1,53 @@
import { MapContainer, Marker, TileLayer, Popup, useMap, useMapEvents, useMapEvent, CircleMarker, LayerGroup, Circle, } from 'react-leaflet'
import 'leaflet/dist/leaflet.css';
import './gepmap.css'
import { useState } from 'react';
import { LatLng, LatLngTuple } from 'leaflet';
import MarkerClusterGroup from 'react-leaflet-cluster'
function LocationMarker() {
const [markers, setMarkers] = useState<LatLng[]>([]); //[new LatLng(31.979163245291875, 34.89121019840241)]
useMapEvent('dblclick', (e) => setMarkers([...markers, e.latlng]))
useMapEvent('zoomanim', (e) => console.log(e))
return markers.map((marker, index) => {
return <Circle key={index} center={marker} radius={300}>
<Popup>
<button onClick={function () {
console.log(index);
setMarkers(function (prevMarkers) {
prevMarkers.splice(index, 1);
return [...prevMarkers]
})
console.log(markers)
}}>
remove
</button>
</Popup>
</Circle>
}
)
}
function GeoMap() {
const position = new LatLng(31.979163245291875, 34.89121019840241)
return (
<div>
<MapContainer id='map' center={position} zoom={13} scrollWheelZoom={true}>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<MarkerClusterGroup animate={true} animateAddingMarkers={false}>
<LocationMarker/>
</MarkerClusterGroup>
<LayerGroup>
{/* <CircleLayer/> */}
</LayerGroup>
</MapContainer>
</div>
)
}
export default GeoMap

4
src/geomap/gepmap.css Normal file
View File

@@ -0,0 +1,4 @@
#map {
height: 100vh;
width: 100%;
}