Activate/deactivate drawing mode

i have a button on my project, the button must have a capability to enter the drawing mode and user can drawing and pick point after clicking the button. if the drawing or pickpoint is done, user can click the button again to exit the drawing mode and disable the screenSpaceEventHandler. i tried to use the state variable on-off like this below but it still can pick point when the eventHandler is destroyed. any idea to solve this? thanks in advance

let eventHandler = new ScreenSpaceEventHandler(
      this.terria.cesium.scene.canvas
    );

    if (this.inDrawMode === true){
      
      this.inDrawMode=!this.inDrawMode
      console.log("indrawmode is ", this.inDrawMode,"mode drawing");
      
      eventHandler.setInputAction(
        function startLook(){console.log(8)},
        ScreenSpaceEventType.RIGHT_CLICK
      );
      
    }
    else if (this.inDrawMode === false) {
      this.inDrawMode=!this.inDrawMode
      console.log("indrawmode isS ", this.inDrawMode,"destroymode");
      eventHandler.destroy();
    }

by the way i wrote this in typescript

Is this the code of everything you’re doing, or just some excerpts? If you follow this code as a linear example as is, then of course it won’t work, so I suspect there’s more to your code than this? What’s the main loop look like? How is this code called, like a button event listeneer, or something else?

Since it’s in TypeScript, is this in an Angular component, for example? Or some other framework with a real-time loop and / or templating system? There’s a million ways to slice and dice what you’re asking for here, so it’s a bit hard to tell you how to do it. I’m sure it’s not a problem with Cesium or the API, but more about how you’ve put your application together.

If it’s just plain code of a loop, try putting a working example into a Sandcastle so we can see what you’re doing. There’s nothing in the code you’ve shown that makes it different from JavaScript.

Cheers,

Alex