Grouping annotations through the AnnotationManager
Grouping annotations can be done in WebViewer both in the UI and programmatically. This can be useful for keeping annotations together and forming more meaningful commentary on your documents. Grouped annotations associate themselves to one primary annotation. Only the comment of the primary annotation will appear in the notes panel.
This is what grouped annotations look like represented in XFDF:
Notice the replyType and inreplyto attributes of the circle annotation which refer to the square annotation as the primary.
Grouping annotations in the UI
Grouping annotations through the UI is straightforward. Simply selection the annotations you want to group and press the group button.
Ungrouping annotations in the UI
Likewise, ungrouping annotations will require first selecting the group and pressing the ungroup button.
Grouping annotations programmatically
Grouping annotations is done through the AnnotationManager. The API is called groupAnnotations and it takes a primary annotation along with an array of annotations that will be grouped with it.
You can group annotations that are on different pages. However, the group's movement will still be constrained by their respective pages.
Grouping an annotation to a group will create another group instead of adding to it, so you must always group to the primary annotation to add a new annotation to the group.
Ungrouping annotations programmatically
Simlar to grouping annotations, the AnnotationManager also provides the ungroupAnnotations function. This function takes an array of annotations to be ungrouped (regardless of which group they belong in) and it will ungroup them without ungrouping other annotations of their respective groups.
A helpful API that will get you all the grouped annotations (both the primary and children) is the getGroupAnnotations API. By passing in any of the annotations that are part of the group, it will provide all the annotations in the group including that one that was passed in.
Although this will return both the primary and the children annotations, it may be helpful to be able to make a distinction between them. The next sections will cover this.
Using isGrouped
The isGrouped API on annotations will tell you whether the annotation is grouped with another. This will only get you secondary annotations that are grouped to a primary annotation. You can leverage this to determine both the parent and children.
Alternatively, you can make use of the InReplyTo property of a grouped secondary annotation along with getAnnotationById on the AnnotationManager to get the primary annotation.
Getting grouped children using the primary annotation
If you have the primary annotation of a group, you can use getGroupedChildren to get all the child annotations that are grouped with it. You could also use this to check for a primary annotation.