muss noch für update der Bereich Marker gearbeitet werden

This commit is contained in:
ISA
2024-12-20 14:50:30 +01:00
parent 6155561f14
commit a82a92e89a
3 changed files with 28 additions and 26 deletions

View File

@@ -174,17 +174,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}); });
const [polylineEventsDisabled, setPolylineEventsDisabled] = useRecoilState(polylineEventsDisabledState); // Recoil State 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(() => { /* 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 const bereichUrl = `http://${hostname}:${port}/api/talas_v5_DB/bereich/readBereich?m=${mValue}`; // Dynamischer Hostname und Port
// Bereichs-Marker basierend auf dynamischer URL laden // 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, 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"); //const bereicheMarkers = useBereicheMarkersLayer(map, oms, "/api/talas_v5_DB/bereich/readBereich?m=12");

View File

@@ -43,7 +43,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
}); });
}; };
useEffect(() => { /* useEffect(() => {
// Hole die Daten aus der API // Hole die Daten aus der API
const fetchBereiche = async () => { const fetchBereiche = async () => {
try { try {
@@ -82,7 +82,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
}; };
fetchBereiche(); fetchBereiche();
}, [apiUrl]); }, [apiUrl]); */
useEffect(() => { useEffect(() => {
// Initialisiere die Sichtbarkeit beim ersten Laden // Initialisiere die Sichtbarkeit beim ersten Laden
@@ -108,7 +108,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
clearInterval(intervalId); clearInterval(intervalId);
}; };
}, [map, bereicheMarkers, oms]); }, [map, bereicheMarkers, oms]);
/*
useEffect(() => { useEffect(() => {
const fetchBereiche = async () => { const fetchBereiche = async () => {
try { try {
@@ -124,9 +124,9 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
// Tooltip // Tooltip
marker.bindTooltip( marker.bindTooltip(
` `
<strong>Bereich:</strong> ${item.location_name} <br /> <strong>Bereich:</strong> ${item.location_name} <br />
<strong>Standort:</strong> ${item.area_name} <br /> <strong>Standort:</strong> ${item.area_name} <br />
`, `,
{ {
permanent: false, permanent: false,
direction: "top", direction: "top",
@@ -138,7 +138,8 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
marker.on("dragend", async (e) => { marker.on("dragend", async (e) => {
const { lat, lng } = e.target.getLatLng(); const { lat, lng } = e.target.getLatLng();
try { 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 }); console.log("Koordinaten erfolgreich aktualisiert:", { lat, lng });
} catch (error) { } catch (error) {
console.error("Fehler beim Aktualisieren der Koordinaten:", error); console.error("Fehler beim Aktualisieren der Koordinaten:", error);
@@ -155,7 +156,7 @@ const useBereicheMarkersLayer = (map, oms, apiUrl) => {
}; };
fetchBereiche(); fetchBereiche();
}, [apiUrl]); */ }, [apiUrl]);
useEffect(() => { useEffect(() => {
if (map) { if (map) {

View File

@@ -1,8 +1,8 @@
// /pages/api/talas_v5_DB/bereich/updateBereich.js // /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) { export default async function handler(req, res) {
const pool = getPool(); // Singleton-Pool verwenden const pool = getPool();
if (req.method !== "PUT") { if (req.method !== "PUT") {
return res.status(405).json({ error: "Nur PUT Methode erlaubt" }); 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]); const [result] = await connection.query(query, [x, y, idLocation, idMap]);
if (result.affectedRows > 0) { 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 { } 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) { } catch (error) {
console.error("Fehler beim Aktualisieren der Koordinaten:", 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 { } finally {
if (connection) connection.release(); if (connection) {
connection.release();
}
} }
} }