From e269d394e77b92429b013728fb95b1b9a468eff5 Mon Sep 17 00:00:00 2001 From: franmagn Date: Wed, 5 Nov 2025 15:27:03 +0100 Subject: [PATCH] fix(#47): :bug: fix deletion of name labels in UI fixed behaviour after deleting measurements. Now UI is immediately refreshed, not needing anymore to move the camera position to see the labels of deleted points disappear --- src/MeasurementControl/measurementsPanel.js | 25 +++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/MeasurementControl/measurementsPanel.js b/src/MeasurementControl/measurementsPanel.js index e01442f..5be335e 100644 --- a/src/MeasurementControl/measurementsPanel.js +++ b/src/MeasurementControl/measurementsPanel.js @@ -918,9 +918,13 @@ export function initMeasurementsPanel(viewer) { // Cleanup overlay labels for removed measurements and update positions try { // remove overlay labels for uuids that no longer exist - const known = new Set(itemsRaw.map((it) => it.obj.uuid)) + const uuidsWithPoints = new Set( + itemsRaw + .filter((it) => it.obj && it.obj.points && it.obj.points.length > 0) + .map((it) => it.obj.uuid) + ) for (const k of Array.from(overlayMap.keys())) { - if (!known.has(k)) { + if (!uuidsWithPoints.has(k)) { const el = overlayMap.get(k) if (el && el.parentElement) el.parentElement.removeChild(el) overlayMap.delete(k) @@ -947,6 +951,16 @@ export function initMeasurementsPanel(viewer) { try { obj.addEventListener(ev, () => { rebuildMeasurementList() + // If this object no longer has any points, remove any overlay + // immediately so the on-canvas label doesn't linger. + try { + if (!obj.points || obj.points.length === 0) { + const ol = overlayMap.get(obj.uuid) + if (ol && ol.parentElement) ol.parentElement.removeChild(ol) + overlayMap.delete(obj.uuid) + } + } catch (_e) {} + if (lastSelection.uuid === obj.uuid) { updateActiveSelection(obj.uuid) showPanelInMeasurements() @@ -1112,6 +1126,13 @@ export function initMeasurementsPanel(viewer) { scene.removeVolume(obj) else if (scene.removeProfile && scene.profiles.includes(obj)) scene.removeProfile(obj) + // Remove any on-canvas overlay immediately for this uuid so the + // label doesn't linger while other async updates occur. + try { + const ol = overlayMap.get(obj.uuid) + if (ol && ol.parentElement) ol.parentElement.removeChild(ol) + overlayMap.delete(obj.uuid) + } catch (_e) {} rebuildMeasurementList() return }