fix: Gerätemarker-Sichtbarkeit an Redux-Layerzustand gekoppelt
- Hardcodiertes Zeichnen der Gerätemarker beim Initialisieren entfernt - Sichtbarkeitssteuerung vollständig über mapLayersVisibility aus Redux umgesetzt - Dynamische Layererzeugung aus GisSystemStatic integriert - Marker werden nur angezeigt, wenn zugehöriger Layer aktiv ist
This commit is contained in:
@@ -17,12 +17,12 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior
|
||||
const [markerStates, setMarkerStates] = useState({});
|
||||
const layerRefs = useRef({});
|
||||
|
||||
// Marker initialisieren
|
||||
// Marker initialisieren (nicht sichtbar machen)
|
||||
useEffect(() => {
|
||||
if (!map || GisSystemStatic.length === 0) return;
|
||||
|
||||
GisSystemStatic.forEach(({ Name, IdSystem }) => {
|
||||
const key = `system-${IdSystem}`; // ✅ Einheitlicher Key
|
||||
const key = `system-${IdSystem}`; // Einheitlicher Key
|
||||
|
||||
if (!layerRefs.current[key]) {
|
||||
layerRefs.current[key] = new L.LayerGroup().addTo(map);
|
||||
@@ -30,12 +30,11 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior
|
||||
|
||||
createAndSetDevices(
|
||||
IdSystem,
|
||||
(newMarkers) => {
|
||||
setMarkerStates((prev) => ({ ...prev, [key]: newMarkers }));
|
||||
newMarkers.forEach((m) => {
|
||||
layerRefs.current[key].addLayer(m);
|
||||
if (oms) oms.addMarker(m);
|
||||
});
|
||||
newMarkers => {
|
||||
setMarkerStates(prev => ({ ...prev, [key]: newMarkers }));
|
||||
|
||||
// ❌ NICHT direkt zur Karte hinzufügen
|
||||
// Sichtbarkeit folgt im 2. useEffect
|
||||
checkOverlappingMarkers(map, newMarkers, plusRoundIcon, oms);
|
||||
},
|
||||
GisSystemStatic,
|
||||
@@ -44,14 +43,14 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior
|
||||
});
|
||||
}, [map, GisSystemStatic, priorityConfig]);
|
||||
|
||||
// Sichtbarkeit aktualisieren
|
||||
// Sichtbarkeit nach Redux-Status steuern
|
||||
useEffect(() => {
|
||||
if (!map) return;
|
||||
const editMode = localStorage.getItem("editMode") === "true";
|
||||
|
||||
Object.entries(markerStates).forEach(([key, markers]) => {
|
||||
const isVisible = mapLayersVisibility[key];
|
||||
markers.forEach((marker) => {
|
||||
markers.forEach(marker => {
|
||||
const hasLayer = map.hasLayer(marker);
|
||||
if (editMode || !isVisible) {
|
||||
if (hasLayer) map.removeLayer(marker);
|
||||
@@ -61,9 +60,7 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior
|
||||
});
|
||||
});
|
||||
|
||||
const allMarkers = Object.values(markerStates)
|
||||
.filter(Array.isArray) // nur Arrays zulassen
|
||||
.flat();
|
||||
const allMarkers = Object.values(markerStates).filter(Array.isArray).flat();
|
||||
|
||||
checkOverlappingMarkers(map, allMarkers, plusRoundIcon);
|
||||
}, [map, markerStates, mapLayersVisibility]);
|
||||
|
||||
Reference in New Issue
Block a user