Skip to content

docs(#43): 📝 Add JSdocs describing what the functions in this fi… #44

Merged
merged 1 commit into from
Oct 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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