Skip to content
Merged
26 changes: 26 additions & 0 deletions packages/core/src/RenderingEngine/WSIViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import triggerEvent from '../utilities/triggerEvent';
import { peerImport } from '../init';
import microscopyViewportCss from '../constants/microscopyViewportCss';
import type { DataSetOptions } from '../types/IViewport';
import eventTarget from '../eventTarget';

let WSIUtilFunctions = null;
const EVENT_POSTRENDER = 'postrender';
const TOOLS_ANNOTATION_REMOVED_EVENT = 'CORNERSTONE_TOOLS_ANNOTATION_REMOVED';
Comment thread
mbellehumeur marked this conversation as resolved.
Outdated
/**
* A viewport which shows a microscopy view using the dicom-microscopy-viewer
* library. This viewport accepts standard CS3D annotations, and responds
Expand Down Expand Up @@ -61,6 +63,22 @@ class WSIViewport extends Viewport {
};

private viewer;
private annotationRemovedListener: EventListener = (evt: Event) => {
const { detail } = evt as CustomEvent<{
Comment thread
mbellehumeur marked this conversation as resolved.
annotation?: {
metadata?: {
FrameOfReferenceUID?: string;
};
};
}>;

const annotationFOR =
detail?.annotation?.metadata?.FrameOfReferenceUID ?? null;

if (!annotationFOR || annotationFOR === this.frameOfReferenceUID) {
this.postrender();
}
};

/**
* The VOI Range is used to apply contrast/brightness adjustments to the image.
Expand Down Expand Up @@ -130,13 +148,21 @@ class WSIViewport extends Viewport {
EVENTS.ELEMENT_DISABLED,
this.elementDisabledHandler
);
eventTarget.addEventListener(
TOOLS_ANNOTATION_REMOVED_EVENT,
this.annotationRemovedListener
);
}

private removeEventListeners() {
this.canvas.removeEventListener(
EVENTS.ELEMENT_DISABLED,
this.elementDisabledHandler
);
eventTarget.removeEventListener(
TOOLS_ANNOTATION_REMOVED_EVENT,
this.annotationRemovedListener
);
}

private elementDisabledHandler() {
Expand Down
Loading