by David Crowther
Question:
Is it possible to hide legend items for a GeoServer WMS Layer?
Answer:
Yes – in later versions of GeoServer the option to hide legend items but still show the theme category within in the WMS layer is now possible.
There are two commands that can be used:
<VendorOption name=”inclusion”>legendonly</VendorOption>
This will mean that the chosen element/item will be defined in the Legend but not shown within the map.
<VendorOption name=”inclusion”>maponly</VendorOption>
This will mean that the chosen element/item will be shown in the Map but not defined in the legend.
So, in this case it is the second vendor option – maponly – that we require.
Why may you want to do this?
There could be a number of reasons, for example your current Style associated to your WMS uses a classification field to style the data,…
- but there are too many classifications (legend items), and the legend looks overly busy
- or there is an item that you would like to see in the map but don’t necessarily need to be listed in the legend items
… in this example we will update the style file used to display the sub types for the Sites Layer from the Ordnance Survey National Geographic Database.
Currently there are over 25 individual legend items.
In GeoServer we can edit the Style file associated to the layer…
… and in this example we will update the Rule which styles the map features where the field oslanduset = ‘Unknown Use’
Inserting the vendor option to only include in Map Only… the vendor option should be inserted after the symbolizer and before the end of the Rule.
Note that the validation check may not pass… however the layer will still be ok to display.
If you check the preview legend option we can now see that the ‘Unknown Use’ Subtype is now not listed in the legend.
And when viewed within your GIS e.g. the Arkance webGIS MapThat – we can see that the map features for Unknown Use (pink areas) are still shown in the map but are now not listed in the legend.
This allows you to unclutter the legend in your GIS, but still show all the map features in the map.
If you update the Style file and change the vendor option to be legendonly….
… the Legend item for ‘Unknown Use’ will now be displayed….
… but the features within the map are now hidden!
Comments
0 comments
Please sign in to leave a comment.