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) }