Replicating built-in annotation tool variants (custom UI)
Annotation tool variants are alternate configurations that apply different initial properties when creating annotations. For example, the arrow variant uses the line drawing mode with an arrow preset that adds an arrowhead; a dashed rectangle uses the rectangle drawing mode with a preset that applies a dashed border.
To reproduce a built-in variant in a custom UI, set both pieces of state that the built-in toolbar sets for you: the interaction mode, which controls the creation tool or drawing behavior, and the current annotation preset, which supplies the initial properties for the annotation. The preset ID is the string you pass to setCurrentAnnotationPreset, backed by the instance’s annotationPresets, or by defaultAnnotationPresets before you load the viewer. When you hide the default toolbar and build your own tools, set the pair that matches the tool you’re offering.
If a tool doesn’t use a named built-in variant, you can pass null for the preset. To change colors, stroke width, and other defaults, see annotation presets or register your own IDs with setAnnotationPresets.
Minimal recipe
In your click or selection handler, set the preset and the view state’s interactionMode. The order of these calls doesn’t matter; the important part is that they match the tool you’re offering. Here’s the same pairing the default “Arrow” tool uses:
instance.setCurrentAnnotationPreset("arrow");instance.setViewState((vs) => vs.set("interactionMode", NutrientViewer.InteractionMode.SHAPE_LINE));Which preset goes with which interaction mode?
The first column lists NutrientViewer.InteractionMode values you set on the view state. The second column lists built-in preset IDs you can pass to setCurrentAnnotationPreset for that mode.
| Interaction mode | Built-in preset IDs |
|---|---|
INK | ink, highlighter, ink-signature, es-signature |
TEXT_HIGHLIGHTER | highlight, text-highlighter, underline, squiggle, strikeout |
REDACT_TEXT_HIGHLIGHTER | redaction |
SHAPE_LINE | line, arrow |
SHAPE_RECTANGLE | rectangle, cloudy-rectangle, dashed-rectangle |
SHAPE_ELLIPSE | ellipse, cloudy-ellipse, dashed-ellipse |
SHAPE_POLYGON | polygon, cloudy-polygon, dashed-polygon |
SHAPE_POLYLINE | polyline |
DISTANCE | distance |
PERIMETER | perimeter |
RECTANGLE_AREA | rectangle-area |
ELLIPSE_AREA | ellipse-area |
POLYGON_AREA | polygon-area |
REDACT_SHAPE_RECTANGLE | redaction |
NOTE | note |
TEXT | text |
The defaults also include stamp, image, and widget in the annotation presets map. They’re a good match if you’re implementing stamp, image, or widget tools and want the same out-of-the-box property bundles.
See also
- Replace the main toolbar with UI slots — Minimal preset, sidebar shell, and API map when you replace
tools.main - Customizing variant buttons in the default toolbar
- UI customization (slots)
ViewStatesetCurrentAnnotationPresetsetAnnotationPresets