Developer’s Corner: GeoServer GetLegendGraphic Enhancements
recently some fixes and enhancements were made by GeoSolutions to GeoServer, in particular to the WMS GetLegendGraphic request.
Layer groups support
The first improvement was done to produce a legend for layer groups, a very much needed functionality, to simplify and support wide usage of layer groups in GeoServer.
The support for layer groups is quite flexible. You can:
- specify a layergroup name in the LAYER parameter to have a legend with default options
- specify a custom style for some or all of the layer group sublayers with the STYLE parameter: just use a list of style names (one for each layer, separated by commas), leaving empty those that you don’t want to override
- specify a custom rule for some or all of the layer group sublayers with the RULE parameter, using it in the same way STYLE is used
The layer title (or name if title is not defined) is printed on top of each layer of the group, unless you specify forceTitles=off in the LEGEND_OPTIONS parameter.
Some examples, using default GeoServer
Mixed geometry support
Until now, asking a legend for a layer with a generic GEOMETRY
type, tipically used for mixed type (puncutal, linear and polygonal) geometries, would produce an exception in GeoServer
, because it was not clear what kind of sample icon should be produced.
From now on, the sample icon is produced looking at the requested SLD style, choosing the best matching geometry type based on the symbolizers:
- A polygon is chosen if at least a PolygonSymbolizer is present
- A polyline is chosen if no PolygonSymbolizer is present, and at least a LineSymbolizer is present
- A point is chosen in any other case
Dynamic symbol size handling
Until now asking for a legend for a punctual layer, where symbols or images with very big or very small size are used, compared to the icon size, the legend will be unreadable, as the symbol would be rendered with the requested size.
From now on, the symbol sizes are rescaled to always fall inside the icon requested box, and to respect a minimum size (defaulted to 3 pixels). The default minimum size can be overridden with the minSymbolSize:
More, for a style with multiple rules, the sizes of each rule are rendered proportional to tthe respective style sizes.
Look at the following image for a before – after effect example:
It is eventually worth to point out that all this fixes and enhancements are already available in the latest GeoServer
nightlies, for the 2.2.x, 2.3.x, and 2.4.x series.