OperationType getLegendGraphic = getCapabilities().getRequest().getGetLegendGraphic();
if( getLegendGraphic == null ){
// this wms server does not support legend graphics
return icon;
}
GetLegendGraphicRequest request = createGetLegendGraphicRequest();
request.setLayer( layer.getName() );
request.setWidth("16");
request.setHeight("16");
String desiredFormat = null;
List<String> formats = getLegendGraphic.getFormats();
if (formats.contains("image/png")) {
desiredFormat = "image/png";
}
else if (formats.contains("image/gif")) {
desiredFormat = "image/gif";
}
else {
// there is no format that I am sure we can deal with :-(
// the danger here is requesting PDF from geoserver
// (because everyone wants a PDF legend graphics - wot?)
return icon;
}
request.setFormat(desiredFormat);
request.setStyle("");
URL legendGraphics = request.getFinalURL();
icon = new ImageIcon( legendGraphics );
}
return icon;
}