1Webviewer(...).then((instance) => {
2 const { Core, UI } = instance;
3 const { Annotations, annotationManager, Tools, documentViewer } = Core;
4
5 // Beginning Custom Annotation Class
6 class Rotatable extends Annotations.CustomAnnotation {
7 constructor() {
8 super('rotatable');
9 this.Subject = 'Rotatable';
10 this.selectionModel = RotatableSelectionModel;
11 }
12
13 draw(ctx, pageMatrix) {
14 this.setStyles(ctx, pageMatrix);
15
16 const { x, y, width, height } = this.getUnrotatedDimensions();
17
18 ctx.translate(x + width / 2, y + height / 2);
19 ctx.rotate(-Annotations.RotationUtils.getRotationAngleInRadiansByDegrees(this['Rotation']));
20 ctx.translate(-x - width / 2, -y - height / 2);
21
22 ctx.translate(x, y);
23 ctx.beginPath();
24 ctx.moveTo(0, 0);
25 ctx.lineTo(width, 0);
26 ctx.lineTo(width, height);
27 ctx.lineTo(0, height);
28 ctx.lineTo(0, 0);
29 ctx.lineTo(width, height);
30 ctx.moveTo(width, 0);
31 ctx.lineTo(0, height);
32 ctx.stroke();
33 }
34 }
35
36 Object.assign(Rotatable.prototype, Annotations.RotationUtils.RectangularCustomAnnotationRotationMixin);
37
38 Rotatable.prototype.elementName = 'rotatable';
39
40 annotationManager.registerAnnotationType(Rotatable.prototype.elementName, Rotatable);
41 // End Custom Annotation Class
42
43 // Beginning Selection Model
44 class RotatableSelectionModel extends Annotations.BoxSelectionModel {
45 constructor(annotation, canModify, isSelected, documentViewer) {
46 super(annotation, canModify, isSelected, documentViewer);
47
48 const controlHandles = this.getControlHandles();
49
50 if (canModify && documentViewer.getAnnotationManager().isFreeformRotationEnabled() && annotation.hasRotationControlEnabled()) {
51 controlHandles.push(new Annotations.RotationControlHandle(Annotations.ControlHandle['rotationHandleWidth'], Annotations.ControlHandle['rotationHandleHeight'], 40, annotation, documentViewer));
52 }
53 }
54 }
55 // End Selection Model
56
57 // Beginning Tool
58 class RotatableCreateTool extends Tools.GenericAnnotationCreateTool {
59 constructor(documentViewer) {
60 super(documentViewer, Rotatable);
61 }
62 }
63
64 const rotatableToolName = 'AnnotationCreateRotatable';
65
66 const rotatableTool = new RotatableCreateTool(documentViewer);
67 UI.registerTool({
68 toolName: rotatableToolName,
69 toolObject: rotatableTool,
70 buttonImage: '<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 64 64">' +
71 '<line x1="9.37" x2="54.63" y1="9.37" y2="9.37" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/>' +
72 '<line x1="9.37" x2="9.37" y1="54.63" y2="9.37" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/>' +
73 '<line x1="54.63" x2="54.63" y1="9.37" y2="54.63" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/>' +
74 '<line x1="9.37" x2="54.63" y1="54.63" y2="54.63" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/>' +
75 '<line x1="9.37" x2="54.63" y1="9.37" y2="54.63" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/>' +
76 '<line x1="9.37" x2="54.63" y1="54.63" y2="9.37" fill="none" stroke="#010101" stroke-miterlimit="10" stroke-width="4"/>' +
77 '</svg>',
78 buttonName: 'rotatableToolButton',
79 tooltip: 'Rotatable'
80 }, Rotatable);
81
82 UI.setHeaderItems((header) => {
83 header.getHeader('toolbarGroup-Shapes').get('freeHandToolGroupButton').insertBefore({
84 type: 'toolButton',
85 toolName: rotatableToolName
86 });
87 });
88 // End Tool
89});