Annotation Popups
A Popup that shows information about an annotation when the user clicks on it is a common requirement. Annotorious makes it easy to build your own custom popups in React with the ImageAnnotationPopup component.
Basic Example
Here’s a basic example of how to build a custom popup with the ImageAnnotationPopup component:
ImageAnnotationPopup is completely unstyled. Be sure to add CSS styles according to your needs.
Editing Body Payload
Popups aren not just for displaying information – they’re also great for editing annotation content. Annotorious follows the W3C Web Annotation Data Model, storing custom payload in AnnotationBody objects. The ImageAnnotationPopup component provides an easy way to manipulate these bodies through callback props.
onCreateBody(body: Partial<AnnotationBody>)
: adds a new body to the annotation.onDeleteBody(id: string)
: removes a body from the anntation using its ID.onUpdateBody(current: AnnotationBody, next: Partial<AnnotationBody>)
: modifies an existing body by replacing it with an updated version.
Example: Editable Comments
Let’s look at a more advanced popup that allows users to view and edit comments.
In this example, we will store comments in a body with a commenting
purpose.
OpenSeadragon
Building popups for OpenSeadragon works exactly the same way. There is only one crucial difference: be sure to use the OpenSeadragonAnnotationPopup component instead of ImageAnnotationPopup. This component will also handle popup positioning correctly when zooming and panning the viewer.