From 4da47a88353c158631d2754ddbc53462dcadd466 Mon Sep 17 00:00:00 2001 From: livio Date: Thu, 24 Sep 2026 08:15:58 +0200 Subject: [PATCH] Consenti di rinominare gli oggetti mappa --- LMEMappeCatastaliApp.csproj | 4 +-- wwwroot/css/app.css | 19 +++++++++++++ wwwroot/js/lme-map.js | 56 +++++++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/LMEMappeCatastaliApp.csproj b/LMEMappeCatastaliApp.csproj index 006a3ad..b1980e7 100644 --- a/LMEMappeCatastaliApp.csproj +++ b/LMEMappeCatastaliApp.csproj @@ -28,8 +28,8 @@ com.companyname.lmemappecatastaliapp - 0.2.22 - 26 + 0.2.23 + 27 None diff --git a/wwwroot/css/app.css b/wwwroot/css/app.css index 2b1d886..6887dc0 100644 --- a/wwwroot/css/app.css +++ b/wwwroot/css/app.css @@ -283,6 +283,10 @@ input[type="checkbox"] { list-style: none; } +.layer-manager-object > summary { + grid-template-columns: 28px 20px minmax(0, 1fr) auto auto auto; +} + .layer-manager-group > summary::-webkit-details-marker, .layer-manager-block > summary::-webkit-details-marker, .layer-manager-object > summary::-webkit-details-marker { @@ -302,6 +306,21 @@ input[type="checkbox"] { cursor: grab; } +.layer-rename-button { + min-height: 28px; + padding: 0 8px; + border: 1px solid #bfd4cd; + border-radius: 4px; + background: #eef8f5; + color: var(--accent-strong); + font-size: 10px; + font-weight: 800; +} + +.layer-rename-button:active { + background: #d9eee7; +} + .layer-move-buttons { display: inline-grid; grid-template-columns: 24px 24px; diff --git a/wwwroot/js/lme-map.js b/wwwroot/js/lme-map.js index 3f7f708..5b9024f 100644 --- a/wwwroot/js/lme-map.js +++ b/wwwroot/js/lme-map.js @@ -1145,6 +1145,42 @@ function managedObjectLabel(record, index) { return `Oggetto ${index + 1}`; } +function managedObjectEditableName(record) { + const properties = record?.layer?.feature?.properties || {}; + return properties.name || properties.Name || properties.label || properties.LABEL || ""; +} + +function managedObjectCanRename(record) { + return ["drawings", "imported", "importedSheets"].includes(record.categoryKey) + && record.layer?.feature?.properties; +} + +function renameManagedObject(record, index) { + if (!managedObjectCanRename(record)) { + return; + } + const currentName = String(managedObjectEditableName(record) || managedObjectLabel(record, index)).trim(); + const requestedName = window.prompt("Nuovo nome oggetto", currentName); + if (requestedName === null) { + return; + } + const name = requestedName.trim().slice(0, 120); + if (!name) { + setInfo("Nome non modificato: inserisci un testo."); + return; + } + const properties = record.layer.feature.properties; + properties.name = name; + record.layer.lmeManagerLabel = record.categoryKey === "drawings" && record.layer instanceof L.Marker + ? `POI: ${name}` + : null; + updateStoredFeaturePopup(record.layer); + refreshImportedMeasurements(); + refreshDrawingMeasurements(); + refreshLayerManager(); + setInfo(`Oggetto rinominato: ${name}.`); +} + function managedObjectDetails(layer) { const details = []; const properties = layer?.feature?.properties || {}; @@ -1280,10 +1316,18 @@ function renderLayerManagerObject(record, index) { object.dataset.objectId = record.id; bindLayerManagerExpansion(object, `object:${record.id}`); const visible = !lmeState.managerHiddenObjectIds.has(record.id); - object.innerHTML = `${escapeHtml(managedObjectLabel(record, index))}${layerManagerMoveButtons("oggetto")}›
`; + const renameButton = managedObjectCanRename(record) + ? `` + : ""; + object.innerHTML = `${escapeHtml(managedObjectLabel(record, index))}${renameButton}${layerManagerMoveButtons("oggetto")}›
`; const checkbox = object.querySelector("input"); checkbox.addEventListener("click", event => event.stopPropagation()); checkbox.addEventListener("change", () => setManagedObjectVisible(record, checkbox.checked, true)); + object.querySelector(".layer-rename-button")?.addEventListener("click", event => { + event.preventDefault(); + event.stopPropagation(); + renameManagedObject(record, index); + }); object.querySelector(".layer-manager-title").addEventListener("click", event => { event.preventDefault(); event.stopPropagation(); @@ -2641,10 +2685,18 @@ function clearManagedCategoryState(categoryKey) { } function bindStoredFeaturePopup(feature, layer) { - const properties = feature?.properties || {}; + updateStoredFeaturePopup(layer, feature?.properties); +} + +function updateStoredFeaturePopup(layer, sourceProperties) { + const properties = sourceProperties || layer?.feature?.properties || {}; const label = properties.name || properties.Name || properties.label || properties.LABEL; if (label) { layer.bindPopup(`${escapeHtml(label)}`); + return; + } + if (typeof layer?.unbindPopup === "function") { + layer.unbindPopup(); } }