Skip to content

Commit

Permalink
docs(#43): 📝 Add JSdocs describing what the functions in this file does
Browse files Browse the repository at this point in the history
  • Loading branch information
gautegf committed Oct 26, 2025
1 parent 9284341 commit 722c15d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/AnnotationControl/persistence.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/**
* Annotation persistence.
* - Loads annotations from JSON and rebuilds the live tree.
* - Serializes live annotations (title, description, position, cameraPosition).
* - Autosaves to server (saveUrl) and localStorage on changes.
*
* Usage (minimal):
* const api = initAnnotationPersistence(viewer, { jsonUrl: '/annotations/annotations.json' })
* // api: { getAnnotationsJSON, saveToServer, snapshotToLocalStorage, loadFromJson, serializeGrouped }
*/

/**
* Initialize annotation persistence.
* @param {Potree.Viewer} viewer - Potree viewer with scene.annotations as root
* @param {Object} [options]
* @param {string} [options.jsonUrl] - URL to fetch/load annotations JSON
* @param {string} [options.saveUrl] - URL to POST saved JSON (defaults set automatically)
* @returns {{
* getAnnotationsJSON: function(): object,
* saveToServer: function(object=): Promise<object>,
* snapshotToLocalStorage: function(): void,
* loadFromJson: function(): Promise<void>,
* serializeGrouped: function(): object
* }}
*/
export function initAnnotationPersistence(viewer, options = {}) {
const jsonUrl = options.jsonUrl || '/annotations/annotations.json'
const defaultSaveUrl = (() => {
Expand Down Expand Up @@ -255,7 +280,7 @@ export function initAnnotationPersistence(viewer, options = {}) {
last = cur
debouncedSnapshot()
}
if (frames++ < 90) requestAnimationFrame(poll) // ~1.5s at 60fps
if (frames++ < 90) requestAnimationFrame(poll)
}
requestAnimationFrame(poll)
}
Expand Down

0 comments on commit 722c15d

Please sign in to comment.