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", "http://niles.iplantcollaborative.org:80/geoserver/wms",
                        LAYERS: 'Shapefile.py',
                        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?


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

  • 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
  • 1
    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
  • 2
    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
  • 1
    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...

  • by grouping i mean that I have used the geoserver group layer. the shapefile.py 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 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.