By David Crowther
How do you create a Legend for a WMS Layer in MapThat?
As long as the source Web Map Service (WMS) is publishing a Legend Capability, MapThat can consume that Legend and render it with your layer.
External WMS Layers:
If the WMS is accessed from an external source e.g. the Environment Agency or Historic England, we will have no control over the Legend that is being published and MapThat will simply show the Legend as it is provided.
For example here is the Legend for Coal Areas, Flood Zones, Conservation Areas and Listed Buildings. Here the supplier is simply publishing either a point icon (for Listed Buildings) or a simple polygon/polyline style for the other WMS layers. In most cases we would expect the WMS Legend icons to reflect the style of the objects as they are shown in the map, thus allowing MapThat users to differentiate between the map layers.
Internal WMS Layers:
For internal WMS layers we have a lot more control. Cadline’s WMS publisher of choice is GeoServer and using the Style options in GeoServer you can publish your layers with high levels of customisation and styling, all of which are then supported by a default Legend.
For example in GeoServer here is a layer of LSOA polygons that are styled into 3 Rules based on Population values. As part of the Style settings the Title of each Rule is then used to create a Legend which is supplied as part of the WMS.
In the Styles page click Preview Legend and the Legend is shown, where each Rule is listed with their Title used the category value.
If required you can edit the Title value for a Rule and the Legend will then be edited. For example we will change the top Rule to say Low Population Count.
Validate and Apply the change to the XML and then re-preview the Legend to see that the Legend has now been customised.
…. changing the Title for all 3 Ranges means that the Legend is now fully configured.
Now shown within MapThat the Legend for this WMS layer reflects the settings in the STYLE file associated to the GeoServer WMS layer.
Here is another example of how the GeoServer Legend….
…is now embedded below the layer in MapThat.
Configure MapThat to Show WMS Legend:
Finally you will need to configure your Layer in the MapThat Admin Forms to use the WMS Legend.
To show the WMS legend in MapThat we have utilised the Legend/Themes panel which sits below the Layer - we don’t use the Layer Icon.
MapThat Themes are generally thematic maps linked to a Layer where we style the Layer based on an attribute e.g. Deprivation Rate.
Here the Layer is linked to a MapThat THEME called Liverpool Dep Quantile which styles the LSOA polygons using the dep_quantile field.
This THEME is then linked to the Liverpool Deprivation Layer.
In the Data Layer Settings for the Liverpool Deprivation Layer, you now have two options related to the THEME associated to it.
- Render Thematic Legend – This will show the Legend. If unticked then the user cannot see the Legend.
- Auto Reveal Thematic Legend – This will mean that the Legend Categories are auto shown when the Layers is ticked on.
For WMS Layers, there is no need to create an extra THEME record and associate it to the WMS layer. Instead MapThat will by default look for any Legend based on the Web Map Service URL that is provided.
So using the above Data Layers Settings you can choose to Show (Render) and Auto Reveal the WMS Legend for your WMS layer. E.g. making the above settings for my PCC Adopted Highways WMS layer means that the WMS Legend is shown and auto opened when the user ticks the layer on.
If you wish you can change the Data Layer Settings for a WMS and choose to not show the WMS Legend. Here for the Coal Areas WMS we have unticked the Thematic Legend options for the Layer….
… which means that when the user ticks to display the Coal Areas WMS, the layer loads but no Legend is shown below the Layer Name.