feat: filter ALKIS layers by project and auto-zoom to project boundaries at startup
Deploy Standortplaner / deploy (push) Successful in 16s
Details
Deploy Standortplaner / deploy (push) Successful in 16s
Details
This commit is contained in:
parent
261b7a1bf3
commit
685bfb1f3b
17
app.js
17
app.js
|
|
@ -1218,7 +1218,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
||||||
// ALKIS aus Datenbank IMMER laden
|
// ALKIS aus Datenbank IMMER laden
|
||||||
console.log("Lade ALKIS-Layer aus Datenbank...");
|
console.log("Lade ALKIS-Layer aus Datenbank...");
|
||||||
const alkisResp = await fetch('/api/layers/alkis').catch(err => {
|
const projId = getProjektId();
|
||||||
|
const alkisResp = await fetch(`/api/layers/alkis?project=${encodeURIComponent(projId)}`).catch(err => {
|
||||||
console.error("Netzwerkfehler beim Laden des ALKIS-Layers:", err);
|
console.error("Netzwerkfehler beim Laden des ALKIS-Layers:", err);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
@ -1228,6 +1229,20 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
console.log(`ALKIS API: ${data.features ? data.features.length : 0} Features erhalten.`);
|
console.log(`ALKIS API: ${data.features ? data.features.length : 0} Features erhalten.`);
|
||||||
await processALKISData(data, "Eigentümer (ALKIS DB)");
|
await processALKISData(data, "Eigentümer (ALKIS DB)");
|
||||||
|
|
||||||
|
// Auto-zoom to project parcels bounds if features exist
|
||||||
|
const alkisLayer = overlays["Eigentümer (ALKIS DB)"];
|
||||||
|
if (alkisLayer && data.features && data.features.length > 0) {
|
||||||
|
try {
|
||||||
|
const bounds = alkisLayer.getBounds();
|
||||||
|
if (bounds.isValid()) {
|
||||||
|
state.map.fitBounds(bounds);
|
||||||
|
console.log("Erfolgreich auf ALKIS-Flächen gezoomt.");
|
||||||
|
}
|
||||||
|
} catch (zoomErr) {
|
||||||
|
console.error("Fehler beim Zoomen auf ALKIS-Flächen:", zoomErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cleanupLocalOwnerLayers();
|
cleanupLocalOwnerLayers();
|
||||||
} else {
|
} else {
|
||||||
const errorText = alkisResp ? await alkisResp.text() : "Server nicht erreichbar";
|
const errorText = alkisResp ? await alkisResp.text() : "Server nicht erreichbar";
|
||||||
|
|
|
||||||
69
server.js
69
server.js
|
|
@ -210,41 +210,60 @@ app.get('/api/sicherung/:projekt_id', async (req, res) => {
|
||||||
|
|
||||||
// NEU: API zum Laden des ALKIS-Layers als GeoJSON
|
// NEU: API zum Laden des ALKIS-Layers als GeoJSON
|
||||||
app.get('/api/layers/alkis', async (req, res) => {
|
app.get('/api/layers/alkis', async (req, res) => {
|
||||||
log("Lade ALKIS-Layer aus Datenbank...");
|
const projectParam = req.query.project || req.query.projekt_id || req.query.projekt;
|
||||||
|
log(`Lade ALKIS-Layer aus Datenbank für Projekt: ${projectParam || 'alle'}`);
|
||||||
|
const client = await pool.connect();
|
||||||
try {
|
try {
|
||||||
const result = await pool.query(
|
let query = `
|
||||||
`SELECT jsonb_build_object(
|
|
||||||
'type', 'FeatureCollection',
|
|
||||||
'features', jsonb_agg(features.feature)
|
|
||||||
)
|
|
||||||
FROM (
|
|
||||||
SELECT jsonb_build_object(
|
SELECT jsonb_build_object(
|
||||||
'type', 'Feature',
|
'type', 'Feature',
|
||||||
'id', id,
|
'id', a.id,
|
||||||
'geometry', ST_AsGeoJSON(ST_Transform(geom, 4326))::jsonb,
|
'geometry', ST_AsGeoJSON(ST_Transform(a.geom, 4326))::jsonb,
|
||||||
'properties', jsonb_build_object(
|
'properties', jsonb_build_object(
|
||||||
'id', id,
|
'id', a.id,
|
||||||
'vorname', "VNA",
|
'vorname', a."VNA",
|
||||||
'nachname', "GNA",
|
'nachname', a."GNA",
|
||||||
'FSK', "FSK",
|
'FSK', a."FSK",
|
||||||
'PLZ', "PLZ",
|
'PLZ', a."PLZ",
|
||||||
'ORP', "ORP",
|
'ORP', a."ORP",
|
||||||
'STR', "STR",
|
'STR', a."STR",
|
||||||
'HSN', "HSN",
|
'HSN', a."HSN",
|
||||||
'FLN', "FLN",
|
'FLN', a."FLN",
|
||||||
'ZAE', "FSN__ZAE",
|
'ZAE', a."FSN__ZAE",
|
||||||
'NEN', "FSN__NEN",
|
'NEN', a."FSN__NEN",
|
||||||
'status', status,
|
'status', a.status,
|
||||||
'notiz', notiz
|
'notiz', a.notiz
|
||||||
)
|
)
|
||||||
) AS feature
|
) AS feature
|
||||||
FROM geodaten.flaecheneigentuemer_alkis
|
FROM geodaten.flaecheneigentuemer_alkis a
|
||||||
) features`
|
`;
|
||||||
);
|
const params = [];
|
||||||
|
|
||||||
|
if (projectParam) {
|
||||||
|
const projId = await resolveProjectId(client, projectParam);
|
||||||
|
if (projId) {
|
||||||
|
query += ` JOIN geodaten.flaecheneigentuemer_alkis_zuweisung z ON a."FSK" = z.fsk WHERE z.projekt_id = $1`;
|
||||||
|
params.push(projId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sql = `
|
||||||
|
SELECT jsonb_build_object(
|
||||||
|
'type', 'FeatureCollection',
|
||||||
|
'features', COALESCE(jsonb_agg(features.feature), '[]'::jsonb)
|
||||||
|
)
|
||||||
|
FROM (
|
||||||
|
${query}
|
||||||
|
) features
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await client.query(sql, params);
|
||||||
res.json(result.rows[0].jsonb_build_object);
|
res.json(result.rows[0].jsonb_build_object);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log(`FEHLER beim Laden des ALKIS-Layers: ${err.message}`);
|
log(`FEHLER beim Laden des ALKIS-Layers: ${err.message}`);
|
||||||
res.status(500).json({ error: err.message });
|
res.status(500).json({ error: err.message });
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue