sfletche
sfletche

Reputation: 49714

OpenLayers 2 trigger event when baselayer changes

I want my application to do something when the base layer has changed.

Is it possible to handle/catch that event in OpenLayers 2?

Upvotes: 1

Views: 786

Answers (1)

John Powell
John Powell

Reputation: 12571

Yes, it is possible:

map.events.register("changebaselayer", this, function (obj) {
    if (obj.layer.name == 'layer_name') {
       //do something if new base layer is equal to layer_name
       ....
   }
});

You can see all the possible events you can hook into in the source for OpenLayers/Map.js although the actual event will be triggered by the LayerSwitcher.

Upvotes: 1

Related Questions