- Split utils.js into three separate files to enhance modularity and maintainability: 1. geometryUtils.js: Contains geometry-related functions like parsePoint and findClosestPoints. 2. mapUtils.js: Contains functions related to map operations such as redrawPolyline and saveLineData. 3. markerUtils.js: Contains functions related to marker operations like insertNewMarker and handleEditPoi. - Updated import statements in the relevant files to reflect the new structure. - Ensured that each utility module is self-contained and has clear responsibilities. This refactor improves the separation of concerns, making the codebase more organized and easier to navigate. Future maintenance and enhancements can now be more easily localized to the appropriate utility module.
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
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();
|
|
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);
|
|
};
|