Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
1  
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

1 Answer 1

You could use some JavaScript like the following:

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

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

 
discard

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.