diff --git a/components/MapComponent.js b/components/MapComponent.js
index d83bc13f0..7c5ec6695 100644
--- a/components/MapComponent.js
+++ b/components/MapComponent.js
@@ -1,6 +1,6 @@
// components/MapComponent.js
import React, { useEffect, useRef, useState } from "react";
-import ReactDOM from "react-dom/client"; // Import from 'react-dom/client'
+//import ReactDOM from "react-dom/client"; // Import from 'react-dom/client'
import L, { marker } from "leaflet";
import "leaflet/dist/leaflet.css";
import "leaflet-contextmenu/dist/leaflet.contextmenu.css";
@@ -10,7 +10,7 @@ import dynamic from "next/dynamic";
import "leaflet.smooth_marker_bouncing";
import OverlappingMarkerSpiderfier from "overlapping-marker-spiderfier-leaflet";
import DataSheet from "./DataSheet.js";
-import { useRecoilState, useRecoilValue, RecoilRoot } from "recoil";
+import { useRecoilState, useRecoilValue } from "recoil";
import { gisStationsStaticDistrictState } from "../store/atoms/gisStationState.js";
import { gisSystemStaticState } from "../store/atoms/gisSystemState.js";
import { mapLayersState } from "../store/atoms/mapLayersState.js";
@@ -18,9 +18,23 @@ import { selectedAreaState } from "../store/atoms/selectedAreaState.js";
import { zoomTriggerState } from "../store/atoms/zoomTriggerState.js";
import { poiTypState } from "../store/atoms/poiTypState.js";
import ShowAddStationPopup from "./ShowAddStationPopup";
+import { poiReadFromDbTriggerAtom } from '../store/atoms/poiReadFromDbTriggerAtom';
//import { createRoot } from "react-dom/client";
const MapComponent = ({ locations, onLocationUpdate }) => {
+
+ const [showPopup, setShowPopup] = useState(false);
+
+ const openPopup = () => setShowPopup(true);
+ const closePopup = () => setShowPopup(false);
+
+ const handleAddStation = (stationData) => {
+ // Station-Daten speichern oder API-Aufruf durchführen
+ console.log("Neue Station:", stationData);
+ closePopup(); // Schließt das Popup nach dem Hinzufügen
+ };
+
+ const poiReadTrigger = useRecoilValue(poiReadFromDbTriggerAtom);
const [poiTypData, setPoiTypData] = useState(poiTypState); // Recoil State verwenden
const poiLayerRef = useRef(null); // Referenz auf die Layer-Gruppe für Datenbank-Marker
const mapRef = useRef(null); // Referenz auf das DIV-Element der Karte
@@ -257,7 +271,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
zoomControl: false,
contextmenu: true,
contextmenuItems: [
- { text: "Station hinzufügen", callback: showAddStationPopup },
+ { text: "Station hinzufügen"},
{
text: "Station öffnen (Tab)",
icon: "img/screen_new.png",
@@ -307,7 +321,8 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
// Rufe hier Funktionen auf, die eine initialisierte Karte benötigen.
});
}
- }, [mapRef, map]); // Prüfe die Abhängigkeiten sorgfältig
+ console.log("trigger in MapComponent.js:", poiReadTrigger);
+ }, [mapRef, map, poiReadTrigger]); // Prüfe die Abhängigkeiten sorgfältig
//------------------------------------------
function parsePoint(pointString) {
@@ -339,7 +354,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
console.error("Fehler beim Abrufen der poiTyp Daten:", error);
}
};
-
+ console.log("trigger in MapComponent.js in fetchPoiTypData:", poiReadTrigger);
fetchPoiTypData();
}, []);
@@ -409,16 +424,16 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
};
//-----Kontextmenu----ende------------
// Ensure this function is only called when map is initialized and available
- const showAddStationPopup = (e, map) => {
- const container = L.DomUtil.create("div");
+/* const showAddStationPopup = (e, map) => {
+ const container = L.DomUtil.create("div");
// Create a root container for the React component inside the popup
const root = ReactDOM.createRoot(container);
root.render(
-
Type: ${location.idPoiTyp || "N/A oder location.idPoiTyp=0"}
Lat: ${latitude.toFixed(5)}, Lng: ${longitude.toFixed(5)}`
+ `${location.description || "Unbekannt"}
Type: ${
+ location.idPoiTyp || "N/A"
+ }
Lat: ${latitude.toFixed(5)}, Lng: ${longitude.toFixed(5)}`
);
-
- // Event-Handler für Mouseover und Mouseout hinzufügen
+
+ // Event-Handler hinzufügen
marker.on("mouseover", function () {
this.openPopup();
});
marker.on("mouseout", function () {
this.closePopup();
});
-
- marker.on("dragend", function (e) {
+
+ marker.on("dragend", (e) => {
const newLat = e.target.getLatLng().lat;
const newLng = e.target.getLatLng().lng;
const markerId = e.target.options.id;
updateLocationInDatabase(markerId, newLat, newLng).then(() => {
onLocationUpdate(markerId, newLat, newLng);
+ console.log("trigger in MapComponent.js:", poiReadTrigger);
});
});
-
+
marker.addTo(poiLayerRef.current);
});
}
- }, [map, locations, onLocationUpdate]); // Dieser Effekt läuft, wenn `map`, `locations` oder `onLocationUpdate` sich ändern
+
+ }, [map, locations, onLocationUpdate,poiReadTrigger]);
+
+ //------------------------------------------
function parsePoint(position) {
const [longitude, latitude] = position.slice(6, -1).split(" ");
@@ -1476,10 +1504,30 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
}
}, [map, zoomTrigger]);
+ //---------------------------------------------------------
+ useEffect(() => {
+ console.log("Aktualisierung in MapComponent.js:", poiReadTrigger);
+
+ // Logik zur Aktualisierung der Map hier hinzufügen
+ // Beispiel: Daten neu laden oder aktualisieren
+
+}, [poiReadTrigger]);
//---------------------------------------------------------
return (
<>
+