Add map component
This commit is contained in:
53
src/geomap/geomap.tsx
Normal file
53
src/geomap/geomap.tsx
Normal 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='© <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
4
src/geomap/gepmap.css
Normal file
@@ -0,0 +1,4 @@
|
||||
#map {
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
Reference in New Issue
Block a user