Rasterex API/docs/components/measurement/count-point-mode

Count Point Mode

Let users place multiple count points on one count annotation until the mode is turned off.

Overview

insertCountPointMode starts or stops continuous point placement for a specific count annotation.

When the mode is enabled, each point the user places is added to the count annotation identified by guid. The mode remains active until the host sends the same message with enabled: false or the demo canvas clears it during a context change.

The working demo exposes this mode from two places: the count annotation properties panel and the select-annotation panel.

  • Start Mode: Send insertCountPointMode with enabled: true and the count annotation guid.
  • Stop Mode: Send insertCountPointMode with enabled: false and the same guid.
  • Active Target: The demo keeps one active continuous count target at a time.
  • Visible State: The demo shows Continuous On for the active count annotation in the select-annotation panel.

Quick Start

Enable the mode when the user wants to place several points on one count annotation. Disable it when the user clicks the toggle again, selects another annotation, deletes the target annotation, changes files, or closes/reloads the canvas.

Enable continuous add

const iframe = document.querySelector('[data-viewer-iframe]');

iframe.contentWindow?.postMessage({
  type: 'insertCountPointMode',
  payload: {
    enabled: true,
    guid: 'COUNT-ANNOTATION-GUID',
    requestId: 'count-mode-on-001'
  }
}, '*');

Disable continuous add

const iframe = document.querySelector('[data-viewer-iframe]');

iframe.contentWindow?.postMessage({
  type: 'insertCountPointMode',
  payload: {
    enabled: false,
    guid: 'COUNT-ANNOTATION-GUID',
    requestId: 'count-mode-off-001'
  }
}, '*');

Host State Pattern

Track the active count annotation GUID in the host. This makes it clear which annotation owns continuous mode and which GUID must be used when turning the mode off.

const iframe = document.querySelector('[data-viewer-iframe]');
let activeCountInsertModeGuid = null;

function setCountPointMode(guid, enabled) {
  iframe.contentWindow?.postMessage({
    type: 'insertCountPointMode',
    payload: {
      enabled,
      guid,
      requestId: `count-mode-${enabled ? 'on' : 'off'}-${Date.now()}`
    }
  }, '*');

  activeCountInsertModeGuid = enabled ? guid : null;
}

function toggleContinuousAdd(guid) {
  const isActive = activeCountInsertModeGuid === guid;

  if (isActive) {
    setCountPointMode(guid, false);
    return;
  }

  if (activeCountInsertModeGuid) {
    setCountPointMode(activeCountInsertModeGuid, false);
  }

  setCountPointMode(guid, true);
}
Host State Pattern

Control Flow

The demo canvas keeps continuous count mode tied to one annotation GUID and sends an explicit disable message whenever the mode needs to stop.

Host Sends

1. Host identifies the count annotation

The host uses the active selection GUID and only exposes the control for count annotations.

typescript
Host Sends

2. Host enables insertCountPointMode

The host sends `enabled: true` for the selected count annotation GUID.

typescript
{
  type: 'insertCountPointMode',
  payload: {
    enabled: true,
    guid: 'COUNT-ANNOTATION-GUID',
    requestId: 'count-mode-on-001'
  }
}
Canvas Emits

3. Canvas stays in count placement mode

While the mode is active, the canvas continues attaching placed count points to the same annotation.

typescript
Host Sends

4. Host disables insertCountPointMode

To stop the mode, the host sends `insertCountPointMode` again with `enabled: false` and the active count annotation GUID.

typescript
{
  type: 'insertCountPointMode',
  payload: {
    enabled: false,
    guid: 'COUNT-ANNOTATION-GUID',
    requestId: 'count-mode-off-001'
  }
}

Payload

The GUID identifies the target count annotation. The enabled value tells the canvas whether to enter or exit continuous placement mode for that annotation.

  • enabled: true starts continuous add mode and false stops it.
  • guid: the count annotation that receives the inserted points.
  • requestId: optional tracing value for logging or request correlation.
{
  type: "insertCountPointMode",
  payload: {
    enabled: true,
    guid: "COUNT-ANNOTATION-GUID",
    requestId: "count-mode-on-001"
  }
}
Payload

When to Stop the Mode

Your host application should stop continuous mode any time the user is no longer intentionally adding points to the same count annotation.

  • Stop when the user clicks Stop Count Mode or turns Continuous Add off.
  • Stop before enabling continuous mode for another count annotation.
  • Stop when the selected annotation changes to a different annotation.
  • Stop when the selected count annotation is unselected or deleted.
  • Stop when the active file changes.
  • Stop when the canvas is closed, unloaded, or reloaded.

Additional Resources

Continue with related measurement workflows that commonly surround count insertion.