From 4069988798e2305ef3420de3b6523a71e76abd56 Mon Sep 17 00:00:00 2001 From: Johannes Baumeister Date: Fri, 3 Jul 2026 11:24:48 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20Gebietsumring=20(potentialfl?= =?UTF-8?q?=C3=A4chen=5Fwind)=20from=20DB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 33 +++++++++++++++++++++++++++++++ server.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/app.js b/app.js index a033992..1b9416a 100644 --- a/app.js +++ b/app.js @@ -1233,6 +1233,39 @@ document.addEventListener('DOMContentLoaded', async () => { } } + // Gebietsumring (Potentialflächen) aus Datenbank laden + console.log("Lade Potentialflächen-Layer aus Datenbank..."); + const potResp = await fetch(`/api/layers/potentialflaechen?project=${encodeURIComponent(projId)}`).catch(err => { + console.error("Netzwerkfehler beim Laden des Potentialflächen-Layers:", err); + return null; + }); + + if (potResp?.ok) { + const data = await potResp.json(); + console.log(`Potentialflächen API: ${data.features ? data.features.length : 0} Features erhalten.`); + if (data.features && data.features.length > 0) { + const potLayer = L.geoJSON(data, { + style: { + color: "#00aaff", + weight: 2, + fillOpacity: 0.1, + dashArray: '5, 5' + }, + onEachFeature: (feature, layer) => { + layer.bindPopup(`Gebietsumring`); + } + }); + + const label = "Gebietsumring (DB)"; + overlays[label] = potLayer; + state.map.addLayer(potLayer); + layerControl.addOverlay(potLayer, label); + } + } else { + const errorText = potResp ? await potResp.text() : "Server nicht erreichbar"; + console.warn("Potentialflächen-Layer konnte nicht geladen werden:", errorText); + } + // ALKIS aus Datenbank IMMER laden console.log("Lade ALKIS-Layer aus Datenbank..."); const alkisResp = await fetch(`/api/layers/alkis?project=${encodeURIComponent(projId)}`).catch(err => { diff --git a/server.js b/server.js index a334880..db89e8d 100644 --- a/server.js +++ b/server.js @@ -492,6 +492,64 @@ app.get('/api/layers/alkis', async (req, res) => { } }); +// NEU: API zum Laden der Potentialflächen (Gebietsumring) als GeoJSON +app.get('/api/layers/potentialflaechen', async (req, res) => { + const projectParam = req.query.project || req.query.projekt_id || req.query.projekt; + log(`Lade Potentialflächen-Layer aus Datenbank für Projekt: ${projectParam || 'alle'}`); + const client = await pool.connect(); + try { + const hasAccess = await checkProjectAccess(req, projectParam, client); + if (!hasAccess) { + log(`Zugriff verweigert für Potentialflächen-Layer in Projekt: ${projectParam}`); + return res.status(403).json({ error: 'Keine Berechtigung für dieses Projekt.' }); + } + let whereClause = ''; + const params = []; + + if (projectParam) { + const projId = await resolveProjectId(client, projectParam); + const projName = await resolveProjectName(client, projectParam); + + whereClause = `WHERE projekt_id = $1`; + params.push(projectParam); // e.g. UUID + + if (projId && projId !== projectParam) { + whereClause += ` OR projekt_id = $${params.length + 1}`; + params.push(projId); + } + if (projName && projName !== projectParam && projName !== projId) { + whereClause += ` OR projekt_id = $${params.length + 1}`; + params.push(projName); + } + } + + const result = await client.query( + `SELECT jsonb_build_object( + 'type', 'FeatureCollection', + 'features', COALESCE(jsonb_agg(features.feature), '[]'::jsonb) + ) + FROM ( + SELECT jsonb_build_object( + 'type', 'Feature', + 'geometry', ST_AsGeoJSON(ST_Transform(geom, 4326))::jsonb, + 'properties', jsonb_build_object( + 'id', id + ) + ) AS feature + FROM geodaten."potentialflächen_wind" + ${whereClause} + ) features`, + params + ); + res.json(result.rows[0].jsonb_build_object); + } catch (err) { + log(`FEHLER beim Laden des Potentialflächen-Layers: ${err.message}`); + res.status(500).json({ error: err.message }); + } finally { + client.release(); + } +}); + // NEU: API zum Laden des Artennachweis-Layers als GeoJSON app.get('/api/layers/artennachweis', async (req, res) => { const projectParam = req.query.project || req.query.projekt_id || req.query.projekt;