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

Is the there a way of clearing the legend in Openlayers by unselecting all the layers? We have a map that starts with several layers.

I was thinking that we might be able to add a button to the map that would do this.

share|improve this question
What do you mean by "legend". AFAIK OpenLayers have no legend-control. Are you using some kind of framework such as GeoEXT or mapfish? – atlefren May 23 '12 at 14:32

You could use some JavaScript like the following:

 for(var i=0;i<map.layers.length;i++) {
    if (!map.layers[i].isBaseLayer)

This will disable all layers except base layers. The legend (LayerSwitcher) will be updated automatically.

share|improve this answer
unicoletti - thanks for that I'll give it a whirl. By legend I did mean LayerSwitcher – Matt T May 23 '12 at 21:15

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.