leaflet layer control events?

user1032402 picture user1032402 · Dec 31, 2012 · Viewed 24.8k times · Source

All, I want to detect user layer selection in order to synchronize my sidebar with the displayed layers.

But I don't see any layer control events in the API reference; How might I tell when such user layer selection has occurred?

As an alternative, I've looked at the layer load and unload events, but I don't see any identification in what's returned. Did I miss that somehow?

Answer

Jabran Saeed picture Jabran Saeed · Sep 6, 2013

There is a "baselayerchange' event defined here http://leafletjs.com/reference.html#control-layers Just bind it to the map object and you are good to go.

map.on('baselayerchange', function(e) {
  console.log(e);
});