fix: leere Array

This commit is contained in:
ISA
2025-08-20 14:41:57 +02:00
parent 819fde9605
commit 22692f8153
7 changed files with 49 additions and 36 deletions

View File

@@ -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 # 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 # basePath wird jetzt in public/config.json gepflegt
# App-Versionsnummer # App-Versionsnummer
NEXT_PUBLIC_APP_VERSION=1.1.326 NEXT_PUBLIC_APP_VERSION=1.1.327

View File

@@ -25,4 +25,4 @@ NEXT_PUBLIC_USE_MOCKS=false
# basePath wird jetzt in public/config.json gepflegt # basePath wird jetzt in public/config.json gepflegt
# App-Versionsnummer # App-Versionsnummer
NEXT_PUBLIC_APP_VERSION=1.1.326 NEXT_PUBLIC_APP_VERSION=1.1.327

View File

@@ -57,7 +57,7 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior
if (layerRefs.current[key]) { if (layerRefs.current[key]) {
// Entferne alle Marker aus der LayerGroup, bevor neue hinzugefügt werden // Entferne alle Marker aus der LayerGroup, bevor neue hinzugefügt werden
layerRefs.current[key].clearLayers(); layerRefs.current[key].clearLayers();
newMarkers.forEach(marker => { (Array.isArray(newMarkers) ? newMarkers : []).forEach(marker => {
// Nur LayerGroup verwenden, nicht direkt auf map // Nur LayerGroup verwenden, nicht direkt auf map
marker.addTo(layerRefs.current[key]); marker.addTo(layerRefs.current[key]);
}); });
@@ -86,7 +86,7 @@ const useDynamicDeviceLayers = (map, GisSystemStatic, mapLayersVisibility, prior
Object.entries(markerStates).forEach(([key, markers]) => { Object.entries(markerStates).forEach(([key, markers]) => {
const isVisible = mapLayersVisibility[key] ?? true; // undefined = true const isVisible = mapLayersVisibility[key] ?? true; // undefined = true
markers.forEach(marker => { (Array.isArray(markers) ? markers : []).forEach(marker => {
const hasLayer = map.hasLayer(marker); const hasLayer = map.hasLayer(marker);
// Logik korrigiert: // Logik korrigiert:

View File

@@ -375,7 +375,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
} }
// vorherige Marker & Polylinien vollständig bereinigen // vorherige Marker & Polylinien vollständig bereinigen
markers.forEach(marker => { (Array.isArray(markers) ? markers : []).forEach(marker => {
marker.remove(); marker.remove();
}); });
cleanupPolylinesForMemory(polylines, map); cleanupPolylinesForMemory(polylines, map);
@@ -394,7 +394,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
polylineVisible // kommt aus Redux polylineVisible // kommt aus Redux
); );
newPolylines.forEach((polyline, index) => { (Array.isArray(newPolylines) ? newPolylines : []).forEach((polyline, index) => {
const tooltipContent = const tooltipContent =
tooltipContents[`${linePositions[index].idLD}-${linePositions[index].idModul}`] || tooltipContents[`${linePositions[index].idLD}-${linePositions[index].idModul}`] ||
"Die Linie ist noch nicht in Webservice vorhanden oder bekommt keine Daten"; "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 // Entferne alle Marker aus der Karte
if (!map) return; // Sicherstellen, dass map existiert if (!map) return; // Sicherstellen, dass map existiert
areaMarkers.forEach(marker => { (Array.isArray(areaMarkers) ? areaMarkers : []).forEach(marker => {
if (map.hasLayer(marker)) { if (map.hasLayer(marker)) {
map.removeLayer(marker); map.removeLayer(marker);
} }
}); });
} else { } else {
// Wenn editMode aktiviert ist, füge die Marker hinzu und aktiviere Dragging // 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)) { if (!map.hasLayer(marker)) {
marker.addTo(map); // Layer hinzufügen marker.addTo(map); // Layer hinzufügen
} }
@@ -836,7 +836,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
useEffect(() => { useEffect(() => {
if (poiTypStatus === "succeeded" && Array.isArray(poiTypData)) { if (poiTypStatus === "succeeded" && Array.isArray(poiTypData)) {
const map = new Map(); 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); setPoiTypMap(map);
} }
}, [poiTypData, poiTypStatus]); }, [poiTypData, poiTypStatus]);
@@ -928,7 +930,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}, [GisSystemStatic]); }, [GisSystemStatic]);
useEffect(() => { useEffect(() => {
if (Array.isArray(GisSystemStatic)) { if (Array.isArray(GisSystemStatic)) {
GisSystemStatic.forEach(system => { (Array.isArray(GisSystemStatic) ? GisSystemStatic : []).forEach(system => {
const key = `system-${system.IdSystem}`; const key = `system-${system.IdSystem}`;
if (!(key in mapLayersVisibility)) { if (!(key in mapLayersVisibility)) {
dispatch(setLayerVisibility({ key, value: true })); // Sichtbarkeit aktivieren dispatch(setLayerVisibility({ key, value: true })); // Sichtbarkeit aktivieren

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "nodemap", "name": "nodemap",
"version": "1.1.326", "version": "1.1.327",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "nodemap", "name": "nodemap",
"version": "1.1.326", "version": "1.1.327",
"dependencies": { "dependencies": {
"@emotion/react": "^11.13.3", "@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0", "@emotion/styled": "^11.13.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "nodemap", "name": "nodemap",
"version": "1.1.326", "version": "1.1.327",
"dependencies": { "dependencies": {
"@emotion/react": "^11.13.3", "@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0", "@emotion/styled": "^11.13.0",

View File

@@ -60,47 +60,58 @@ export const initializeMap = (
mapContainer.innerHTML = ""; mapContainer.innerHTML = "";
} }
// --- CONFIG LOADING ---
let config = null;
let tileLayerUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; let tileLayerUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
let mapCenter = [53.111111, 8.4625];
let mapZoom = 12;
let minZoom = 5; let minZoom = 5;
let maxZoom = 15; let maxZoom = 15;
let mapCenter = [53.111111, 8.4625];
try { try {
if (window && window.__tileSource && window.__tileSourceUrl) { if (window && window.__leafletConfig) {
tileLayerUrl = window.__tileSourceUrl; config = window.__leafletConfig;
minZoom = window.__tileSourceMinZoom;
maxZoom = window.__tileSourceMaxZoom;
} else { } else {
// Synchronous config fetch using XMLHttpRequest (since fetch is async)
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open("GET", "/config.json", false); // false = synchronous xhr.open("GET", "/config.json", false); // false = synchronous
xhr.send(null); xhr.send(null);
if (xhr.status === 200) { if (xhr.status === 200) {
const config = JSON.parse(xhr.responseText); config = JSON.parse(xhr.responseText);
window.__leafletConfig = config;
}
}
if (config) {
// Tile source
if (config.tileSources && config.active && config.tileSources[config.active]) { if (config.tileSources && config.active && config.tileSources[config.active]) {
const source = config.tileSources[config.active]; const tileSource = config.tileSources[config.active];
tileLayerUrl = source.url; tileLayerUrl = tileSource.url || tileLayerUrl;
minZoom = source.minZoom; minZoom = tileSource.minZoom ?? minZoom;
maxZoom = source.maxZoom; maxZoom = tileSource.maxZoom ?? maxZoom;
window.__tileSourceUrl = tileLayerUrl; }
window.__tileSourceMinZoom = minZoom; // Center
window.__tileSourceMaxZoom = maxZoom; if (Array.isArray(config.center)) {
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; 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) { } catch (e) {
// Fallback bleibt OSM // Fallback bleibt OSM und Defaults
} }
let initMap; let initMap;
try { try {
initMap = L.map(mapContainer, { initMap = L.map(mapContainer, {
center: mapCenter, center: mapCenter,
zoom: minZoom, zoom: mapZoom,
minZoom: minZoom, minZoom: minZoom,
maxZoom: maxZoom, maxZoom: maxZoom,
zoomControl: false, zoomControl: false,