From 722c15db123d2d286185ee3da2af212e8253fe2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gaute=20Fl=C3=A6gstad?= Date: Sun, 26 Oct 2025 22:55:54 +0100 Subject: [PATCH] docs(#43): :memo: Add JSdocs describing what the functions in this file does --- src/AnnotationControl/persistence.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/AnnotationControl/persistence.js b/src/AnnotationControl/persistence.js index f991210..fe07b5a 100644 --- a/src/AnnotationControl/persistence.js +++ b/src/AnnotationControl/persistence.js @@ -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, + * snapshotToLocalStorage: function(): void, + * loadFromJson: function(): Promise, + * serializeGrouped: function(): object + * }} + */ export function initAnnotationPersistence(viewer, options = {}) { const jsonUrl = options.jsonUrl || '/annotations/annotations.json' const defaultSaveUrl = (() => { @@ -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) }