From e96d0e33dcda7e553ad2b67c82ebe00342ab4f6a Mon Sep 17 00:00:00 2001 From: Hanka8 Date: Mon, 4 Nov 2024 18:58:29 +0100 Subject: [PATCH] Add bird icon to map --- src/components/FormGeolocation.tsx | 2 +- src/components/Index.tsx | 2 +- src/components/InteractiveMap.tsx | 14 ++++++++++++-- src/types.tsx | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/FormGeolocation.tsx b/src/components/FormGeolocation.tsx index 1ee772c..12459bf 100644 --- a/src/components/FormGeolocation.tsx +++ b/src/components/FormGeolocation.tsx @@ -96,7 +96,7 @@ const LocationForm: React.FC = ({ />
- Insert manually + {geolocationManually ? "Get your location" : "Set adress manually" }
diff --git a/src/components/Index.tsx b/src/components/Index.tsx index d61a273..b12d3ea 100644 --- a/src/components/Index.tsx +++ b/src/components/Index.tsx @@ -74,7 +74,7 @@ const Index: React.FC = () => { return (

Birds around you

- {data && } + {data && }
= ({ latitude, longitude, + setLatitude, + setLongitude, data, }) => { const mapRef = useRef(null); @@ -92,7 +95,7 @@ const InteractiveMap: React.FC = ({ }) ); - vectorSource.addFeature(birdMarker); + vectorSource.addFeature(birdMarker); }); const markerLayer = new VectorLayer({ @@ -101,8 +104,15 @@ const InteractiveMap: React.FC = ({ map.addLayer(markerLayer); + // Add click event listener to the map + map.on("singleclick", (event) => { + const clickedCoordinate = toLonLat(event.coordinate); // Convert to longitude/latitude + setLatitude(clickedCoordinate[1].toFixed(2)); + setLongitude(clickedCoordinate[0].toFixed(2)); + }); + return () => map.setTarget(undefined); - }, [latitude, longitude, data]); + }, [latitude, longitude, data, setLatitude, setLongitude]); return
; }; diff --git a/src/types.tsx b/src/types.tsx index bfa987f..a5e3c5a 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -93,5 +93,7 @@ export type ErrorProps = { export type InteractiveMapProps = { latitude: string; longitude: string; + setLatitude: (value: string) => void; + setLongitude: (value: string) => void; data: Bird[] | undefined; }; \ No newline at end of file