feat: Add Gebietsumring (potentialflächen_wind) from DB
Deploy Standortplaner / deploy (push) Successful in 17s Details

This commit is contained in:
Johannes Baumeister 2026-07-03 11:24:48 +02:00
parent 60748049ea
commit 4069988798
2 changed files with 91 additions and 0 deletions

33
app.js
View File

@ -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(`<b>Gebietsumring</b>`);
}
});
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 => {

View File

@ -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;