diff --git a/components/MapComponent.js b/components/MapComponent.js index 1edb2aeb8..ec6f6f8e7 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -2481,12 +2481,13 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { } function updateMarkerPosition(newLatLng, lineData, marker) { - const index = lineData.coordinates.findIndex( - (coord) => coord === marker.getLatLng() + const index = lineData.coordinates.findIndex((coord) => + L.latLng(coord[0], coord[1]).equals(marker.getLatLng()) ); if (index !== -1) { lineData.coordinates[index] = [newLatLng.lat, newLatLng.lng]; - drawPolyline(lineData); + redrawPolyline(lineData, map); + saveLineData(lineData); // Speichern der neuen Koordinaten nach dem Verschieben } } @@ -2513,7 +2514,17 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { newPoint.lat, newPoint.lng, ]); + + // Hier direkt speichern nach Einfügen + saveLineData(lineData); + redrawPolyline(lineData, map); + + // Event-Listener für das Verschieben des Markers hinzufügen + newMarker.on("dragend", () => { + updateMarkerPosition(newMarker.getLatLng(), lineData, newMarker); + saveLineData(lineData); // Speichern der neuen Koordinaten nach dem Verschieben + }); } function redrawPolyline(lineData, map) { if (lineData.polyline) map.removeLayer(lineData.polyline);