new SelectionModel(annotation, canModify, isSelected, docViewer)
Create a new selection model.
Parameters:
Name | Type | Description |
---|---|---|
annotation |
Core.Annotations.Annotation | The annotation selected |
canModify |
boolean | Modification of the annotation is allowed |
isSelected |
boolean | The annotation is already selected |
docViewer |
Core.DocumentViewer | An instance of DocumentViewer. |
Members
-
<static> defaultNoPermissionSelectionOutlineColor
-
Defines the default color for the annotation selection outline when the user is not permitted to make modifications.
-
<static> defaultSelectionOutlineColor
-
Defines the default color for the annotation selection outline.
-
<static> selectionAccuracyPadding
-
Defines padding for selection accuracy. Default is 2. Increase this value to make selection more forgiving.
-
<static> selectionOutlineDashSize
-
Defines the dash size for the selection outline. Default is 4;
-
<static> selectionOutlineExtraPadding
-
Defines the default padding between selection control points. The padding only appears when the control points are too close.
-
<static> selectionOutlineThickness
-
Defines thickness of the annotation selection outline. Default is 1.
-
<static> showPaddingWhenAnnotationIsSmall
-
Defines if extra padding should be shown when the selected annotation is too small. Default is true.
-
<static> useDashedLine
-
Defines if a dashed line style should be used for the selection outline. Default is false.
Methods
-
<static> setCustomHandlers(selectionModelClass, selectionModelCustomHandlers)
-
Overwrites the functions in SelectionModel(ex: drawSelectionOutline, getDimensions, testSelection).
Parameters:
Name Type Description selectionModelClass
Core.Annotations.SelectionModel The class (constructor) of the selectionModel selectionModelCustomHandlers
Core.Annotations.SelectionModel.SelectionModelCustomHandlers An object containing multiple handlers to overwrite functions on a SelectionModel. Example
const { Annotations } = instance.Core; const { SelectionModel, BoxSelectionModel } = Annotations; SelectionModel.setCustomHandlers(BoxSelectionModel, { // draws a diagonal dashed along across the middle of the selected annotation drawSelectionOutline(ctx, annotation, zoom, pageMatrix, { selectionModel, originalDrawSelectionOutline }) { if (!(annotation instanceof Annotations.RectangleAnnotation)) { originalDrawSelectionOutline(ctx, annotation, zoom, pageMatrix); return; } if (typeof zoom !== 'undefined') { ctx.lineWidth = SelectionModel.selectionOutlineThickness / zoom; } else { ctx.lineWidth = SelectionModel.selectionOutlineThickness; } if (selectionModel.canModify()) { ctx.strokeStyle = SelectionModel.defaultSelectionOutlineColor.toString(); } else { ctx.strokeStyle = SelectionModel.defaultNoPermissionSelectionOutlineColor.toString(); } ctx.beginPath(); ctx.moveTo(annotation.X, annotation.Y); ctx.lineTo(annotation.X + annotation.Width, annotation.Y + annotation.Height); ctx.closePath(); ctx.stroke(); const dashUnit = SelectionModel.selectionOutlineDashSize / zoom; const sequence = [dashUnit, dashUnit]; ctx.setLineDash(sequence); ctx.strokeStyle = 'rgb(255, 255, 255)'; ctx.stroke(); }, // Get the dimension that is extended by 8 both horizontally and vertically getDimensions(annotation, { selectionModel, originalGetDimensions }) { if (!(annotation instanceof Annotations.RectangleAnnotation)) { return originalGetDimensions(annotation); } const x = annotation.X - 4; const y = annotation.Y - 4; const width = annotation.Width + 2 * 4; const height = annotation.Height + 2 * 4; return new Annotations.Rect(x, y, x + width, y + height); }, testSelection(annotation, x, y, pageMatrix, zoom, rotation, { selectionModel, originalTestSelection }) { if (annotation instanceof Annotations.RectangleAnnotation) { return originalTestSelection(annotation, x, y, pageMatrix, zoom, rotation);; } return Annotations.SelectionAlgorithm.boundingRectTest(annotation, x, y, zoom); } })
-
<static> setSelectionModelPaddingHandler(fn)
-
Defines a function to set selection padding on specific types of annotations.
Parameters:
Name Type Description fn
function A function that returns the padding value for specific types of annotations Example
const { Annotations } = instance.Core; Annotations.SelectionModel.setSelectionModelPaddingHandler((annotation) => { if (annotation instanceof Annotations.FreeTextAnnotation) { return 30; } if (annotation instanceof Annotations.RectangleAnnotation) { return 20; } return 0; });
-
canModify()
-
Indicates that the associated annotation is able to be modified
Returns:
- Type
- boolean
-
drawSelectionOutline(ctx, annotation, zoom)
-
Draws the selection outline of the annotation. By default, a rectangle is drawn based on the annotations x, y, width and height.
Parameters:
Name Type Description ctx
CanvasRenderingContext2D annotation
Core.Annotations.Annotation zoom
number -
getControlHandles()
-
Returns the ControlHandle objects associated with this selection model.
Returns:
An array of ControlHandleObject- Type
- Array.<Core.Annotations.ControlHandle>
-
getDimensions(annotation)
-
Gets the dimensions {x, y, width, height} of the selection bounding box. It may be different from the annotation's bounding box. e.g. The selection bounding box may have a padding.
Parameters:
Name Type Description annotation
Core.Annotations.Annotation Returns:
- Type
- Core.Math.Rect
-
isSelected()
-
Indicates that the associated annotation is already selected. This can be useful to implement different selection behaviors when an annotation is selected.
Returns:
- Type
- boolean
-
testControlHandles(annotation, zoom, x, y)
-
Hit detection for each control handle.
Parameters:
Name Type Description annotation
Core.Annotations.Annotation zoom
number x
number y
number Returns:
The control handle that was hit -
testSelection(annotation, x, y, pageMatrix, zoom, rotation)
-
Determines if the provided point is a hit on the selected annotationhandle. * See Core.Annotations.SelectionAlgorithm for usuable selection algorithms.
Parameters:
Name Type Description annotation
Core.Annotations.Annotation the annotation x
number the x-coordinate of the point to test, in page coordinates y
number the y-coordinate of the point to test, in page coordinates pageMatrix
object the page matrix of the page the annotation is on zoom
number the zoom level of the page the annotation is on rotation
Core.PageRotation the rotation of the page the annotation is on Returns:
true if the provided point is a hit- Type
- boolean
Type Definitions
-
CustomDrawSelectionOutlineHandler(ctx, annotation, zoom, pageMatrix, options)
-
Callback that gets passed to drawSelectionOutlineHandler in setCustomHandlers.
Parameters:
Name Type Description ctx
CanvasRenderingContext2D A canvas context annotation
Core.Annotations.Annotation The annotation being selected zoom
number the current zoom level of the document pageMatrix
object The transformation matrix for the page that the annotation is on options
object Additional options and parameters Properties
Name Type Description selectionModel
Core.Annotations.SelectionModel The selection model of the annotation which is currently selected. originalDrawSelectionOutline
function The original draw function of this selection model -
CustomGetDimensionsHandler(annotation, selectionBox, zoom, options)
-
Callback that gets passed to getDimensionsHandler in setCustomHandlers.
Parameters:
Name Type Description annotation
Core.Annotations.Annotation The annotation being selected selectionBox
Core.Math.Rect zoom
number the current zoom level of the document options
object Optional options Properties
Name Type Description selectionModel
Core.Annotations.SelectionModel The selection model of the annotation which is currently selected. originalGetDimensions
function The original getDimensions function of this selection model Returns:
- Type
- Core.Math.Rect
-
CustomTestSelectionHandler(x, y, pageMatrix, zoom, rotation, options)
-
Callback that gets passed to testSelectionHandler in setCustomHandlers.
Parameters:
Name Type Description x
number The x-coordinate of the point to test, in page coordinates y
number The y-coordinate of the point to test, in page coordinates pageMatrix
object the page matrix of the page the annotation is on zoom
number The zoom level of the page the annotation is on rotation
Core.PageRotation The rotation of the page the annotation is on options
object Optional options Properties
Name Type Description selectionModel
Core.Annotations.SelectionModel The selection model of the annotation which is currently selected. originalTestSelection
function The original draw function of this selection model Returns:
- Type
- boolean
-
SelectionModelCustomHandlers
-
A collection of functions that overwrite the original functions in SelectionModel
Type:
- object
Properties:
Name Type Argument Description drawSelectionOutline
Core.Annotations.SelectionModel.CustomDrawSelectionOutlineHandler <optional>
Changes how a selection model is drawn within WebViewer. getDimensions
Core.Annotations.SelectionModel.CustomGetDimensionsHandler <optional>
Gets the rect of the selection bounding box. testSelection
Core.Annotations.SelectionModel.CustomTestSelectionHandler <optional>
Determines if the provided point is a hit on the selected annotation handle.