.. _configuration.layers.styleslegends: Styles Legends ============== In WMTS and WMS services capabilities documents, styles can be associated with a ```` element that allows clients to retrieve an image representing the style legend. In the following example we can see the ```` element for ``rain`` style (WMS 1.1.0): .. code-block:: xml When using GeoWebCache integration with GeoServer, styles legends are automatically configured for GeoServer layers. Layers configured using a WMS capabilities document will also have their styles legends automatically configured. When configuring a layer using the REST interface or through ``geowebcache.xml`` configuration file the user needs to configure the styles legends, otherwise no ```` elements will be included in WMS and WMTS services capabilities documents. Both REST interface and ``geowebcache.xml`` configuration file use the same XML structure. A legend configuration is associated with a certain style in the context of a certain layer, follows a configuration example: .. code-block:: xml topp:states STYLES population population polygon pophatch http://localhost:8080/geoserver/topp/wms image/jpeg http://localhost:8020/geowebcache/wms 50 100 image/gif http://localhost/polygon.gif 5000 10000 The following properties can be used to configure a legend info: .. list-table:: :widths: 10 90 :header-rows: 1 * - Property - Description * - style - the style to which this legend belongs * - width - the width of the legend image * - height - the height of the legend image * - format - the image format of the legend image * - url - the URL that can be used to retrieve the legend image * - minScale - minimum scale denominator (inclusive) for which this legend image is valid (WMTS only) * - maxScale - maximum scale denominator (exclusive) for which this legend image is valid (WMTS only) This properties can be provided in several ways using ```` and ```` elements. Default values for properties ``width``, ``height`` and ``format`` can be configured using respectively attributes ``defaultWidth``, ``defaultHeight`` and ``defaultFormat`` of ```` element. The default values can be overridden using elements ``width``, ``height`` and ``format`` inside ```` elements. The ``style`` property value needs to be provided using ``style`` attribute of ```` elements. The ``url`` property is a little more complex, if nothing is say the WMS layer base URL will be used to build a WMS ``GetLegendGraphic`` request. Element ```` can be used to provide another base URL, and this one will be used instead of the layer base URL. Element ```` can be used to provide an URL that should be used as is to retrieve the legend image. Properties ``minScale`` and ``maxScale`` can be provided using the ```` element, this properties will only be used by WMTS service. Looking at the example above, the legend configured for ``population`` style will produce the following legend URL for WMTS: .. code-block:: xml Note that the layer base URL was used as the base URL for the legend URL. In the example above a different base URL is provided for the legend associated with style ``pophatch`` using the ```` element. The produced legend URL will look like this for WMTS: .. code-block:: xml In some situations it may be useful to provide an already complete URL to the legend image (custom vendors parameters, a static image or different protocol). In the example above the legend URL for style ``polygon`` will use an already complete URL and will look like this for WMTS: .. code-block:: xml In WMS the legend URL element for ``polygon`` style will look like this: .. code-block:: xml image/gif WMS and WMTS legend URL elements have a different structure and different mandatory elements. In WMTS only properties ``format`` and ``url`` are mandatory. In WMS properties ``width``, ``height``, ``format`` and ``url`` are mandatory.