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.

  • 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

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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