temp
This commit is contained in:
@@ -2383,6 +2383,81 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
setPolylines(newPolylines);
|
||||
}, [map, linePositions, lineColors, tooltipContents]);
|
||||
|
||||
//---------------------------------------------------------
|
||||
//---------------------------------------------------------
|
||||
useEffect(() => {
|
||||
if (!map) return;
|
||||
|
||||
// Funktion zum Hinzufügen eines neuen Punktes
|
||||
const addNewPoint = (latlng, lineData) => {
|
||||
const newCoordinates = [
|
||||
...lineData.coordinates,
|
||||
[latlng.lat, latlng.lng],
|
||||
];
|
||||
// Update der Linie auf der Karte und eventuell Speichern der neuen Koordinaten wie oben beschrieben
|
||||
// Aufruf der Update-Funktion oder was auch immer benötigt wird
|
||||
updateLine(lineData, newCoordinates);
|
||||
};
|
||||
|
||||
// Kontextmenü-Handler
|
||||
const onMapContextMenu = (event) => {
|
||||
// Das Kontextmenü öffnen, Position und eventuelle Optionen hier bestimmen
|
||||
const latlng = event.latlng;
|
||||
console.log("Kontextmenü geöffnet bei:", latlng);
|
||||
|
||||
// Beispiel: Dynamisches Erzeugen eines Menüs (simplifiziert)
|
||||
const contextMenu = L.popup()
|
||||
.setLatLng(latlng)
|
||||
.setContent(
|
||||
'<button onclick="addNewPoint(latlng, lineData)">Punkt hinzufügen</button>'
|
||||
)
|
||||
.openOn(map);
|
||||
|
||||
// Hier müsste `lineData` die spezifische Linieninformation sein, evtl. müssten Sie diese auswählen oder übergeben
|
||||
};
|
||||
|
||||
// Event-Listener hinzufügen
|
||||
map.on("contextmenu", onMapContextMenu);
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
map.off("contextmenu", onMapContextMenu);
|
||||
};
|
||||
}, [map]);
|
||||
|
||||
//--------------------------------------------------------
|
||||
//---------------------------------------------------------
|
||||
const updateLine = (lineData, newCoordinates) => {
|
||||
// Hier Ihr bestehender Code zum Aktualisieren der Linie
|
||||
// z.B. den State aktualisieren oder API-Aufrufe tätigen
|
||||
fetch("/api/talas_v5_DB/gisLines/updateLineCoordinates", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idLD: lineData.idLD,
|
||||
newCoordinates,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log("Koordinaten erfolgreich aktualisiert:", data);
|
||||
// Update der Linien-Daten im State, um die Linie auf der Karte zu aktualisieren
|
||||
setLinePositions((oldLines) =>
|
||||
oldLines.map((line) => {
|
||||
if (line.idLD === lineData.idLD) {
|
||||
return { ...line, coordinates: newCoordinates };
|
||||
}
|
||||
return line;
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Fehler beim Aktualisieren der Koordinaten:", error);
|
||||
});
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
//---------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user