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.

I have four layers in the LayerSwitcher. When the map is loaded all the layers are checked by default. I do not want to show all Layers as checked.How do I uncheck a layer when the map is loaded?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

Use the layer's setVisibility function to turn them off before you add them to the map.

share|improve this answer
add comment

You can get idea from the view page source code of this example.

In given below example, I have added village layer which will be loaded unchecked default on map load. In that code, I have used setVisibility() function.

var village = new OpenLayers.Layer.WMS("Village", "http://localhost:8090/geoserver/cite/wms",
        {
              LAYERS: 'cite:Village_Boundary_geo',
              STYLES: '',
              format: format,
              transparent: true
        },
        {
              singleTile: true,
              ratio: 1,
              isBaseLayer: false,
              yx : {'EPSG:4326' : true}
       }
     );

village.setVisibility(false);

map.addLayers([village]);
share|improve this answer
1  
Your answer would be more useful if it contained an example of the situation of the problem listed in the question and possibly some content from the link you provided. –  Evil Genius Jun 23 at 11:11
add comment

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.