From 26d869f0299d5fd7213b4bc9abe913bb6a07d6d6 Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 20 Aug 2025 09:37:49 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Ger=C3=A4te-Marker=20werden=20nur=20noch?= =?UTF-8?q?=20=C3=BCber=20LayerGroups=20verwaltet,=20doppelte=20Marker=20a?= =?UTF-8?q?uf=20Karte=20verhindert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Geräte-Marker werden vor dem Hinzufügen aus LayerGroups entfernt und nur dort hinzugefügt Keine direkte .addTo(map) mehr für Geräte-Marker Debug-Ausgabe für Marker-Anzahl pro LayerGroup Problem mit mehrfachen Markern auf der Karte behoben --- .env.development | 2 +- .env.production | 2 +- .../devices/hooks/useDynamicDeviceLayers.js | 48 ++++++++++++------- package-lock.json | 4 +- package.json | 2 +- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/.env.development b/.env.development index 46dd9d567..65971fa6e 100644 --- a/.env.development +++ b/.env.development @@ -24,4 +24,4 @@ NEXT_PUBLIC_USE_MOCKS=true # z.B. http://10.10.0.13/xyz/index.aspx -> basePath in config.json auf /xyz setzen # basePath wird jetzt in public/config.json gepflegt # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.1.319 +NEXT_PUBLIC_APP_VERSION=1.1.320 diff --git a/.env.production b/.env.production index 642018afa..4f0d3c7d7 100644 --- a/.env.production +++ b/.env.production @@ -25,4 +25,4 @@ NEXT_PUBLIC_USE_MOCKS=false # basePath wird jetzt in public/config.json gepflegt # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.1.319 +NEXT_PUBLIC_APP_VERSION=1.1.320 diff --git a/components/devices/hooks/useDynamicDeviceLayers.js b/components/devices/hooks/useDynamicDeviceLayers.js index 32f452ee3..b644dc634 100644 --- a/components/devices/hooks/useDynamicDeviceLayers.js +++ b/components/devices/hooks/useDynamicDeviceLayers.js @@ -30,30 +30,44 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior if (!map || GisSystemStatic.length === 0) return; GisSystemStatic.forEach(({ Name, IdSystem }) => { - const key = `system-${IdSystem}`; // Einheitlicher Key - - if (!layerRefs.current[key]) { - layerRefs.current[key] = new L.LayerGroup().addTo(map); + const key = `system-${IdSystem}`; + // LayerGroup-Instanzierung und Bereinigung + if (layerRefs.current[key]) { + // Entferne alte LayerGroup von der Map, falls vorhanden + if (map.hasLayer(layerRefs.current[key])) { + map.removeLayer(layerRefs.current[key]); + } + layerRefs.current[key].clearLayers(); } + // Neue oder wiederverwendete LayerGroup anlegen und zur Map hinzufügen + if (!layerRefs.current[key]) { + layerRefs.current[key] = new L.LayerGroup(); + } + layerRefs.current[key].addTo(map); + // Debug-Ausgabe + /* console.log( + `[DeviceLayers] LayerGroup für ${key} auf Map hinzugefügt. Aktuelle LayerGroups:`, + Object.keys(layerRefs.current) + ); */ createAndSetDevices( IdSystem, newMarkers => { - const oldMarkers = markerStates[key]; - - // Entferne alte Marker aus Karte und OMS - if (oldMarkers && Array.isArray(oldMarkers)) { - oldMarkers.forEach(marker => { - if (map.hasLayer(marker)) { - map.removeLayer(marker); - } - if (oms) { - oms.removeMarker(marker); - } + // Füge neue Marker der LayerGroup hinzu (nur Geräte-Marker) + if (layerRefs.current[key]) { + // Entferne alle Marker aus der LayerGroup, bevor neue hinzugefügt werden + layerRefs.current[key].clearLayers(); + newMarkers.forEach(marker => { + // Nur LayerGroup verwenden, nicht direkt auf map + marker.addTo(layerRefs.current[key]); }); + // Debug: Anzahl Marker in LayerGroup + console.log( + `[DeviceLayers] ${ + layerRefs.current[key].getLayers().length + } Marker in LayerGroup für ${key}` + ); } - - // Neue Marker setzen setMarkerStates(prev => ({ ...prev, [key]: newMarkers })); }, GisSystemStatic, diff --git a/package-lock.json b/package-lock.json index 8c6b2eba6..5f10c77db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodemap", - "version": "1.1.319", + "version": "1.1.320", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nodemap", - "version": "1.1.319", + "version": "1.1.320", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/package.json b/package.json index 9cad488c8..3158041ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodemap", - "version": "1.1.319", + "version": "1.1.320", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0",