Rasterex APINPM Package/docs/capabilities/styles/annotation-styles

Annotation Styles

Inspect and update styling properties of existing annotations by GUID using the SDK.

Overview

Use viewer.styles.getAnnotationProperties(...) and viewer.styles.setAnnotationProperties(...) to inspect and update the style of an existing annotation by GUID.

Annotation style commands are available after the viewer is mounted, Canvas is ready, and a document is open.

typescript
import { createViewer } from "@rasterex/viewer";

const viewer = createViewer({
  container: "#viewer"
});

await viewer.mount();
await viewer.ready();

await viewer.documents.open({
  url: "https://files.example.com/floor-plan.pdf",
  displayName: "Floor Plan.pdf"
});
Overview

Track Selected Annotation

Listen for selection change events to capture annotation GUIDs:

typescript
let selectedGuid: string | null = null;

const unsubscribe = viewer.annotations.on("selected", (event) => {
  selectedGuid = event.guid ?? null;
});
Track Selected Annotation

Read Properties

Query the current active properties style configurations of a selected annotation:

  • getAnnotationProperties(...) sends getAnnotationProperties and waits for annotationProperties with matching guid values. Avoid overlapping reads for identical GUID references.
typescript
const result = await viewer.styles.getAnnotationProperties({
  guid: "550e8400-e29b-41d4-a716-446655440000",
  timeoutMs: 10000
});

if (result.success && result.props) {
  console.log("Stroke color:", result.props.strokeColor);
}
Read Properties

Update Properties

Update properties using the target annotation GUID:

  • setAnnotationProperties(...) returns void. Update calls run asynchronously as one-way commands.
typescript
viewer.styles.setAnnotationProperties({
  guid: "550e8400-e29b-41d4-a716-446655440000",
  props: {
    strokeColor: "#38BDF8",
    lineWidth: 4,
    transparency: 30
  }
});
Update Properties

Property Structure Reference

Configuration properties structure schema model:

  • strokeColor: Outlines color hex string.
  • fillColor: Fill color hex string.
  • textColor: Label labels typography color hex.
  • lineWidth: Size rating (1 to 10).
  • lineStyle: Layout shape style representation indices (0 solid, 1 dashed, 2 dotted).
  • transparency: Transparency percentage scale (0 opaque to 100 transparent).
  • locked: Lock option state representation boolean value.
  • countType: Shape layout marker indices (0 circle, 1 square, 2 triangle, 3 diamond).
typescript
type AnnotationProperties = {
  strokeColor?: string;
  fillColor?: string;
  textColor?: string;
  lineWidth?: number;
  lineStyle?: number;
  transparency?: number;
  locked?: boolean;
  text?: string;
  countType?: number;
  arrowType?: number;
  measureType?: number;
};
Property Structure Reference

Vanilla Example

Complete integration code setup for Vanilla HTML/JS environments:

<div id="viewer" style="height: 640px"></div>

<div>
  <button type="button" id="text-tool">Text</button>
  <button type="button" id="read-selected">Read Selected Style</button>
  <button type="button" id="update-selected">Update Selected Style</button>
</div>

<p id="status"></p>
Vanilla Example

Canvas Broker Mapping

Broker message mapping for annotation style properties:

  • viewer.styles.getAnnotationProperties(...) maps to getAnnotationProperties.
  • viewer.styles.setAnnotationProperties(...) maps to setAnnotationProperties.