From 17f3025523c1c9ab7e109f7b319c29f2dfa4b6fd Mon Sep 17 00:00:00 2001 From: ISA Date: Sun, 5 May 2024 14:01:59 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge:=20Kontextmen=C3=BC-Option=20f=C3=BCr?= =?UTF-8?q?=20"Station=20hinzuf=C3=BCgen"=20mit=20Koordinaten-Popup=20hinz?= =?UTF-8?q?u?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Füge: Kontextmenü-Option für "Station hinzufügen" mit Koordinaten-Popup hinzu --- components/MapComponent.js | 55 ++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/components/MapComponent.js b/components/MapComponent.js index 7c5ec6695..fc5ae4843 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -24,7 +24,7 @@ import { poiReadFromDbTriggerAtom } from '../store/atoms/poiReadFromDbTriggerAto const MapComponent = ({ locations, onLocationUpdate }) => { const [showPopup, setShowPopup] = useState(false); - + const [popupCoordinates, setPopupCoordinates] = useState({ lat: 52.52, lng: 13.4050 }); // Beispielkoordinaten const openPopup = () => setShowPopup(true); const closePopup = () => setShowPopup(false); @@ -33,6 +33,12 @@ const MapComponent = ({ locations, onLocationUpdate }) => { console.log("Neue Station:", stationData); closePopup(); // Schließt das Popup nach dem Hinzufügen }; + // Beispiel zum Öffnen des Popups mit bestimmten Koordinaten + const openAddStationPopupWithCoordinates = (lat, lng) => { + setPopupCoordinates({ lat, lng }); + setShowPopup(true); + }; + const poiReadTrigger = useRecoilValue(poiReadFromDbTriggerAtom); const [poiTypData, setPoiTypData] = useState(poiTypState); // Recoil State verwenden @@ -271,7 +277,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => { zoomControl: false, contextmenu: true, contextmenuItems: [ - { text: "Station hinzufügen"}, + { text: "Station hinzufügen", callback: addStationCallback }, { text: "Station öffnen (Tab)", icon: "img/screen_new.png", @@ -422,6 +428,12 @@ const MapComponent = ({ locations, onLocationUpdate }) => { map.removeLayer(GMA); loadData(); }; + + // Kontextmenü Callback für "Station hinzufügen" + const addStationCallback = (event) => { + setPopupCoordinates(event.latlng); // Koordinaten des Klicks verwenden + setShowPopup(true); // Popup öffnen + }; //-----Kontextmenu----ende------------ // Ensure this function is only called when map is initialized and available /* const showAddStationPopup = (e, map) => { @@ -1516,18 +1528,33 @@ const MapComponent = ({ locations, onLocationUpdate }) => { return ( <> -
- - - {/* Direkt als JSX verwenden */} - {showPopup && ( - - )} -
+
+ {/* Popup als Modal anzeigen */} + {showPopup && ( +
+
+ +
+
+ )} +