feat: Refactor utils.js into specialized utility modules

- 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.
This commit is contained in:
ISA
2024-07-09 08:10:02 +02:00
parent 467be2c106
commit b53fe1b3f1
6 changed files with 290 additions and 176 deletions

63
utils/mapUtils.js Normal file
View File

@@ -0,0 +1,63 @@
import L from "leaflet";
export const redrawPolyline = (lineData, lineColors, tooltipContents, map) => {
if (!lineData || !lineColors || !tooltipContents || !map) {
console.error("Invalid parameters for redrawPolyline");
return;
}
if (!lineData.coordinates || !Array.isArray(lineData.coordinates)) {
console.error("Invalid coordinates in lineData");
return;
}
const color = lineColors[lineData.idModul] || "#000000";
const tooltipContent =
tooltipContents[lineData.idModul] || "Standard-Tooltip-Inhalt";
if (lineData.polyline) map.removeLayer(lineData.polyline);
lineData.polyline = L.polyline(lineData.coordinates, {
color: color,
}).addTo(map);
lineData.polyline.bindTooltip(tooltipContent, {
permanent: false,
direction: "auto",
});
lineData.polyline.on("mouseover", () => {
lineData.polyline.setStyle({ weight: 10 });
lineData.polyline.bringToFront();
});
lineData.polyline.on("mouseout", () => {
lineData.polyline.setStyle({ weight: 5 });
});
};
export const saveLineData = (lineData) => {
fetch("/api/talas_v5_DB/gisLines/updateLineCoordinates", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
idModul: lineData.idModul,
idLD: lineData.idLD,
newCoordinates: lineData.coordinates,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error("Fehler beim Speichern der Linienänderungen");
}
return response.json();
})
.then((data) => {
console.log("Linienänderungen gespeichert:", data);
})
.catch((error) => {
console.error("Fehler beim Speichern der Linienänderungen:", error);
});
};