Add stable cascading cadastral search and fullscreen map UI

This commit is contained in:
livio committed 2026-09-11 09:45:47 +02:00
1 parent ed8120a7d0
commit 8997f1b728
8 files changed
+8804 -438

No files matched your search

+368 -147
View File
@@ -1,14 +1,32 @@
:root {
--ink: #17212b;
--muted: #63717c;
--surface: #ffffff;
--panel: #f4f6f7;
--line: #d6dde2;
--accent: #14705e;
--accent-strong: #0c5749;
--warning: #a34b08;
--nav-height: 64px;
}
html,
body,
#app,
.app-shell {
.app-shell,
.map-app,
.map-stage {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
html,
body {
font-family: Inter, "Segoe UI", Arial, sans-serif;
background: #101820;
color: #17212b;
background: #d8e0e4;
color: var(--ink);
}
button,
@@ -18,28 +36,32 @@ select {
}
button {
min-height: 38px;
min-height: 42px;
border: 0;
border-radius: 6px;
padding: 0 12px;
background: #176b87;
padding: 0 14px;
background: var(--accent);
color: #fff;
font-weight: 700;
}
button:active {
button:active:not(:disabled) {
transform: translateY(1px);
}
button:disabled {
opacity: 0.48;
}
input,
select {
width: 100%;
min-height: 38px;
border: 1px solid #c8d3dc;
min-height: 44px;
border: 1px solid #bfcbd2;
border-radius: 6px;
padding: 0 10px;
padding: 0 11px;
background: #fff;
color: #17212b;
color: var(--ink);
}
input[type="range"],
@@ -47,35 +69,161 @@ input[type="checkbox"] {
min-height: auto;
}
.map-app {
display: grid;
grid-template-columns: 390px minmax(0, 1fr);
width: 100%;
height: 100%;
.map-stage {
position: relative;
}
.tool-panel {
z-index: 800;
#map {
position: absolute;
inset: 0;
background: #d8e0e4;
}
.map-toolbar {
position: absolute;
top: 12px;
left: 12px;
right: 12px;
z-index: 900;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 52px;
padding: 7px 8px 7px 13px;
border: 1px solid rgba(255, 255, 255, 0.54);
border-radius: 8px;
background: rgba(22, 31, 38, 0.9);
box-shadow: 0 3px 14px rgba(0, 0, 0, 0.22);
color: #fff;
}
.app-identity {
display: flex;
align-items: baseline;
gap: 10px;
min-width: 0;
}
.app-identity strong {
font-size: 18px;
white-space: nowrap;
}
.app-identity span {
overflow: hidden;
color: #bfe6dc;
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
.toolbar-button {
min-height: 38px;
background: #fff;
color: var(--ink);
}
.map-search {
position: absolute;
top: 72px;
left: 12px;
right: 12px;
z-index: 890;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 8px;
max-width: 640px;
padding: 8px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 3px 14px rgba(0, 0, 0, 0.22);
opacity: 0;
pointer-events: none;
transform: translateY(-8px);
transition: opacity 140ms ease, transform 140ms ease;
}
.map-search.is-open {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
}
.gps-overlay {
position: absolute;
right: 12px;
bottom: 78px;
z-index: 850;
display: grid;
grid-template-columns: minmax(160px, auto) auto auto;
align-items: center;
gap: 7px;
max-width: calc(100% - 24px);
padding: 7px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.95);
box-shadow: 0 3px 14px rgba(0, 0, 0, 0.2);
}
.gps-state {
display: grid;
min-width: 0;
padding: 0 6px;
font-size: 11px;
}
.gps-state span,
.gps-state strong {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.gps-state strong {
color: #a33227;
}
.gps-main,
.gps-center {
min-height: 38px;
padding: 0 10px;
white-space: nowrap;
}
.gps-center {
background: #e7ecef;
color: var(--ink);
}
.tool-sheet {
position: absolute;
top: 0;
bottom: var(--nav-height);
left: 0;
z-index: 1100;
display: flex;
flex-direction: column;
gap: 12px;
overflow-y: auto;
padding: 16px;
background: #f6f8f9;
border-right: 1px solid #d8e0e6;
width: min(430px, calc(100% - 48px));
border-right: 1px solid var(--line);
background: var(--panel);
box-shadow: 7px 0 24px rgba(0, 0, 0, 0.24);
}
.brand {
.sheet-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
gap: 14px;
padding: 18px 16px 13px;
border-bottom: 1px solid var(--line);
background: #fff;
}
.eyebrow {
margin: 0 0 3px;
color: #667785;
font-size: 12px;
margin: 0 0 4px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
text-transform: uppercase;
}
@@ -88,74 +236,68 @@ p {
h1 {
margin-bottom: 0;
font-size: 25px;
line-height: 1.08;
font-size: 22px;
line-height: 1.12;
}
h2 {
margin-bottom: 10px;
margin: 10px 0 2px;
font-size: 15px;
}
.status {
border-radius: 999px;
padding: 5px 9px;
background: #dff5e5;
color: #166534;
font-size: 12px;
font-weight: 800;
.close-button {
width: 42px;
min-width: 42px;
padding: 0;
background: #e9eef0;
color: var(--ink);
font-size: 27px;
line-height: 1;
}
.panel-section {
padding: 12px;
border: 1px solid #dbe4ea;
border-radius: 8px;
background: #fff;
}
.input-row,
.button-row {
display: flex;
gap: 8px;
}
.input-row input {
min-width: 0;
}
.field-grid {
.panel-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.field-grid.compact {
grid-template-columns: 1fr;
gap: 12px;
overflow-y: auto;
padding: 15px 16px 24px;
}
label {
display: grid;
gap: 5px;
color: #475866;
color: #45545f;
font-size: 12px;
font-weight: 800;
}
.hint {
margin: 10px 0 0;
color: #667785;
font-size: 12px;
line-height: 1.35;
.button-row {
display: flex;
gap: 8px;
}
.button-row > * {
flex: 1;
}
.primary-command,
.secondary-command {
width: 100%;
}
.secondary-command {
border: 1px solid #b9c7ce;
background: #fff;
color: var(--ink);
}
.file-picker {
position: relative;
min-height: 42px;
min-height: 52px;
place-items: center;
border: 1px dashed #93a7b5;
border: 1px dashed #7e969f;
border-radius: 8px;
background: #f2f7fa;
color: #176b87;
background: #fff;
color: var(--accent-strong);
cursor: pointer;
}
@@ -166,120 +308,199 @@ label {
cursor: pointer;
}
.catalog-progress,
.service-note {
display: grid;
gap: 7px;
padding: 11px;
border: 1px solid #c7dce0;
border-radius: 8px;
background: #edf7f5;
color: #24443e;
font-size: 12px;
line-height: 1.4;
}
.catalog-progress progress {
width: 100%;
accent-color: var(--accent);
}
.service-note p {
margin-bottom: 0;
}
.protected-service {
border-color: #ead4b9;
background: #fff7ea;
color: #5d4024;
}
.layer-toggles {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
gap: 9px;
padding: 4px 0;
}
.layer-toggles label,
.toggle-line {
display: flex;
align-items: center;
gap: 7px;
gap: 8px;
}
.gps-readout {
display: grid;
gap: 6px;
margin-bottom: 10px;
padding: 10px;
border-radius: 8px;
background: #eef6ff;
color: #21405d;
font-size: 13px;
}
.gps-readout strong {
color: #b91c1c;
}
.map-stage {
position: relative;
min-width: 0;
height: 100%;
}
#map {
width: 100%;
height: 100%;
background: #d4dde3;
.layer-toggles input,
.toggle-line input {
width: 18px;
height: 18px;
}
.map-info {
position: absolute;
left: 14px;
right: 14px;
bottom: 14px;
z-index: 700;
max-width: 760px;
left: 12px;
bottom: 76px;
z-index: 820;
max-width: min(620px, calc(100% - 460px));
border-radius: 8px;
padding: 10px 12px;
background: rgba(16, 24, 32, 0.86);
padding: 9px 11px;
background: rgba(22, 31, 38, 0.88);
color: #fff;
font-size: 13px;
font-size: 12px;
pointer-events: none;
}
footer {
color: #667785;
.bottom-tabs {
position: absolute;
right: 0;
bottom: 0;
left: 0;
z-index: 1200;
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
height: var(--nav-height);
padding-bottom: env(safe-area-inset-bottom);
border-top: 1px solid #bcc7cd;
background: rgba(255, 255, 255, 0.98);
}
.bottom-tabs button {
min-width: 0;
min-height: 0;
border-radius: 0;
padding: 0 5px;
background: transparent;
color: #52616c;
font-size: 12px;
line-height: 1.35;
}
.bottom-tabs button.active {
box-shadow: inset 0 3px 0 var(--accent);
color: var(--accent-strong);
}
footer {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.leaflet-bottom {
bottom: calc(var(--nav-height) + 6px);
}
#blazor-error-ui {
background: #fff3cd;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
right: 8px;
bottom: calc(var(--nav-height) + 8px);
left: 8px;
z-index: 2000;
display: none;
border: 1px solid #e4be77;
border-radius: 8px;
padding: 10px 42px 10px 12px;
background: #fff3cd;
color: #5f4614;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
top: 7px;
right: 10px;
cursor: pointer;
}
.status-bar-safe-area {
display: none;
}
@media (max-width: 850px) {
.map-app {
grid-template-columns: 1fr;
grid-template-rows: 45% 55%;
@media (max-width: 700px) {
.map-toolbar {
top: 8px;
left: 8px;
right: 8px;
}
.tool-panel {
border-right: 0;
border-bottom: 1px solid #d8e0e6;
padding: 12px;
.map-search {
top: 68px;
left: 8px;
right: 8px;
}
.brand {
align-items: center;
}
h1 {
font-size: 22px;
}
}
@supports (-webkit-touch-callout: none) {
.status-bar-safe-area {
display: flex;
position: sticky;
top: 0;
height: env(safe-area-inset-top);
background-color: #f6f8f9;
.tool-sheet {
top: 10%;
bottom: var(--nav-height);
width: 100%;
z-index: 1;
border-top: 1px solid var(--line);
border-right: 0;
border-radius: 8px 8px 0 0;
box-shadow: 0 -7px 24px rgba(0, 0, 0, 0.24);
}
.gps-overlay {
right: 8px;
bottom: 116px;
left: 8px;
grid-template-columns: minmax(0, 1fr) auto auto;
max-width: none;
}
.gps-main,
.gps-center {
padding: 0 8px;
font-size: 11px;
}
.map-info {
right: 8px;
bottom: 72px;
left: 8px;
max-width: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bottom-tabs button {
font-size: 11px;
}
}
@media (max-width: 380px) {
.app-identity span {
display: none;
}
.gps-state {
min-width: 0;
}
.gps-center {
display: none;
}
.bottom-tabs button {
font-size: 10px;
}
}
+41 -133
View File
@@ -18,14 +18,14 @@ const lmeState = {
lastPosition: null,
lastWfsLookupAt: 0,
wfsLookupInFlight: false,
duckDb: null,
duckDbConnection: null
fileImportBound: false,
resizeBound: false
};
window.lmeMap = {
init,
search,
locateParcelArea,
locateParcelByPoint,
exportCadastreView,
fitImported,
clearImported,
@@ -41,7 +41,9 @@ window.lmeMap = {
centerOnGps,
toggleTrail,
setNativeGpsPosition,
setGpsError
setGpsError,
resize,
showInfo: setInfo
};
function init() {
@@ -74,6 +76,12 @@ function init() {
refreshCadastreLayer();
bindFileImport();
if (!lmeState.resizeBound) {
window.addEventListener("resize", resize);
window.addEventListener("orientationchange", resize);
lmeState.resizeBound = true;
}
lmeState.map.on("click", async event => {
const info = await queryFeatureInfo(event.latlng);
if (info) {
@@ -112,36 +120,30 @@ async function search(text) {
setInfo(place.display_name);
}
async function locateParcelArea(region, municipality, municipalityCode, sheet, parcel, label) {
if (!sheet || !parcel || (!municipality && !municipalityCode)) {
setInfo("Inserisci Comune o codice catastale, Foglio e Particella.");
async function locateParcelByPoint(latitude, longitude, parcel, label) {
const lat = Number(latitude);
const lon = Number(longitude);
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
setInfo("Coordinate della particella non valide.");
return;
}
setInfo("Cerco la particella nell'indice catastale...");
setInfo(`Recupero il confine ufficiale: ${label}`);
try {
const match = await findParcelIndexPoint(region, municipality, municipalityCode, sheet, parcel);
if (!match) {
const query = [municipality, region, "Italia"].filter(Boolean).join(", ");
await search(query);
setInfo("Particella non trovata nell'indice. Ho aperto il Comune: usa tap/GPS per interrogare AdE.");
return;
}
const meters = 8;
const deltaLat = meters / 111320;
const deltaLon = meters / (111320 * Math.cos(match.lat * Math.PI / 180));
const geojson = await fetchOfficialParcelsByBbox(match.lat - deltaLat, match.lon - deltaLon, match.lat + deltaLat, match.lon + deltaLon);
const deltaLon = meters / (111320 * Math.cos(lat * Math.PI / 180));
const geojson = await fetchOfficialParcelsByBbox(lat - deltaLat, lon - deltaLon, lat + deltaLat, lon + deltaLon);
const normalizedParcel = normalizeParcel(parcel);
const feature = (geojson.features || []).find(item => {
const props = item.properties || {};
return String(props.LABEL || "").trim().toUpperCase() === normalizedParcel.toUpperCase()
|| String(props.NATIONALCADASTRALREFERENCE || "").toUpperCase().endsWith(`.${normalizedParcel.toUpperCase()}`);
}) || (geojson.features || []).find(item => geometryContainsPoint(item.geometry, [match.lon, match.lat])) || geojson.features?.[0];
}) || (geojson.features || []).find(item => geometryContainsPoint(item.geometry, [lon, lat])) || geojson.features?.[0];
if (!feature) {
lmeState.map.setView([match.lat, match.lon], 20);
setInfo("Punto interno trovato, ma il WFS AdE non ha restituito il poligono in quel momento.");
lmeState.map.setView([lat, lon], 20);
setInfo("Posizione trovata, ma il servizio WFS dell'Agenzia non ha restituito il confine. Riprova tra poco.");
return;
}
@@ -151,125 +153,25 @@ async function locateParcelArea(region, municipality, municipalityCode, sheet, p
}).addTo(lmeState.currentParcelLayer);
fitLayer(layer);
const ref = feature.properties?.NATIONALCADASTRALREFERENCE || feature.properties?.INSPIREID_LOCALID || `${match.comune}_${match.foglio}.${match.particella}`;
const ref = feature.properties?.NATIONALCADASTRALREFERENCE || feature.properties?.INSPIREID_LOCALID || label;
setText("parcelState", `Particella selezionata: ${ref}`);
setInfo(`Trovata ${ref}. Ora puoi attivare il GPS e camminare dentro il confine evidenziato.`);
} catch (error) {
setInfo(`Ricerca catastale non completata: ${error.message}`);
setInfo(`Servizio catastale temporaneamente non disponibile: ${error.message}`);
}
}
async function findParcelIndexPoint(region, municipality, municipalityCode, sheet, parcel) {
const conn = await getDuckDbConnection();
const code = (municipalityCode || "").trim().toUpperCase();
const name = (municipality || "").trim().toUpperCase().replaceAll("'", "''");
const normalizedSheet = normalizeSheet(sheet);
const normalizedParcel = normalizeParcel(parcel).replaceAll("'", "''");
let indexWhere = "";
if (code) {
indexWhere = `comune = '${code.replaceAll("'", "''")}'`;
} else {
indexWhere = `upper(DENOMINAZIONE_IT) = '${name}'`;
}
const indexUrl = "https://raw.githubusercontent.com/ondata/dati_catastali/main/S_0000_ITALIA/anagrafica/index.parquet";
const indexRows = await queryDuckDb(conn, `
SELECT comune, file, DENOMINAZIONE_IT
FROM '${indexUrl}'
WHERE ${indexWhere}
LIMIT 5
`);
if (!indexRows.length) {
return null;
}
const row = chooseMunicipalityRow(indexRows, region);
const dataUrl = `https://raw.githubusercontent.com/ondata/dati_catastali/main/S_0000_ITALIA/anagrafica/${row.file}`;
const parcelRows = await queryDuckDb(conn, `
SELECT INSPIREID_LOCALID, comune, foglio, particella, x, y
FROM '${dataUrl}'
WHERE comune = '${row.comune}'
AND foglio = '${normalizedSheet}'
AND upper(particella) = upper('${normalizedParcel}')
LIMIT 1
`);
if (!parcelRows.length) {
return null;
}
const parcelRow = parcelRows[0];
return {
inspireId: parcelRow.INSPIREID_LOCALID,
comune: parcelRow.comune,
foglio: parcelRow.foglio,
particella: parcelRow.particella,
lon: Number(parcelRow.x) / 1000000,
lat: Number(parcelRow.y) / 1000000
};
}
function chooseMunicipalityRow(rows, region) {
const wanted = (region || "").trim().toUpperCase();
if (!wanted) {
return rows[0];
}
return rows.find(row => String(row.file || "").toUpperCase().includes(wanted)) || rows[0];
}
async function getDuckDbConnection() {
if (lmeState.duckDbConnection) {
return lmeState.duckDbConnection;
}
const duckdb = await import("https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm/+esm");
const bundles = duckdb.getJsDelivrBundles();
const bundle = await duckdb.selectBundle(bundles);
const workerUrl = URL.createObjectURL(new Blob([`importScripts("${bundle.mainWorker}");`], { type: "text/javascript" }));
const worker = new Worker(workerUrl);
const logger = new duckdb.ConsoleLogger();
const db = new duckdb.AsyncDuckDB(logger, worker);
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
URL.revokeObjectURL(workerUrl);
const conn = await db.connect();
try {
await conn.query("INSTALL httpfs; LOAD httpfs;");
} catch {
// Some DuckDB-WASM bundles already include HTTP support.
}
lmeState.duckDb = db;
lmeState.duckDbConnection = conn;
return conn;
}
async function queryDuckDb(conn, sql) {
const table = await conn.query(sql);
return table.toArray().map(row => {
if (typeof row.toJSON === "function") {
return row.toJSON();
}
const output = {};
for (const key of Object.keys(row)) {
output[key] = row[key];
}
return output;
});
}
function normalizeSheet(sheet) {
const value = String(sheet || "").trim().toUpperCase();
return /^\d+$/.test(value) ? value.padStart(4, "0") : value;
}
function normalizeParcel(parcel) {
return String(parcel || "").trim().toUpperCase();
}
function resize() {
if (!lmeState.map) {
return;
}
window.setTimeout(() => lmeState.map.invalidateSize({ pan: false }), 50);
}
function exportCadastreView() {
const center = lmeState.map.getCenter();
const zoom = lmeState.map.getZoom();
@@ -280,12 +182,15 @@ function exportCadastreView() {
}
function bindFileImport() {
const input = document.getElementById("gisFileInput");
if (!input) {
if (lmeState.fileImportBound) {
return;
}
input.addEventListener("change", async event => {
document.addEventListener("change", async event => {
if (event.target?.id !== "gisFileInput") {
return;
}
const file = event.target.files?.[0];
if (!file) {
return;
@@ -308,6 +213,7 @@ function bindFileImport() {
setInfo(`File non leggibile: ${error.message}`);
}
});
lmeState.fileImportBound = true;
}
async function readGisFile(file) {
@@ -596,6 +502,8 @@ async function updateOfficialParcelFromPoint(latitude, longitude, accuracy) {
const ref = feature.properties?.NATIONALCADASTRALREFERENCE || feature.properties?.INSPIREID_LOCALID || feature.properties?.LABEL || "particella AdE";
setText("parcelState", `Dentro particella AdE: ${ref}`);
} catch (error) {
setInfo(`Aggiornamento particella GPS non disponibile: ${error.message}`);
} finally {
lmeState.wfsLookupInFlight = false;
}