diff --git a/app.js b/app.js index 8520e25..a91ffb3 100644 --- a/app.js +++ b/app.js @@ -1241,25 +1241,40 @@ document.addEventListener('DOMContentLoaded', async () => { } 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, { style: (feature) => { const props = feature.properties; const firstName = (props.VNA || '').trim(); const lastName = (props.GNA || '').trim(); - const ownerName = `${firstName} ${lastName}`.trim().toLowerCase(); - const stored = state.ownerStatuses[ownerName]; - const status = typeof stored === 'object' ? (stored.status || '') : (stored || props.status || ''); + // Normalisierung des Namens für den Abgleich + 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 opacity = 0.1; - if (STATUS_MAP[status]) { + if (status && STATUS_MAP[status]) { fillColor = STATUS_MAP[status].color; opacity = 0.7; - } else if (status === 'none' || status === '') { - fillColor = 'transparent'; - opacity = 0.1; } return { @@ -1271,16 +1286,31 @@ document.addEventListener('DOMContentLoaded', async () => { }, onEachFeature: (feature, layer) => { if (feature.properties) { - const status = feature.properties.status || 'Kein Status'; - const notiz = feature.properties.notiz || ''; + const props = feature.properties; + 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 = `${layerName}

`; - popup += `Eigentümer: ${feature.properties.VNA} ${feature.properties.GNA}
`; + popup += `Eigentümer: ${firstName} ${lastName}
`; popup += `Status: ${status}
`; if (notiz) popup += `Notiz: ${notiz}
`; popup += `
`; - for (let key in feature.properties) { + for (let key in props) { if (['VNA', 'GNA', 'status', 'notiz', 'id'].includes(key)) continue; - const val = feature.properties[key]; + const val = props[key]; if (val !== null && val !== undefined) popup += `${key}: ${val}
`; } layer.bindPopup(popup); @@ -1460,8 +1490,8 @@ document.addEventListener('DOMContentLoaded', async () => { Object.keys(owners).sort().forEach(name => { const data = owners[name]; const stored = state.ownerStatuses[name.toLowerCase()] || { status: 'none', notiz: '' }; - const status = typeof stored === 'string' ? stored : (stored.status || 'none'); - const notiz = typeof stored === 'string' ? '' : (stored.notiz || ''); + const status = typeof stored === 'object' ? (stored.status || 'none') : (stored || 'none'); + const notiz = typeof stored === 'object' ? (stored.notiz || '') : ''; const row = document.createElement('tr'); row.innerHTML = `