feat: add API endpoint for updating line geometries, but need fix bugs
This commit is contained in:
@@ -2171,14 +2171,40 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
|
||||
// Draw polyline
|
||||
const polyline = L.polyline(lineData.coordinates, { color }).addTo(map);
|
||||
|
||||
//---------------------------
|
||||
// Function to update the polyline when markers are dragged
|
||||
markers.forEach((marker) => {
|
||||
marker.on("drag", () => {
|
||||
const newCoords = markers.map((marker) => marker.getLatLng());
|
||||
polyline.setLatLngs(newCoords);
|
||||
markers.forEach((marker, index) => {
|
||||
marker.on("dragend", () => {
|
||||
const newCoords = marker.getLatLng();
|
||||
lineData.coordinates[index] = [newCoords.lat, newCoords.lng];
|
||||
polyline.setLatLngs(lineData.coordinates);
|
||||
|
||||
// Senden der aktualisierten Koordinaten an den Server
|
||||
fetch("/api/talas_v5_DB/gisLines/updateGisLines", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idModul: lineData.idModul,
|
||||
newCoordinates: lineData.coordinates,
|
||||
}),
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log("Update erfolgreich:", data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error updating data:", error.message);
|
||||
});
|
||||
});
|
||||
});
|
||||
//---------------------------
|
||||
|
||||
// Fit map to show all markers and polylines
|
||||
const group = new L.featureGroup([...markers, polyline]);
|
||||
|
||||
Reference in New Issue
Block a user