fix: Layer-Visibility-Konflikt bei SMS Modem behoben

- Ursache des Problems: Inkonsistenz bei der Benennung des Layers in `useLayerVisibility` ("SMSFunkmodem" vs. "SMSModem").
- Anpassung des Layer-Namens in `useLayerVisibility`, um mit der `GisSystemStatic`-Datenstruktur und `mapLayersVisibility` übereinzustimmen.
- Konflikt führte dazu, dass der SMS Modem-Layer nicht korrekt sichtbar/unsichtbar geschaltet wurde.
- Debugging und Anpassungen führten zur erfolgreichen Behebung des Fehlers.

Dieser Fix stellt sicher, dass die Sichtbarkeit der Marker-Layer konsistent und wie erwartet funktioniert.
This commit is contained in:
ISA
2024-11-29 11:10:03 +01:00
parent 35915bb91f
commit 4a9381ae46
6 changed files with 203 additions and 182 deletions

View File

@@ -4,49 +4,60 @@ import L from "leaflet";
import "leaflet-contextmenu";
import { addContextMenuToMarker } from "../../utils/addContextMenuToMarker";
const useSmsfunkmodemMarkersLayer = (map, oms, GisSystemStatic, priorityConfig) => {
const useSmsfunkmodemMarkersLayer = (map, oms, GisSystemStatic, priorityConfig, isVisible) => {
const [smsfunkmodemMarkers, setSmsfunkmodemMarkers] = useState([]);
useEffect(() => {
if (map && GisSystemStatic) {
const markers = GisSystemStatic.filter((station) => station.System === 111).map((station) => {
const marker = L.marker([station.Latitude, station.Longitude], {
icon: L.icon({
iconUrl: "/img/icons/pois/sms-funkmodem.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
}),
id: station.id,
areaName: station.Area_Name,
draggable: false,
}).bindPopup(`
<div>
<b class="text-xl text-black-700">${station.Area_Name || "Unbekannt"}</b><br>
${station.Description || "No Description"}<br>
</div>
`);
if (!map || !GisSystemStatic) return;
marker.on("mouseover", function () {
this.openPopup();
});
// Debugging: Logge die Sichtbarkeit und die übergebenen Daten
console.log("isVisible für SMS Modem:", isVisible);
console.log("Alle Stationen in GisSystemStatic:", GisSystemStatic);
marker.on("mouseout", function () {
this.closePopup();
});
// Hilfsfunktion: Normalisiert Strings
const normalizeString = (str) => str?.trim().toLowerCase() || "";
addContextMenuToMarker(marker);
// Filter für SMS Modem (System === 111 oder Name entspricht "SMS Modem")
const markers = isVisible
? GisSystemStatic.filter((station) => station.System === 111 || normalizeString(station.Name) === "SMS Modem").map((station) => {
console.log("Gefundener SMS Modem-Marker:", station); // Debugging
const marker = L.marker([station.Latitude, station.Longitude], {
icon: L.icon({
iconUrl: "/img/icons/pois/sms-funkmodem.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
}),
id: station.id,
areaName: station.Area_Name,
draggable: false,
}).bindPopup(`
<div>
<b class="text-xl text-black-700">${station.Area_Name || "Unbekannt"}</b><br>
${station.Description || "No Description"}<br>
</div>
`);
return marker;
});
// Füge ein Kontextmenü hinzu
addContextMenuToMarker(marker);
return marker;
})
: [];
setSmsfunkmodemMarkers(markers);
markers.forEach((marker) => {
marker.addTo(map);
oms.addMarker(marker);
});
}
}, [map, GisSystemStatic, priorityConfig]);
// Setze die Marker im Zustand
setSmsfunkmodemMarkers(markers);
// Füge Marker zur Karte hinzu
markers.forEach((marker) => {
marker.addTo(map);
oms.addMarker(marker);
});
// Cleanup: Entferne Marker bei Deaktivierung oder wenn der Hook entladen wird
return () => {
markers.forEach((marker) => marker.remove());
};
}, [map, GisSystemStatic, isVisible]);
return smsfunkmodemMarkers;
};