diff --git a/index.html b/index.html index 8b4585e..b99b2ec 100644 --- a/index.html +++ b/index.html @@ -2761,12 +2761,20 @@ try { console.log("Starte Daten-Abruf vom Server..."); + const sanitize = (gj) => { + if (!gj || !gj.features) return { type: "FeatureCollection", features: [] }; + return { + ...gj, + features: gj.features.filter(f => f && f.geometry && f.geometry.coordinates) + }; + }; + // 1. Eigentümer / Flurstücke const ownersRes = await fetch(`${API_BASE}/owners`); if (ownersRes.ok) { - let geojson = await ownersRes.json(); + let geojson = sanitize(await ownersRes.json()); // Transformation falls die DB UTM-Koordinaten liefert (z.B. > 1000) - if (geojson.features && geojson.features.length > 0) { + if (geojson.features.length > 0) { const firstCoord = geojson.features[0].geometry?.coordinates?.[0]?.[0]?.[0] || 0; if (Math.abs(firstCoord) > 1000) { console.log("Erkannte UTM-Koordinaten in DB, transformiere..."); @@ -2776,7 +2784,6 @@ state.owners = geojson; updateOwnerLayer(); - // Auto-Zoom auf die Daten beim ersten Laden if (layers.owners.getBounds().isValid()) { map.fitBounds(layers.owners.getBounds()); } @@ -2787,7 +2794,6 @@ if (variantsRes.ok) { const variants = await variantsRes.json(); if (variants && variants.length > 0) { - // Merging logic to preserve existing objects but update routes variants.forEach(sv => { const local = state.variants.find(lv => lv.id === sv.id); if (local) { @@ -2802,17 +2808,24 @@ // 3. Nutzungen const usageRes = await fetch(`${API_BASE}/usage`); if (usageRes.ok) { - state.usage = await usageRes.json(); + state.usage = sanitize(await usageRes.json()); updateUsageLayer(); } // 4. WEA const weaRes = await fetch(`${API_BASE}/wea`); if (weaRes.ok) { - state.wea = await weaRes.json(); + state.wea = sanitize(await weaRes.json()); updateWEALayer(); } + // 5. Infratruktur + const infraRes = await fetch(`${API_BASE}/infrastructure`); + if (infraRes.ok) { + state.infrastructure = sanitize(await infraRes.json()); + updateInfrastructureLayer(); + } + console.log("Daten erfolgreich vom Server geladen."); } catch (err) { console.error("Fehler beim Laden der Server-Daten:", err);