From 22692f815335dc23f67093bdd2ad3d32e57ea475 Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 20 Aug 2025 14:41:57 +0200 Subject: [PATCH] fix: leere Array --- .env.development | 2 +- .env.production | 2 +- .../devices/hooks/useDynamicDeviceLayers.js | 4 +- components/mainComponent/MapComponent.js | 14 +++-- package-lock.json | 4 +- package.json | 2 +- utils/initializeMap.js | 57 +++++++++++-------- 7 files changed, 49 insertions(+), 36 deletions(-) diff --git a/.env.development b/.env.development index 42643a969..cad85168b 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.326 +NEXT_PUBLIC_APP_VERSION=1.1.327 diff --git a/.env.production b/.env.production index 7e4d4b56a..6eb07fc00 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.326 +NEXT_PUBLIC_APP_VERSION=1.1.327 diff --git a/components/devices/hooks/useDynamicDeviceLayers.js b/components/devices/hooks/useDynamicDeviceLayers.js index 16f48390f..8dd8361c7 100644 --- a/components/devices/hooks/useDynamicDeviceLayers.js +++ b/components/devices/hooks/useDynamicDeviceLayers.js @@ -57,7 +57,7 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior if (layerRefs.current[key]) { // Entferne alle Marker aus der LayerGroup, bevor neue hinzugefügt werden layerRefs.current[key].clearLayers(); - newMarkers.forEach(marker => { + (Array.isArray(newMarkers) ? newMarkers : []).forEach(marker => { // Nur LayerGroup verwenden, nicht direkt auf map marker.addTo(layerRefs.current[key]); }); @@ -86,7 +86,7 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior Object.entries(markerStates).forEach(([key, markers]) => { const isVisible = mapLayersVisibility[key] ?? true; // undefined = true - markers.forEach(marker => { + (Array.isArray(markers) ? markers : []).forEach(marker => { const hasLayer = map.hasLayer(marker); // Logik korrigiert: diff --git a/components/mainComponent/MapComponent.js b/components/mainComponent/MapComponent.js index 952218cd3..753f56780 100644 --- a/components/mainComponent/MapComponent.js +++ b/components/mainComponent/MapComponent.js @@ -375,7 +375,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { } // vorherige Marker & Polylinien vollständig bereinigen - markers.forEach(marker => { + (Array.isArray(markers) ? markers : []).forEach(marker => { marker.remove(); }); cleanupPolylinesForMemory(polylines, map); @@ -394,7 +394,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { polylineVisible // kommt aus Redux ); - newPolylines.forEach((polyline, index) => { + (Array.isArray(newPolylines) ? newPolylines : []).forEach((polyline, index) => { const tooltipContent = tooltipContents[`${linePositions[index].idLD}-${linePositions[index].idModul}`] || "Die Linie ist noch nicht in Webservice vorhanden oder bekommt keine Daten"; @@ -616,14 +616,14 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { // Entferne alle Marker aus der Karte if (!map) return; // Sicherstellen, dass map existiert - areaMarkers.forEach(marker => { + (Array.isArray(areaMarkers) ? areaMarkers : []).forEach(marker => { if (map.hasLayer(marker)) { map.removeLayer(marker); } }); } else { // Wenn editMode aktiviert ist, füge die Marker hinzu und aktiviere Dragging - areaMarkers.forEach(marker => { + (Array.isArray(areaMarkers) ? areaMarkers : []).forEach(marker => { if (!map.hasLayer(marker)) { marker.addTo(map); // Layer hinzufügen } @@ -836,7 +836,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { useEffect(() => { if (poiTypStatus === "succeeded" && Array.isArray(poiTypData)) { const map = new Map(); - poiTypData.forEach(item => map.set(item.idPoiTyp, item.name)); + (Array.isArray(poiTypData) ? poiTypData : []).forEach(item => + map.set(item.idPoiTyp, item.name) + ); setPoiTypMap(map); } }, [poiTypData, poiTypStatus]); @@ -928,7 +930,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }, [GisSystemStatic]); useEffect(() => { if (Array.isArray(GisSystemStatic)) { - GisSystemStatic.forEach(system => { + (Array.isArray(GisSystemStatic) ? GisSystemStatic : []).forEach(system => { const key = `system-${system.IdSystem}`; if (!(key in mapLayersVisibility)) { dispatch(setLayerVisibility({ key, value: true })); // Sichtbarkeit aktivieren diff --git a/package-lock.json b/package-lock.json index eaf52ed78..073234d78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodemap", - "version": "1.1.326", + "version": "1.1.327", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nodemap", - "version": "1.1.326", + "version": "1.1.327", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/package.json b/package.json index 4da835559..cc89a00f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodemap", - "version": "1.1.326", + "version": "1.1.327", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/utils/initializeMap.js b/utils/initializeMap.js index dac1fc7fa..8c979e87f 100644 --- a/utils/initializeMap.js +++ b/utils/initializeMap.js @@ -60,47 +60,58 @@ export const initializeMap = ( mapContainer.innerHTML = ""; } + // --- CONFIG LOADING --- + let config = null; let tileLayerUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; + let mapCenter = [53.111111, 8.4625]; + let mapZoom = 12; let minZoom = 5; let maxZoom = 15; - let mapCenter = [53.111111, 8.4625]; try { - if (window && window.__tileSource && window.__tileSourceUrl) { - tileLayerUrl = window.__tileSourceUrl; - minZoom = window.__tileSourceMinZoom; - maxZoom = window.__tileSourceMaxZoom; + if (window && window.__leafletConfig) { + config = window.__leafletConfig; } else { - // Synchronous config fetch using XMLHttpRequest (since fetch is async) const xhr = new XMLHttpRequest(); xhr.open("GET", "/config.json", false); // false = synchronous xhr.send(null); if (xhr.status === 200) { - const config = JSON.parse(xhr.responseText); - if (config.tileSources && config.active && config.tileSources[config.active]) { - const source = config.tileSources[config.active]; - tileLayerUrl = source.url; - minZoom = source.minZoom; - maxZoom = source.maxZoom; - window.__tileSourceUrl = tileLayerUrl; - window.__tileSourceMinZoom = minZoom; - window.__tileSourceMaxZoom = maxZoom; - if (source.center && Array.isArray(source.center) && source.center.length === 2) { - mapCenter = source.center; - } else if (config.center && Array.isArray(config.center) && config.center.length === 2) { - mapCenter = config.center; - } - } + config = JSON.parse(xhr.responseText); + window.__leafletConfig = config; + } + } + if (config) { + // Tile source + if (config.tileSources && config.active && config.tileSources[config.active]) { + const tileSource = config.tileSources[config.active]; + tileLayerUrl = tileSource.url || tileLayerUrl; + minZoom = tileSource.minZoom ?? minZoom; + maxZoom = tileSource.maxZoom ?? maxZoom; + } + // Center + if (Array.isArray(config.center)) { + mapCenter = config.center; + } + // Zoom (optional, fallback to 12) + if (typeof config.zoom === "number") { + mapZoom = config.zoom; + } + // minZoom/maxZoom global fallback + if (typeof config.minZoom === "number") { + minZoom = config.minZoom; + } + if (typeof config.maxZoom === "number") { + maxZoom = config.maxZoom; } } } catch (e) { - // Fallback bleibt OSM + // Fallback bleibt OSM und Defaults } let initMap; try { initMap = L.map(mapContainer, { center: mapCenter, - zoom: minZoom, + zoom: mapZoom, minZoom: minZoom, maxZoom: maxZoom, zoomControl: false,