Measure Widget 2.15 for Web App Builder - Issue with ESC key press

319
1
Jump to solution
01-24-2023 08:45 AM
LanceCole
MVP Regular Contributor

First, Thanks, @TomSellsted, for a great widget.  I have found it very helpful.

I did note a minor issue that I am unsure how to clean up.  If you draw a multipart polygon or line and press 'ESC' to quit the sketch, the line or polygon is removed, but the labels remain.  Also, the widget remains in draw mode, and behavior is erratic if you continue to use the widget.

How can the widget be modified to remove the active text symbols and cleanly terminate the current sketch?

Sketching:

LanceCole_0-1674578257214.png

After pressing 'ESC', labels remain

LanceCole_1-1674578376634.png

Behavior after:  Cannot see the first segment until the second click and only the last label is displayed upon completion.

LanceCole_0-1674580134259.png

 

 

 

0 Kudos
1 Solution

Accepted Solutions
LanceCole
MVP Regular Contributor

I was able to fix this by adding a 'keydown' bind event in the postCreate function.  I could only get it to work by binding it to the document.body.  Added a conditional to stop the propagation of the 'ESC' if measure.Type is set and to also exit editing if editing is enabled.

this.own(on(document.body, "keydown", lang.hitch(this, function(evt) {
  if(evt.keyCode == keys.ESCAPE) {
    if(this.measureType) {
      event.stop(evt);
    } else if (this.editingEnabled) {
      this.editToolbar.deactivate();
      this.editingEnabled = false;
    }
  }
}

 

View solution in original post

0 Kudos
1 Reply
LanceCole
MVP Regular Contributor

I was able to fix this by adding a 'keydown' bind event in the postCreate function.  I could only get it to work by binding it to the document.body.  Added a conditional to stop the propagation of the 'ESC' if measure.Type is set and to also exit editing if editing is enabled.

this.own(on(document.body, "keydown", lang.hitch(this, function(evt) {
  if(evt.keyCode == keys.ESCAPE) {
    if(this.measureType) {
      event.stop(evt);
    } else if (this.editingEnabled) {
      this.editToolbar.deactivate();
      this.editingEnabled = false;
    }
  }
}

 

0 Kudos