95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
// /utils/markerUtils.js
|
|
import circleIcon from "../components/CircleIcon";
|
|
import { saveLineData, redrawPolyline } from "./mapUtils";
|
|
|
|
export const insertNewMarker = (closestPoints, newPoint, lineData, map) => {
|
|
const newMarker = L.marker(newPoint, {
|
|
icon: circleIcon,
|
|
draggable: true,
|
|
}).addTo(map);
|
|
lineData.coordinates.splice(closestPoints[2], 0, [
|
|
newPoint.lat,
|
|
newPoint.lng,
|
|
]);
|
|
|
|
// Hier direkt speichern nach Einfügen
|
|
saveLineData(lineData);
|
|
|
|
redrawPolyline(lineData);
|
|
|
|
// Event-Listener für das Verschieben des Markers hinzufügen
|
|
newMarker.on("dragend", () => {
|
|
const newCoords = newMarker.getLatLng();
|
|
setNewCoords(newCoords);
|
|
const newCoordinates = [...lineData.coordinates];
|
|
newCoordinates[closestPoints[2]] = [newCoords.lat, newCoords.lng];
|
|
lineData.coordinates = newCoordinates;
|
|
redrawPolyline(lineData);
|
|
|
|
updateMarkerPosition(newMarker.getLatLng(), lineData, newMarker);
|
|
saveLineData(lineData); // Speichern der neuen Koordinaten nach dem Verschieben
|
|
});
|
|
};
|
|
|
|
export const handleEditPoi = (
|
|
marker,
|
|
userRights,
|
|
setCurrentPoiData,
|
|
setShowPoiUpdateModal,
|
|
fetchPoiData,
|
|
toast
|
|
) => {
|
|
// Prüfung, ob der Benutzer die notwendigen Rechte hat
|
|
if (!userRights || !userRights.includes(56)) {
|
|
toast.error("Benutzer hat keine Berechtigung zum Bearbeiten.", {
|
|
position: "top-center",
|
|
autoClose: 5000,
|
|
hideProgressBar: false,
|
|
closeOnClick: true,
|
|
pauseOnHover: true,
|
|
draggable: true,
|
|
progress: undefined,
|
|
});
|
|
console.log("Benutzer hat keine Berechtigung zum Bearbeiten.");
|
|
return; // Beendet die Funktion frühzeitig, wenn keine Berechtigung vorliegt
|
|
}
|
|
|
|
setCurrentPoiData({
|
|
idPoi: marker.options.id,
|
|
name: marker.options.name,
|
|
description: marker.options.description,
|
|
});
|
|
|
|
fetchPoiData(marker.options.id);
|
|
|
|
setShowPoiUpdateModal(true);
|
|
};
|
|
|
|
export const removeMarker = (marker, lineData, currentZoom, currentCenter) => {
|
|
// Save zoom and center to localStorage
|
|
//localStorage.setItem("mapZoom", currentZoom);
|
|
//localStorage.setItem("mapCenter", JSON.stringify(currentCenter));
|
|
|
|
// Find the index of the coordinate that matches the marker's position
|
|
const index = lineData.coordinates.findIndex((coord) =>
|
|
L.latLng(coord[0], coord[1]).equals(marker.getLatLng())
|
|
);
|
|
|
|
if (index !== -1) {
|
|
// Remove the coordinate from the line data
|
|
lineData.coordinates.splice(index, 1);
|
|
|
|
// Redraw the polyline with the updated coordinates
|
|
redrawPolyline(lineData);
|
|
|
|
// Remove the marker from the map
|
|
marker.remove();
|
|
|
|
// Save the updated line data
|
|
saveLineData(lineData);
|
|
|
|
// Refresh the browser
|
|
window.location.reload();
|
|
}
|
|
};
|