add geomap components
This commit is contained in:
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
||||
import reactLogo from './assets/react.svg'
|
||||
import viteLogo from '/vite.svg'
|
||||
import './App.css'
|
||||
import GeoMap from './geomap/geomap'
|
||||
import GeoMap from './components/geomap/geomap'
|
||||
|
||||
function App() {
|
||||
const [count, setCount] = useState(0)
|
||||
|
||||
68
src/components/geomap/geomap.tsx
Normal file
68
src/components/geomap/geomap.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
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]));
|
||||
|
||||
return markers.map((marker, index) => {
|
||||
return (
|
||||
<Circle
|
||||
key={index}
|
||||
center={marker}
|
||||
radius={200}
|
||||
className="circle-marker"
|
||||
>
|
||||
<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;
|
||||
@@ -1,53 +0,0 @@
|
||||
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
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import GeoMap from './geomap/geomap.tsx'
|
||||
import GeoMap from './components/geomap/geomap.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
|
||||
Reference in New Issue
Block a user