Feature: Add interactive markers to polyline via context menu

This commit is contained in:
ISA
2024-06-27 15:03:16 +02:00
parent 9164574559
commit d7a1816176

View File

@@ -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);