Skip to content

Commit

Permalink
fix(#5): 🐛 fixed issues where the title for displayed data was not up…
Browse files Browse the repository at this point in the history
…dated
  • Loading branch information
gautegf committed Oct 4, 2025
1 parent e1175ca commit e575fbf
Showing 1 changed file with 128 additions and 19 deletions.
147 changes: 128 additions & 19 deletions src/MeasurementControl/measurementsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,47 +313,156 @@ window.initMeasurementsPanel = function initMeasurementsPanel(viewer) {
})
countSpan.textContent = groups.get(type).length
})
if (originalPropertiesPanel.parentElement === targetContainer) {
let selectedUUID = null
try {
const tree = $('#jstree_scene').jstree && $('#jstree_scene').jstree()
if (tree) {
const sel = tree.get_selected(true)[0]
sel &&
sel.data &&
isMeasurementUUID(sel.data.uuid) &&
(selectedUUID = sel.data.uuid)
}
} catch (_e) {}

const titleEl = targetContainer.querySelector('#measurement_data_title')
if (
selectedUUID &&
listRoot.querySelector(`.m-row[data-uuid="${selectedUUID}"]`)
) {
// Update lastSelection + active row highlight
updateActiveSelection(selectedUUID)
if (titleEl) titleEl.textContent = `Data for ${lastSelection.label}`
} else {
lastSelection.uuid = null
lastSelection.label = ''
if (titleEl) titleEl.textContent = 'Measurement Data'
}
}
}

rebuildMeasurementList()

// Hook into scene add/remove events to refresh list
viewer.scene.addEventListener('measurement_added', (e) => {
const obj = e.measurement || e.object || e.detail || null
// Some measurements start as a point, then become distance or height when adding more points to it. This is a listener for that.
if (obj && obj.addEventListener && !obj._mp_listenersAttached) {
function handleMeasurementLikeAdded(obj) {
if (!obj) return
// Attach point/marker listeners for any measurement-like object with points
if (obj.addEventListener && !obj._mp_listenersAttached) {
obj._mp_listenersAttached = true
// Potree measurement objects usually fire their own events; fallback to polling if needed
;[
'marker_added',
'marker_removed',
'point_added',
'point_removed'
].forEach((ev) => {
try {
obj.addEventListener(ev, () => rebuildMeasurementList())
obj.addEventListener(ev, () => {
rebuildMeasurementList()
if (lastSelection.uuid === obj.uuid) {
updateActiveSelection(obj.uuid)
showPanelInMeasurements()
}
})
} catch (_e) {}
})
}

// Distance/Height/Angle measurements can change type based on point count
if (!obj._mp_typeWatcher && obj.points) {
obj._mp_typeWatcher = true
let lastType = resolveType(obj)
const watcher = setInterval(() => {
const currentType = resolveType(obj)
if (currentType !== lastType) {
lastType = currentType
rebuildMeasurementList()
if (lastSelection.uuid === obj.uuid) {
updateActiveSelection(obj.uuid)
showPanelInMeasurements()
}
}
if (currentType !== 'Point' || (obj.points && obj.points.length > 1)) {
clearInterval(watcher)
}
}, 250)
}
rebuildMeasurementList()
if (obj && isMeasurementUUID(obj.uuid)) {
showPanelInMeasurements()
} else {
if (!isMeasurementUUID(obj.uuid)) return
let autoSelect = false
try {
const tree = $('#jstree_scene').jstree && $('#jstree_scene').jstree()
if (tree) {
const sel = tree.get_selected(true)[0]
if (sel && sel.data && isMeasurementUUID(sel.data.uuid)) {
showPanelInMeasurements()
}
if (!sel || !sel.data || !isMeasurementUUID(sel.data.uuid))
autoSelect = true
}
} catch (_e) {}
if (autoSelect) {
try {
const treeEl = document.getElementById('jstree_scene')
if (treeEl && $(treeEl).jstree) {
const tree = $(treeEl).jstree()
const measurementsRoot = tree.get_json('measurements')
const findNode = (root) =>
root.children.find((ch) => ch.data && ch.data.uuid === obj.uuid)
const node = measurementsRoot && findNode(measurementsRoot)
if (node) {
$.jstree.reference(node.id).deselect_all()
$.jstree.reference(node.id).select_node(node.id)
updateActiveSelection(obj.uuid)
}
}
} catch (_e) {}
} else {
updateActiveSelection(obj.uuid)
}
showPanelInMeasurements()
}

viewer.scene.addEventListener('measurement_added', (e) => {
const obj = e.measurement || e.object || e.detail || null
handleMeasurementLikeAdded(obj)
})
viewer.scene.addEventListener('volume_added', (e) => {
const obj = e.volume || e.object || e.detail || null
handleMeasurementLikeAdded(obj)
})
viewer.scene.addEventListener('profile_added', (e) => {
const obj = e.profile || e.object || e.detail || null
handleMeasurementLikeAdded(obj)
})

viewer.scene.addEventListener('measurement_removed', (e) => {
rebuildMeasurementList()
const removed = e.measurement || e.object || e.detail || null
if (removed && removed.uuid && removed.uuid === lastSelection.uuid) {
lastSelection.uuid = null
lastSelection.label = ''
const titleEl = targetContainer.querySelector('#measurement_data_title')
if (titleEl) titleEl.textContent = 'Measurement Data'
}
})
viewer.scene.addEventListener('volume_removed', (e) => {
rebuildMeasurementList()
const removed = e.volume || e.object || e.detail || null
if (removed && removed.uuid && removed.uuid === lastSelection.uuid) {
lastSelection.uuid = null
lastSelection.label = ''
const titleEl = targetContainer.querySelector('#measurement_data_title')
if (titleEl) titleEl.textContent = 'Measurement Data'
}
})
viewer.scene.addEventListener('profile_removed', (e) => {
rebuildMeasurementList()
const removed = e.profile || e.object || e.detail || null
if (removed && removed.uuid && removed.uuid === lastSelection.uuid) {
lastSelection.uuid = null
lastSelection.label = ''
const titleEl = targetContainer.querySelector('#measurement_data_title')
if (titleEl) titleEl.textContent = 'Measurement Data'
}
})
//volume and profile have their own event handlers and wont be included in the basic "measurement_added"
viewer.scene.addEventListener('measurement_removed', rebuildMeasurementList)
viewer.scene.addEventListener('volume_added', rebuildMeasurementList)
viewer.scene.addEventListener('volume_removed', rebuildMeasurementList)
viewer.scene.addEventListener('profile_added', rebuildMeasurementList)
viewer.scene.addEventListener('profile_removed', rebuildMeasurementList)

// Click handling for selection, focus and delete
listRoot.addEventListener('click', (e) => {
Expand Down Expand Up @@ -412,7 +521,7 @@ window.initMeasurementsPanel = function initMeasurementsPanel(viewer) {
$.jstree.reference(node.id).select_node(node.id)
}
}
updateActiveSelection(uuid)
updateActiveSelection(uuid)
showPanelInMeasurements()
}
})
Expand Down

0 comments on commit e575fbf

Please sign in to comment.