tags:

views:

1596

answers:

1

I want to add and remove the same event for Google map.

because I have attached a Listener to 'moveend' event on map , so event a big infoWindow opens , then also 'moveend' event occures ,which I don't want to run for this thing. Any idea how can I turn ON and OFF 'moveend' event Listener ?

+3  A: 

You can remove an event listener but you have to pass the exact listener returned when you added one.

e.g.

//add moveend listener
var moveendListener = GEvent.addListener(source, "moveend", yourfunction);

//remove moveend listener
GEvent.removeListener(moveendListener);

or

//remove all listeners associated with an event
GEvent.clearListeners(source, "moveend") ;

EDIT: another option is to have the function the listener calls behave differently under different conditions.

e.g.

function moveendHandler() {
    if (isWhateverActive()) return;

    //code to run if whatever is not active
}
Jonathan Fingland