Class: Annotation

Annotation

Represents an annotation that can be drawn as an overlay on a canvas. An annotation is a decoration (text, graphics element, glyph) that provides additional information for interpreting underlying drawings. Each annotation has a unique identifier and can contain various properties such as description, category, drawing style, labels, etc.


new Annotation( [options])

Creates a new Annotation instance.

Parameters:
Name Type Argument Description
options Object <optional>

Configuration options for the annotation.

Properties
Name Type Argument Default Description
id string <optional>

Unique identifier for the annotation. If not provided, a UUID will be generated.

code string <optional>

A code identifier for the annotation.

label string <optional>
''

Display label for the annotation.

description string <optional>

HTML text containing a comprehensive description.

class string <optional>

Category or classification of the annotation.

target string <optional>

Target element or area this annotation refers to.

svg string <optional>

SVG content for the annotation.

image Object <optional>

Image data associated with the annotation.

region Object <optional>

Region coordinates {x, y, w, h} for the annotation.

data Object <optional>
{}

Additional custom data for the annotation.

style Object <optional>

Style configuration for rendering.

bbox BoundingBox <optional>

Bounding box of the annotation.

visible boolean <optional>
true

Visibility state of the annotation.

state Object <optional>

State variables for the annotation.

ready boolean <optional>
false

Indicates if SVG conversion is complete.

needsUpdate boolean <optional>
true

Indicates if annotation needs updating.

editing boolean <optional>
false

Indicates if annotation is being edited.

Source:

Methods


<static> fromJsonLd(entry)

Creates an Annotation instance from a JSON-LD format string.

Parameters:
Name Type Description
entry Object

The JSON-LD object representing an annotation.

Source:
Throws:

If the entry is not a valid JSON-LD annotation or contains unsupported selectors.

Type
Error
Returns:

A new Annotation instance.

Type
Annotation

getBBoxFromElements()

Calculates and returns the bounding box of the annotation based on its elements or region. The coordinates are always relative to the top-left corner of the canvas.

Source:
Returns:

The calculated bounding box of the annotation. If the annotation has no elements and no region, returns an empty bounding box. If the annotation has a region but no elements, returns a bounding box based on the region. If the annotation has elements, calculates the bounding box that encompasses all elements.

Type
BoundingBox

toJsonLd()

Converts the annotation to a JSON-LD format object.

Source:
Returns:

A JSON-LD representation of the annotation including context, id, type, body (with code, class, and description), and target selector information.

Type
Object