Skip to content

Events

Lifecycle events are emitted by the annotator in response to user activities. You can attach a handler to the annotator instance via the on method.

anno.on('clickAnnotation', (annotation) => {
console.log('User clicked annotation: ' + annotation.id);
});

Use lifecycle event listeners to respond to user actions, for example:

  • Trigger save actions to a database backend.
  • Update other parts of your user interface in reponse to changes in annotation state.
  • Implement custom behavior in your application based on annotation interactions.
anno.on('clickAnnotation', (annotation, originalEvent) => {
console.log('Annotation clicked: ' + annotation.id);
});

Fired when a user clicks on an annotation. Provides both the annotation object and the original pointer event.

ArgumentTypeDescription
annotationImageAnnotationThe clicked annotation.
originalEventPointerEventThe associated pointer event.
anno.on('createAnnotation', (annotation) => {
console.log('Annotation created: ' + annotation.id);
});

Fired after a new annotation is created.

ArgumentTypeDescription
annotationImageAnnotationThe new annotation.
anno.on('deleteAnnotation', (annotation) => {
console.log('Annotation deleted: ' + annotation.id);
});

Fired after an annotation is deleted.

ArgumentTypeDescription
annotationImageAnnotationThe deleted annotation.
anno.on('mouseEnterAnnotation', (annotation) => {
console.log('Mouse entered: ' + annotation.id);
});

Fired when the mouse cursor enters the area of an annotation.

ArgumentTypeDescription
annotationImageAnnotationThe hovered annotation.
anno.on('mouseLeaveAnnotation', (annotation) => {
console.log('Mouse left: ' + annotation.id);
});

Fired when the mouse cursor leaves the area of an annotation.

ArgumentTypeDescription
annotationImageAnnotationThe hovered annotation.
anno.on('selectionChanged', (annotations) => {
console.log('Selected annotations', annotations);
});

Fired when the set of selected annotation changes. For future compatibility, the argument is an array. However, only single annotation will be returned currently.

When the user de-selects an annotation, the event will be fired with an empty array.

ArgumentTypeDescription
annotationsArray<ImageAnnotation>The selected annotation(s) (or an empty array).
anno.on('updateAnnotation', ((updated, previous) => void) => {
console.log('Annotation was updated.');
console.log('Annotation before upate: ' + previous);
console.log('Annotation after update: ' + updated);
});

Fired when an existing annotation is modified. Provides both the updated annotation and the previous state of the annotation.

ArgumentTypeDescription
updatedImageAnnotationThe new annotation after the update.
previousImageAnnotationThe annotation before the update.

OpenSeadragon only.

anno.on('viewportIntersect', (annotations) => {
console.log('Annotations in viewport', annotations);
});

Fired when the set of annotations visible in the current viewport changes. This event is only available on the OpenSeadragonAnnotator and will respond to zooming and panning of the OpenSeadragon image.

ArgumentTypeDescription
annotationsArray<ImageAnnotation>The annotations in the current viewport.