Line, Polygon, Polyline, Freehand, Ellipse, Rectangle, Stamp, FreeText annotations show a rotation control when selected. This control handle lets the user rotate the annotation with a full range (360 degrees).
To rotate annotations programmatically, supported annotations have a rotate
function that takes an angle to rotate by:
JavaScript (SDK v8.0+) 1 const { annotationManager, Annotations } = instance.Core;
2 annotationManager. getAnnotationsList (). forEach (( annotation ) => {
3 if (annotation instanceof Annotations . RectangleAnnotation ) {
4 annotation. rotate ( 45 );
5 }
6 });
By default, freeform rotation is enabled for all Line, Polyline, Polygon or Freehand annotations. In order to disable it, the following can be done:
JavaScript (SDK v8.0+) JavaScript (SDK v7.0+)
1 const annotManager = instance.Core.annotationManager;
2 annotManager. setRotationOptions ({
3 isEnabled : false ,
4 });
1 const { annotManager } = instance;
2 annotManager. setFreeformRotationEnabled ( false );
Using the setRotationOptions API, then you can disable rotation completely. If you would like to disable free form rotation on certain annotations, then the following can be used instead:
JavaScript (SDK v8.0+) JavaScript (SDK v7.0+)
1 Webviewer ( ... )
2 . then ( instance => {
3 const { annotationManager } = instance.Core;
4
5 annotationManager. addEventListener ( ' annotationChanged ' , ( annotations , action ) => {
6 if (action === ' add ' ) {
7 annotations. forEach (( annotation ) => {
8 annotation. disableRotationControl ();
9 });
10 }
11 });
12 });
1 Webviewer ( ... )
2 . then ( instance => {
3 const { annotManager } = instance;
4
5 annotManager. on ( ' annotationChanged ' , ( annotations , action ) => {
6 if (action === ' add ' ) {
7 annotations. forEach (( annotation ) => {
8 annotation. setRotationControlEnabled ( false );
9 });
10 }
11 });
12 });
Vice-versa, to enable rotation controls, you would use the enableRotationControl API.
If you would like to configure the rotation type and rotation step sizes, that can be done with the same setRotationOptions API.
JavaScript (SDK v8.0+) 1 const annotManager = instance.Core.annotationManager;
2 annotManager. setRotationOptions ({
3 isEnabled : true ,
4 defaultRotationType : Core.AnnotationManager.RotationTypes. SNAP_ROTATION ,
5 hotkeyTogglesRotationType : false ,
6 snapAngleStepSizeInDegrees : 60 ,
7 });