On double click/Enter, i want to finish marking of annotation where the last point was set and not where the cursor is present

I want to finish marking of Area and perimeter annotation where the last point was marked while drawing and not where the current position of cursor is.

For finish marking using ENTER, i am using this -

this.viewerInstance.hotkeys.on('enter', e => {
this.toolSelected.mouseDoubleClick(e);
});

How to do that ?

Hey there!

This one is a bit tricky just because of the timing of how all that works.

Basically the final point of the annotation is added after the double click event, so we can listen for any annotations that get added right after a double click, and then delete it.

This code should do what you want:

const { docViewer, Tools, annotManager } = instance;

const perimeterTool = docViewer.getTool(Tools.ToolNames.PERIMETER_MEASUREMENT);

docViewer.on('dblClick', () => {
  const perimeterAddedHandler = (annotation) => {
    annotation.getPath().pop();
    annotation.adjustRect();
    annotManager.redrawAnnotation(annotation);

    perimeterTool.off('annotationAdded', perimeterAddedHandler);
  };

  perimeterTool.on('annotationAdded', perimeterAddedHandler);

  setTimeout(() => {
    // if no perimeter annotation is added just after the double click
    // then it must not have added an annotation so we can remove the handler
    perimeterTool.off('annotationAdded', perimeterAddedHandler);
  }, 100);
});

Basically this just checks if there was an annotation added shortly after double clicking, and it removes the last point from it if there was.

I hope this helps!
Thanks,
Logan

Hi Logan,

This works somewhat close to what I expected but I want to trigger this only on ENTER keyboard event (Changed requirement). On double click, it doesn’t work properly so only on ‘ENTER’ it should go back to one point back.

Also from this, its is not working,
this.viewerInstance.hotkeys.on('enter', e => { this.toolSelected.mouseDoubleClick(e); });

How can I trigger this feature only on enter and not on double click by mouse.

Hey there!

This code should do the trick. Its basically the same thing, just wrapped in the enter event:

  const { docViewer, Tools, annotManager } = instance;
  const perimeterTool = docViewer.getTool(Tools.ToolNames.PERIMETER_MEASUREMENT);
  
  instance.hotkeys.on('enter', e => {

    const perimeterAddedHandler = (annotation) => {
      annotation.getPath().pop();
      annotation.adjustRect();
      annotManager.redrawAnnotation(annotation);
  
      perimeterTool.off('annotationAdded', perimeterAddedHandler);
    };
  
    perimeterTool.on('annotationAdded', perimeterAddedHandler);
  
    setTimeout(() => {
      // if no perimeter annotation is added just after the double click
      // then it must not have added an annotation so we can remove the handler
      perimeterTool.off('annotationAdded', perimeterAddedHandler);
    }, 100);

    console.log('test')
    instance.docViewer.getToolMode().mouseDoubleClick()
  })