[GIS] How to record a base layer change event in OpenLayers

eventslayersopenlayers-2

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?

Best Answer

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
    }
});