Working with annotation selection using the AnnotationManager
Annotation selection is intuitively understood as selecting and/or clicking on a visible annotation in the viewer. The AnnotationManager allows you to get the selected annotations at any point in time. This could be helpful in serializing only selected annotations after pressing a button.
The AnnotationManager can also be used to select and deselect annotations. This may be helpful to batch select annotations and bring them into attention in the viewer for a review process.
Getting selected annotations
Aside from the annotationSelected event, the AnnotationManager provides the getSelectedAnnotations API that can be called on demand instead of hooking into an event.
// Save Button in HTML
<button onclick="saveXFDF()">Save XFDF</button>
// JavaScript
const { annotationManager } = instance.Core;
async function saveXFDF() {
const selected = annotationManager.getSelectedAnnotations();
const xfdf = await annotationManager.exportAnnotations({ annotationList: selected });
// Save XFDF
}// Save Button in HTML
<button onclick="saveXFDF()">Save XFDF</button>
// JavaScript
const { annotManager } = instance;
async function saveXFDF() {
const selected = annotManager.getSelectedAnnotations();
const xfdf = await annotManager.exportAnnotations({ annotList: selected });
// Save XFDF
}Selecting annotations
Selecting annotations through the AnnotationManager is done using either the selectAnnotation or selectAnnotations APIs.
Deselecting annotations
Deselecting annotations can be done in a similar way using the deselectAnnotation and deselectAnnotations APIs. This could be potentially used to deselect certain annotations after selecting a group of annotations.
Alternatively, you can use deselectAllAnnotations to deselect all selected annotations.
Jumping to annotations
When selecting an annotation via the notes panel, you will notice that the viewer will jump to the selected annotation. This can be triggered with the jumpToAnnotation API on the AnnotationManager. You can then use this API to focus on certain selected annotations or simply jumping to an annotation after creation.
Next steps
You can customize how selection models look and work on annotations. See how you can customize it in our custom annotation guide.
Last updated
Was this helpful?