2

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",
                "http://maps.opengeo.org/geowebcache/service/wms",
                {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());
                map.zoomToExtent(bounds);

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?

Sam007
  • 4,395
  • 7
  • 48
  • 69

2 Answers2

1

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

atlefren
  • 4,307
  • 20
  • 35
  • 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
  • Oh great I thought I could use them separetly, so now i have to load them one after the other? – Sam007 May 14 '12 at 22:33
  • 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
  • That is the problem I am trying to avoid. See if I add each one of them as WMS, if I switch one on I am not able to see the other one. They are basically point shapefiles which I want the user to see simultaneously. Meaning it will be overlaid on a raster which is the base map. Therefore I have to go for WFS and here is that question. http://gis.stackexchange.com/questions/25446/unable-to-create-wfs-successfully – Sam007 May 14 '12 at 23:02
  • 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
0

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

urcm
  • 22,533
  • 4
  • 57
  • 109
  • 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. – urcm 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