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

i have used LayerSwitcher() before and it has worked fine but I am now trying to use it with the group layers in Geoserver and the map blanks out.

tiled = new OpenLayers.Layer.WMS(
                    "Geoserver layers - Tiled", "",
                        LAYERS: '',
                        STYLES: '',
                        format: format,
                        tiled: !pureCoverage,
                        tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
                        buffer: 0,
                        displayOutsideMaxExtent: true,
                        isBaseLayer: true,
                        displayInLayerSwitcher: true
var imagery = new OpenLayers.Layer.WMS(
                "Global Imagery",
                {layers: "bluemarble"}
                map.addLayers([tiled, imagery]);

                // build up all controls
                map.addControl(new OpenLayers.Control.PanZoomBar({
                    position: new OpenLayers.Pixel(2, 15)

                map.addControl(new OpenLayers.Control.Navigation());
                map.addControl(new OpenLayers.Control.Scale($('scale')));
                map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
                map.addControl(new OpenLayers.Control.LayerSwitcher());

The moment I comment out the LayerSwitcher(), the map is rendered fine.

Also, I tried adding a new WMS, imagery (in the code above), and if I try to do the following,

map.addLayers([imagery, tiled]);

I am only able to see a broken image. Can we not add a layer through code with group layers?

Where am I going wrong?

share|improve this question
up vote 1 down vote accepted

I do not completely understand your question, but when it comes to layer groups from Geoserver affecting the LayerSwitcher in OpenLayers: this is impossible, OpenLayers cannot tell the difference between a layer group wms and a single layer wms.

As for your problem with "one layer switching off when the other is turned on": This is because OpenLayers treats your wms layers as baselayers. Try to add isBaseLayer: false to the properties of one of your layers (and perhaps transparent: true), then they will show up at the same time

share|improve this answer
I think openlayer is considering the entire layer group as a single layer – Sam007 May 14 '12 at 22:10
Tried transparent: true it is the same output – Sam007 May 14 '12 at 22:14
ofcourse, openlayers treats the layer group as a single layer, that is the purpose of the layer group – atlefren May 14 '12 at 22:22
if you need to turn them on and off separately, you have to add each as a wms layer in openlayers, yes – atlefren May 14 '12 at 22:48
did you set the transparent:true on the wms params object (not the openlayers class properties object), in other words; in the first block of {} ? – atlefren May 14 '12 at 23:06

firstly I would like to specify that i dont see any grouping definition in your code. i dont know the new openlayers api whether support group layers or not. But you can check out this from old trunk here... and here..

i âm doing it in extjs grid panel as this. Maybe in geoext tree module can help you...

i hope it helps you...

share|improve this answer
by grouping i mean that I have used the geoserver group layer. the that you see, are the group layers containing 3 shapefiles and raster. – Sam007 May 14 '12 at 18:23
oh sorry, someone can misunderstand from your question. you should add ....Group Layers from GeoServer. – Aragon May 14 '12 at 18:37
Done :) Any solution now how I can resolve this issue? – Sam007 May 14 '12 at 18:45
The problem with using WMS constantly is that if one layer is switched on the other then turns off. How can I get both on? – Sam007 May 14 '12 at 18:59

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.