Switch back to 'Select' tool after creating an annotation

How to programmatically switch the tool to ‘Select’ tool or ‘Pan’ tool soon after the user created an annotation using a another tool.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

You can do so by attaching an event listener to the annotationManager like this:

const {AnnotationManager, annotationManager, documentViewer, Tools} = instance.Core
annotationManager.addEventListener(AnnotationManager['Events']['ANNOTATION_CHANGED'], function(annotations, action) {
  if (action === 'add') {
    const originalMethod = Tools.GenericAnnotationCreateTool.prototype.switchOut;
    Tools.GenericAnnotationCreateTool.prototype.switchOut = function(newTool) {
      if (this['annotation'] !== null && this['annotation'] !== undefined) {
        this['annotation'] = null;
      }
      Tools.AnnotationSelectTool.prototype.switchOut.call(this, newTool);
    }
    const tool = documentViewer.getTool(Tools.ToolNames.PAN);
    // If you want to switch to the "Select" tool you can use the following line:
    // const tool = annotationManager.getTool(Tools.ToolNames.EDIT)
    documentViewer.setToolMode(tool);
    Tools.GenericAnnotationCreateTool.prototype.switchOut = originalMethod;
  }
});

You can also take a look at this page for more examples on how you can work with annotation events.

Thanks @ychen for the solution.