feat: Marker-Cleanup zur Vermeidung von Memory Leaks implementiert

- cleanupMarkers() Utility in /utils/common/cleanupMarkers.js erstellt
- Marker-Cleanup in MapComponent.js vor createAndSetDevices() integriert
- createAndSetDevices.js von Cleanup-Verantwortung befreit (reine Erzeugung)
- setupPOIs.js erweitert um cleanupMarkers() vor Layer-Neuerstellung
- poiUtils.js und markerUtils.js angepasst: cleanupMarkers() ersetzt .remove()
- Memory Leaks durch verwaiste Tooltips, Events und Marker behoben
- Grundlage für wiederverwendbare Marker-Cleanup-Logik für POIs, Geräte, Linien geschaffen
This commit is contained in:
ISA
2025-06-06 10:21:56 +02:00
parent ec31b36b3d
commit f7f7122620
10 changed files with 160 additions and 55 deletions

View File

@@ -6,9 +6,10 @@ import { redrawPolyline } from "./polylines/redrawPolyline.js";
import { store } from "../redux/store";
import { updatePolylineCoordinatesThunk } from "../redux/thunks/database/polylines/updatePolylineCoordinatesThunk";
import { cleanupMarkers } from "@/utils/common/cleanupMarkers";
// 🧠 Zentrale Redux-Dispatch-Hilfsfunktion
const savePolylineRedux = (lineData) => {
const savePolylineRedux = lineData => {
return store
.dispatch(
updatePolylineCoordinatesThunk({
@@ -18,7 +19,7 @@ const savePolylineRedux = (lineData) => {
})
)
.unwrap()
.catch((error) => {
.catch(error => {
console.error("Fehler beim Speichern der Linienkoordinaten:", error.message);
});
};
@@ -49,12 +50,14 @@ export const insertNewPOI = (closestPoints, newPoint, lineData, map) => {
};
export const removePOI = (marker, lineData, currentZoom, currentCenter) => {
const index = lineData.coordinates.findIndex((coord) => L.latLng(coord[0], coord[1]).equals(marker.getLatLng()));
const index = lineData.coordinates.findIndex(coord =>
L.latLng(coord[0], coord[1]).equals(marker.getLatLng())
);
if (index !== -1) {
lineData.coordinates.splice(index, 1);
redrawPolyline(lineData);
marker.remove();
cleanupMarkers([marker]);
savePolylineRedux(lineData);
window.location.reload();
}