Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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 + " " +;

map = new OpenLayers.Map('map', {
        eventListeners: {
            "moveend": mapEvent,
            "zoomend": mapEvent,
            "changelayer": mapLayerChanged,
            "changebaselayer": mapBaseLayerChanged
share|improve this answer
How could I have missed that out? Oh my.. Thank you! – Question Overflow Nov 2 '12 at 8:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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