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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user