I have a dynamic style in Geoserver, like below:
<sld:ColorMap>
<sld:ColorMapEntry color="#2c7bb6" quantity="${env('low',0)}" label="${env('low',0)}"/>
<sld:ColorMapEntry color="#64a5cd" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 1 / 9}"/>
<sld:ColorMapEntry color="#9dcfe4" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 2 / 9}"/>
<sld:ColorMapEntry color="#c7e6db" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 3 / 9}"/>
<sld:ColorMapEntry color="#edf7c9" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 4 / 9}"/>
<sld:ColorMapEntry color="#ffedaa" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 5 / 9}"/>
<sld:ColorMapEntry color="#fec980" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 6 / 9}"/>
<sld:ColorMapEntry color="#f99e59" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 7 / 9}"/>
<sld:ColorMapEntry color="#e85b3a" quantity="${env('low',0) + (env('high',0) - env('low',0)) * 8 / 9}"/>
<sld:ColorMapEntry color="#d7191c" quantity="${env('high',0)}" label="${env('high',0)}"/>
</sld:ColorMap>
An example request:
/geoserver/temper/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&LAYER=temper:A%C3%91O2017&WIDTH=30&HEIGHT=5&transparent=true&STYLE=estilo_fijo&env=low:11;high:13;&LEGEND_OPTIONS=fontSize:15;fontColor:0xFFFFFF0;fontStyle:bold;dpi:180;mx:0.2;my:0.2;dx:2;dy:2;absoluteMargins:True;
I was expecting labels to take the values provided with the enviroment variables passed in the GetLegendGraphics
request, as it's working with the quantity
parameter for GetMap requests.
The output image i'm getting:
It seems that whatever you pass in the label
parameter is treated as string
, and dynamic values are not working with the syntax used.
So it's possible and I'm using the wrong syntax? Or it's not possible to make the label dynamic?
Also, Geoserver says my style is not valid and get some errors during the validation, but the style is working:
line 18: cvc-attribute.3: The value '${env('low',0) + (env('high',0) –
env('low',0)) * 7 / 9}' of attribute 'quantity' on element
'sld:ColorMapEntry' is not valid with respect to its type, 'double'.
Best Answer
The documentation does not include "label" as an attribute that can take expressions, it states "Most of the ColorMapEntry attributes (color, quantity and opacity) can be defined using cql expressions". So only color, quantity and opacity can use expressions, see also:
http://docs.geoserver.org/stable/en/user/styling/sld/reference/rastersymbolizer.html#cql-expressions
Not all is lost though, if you want you push for "label" to also support expressions, see the expected process here:
https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer