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 am using GeoServer alongwith the default, build in GeoWebCache. I am using Extjs and GeoExt, as well. Everything is running well, except for the legend graphics request. My code for layers is as follows:

var MyLayer = new OpenLayers.Layer.WMS( "MyLayer",
        "http://my-ip-address/geoserver/gwc/service/wms",
        {layers: 'MyLayer',transparent: "true",format: "image/png",
        tileSize: new OpenLayers.Size(256,256),
                tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom },
                { isBaseLayer: false, visibility:false} );

And for legend panel:

var legend = new GeoExt.LegendPanel({
    title: "Map Legend",
    iconCls: 'legend',
                autoScroll: true,
                defaults: {
                    cls: 'legend-item',
        baseParams: {FORMAT: 'image/png'}
                },
                items: []
            });

Whenever I am trying to open this map, I am getting the layer name in my legend panel, but there is no image for layer legend and firebug is giving this error:

"NetworkError: 400 Bad Request - http://my-ip-address/geoserver/gwc/service/wms?TRANSPARENT=true&TILESIZE=256,256&TILESORIGIN=72.45,24.45&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application.ogc.se_xml&LAYER=MyLayer&FORMAT=image/gif&SCALE=2500000.0000000005&FORMAT=image/png"

I understand I will have to replace part of the URL request for GetLegendGraphic. But I am not able to do the same.Could anybody tell me how to accomplish this?

  • I am using GeoServer 2.1.1; GeoWebCache 1.2.6, OpenLayers 2.11, Ext 3.2.1 and GeoExt 1.1.
share|improve this question

5 Answers 5

up vote 3 down vote accepted

The correct url for the legend graphic for each layer and style is embedded in the GetCapabilities response as the LegendURL element. To get it:

  1. fetch the capabilities xml document
  2. parse it (OpenLayers has a parser class)
  3. retrieve the LegendURL for each layer you're interested in

Alternatively you can build a GetLegendGraphic request by following the documentation here.

share|improve this answer
    
I need a little bit more explanation. Can you provide me an example! –  thelastray Mar 19 '12 at 8:54

Finally I am able to fetch LegendGraphic. from this post.

All I had to do is loop through all my layers, and then set the legendURL.

 var layers; 
 for(var i = 1; i < map.layers.length; i++) 
 { 
    layers = mapPanel.layers.getAt(i);
    layers.set("legendURL","http://my-ip-address/geoserver/wms?TRANSPARENT=true&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fpng&LAYER=" + map.layers[i].params["LAYERS"]); 
  } 

May be this will help someone else!

share|improve this answer

For me it worked just to use the gx_urllegend instead of the gx_wmslegend:

items: [{
    xtype: 'gx_legendpanel',
            defaults: {
                labelCls: 'mylabel',
                style: 'padding:5px'
            },
            dynamic: true,
            layerStore: Ext.getStore('Layers'),
            preferredTypes: ['gx_urllegend'],
        }
share|improve this answer

An easier way of solving this is rewriting the GetLegendGraphics URL using a reverse proxy like Varnish and getting rid of "/gwc/service". The standard WMS server will responde instead of GWC.

The Varnish rule may be:

if (req.url ~ "/gwc/service/" && req.url ~ "REQUEST=GetLegendGraphic") {
     set req.url = regsub(req.url, "/gwc/service/", "/");
}
share|improve this answer

As a work around you can enable "direct WMS integration" and use the same WMS end point for tiled and non tiled requests, meaning the GetLegendGraphic request will be handled directly by GeoServer.

For example, in the following case:

layBase = new OpenLayers.Layer.WMS("BASE", "http://:/geoserver/gwc/service/wms/icom-icom-base/wms?", { layers : "icom-base:BASE", format : 'image/png' }

The direct WMS integration would be:

layBase = new OpenLayers.Layer.WMS("BASE", "http://:/geoserver/icom-base/wms?", { layers : "icom-base:BASE", format : 'image/png', tiled : true }

Look at the following link for detailed requeriments: http://docs.geoserver.org/latest/en/user/geowebcache/using.html

share|improve this answer

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.