Select to view content in your preferred language

Tell Widget to stop listening for mouse click

518
3
Jump to solution
09-06-2018 11:45 AM
ChetEgbert1
Emerging Contributor

Simple question.  I placed this.own(on(this.map, "click", lang.hitch(this, this._onMapClick))); in postCreate to start my widget listening for mouse clicks.  How to I undo this command on widget onClose? 

Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Chet,

  It is as simple as assigning a var to the listener:

this.own(this.clickEvtHandler = on(this.map, "click", lang.hitch(this, this._onMapClick)));

...

onClose: function(){
  this.clickEvtHandler.remove();
...

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Chet,

  It is as simple as assigning a var to the listener:

this.own(this.clickEvtHandler = on(this.map, "click", lang.hitch(this, this._onMapClick)));

...

onClose: function(){
  this.clickEvtHandler.remove();
...
0 Kudos
ChetEgbert1
Emerging Contributor

Thanks.

I found this worked but modified for version 3.x

onOpen

this._clickEvt = this.map.on("click", lang.hitch(this, this._onMapClick));

onClose

this._clickEvt.remove();

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chet,

   WAB is v3.x of the API...? Also I know that code works fine in a widget, as I have it working in some of mine. Anyway don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos