Skip to content

Commit

Permalink
refactor(#4): add monotonic numbering (in live scene) to created anno…
Browse files Browse the repository at this point in the history
…tations

add an increasing number to each new annotation created. Now works also in the live scene (for each UUID)
  • Loading branch information
franmagn committed Oct 14, 2025
1 parent 53343ed commit 1634ea8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/AnnotationControl/annotationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ export function initAnnotationsPanel(viewer) {
// ignore rename failures
}
}

function _findLiveAnnotationByUUID(uuid) {
if (!uuid || !viewer || !viewer.scene || !viewer.scene.annotations) return null
try {
const coll =
(viewer.scene.annotations.flatten && viewer.scene.annotations.flatten()) ||
(viewer.scene.annotations.descendants && viewer.scene.annotations.descendants()) ||
viewer.scene.annotations.children || []
for (const a of coll) {
if (!a) continue
if (a.uuid === uuid || (a.data && a.data.uuid === uuid)) return a
}
} catch (e) {
// fallback
try {
const coll2 = viewer.scene.annotations.children || []
for (const a of coll2) if (a && (a.uuid === uuid || (a.data && a.data.uuid === uuid))) return a
} catch (e) {}
}
return null
}
function updateAnnotationsList() {
// Implementation for listing annotations
targetContainer.innerHTML = ''
Expand Down Expand Up @@ -134,6 +155,18 @@ export function initAnnotationsPanel(viewer) {
const newName = `Annotation #${idx}`
_renameJSTreeNode(it.node.id, newName)
it.node.text = newName
// update live annotation object's title/name so in-scene label matches
try {
const live = _findLiveAnnotationByUUID(it.data.uuid)
if (live) {
if (typeof live.title !== 'undefined') live.title = newName
if (typeof live.name !== 'undefined') live.name = newName
// for Potree Annotation object, data.title or similar may be used
if (live.data) live.data.title = newName
}
} catch (e) {
// ignore live-update failures
}
}
}
} catch (e) {
Expand Down

0 comments on commit 1634ea8

Please sign in to comment.