DrawLayer
Source: drawLayer.js:60
Draw layer.
Not an EventTarget in order to forward native DOM events while preserving preventDefault() for tools (see '#fireDomEvent').
Constructor
new DrawLayer(containerDiv: HTMLDivElement): DrawLayerParameters
containerDiv(HTMLDivElement) — The layer div, its id will be used as this layer id.
Instance Methods
setShapeHandler(handler: DrawShapeHandler | undefined)
Set the draw shape handler.
Parameters
handler(DrawShapeHandler | undefined) — The shape handler.
getDataId(): string
Get the associated data id.
Returns
string— The id.
getReferenceLayerId(): string
Get the reference layer id.
Returns
string— The id.
getKonvaStage(): Konva.Stage
Get the Konva stage.
Returns
Konva.Stage— The stage.
getKonvaLayer(): Konva.Layer
Get the Konva layer.
Returns
Konva.Layer— The layer.
getDrawController(): DrawController
Get the draw controller.
Returns
DrawController— The controller.
setPlaneHelper(helper: PlaneHelper)
Set the plane helper.
Parameters
helper(PlaneHelper) — The helper.
getId(): string
Get the id of the layer.
Returns
string— The string id.
removeFromDOM()
Remove the HTML element from the DOM.
getBaseSize(): Scalar2D
Get the layer base size (without scale).
Returns
Scalar2D— The size as {x,y}.
getOpacity(): number
Get the layer opacity.
Returns
number— The opacity ([0:1] range).
setOpacity(alpha: number)
Set the layer opacity.
Parameters
alpha(number) — The opacity ([0:1] range).
addFlipOffsetX()
Add a flip offset along the layer X axis.
addFlipOffsetY()
Add a flip offset along the layer Y axis.
flipScaleX()
Flip the scale along the layer X axis.
flipScaleY()
Flip the scale along the layer Y axis.
flipScaleZ()
Flip the scale along the layer Z axis.
setScale(newScale: Scalar3D, center?: Point3D)
Set the layer scale.
Parameters
initScale(newScale: Scalar3D, absoluteZoomOffset: Scalar2D)
Initialise the layer scale.
Parameters
newScale(Scalar3D) — The scale as {x,y,z}.absoluteZoomOffset(Scalar2D) — The zoom offset as {x,y} without the fit scale (as provided by getAbsoluteZoomOffset).
setOffset(newOffset: Scalar3D)
Set the layer offset.
Parameters
newOffset(Scalar3D) — The offset as {x,y,z}.
setBaseOffset(
scrollOffset: Vector3D,
planeOffset: Vector3D,
): boolean
Set the base layer offset. Updates the layer offset.
Parameters
scrollOffset(Vector3D) — The scroll offset vector.planeOffset(Vector3D) — The plane offset vector.
Returns
boolean— True if the offset was updated.
display(flag: boolean)
Display the layer.
Parameters
flag(boolean) — Whether to display the layer or not.
isVisible(): boolean
Check if the layer is visible.
Returns
boolean— True if the layer is visible.
draw()
Draw the content (imageData) of the layer. The imageData variable needs to be set.
initialise(
size: Scalar2D,
spacing: Scalar2D,
refLayerId: string,
)
Initialise the layer: set the canvas and context.
Parameters
size(Scalar2D) — The image size as {x,y}.spacing(Scalar2D) — The image spacing as {x,y}.refLayerId(string) — The reference image dataId.
setAnnotationGroup(
annotationGroup: AnnotationGroup,
dataId: string,
exeCallback: object,
)
Set the annotation group.
Parameters
annotationGroup(AnnotationGroup) — The annotation group.dataId(string) — The associated data id.exeCallback(object) — The undo stack callback.
activateCurrentPositionShapes(flag: boolean)
Activate shapes at current position.
Parameters
flag(boolean) — The flag to activate or not.
fitToContainer(
containerSize: Scalar2D,
divToWorldSizeRatio: number,
fitOffset: Scalar2D,
)
Fit the layer to its parent container.
Parameters
containerSize(Scalar2D) — The container size as {x,y}.divToWorldSizeRatio(number) — The div to world size ratio.fitOffset(Scalar2D) — The fit offset as {x,y}.
getAnnotationAt(
planePoint: Point2D,
tolerance?: number,
): Annotation | undefined
Get the top most visible annotation at the current position that contains the input plane point.
Parameters
planePoint(Point2D) — The plane point, in the reference view layer plane coordinates.tolerance(number, optional, default: 0) — Optional maximum distance to a shape, in plane coordinates, defaults to 0.
Returns
Annotation| undefined— The annotation, undefined if none.
isAnnotationVisible(id: string): boolean
Check the visibility of an annotation.
Parameters
id(string) — The id of the annotation.
Returns
boolean— True if the annotation is visible.
setAnnotationVisibility(id: string, visible?: boolean): boolean
Set the visibility of an annotation.
Parameters
id(string) — The id of the annotation.visible(boolean, optional) — True to set to visible, will toggle visibility if not defined.
Returns
boolean— False if the annotation shape cannot be found.
highlightAnnotation(id: string, duration?: number): boolean
Temporarily highlight an annotation: its opacity progressively dims to 20% and comes back to normal in one pulse. Only one annotation is highlighted at a time: a new call resets the previous highlight.
Parameters
id(string) — The id of the annotation.duration(number, optional) — The highlight duration in milliseconds, defaults to 500.
Returns
boolean— False if the annotation shape cannot be found.
setLabelsVisibility(visible?: boolean)
Set the visibility of all labels.
Parameters
visible(boolean, optional) — True to set to visible, will toggle visibility if not defined.
setLabelVisibility(shapeGroup: Konva.Group)
Set a shape group label visibility according to this layer setting.
Parameters
shapeGroup(Konva.Group) — The shape group.
deleteDraw(_id: string, _exeCallback: function)
Delete a Draw from the stage.
Since v0.34, please switch to `annotationGroup.remove`.
Parameters
_id(string) — The id of the group to delete._exeCallback(function) — The callback to call once the DeleteCommand has been executed.
deleteDraws(_exeCallback: function)
Delete all Draws from the stage.
Since v0.34, please switch to `annotationGroup.remove`.
Parameters
_exeCallback(function) — The callback to call once the DeleteCommand has been executed.
getNumberOfDraws(): number | undefined
Get the total number of draws of this layer (at all positions).
Returns
number | undefined— The total number of draws.
bindInteraction()
Enable and listen to container interaction events.
unbindInteraction()
Disable and stop listening to container interaction events.
setCurrentPosition(position: Point, index?: Index): boolean
Set the current position.
Parameters
Returns
boolean— True if the position was updated.
addEventListener(type: string, callback: function)
Add an event listener to this class.
Parameters
type(string) — The event type.callback(function) — The function associated with the provided event type, will be called with the fired event.
removeEventListener(type: string, callback: function)
Remove an event listener from this class.
Parameters
type(string) — The event type.callback(function) — The function associated with the provided event type.