From 261b7a1bf3f642b1895e37dd650b62c7a62db92e Mon Sep 17 00:00:00 2001 From: Johannes Baumeister Date: Thu, 25 Jun 2026 09:19:05 +0200 Subject: [PATCH] feat: resolve project ID from URL parameters and auto-zoom to project parcels --- app.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 41e3c4a..e4c6835 100644 --- a/app.js +++ b/app.js @@ -17,6 +17,11 @@ document.addEventListener('DOMContentLoaded', async () => { hasLoadedFromDB: false }; + const getProjektId = () => { + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get('project') || urlParams.get('projekt') || urlParams.get('projekt_id') || "BWSamern-Ohne"; + }; + const STATUS_MAP = { 'Ablehnung': { color: '#ff0000', desc: 'Der Eigentümer lehnt das Vorhaben strikt ab.' }, 'Erwartet Negativ': { color: '#ffa500', desc: 'Erste Signale oder Tendenzen deuten auf eine Ablehnung hin.' }, @@ -1865,7 +1870,7 @@ document.addEventListener('DOMContentLoaded', async () => { setTimeout(() => element.style.borderColor = '', 1500); } - const projekt_id = "BWSamern-Ohne"; + const projekt_id = getProjektId(); try { const response = await fetch('/api/sicherung', { @@ -1941,7 +1946,7 @@ document.addEventListener('DOMContentLoaded', async () => { }); async function loadOwnerStatusesFromDB() { - const projekt_id = "BWSamern-Ohne"; + const projekt_id = getProjektId(); console.log("Lade Eigentümer-Status aus Datenbank..."); try { const response = await fetch(`/api/sicherung/${projekt_id}`); @@ -2009,6 +2014,26 @@ document.addEventListener('DOMContentLoaded', async () => { } } } + + // Auto-zoom to project parcels + if (ownerLayerName && overlays[ownerLayerName]) { + const layer = overlays[ownerLayerName]; + const layers = layer.getLayers(); + const matchedLayers = layers.filter(l => { + if (!l.feature?.properties) return false; + const props = l.feature.properties; + const firstName = (props.vorname || props.VNA || '').trim(); + const lastName = (props.nachname || props.GNA || '').trim(); + const matched = getAlkisOwnerStatus(firstName, lastName, state); + return matched && matched.status && matched.status.toLowerCase() !== 'none'; + }); + + if (matchedLayers.length > 0) { + const group = L.featureGroup(matchedLayers); + state.map.fitBounds(group.getBounds()); + console.log(`Auto-Zoom auf ${matchedLayers.length} Flächen des Projekts ausgeführt.`); + } + } } catch (e) { console.error("Fehler bei der Initialisierung des Planungstools:", e); } finally { @@ -2085,7 +2110,7 @@ document.addEventListener('DOMContentLoaded', async () => { const statusEl = document.getElementById('statusInfo'); if (statusEl) statusEl.innerText = "Speicherung läuft..."; - const projekt_id = "BWSamern-Ohne"; + const projekt_id = getProjektId(); const turbineData = state.turbines.map(t => ({ nr: t.nr, variant: t.variant, @@ -2122,7 +2147,7 @@ document.addEventListener('DOMContentLoaded', async () => { } async function loadTurbinesFromDB() { - const projekt_id = "BWSamern-Ohne"; + const projekt_id = getProjektId(); const statusEl = document.getElementById('statusInfo'); console.log(`Lade WEAs aus Datenbank für Projekt: ${projekt_id}...`); try {