srinivas
srinivas

Reputation: 5098

overlayadd & overlayremove events are not being fired on leaflet maps

I am just trying to listen to basic 'overlayadd' and 'overlayremove' events on the Layers Control object in leaflet maps. But for some reason I these events are not being fired. I added a 'baselayerchange' event listener and that is being fired correctly but not the overlay events. Anyone have any clues?

//this works        
map.on('baselayerchange', function(a) {
        console.log(a);
        alert("The layer changed to " + baseMaps[a.name].getLayers()[0].getLatLng().lat);
    });

//these two do not work
map.on('overlayadd', function(a) {
  alert(a);
});

map.on('overlayremove', function(a) {
   console.log(a);
});

Upvotes: 2

Views: 2287

Answers (1)

srinivas
srinivas

Reputation: 5098

Updates to my question above: I was using Leaflet v0.5. After updating to version 0.6.4 the problems went away, and both the 'overlayadd' and 'overlayremove' are being fired properly.

Upvotes: 1

Related Questions