Harden owner name matching with normalization and add detailed debug logging for map synchronization
Deploy Bürgerwind / deploy (push) Successful in 16s Details

This commit is contained in:
Johannes Baumeister 2026-05-01 10:19:15 +02:00
parent c5469e7fa5
commit cccdce49c1
1 changed files with 44 additions and 14 deletions

58
app.js
View File

@ -1241,25 +1241,40 @@ document.addEventListener('DOMContentLoaded', async () => {
} }
async function processALKISData(geojson, layerName) { async function processALKISData(geojson, layerName) {
console.log(`Verarbeite ALKIS-Daten für Layer: ${layerName}. Features: ${geojson.features ? geojson.features.length : 0}`);
const layer = L.geoJSON(geojson, { const layer = L.geoJSON(geojson, {
style: (feature) => { style: (feature) => {
const props = feature.properties; const props = feature.properties;
const firstName = (props.VNA || '').trim(); const firstName = (props.VNA || '').trim();
const lastName = (props.GNA || '').trim(); const lastName = (props.GNA || '').trim();
const ownerName = `${firstName} ${lastName}`.trim().toLowerCase();
const stored = state.ownerStatuses[ownerName]; // Normalisierung des Namens für den Abgleich
const status = typeof stored === 'object' ? (stored.status || '') : (stored || props.status || ''); const normalize = (s) => (s || '').toString().toLowerCase().replace(/[\s,.-]/g, '').trim();
const ownerKey = normalize(firstName + lastName);
// Suche in den geladenen Status-Einträgen
let status = '';
let foundInState = false;
// Wir suchen im state.ownerStatuses (der aus /api/sicherung geladen wurde)
for (let key in state.ownerStatuses) {
if (normalize(key) === ownerKey) {
status = state.ownerStatuses[key].status;
foundInState = true;
break;
}
}
// Fallback auf die Properties im GeoJSON selbst
if (!status) status = props.status || '';
let fillColor = 'transparent'; let fillColor = 'transparent';
let opacity = 0.1; let opacity = 0.1;
if (STATUS_MAP[status]) { if (status && STATUS_MAP[status]) {
fillColor = STATUS_MAP[status].color; fillColor = STATUS_MAP[status].color;
opacity = 0.7; opacity = 0.7;
} else if (status === 'none' || status === '') {
fillColor = 'transparent';
opacity = 0.1;
} }
return { return {
@ -1271,16 +1286,31 @@ document.addEventListener('DOMContentLoaded', async () => {
}, },
onEachFeature: (feature, layer) => { onEachFeature: (feature, layer) => {
if (feature.properties) { if (feature.properties) {
const status = feature.properties.status || 'Kein Status'; const props = feature.properties;
const notiz = feature.properties.notiz || ''; const firstName = (props.VNA || '').trim();
const lastName = (props.GNA || '').trim();
const normalize = (s) => (s || '').toString().toLowerCase().replace(/[\s,.-]/g, '').trim();
const ownerKey = normalize(firstName + lastName);
let status = props.status || 'Kein Status';
let notiz = props.notiz || '';
for (let key in state.ownerStatuses) {
if (normalize(key) === ownerKey) {
status = state.ownerStatuses[key].status;
notiz = state.ownerStatuses[key].notiz;
break;
}
}
let popup = `<b>${layerName}</b><br><hr style="margin: 5px 0; border: 0; border-top: 1px solid #444;">`; let popup = `<b>${layerName}</b><br><hr style="margin: 5px 0; border: 0; border-top: 1px solid #444;">`;
popup += `<b>Eigentümer:</b> ${feature.properties.VNA} ${feature.properties.GNA}<br>`; popup += `<b>Eigentümer:</b> ${firstName} ${lastName}<br>`;
popup += `<b>Status:</b> ${status}<br>`; popup += `<b>Status:</b> ${status}<br>`;
if (notiz) popup += `<b>Notiz:</b> ${notiz}<br>`; if (notiz) popup += `<b>Notiz:</b> ${notiz}<br>`;
popup += `<hr style="margin: 5px 0; border: 0; border-top: 1px solid #444;">`; popup += `<hr style="margin: 5px 0; border: 0; border-top: 1px solid #444;">`;
for (let key in feature.properties) { for (let key in props) {
if (['VNA', 'GNA', 'status', 'notiz', 'id'].includes(key)) continue; if (['VNA', 'GNA', 'status', 'notiz', 'id'].includes(key)) continue;
const val = feature.properties[key]; const val = props[key];
if (val !== null && val !== undefined) popup += `<b>${key}:</b> ${val}<br>`; if (val !== null && val !== undefined) popup += `<b>${key}:</b> ${val}<br>`;
} }
layer.bindPopup(popup); layer.bindPopup(popup);
@ -1460,8 +1490,8 @@ document.addEventListener('DOMContentLoaded', async () => {
Object.keys(owners).sort().forEach(name => { Object.keys(owners).sort().forEach(name => {
const data = owners[name]; const data = owners[name];
const stored = state.ownerStatuses[name.toLowerCase()] || { status: 'none', notiz: '' }; const stored = state.ownerStatuses[name.toLowerCase()] || { status: 'none', notiz: '' };
const status = typeof stored === 'string' ? stored : (stored.status || 'none'); const status = typeof stored === 'object' ? (stored.status || 'none') : (stored || 'none');
const notiz = typeof stored === 'string' ? '' : (stored.notiz || ''); const notiz = typeof stored === 'object' ? (stored.notiz || '') : '';
const row = document.createElement('tr'); const row = document.createElement('tr');
row.innerHTML = ` row.innerHTML = `