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 }