Remove Token Listeners

somewhat simple problem (explain) this time:

I have an array of tokens that I equip with eventlisteners:

for (i in markersArray) {
google.maps.event.addListener(markersArray[i], 'click', function() {        
    //stuff it does
    google.maps.event.removeListener(?????)     //remove self... but HOW?!
});}

as I mention in the comment, I just want the listener to be deleted after it is clicked.

the problem is that I do not know what a descriptor is for a listener.

+5
source share
4 answers

You can use "addListenerOnce". Then you don’t even have to worry about removing the listener.

addListenerOnce (example: Object, eventName: string, handler: Function)

Like event.AddListener, but the handler removes itself after processing the first event.

+4
source

clearListeners(instance:Object, eventName:string) http://code.google.com/apis/maps/documentation/javascript/reference.html

+2

, ( , ). google.maps.event . .

var markersListeners = [];

for (i in markersArray)
{
    markersListeners[i] = google.maps.event.addListener(markersArray[i], 'click', function()
    {
        //stuff it does
        google.maps.event.removeListener(markersListeners[i]);
    });
}

: . removeListener (markersArray [i]), , , .

0

, : https://developers.google.com/maps/documentation/javascript/events#removing

var listener1 = marker.addListener('click', aFunction);
var listener2 = marker.addListener('mouseover', bFunction);

// Remove listener1 and listener2 from marker instance.
google.maps.event.clearInstanceListeners(marker);
0

All Articles