handleKeyboardEvent()

in pathology/viewer/src/components/image-viewer-side-nav/image-viewer-side-nav.component.ts [415:465]


  handleKeyboardEvent(event: KeyboardEvent) {
    const pressedKey = event.key;
    if (pressedKey === 'Backspace' && !this.editModeSelectedAnnotationOverlay) {
      if (this.selectedFeature) {
        this.deleteSelectedAnnotation();
      }
    }

    const overLayPosition = this.selectedAnnotationOverlay?.getPosition();
    if (this.isOverlayTemplateFocused || overLayPosition) {
      return;
    }
    const olMap = this.olMap;
    if (!olMap) return;


    if (pressedKey === '+') {
      const currentZoom = olMap.getView().getZoom() ?? 0;
      olMap.getView().setZoom(currentZoom + 1);
    }
    if (pressedKey === '-') {
      const currentZoom = olMap.getView().getZoom() ?? 0;
      olMap.getView().setZoom(currentZoom - 1);
    }
    const pressedKeyLowerCase = pressedKey.toLowerCase();
    const isSelect = pressedKeyLowerCase === 's';
    const isMeasure = pressedKeyLowerCase === 'm';
    const isDraw = pressedKeyLowerCase === 'd';
    const isRectangle = pressedKeyLowerCase === 'r';
    const isPoint = pressedKeyLowerCase === 'p';


    if (environment.ENABLE_ANNOTATIONS) {
      if (isDraw) {
        this.onDrawPolygonsTool(ViewerMenuAction.DRAW_POLYGON);
      }
      if (isRectangle) {
        this.onDrawPolygonsTool(ViewerMenuAction.DRAW_BOX);
      }
      if (isPoint) {
        this.onDrawPolygonsTool(ViewerMenuAction.DRAW_POINT);
      }
      if (isMeasure) {
        this.onMeasureTool();
      }
    }

    if (isSelect) {
      this.onSelectTool();
    }
  }