The OpenLayers.Control class possesses an eventListener property which could be used in the layer switcher control. I am not sure how to make use of it to detect a base layer change event so that I can store the variable name of the chosen layer to be used subsequently when the user navigate back to the map page. Can anyone give me some hints?

1 Answer 1


You can check this link and view page source: Events Example

I think it has exactly what you want.

function mapBaseLayerChanged(event) {
    log(event.type + " " + event.layer.name);

map = new OpenLayers.Map('map', {
        eventListeners: {
            "moveend": mapEvent,
            "zoomend": mapEvent,
            "changelayer": mapLayerChanged,
            "changebaselayer": mapBaseLayerChanged
  • How could I have missed that out? Oh my.. Thank you! Nov 2, 2012 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.