GeoServer– Hide Legend Items

Marketing
Marketing
  • Updated

by David Crowther

Hide legend 1.png

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.

Hide legend 2.jpg

Currently there are over 25 individual legend items.

In GeoServer we can edit the Style file associated to the layer…

Hide legend 3.jpg

… and in this example we will update the Rule which styles the map features where the field oslanduset = ‘Unknown Use’

Hide legend 4.jpg

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.

Hide legend 5.jpg

Note that the validation check may not pass… however the layer will still be ok to display.

Hide legend 6.jpg

If you check the preview legend option we can now see that the ‘Unknown Use’ Subtype is now not listed in the legend.

Hide legend 7.jpg

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.

Hide legend 8.jpg

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

Hide legend 9.jpg

… the Legend item for ‘Unknown Use’ will now be displayed….

Hide legend 10.jpg

… but the features within the map are now hidden!

Hide legend 11.jpg

 

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.