deactivate draw-end handler

749
5
07-28-2014 05:58 AM
maximcouton
New Contributor III

Hi,

He is my problem,

var tb = new Draw(map);

tb.on("draw-end", lang.hitch(map, getAreaAndLength));

How can I later deactivate this handler ?

I wante something like :  tb.on("draw-end").set(null)  ??

This is because I have to switch between two handlers,

IF set directely the second handler it still call the first

so finally , it calls the two handlers.

Thanks,

Maxim

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Maxim,

  If you setup a variable for the event then you can just use the remove function.

var signal = tb.on("draw-end", lang.hitch(map, getAreaAndLength));

signal.remove();

maximcouton
New Contributor III

Its:

    tb.onDrawEnd.after.remove();

Maxim,

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Maxim,

   As with many things there are a couple of ways to do it. Don't forget to mark people responses as helpful (if you think they are) using the actions menu link. Also if you think that your answer is the best than mark yours as the correct answer.

0 Kudos
maximcouton
New Contributor III

Ok,

I tried to use directely tb.remove() but I am getting the exception that remove is not defined. So after seaching a while in the debugger options I found the remove funtion you suggested in  onDrawEnd.after.remove();

Thanks Robert,

0 Kudos
JeffPace
MVP Alum

I think you should use once

Incidentally, dojo/on includes a convenience method for doing exactly this: on.once. It accepts the same parameters as on, but will automatically remove the handler once it is fired.

Events with Dojo - The Dojo Toolkit

0 Kudos