diff --git a/components/MapComponent.js b/components/MapComponent.js
index ef6719f56..5d4cfea87 100644
--- a/components/MapComponent.js
+++ b/components/MapComponent.js
@@ -174,17 +174,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
});
const [polylineEventsDisabled, setPolylineEventsDisabled] = useRecoilState(polylineEventsDisabledState); // Recoil State
- const handleLocationUpdate = async (idLocation, idMap, newCoords) => {
- try {
- const result = await updateLocation(idLocation, idMap, newCoords);
- console.log("Erfolgreiche Aktualisierung:", result);
-
- // Aktualisieren Sie Marker oder andere Elemente
- } catch (error) {
- console.error("Fehler beim Aktualisieren der Location:", error);
- }
- };
-
//---------------------------------------------------------------
/* useEffect(() => {
@@ -805,7 +794,17 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
const bereichUrl = `http://${hostname}:${port}/api/talas_v5_DB/bereich/readBereich?m=${mValue}`; // Dynamischer Hostname und Port
// Bereichs-Marker basierend auf dynamischer URL laden
- const bereicheMarkers = useBereicheMarkersLayer(map, oms, bereichUrl);
+ const handleLocationUpdate = async (idLocation, idMap, newCoords) => {
+ try {
+ const result = await updateLocation(idLocation, idMap, newCoords); // Update-API
+ console.log("Koordinaten erfolgreich aktualisiert:", result);
+ } catch (error) {
+ console.error("Fehler beim Aktualisieren der Location:", error);
+ }
+ };
+
+ // Bereichs-Marker basierend auf dynamischer URL laden
+ const bereicheMarkers = useBereicheMarkersLayer(map, oms, bereichUrl, handleLocationUpdate);
//const bereicheMarkers = useBereicheMarkersLayer(map, oms, editMode ? `/api/talas_v5_DB/bereich/readBereich?editMode=true` : `/api/talas_v5_DB/bereich/readBereich`);
//const bereicheMarkers = useBereicheMarkersLayer(map, oms, "/api/talas_v5_DB/bereich/readBereich?m=12");
diff --git a/hooks/layers/useBereicheMarkersLayer.js b/hooks/layers/useBereicheMarkersLayer.js
index c724081fd..130e1e150 100644
--- a/hooks/layers/useBereicheMarkersLayer.js
+++ b/hooks/layers/useBereicheMarkersLayer.js
@@ -43,7 +43,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
});
};
- useEffect(() => {
+ /* useEffect(() => {
// Hole die Daten aus der API
const fetchBereiche = async () => {
try {
@@ -82,7 +82,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
};
fetchBereiche();
- }, [apiUrl]);
+ }, [apiUrl]); */
useEffect(() => {
// Initialisiere die Sichtbarkeit beim ersten Laden
@@ -108,7 +108,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
clearInterval(intervalId);
};
}, [map, bereicheMarkers, oms]);
- /*
+
useEffect(() => {
const fetchBereiche = async () => {
try {
@@ -124,9 +124,9 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
// Tooltip
marker.bindTooltip(
`
- Bereich: ${item.location_name}
- Standort: ${item.area_name}
- `,
+ Bereich: ${item.location_name}
+ Standort: ${item.area_name}
+ `,
{
permanent: false,
direction: "top",
@@ -138,7 +138,8 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
marker.on("dragend", async (e) => {
const { lat, lng } = e.target.getLatLng();
try {
- await updateLocation(item.idLocation, item.idMaps, { x: lat, y: lng });
+ // Update API aufrufen
+ await updateLocation(item.idLocation, item.idMaps, { x: lat, y: lng }); // Update-Funktion
console.log("Koordinaten erfolgreich aktualisiert:", { lat, lng });
} catch (error) {
console.error("Fehler beim Aktualisieren der Koordinaten:", error);
@@ -155,7 +156,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
};
fetchBereiche();
- }, [apiUrl]); */
+ }, [apiUrl]);
useEffect(() => {
if (map) {
diff --git a/pages/api/talas_v5_DB/bereich/updateBereich.js b/pages/api/talas_v5_DB/bereich/updateBereich.js
index 7e419eb6d..78376563c 100644
--- a/pages/api/talas_v5_DB/bereich/updateBereich.js
+++ b/pages/api/talas_v5_DB/bereich/updateBereich.js
@@ -1,8 +1,8 @@
// /pages/api/talas_v5_DB/bereich/updateBereich.js
-import getPool from "../../../utils/mysqlPool"; // Singleton-Pool importieren
+import getPool from "../../../utils/mysqlPool";
export default async function handler(req, res) {
- const pool = getPool(); // Singleton-Pool verwenden
+ const pool = getPool();
if (req.method !== "PUT") {
return res.status(405).json({ error: "Nur PUT Methode erlaubt" });
@@ -22,14 +22,16 @@ export default async function handler(req, res) {
const [result] = await connection.query(query, [x, y, idLocation, idMap]);
if (result.affectedRows > 0) {
- res.status(200).json({ success: true, message: "Koordinaten erfolgreich aktualisiert" });
+ return res.status(200).json({ success: true, message: "Koordinaten erfolgreich aktualisiert" });
} else {
- res.status(404).json({ error: "Kein Eintrag gefunden, der aktualisiert werden konnte" });
+ return res.status(404).json({ error: "Kein Eintrag gefunden, der aktualisiert werden konnte" });
}
} catch (error) {
console.error("Fehler beim Aktualisieren der Koordinaten:", error);
- res.status(500).json({ error: "Interner Serverfehler beim Aktualisieren der Koordinaten" });
+ return res.status(500).json({ error: "Interner Serverfehler beim Aktualisieren der Koordinaten" });
} finally {
- if (connection) connection.release();
+ if (connection) {
+ connection.release();
+ }
}
}