2

Is there a way to add dynamic text decoration via a geoserver layout.xml that reflects the &time param of a geoserver WMS request?

I know from here how to display frame parameters as decorations for animations by using value="${avalue}" in layout.xml and each animation frame shows the avalue param correctly, but for a non animation request there is no &avalue just &time and value="${time}" doesn't seem to work.

Here is the layout that works for animations:

<layout>
  <decoration type="text" affinity="bottom,left" offset="16,6">
    <option name="message" value="Leaf Out Date: ${avalue}"/>
    <option name="font-size" value="22"/>
    <option name="font-family" value="Arial"/>
    <option name="halo-radius" value="2"/>
  </decoration>
  <decoration type="legend" affinity="bottom,right" offset="6,-6" size="0,0"/>
</layout>

My non animation request looks like this:

http://myserver/geoserver/si-x/wms?service=WMS&request=GetMap&layers=si-x:average_leaf_ncep_states&format_options=layout:leafout_web&styles=si-x:leafout_bimonthly&time=2016-2-18&bbox=-125.020833333333,24.0625,-66.479166666662,49.937500000002&width=1400&height=600&srs=EPSG:4269&format=image/png

1

I had the same problem recently and by studying the source code of recent GeoServer (2.10) I found out the solution.

You can include a time-like env parameter in your request and then use it in your layout.

E.g.:

http://myserver/geoserver/si-x/wms?service=WMS&request=GetMap&layers=si-x:average_leaf_ncep_states&format_options=layout:leafout_web&styles=si-x:leafout_bimonthly&time=2016-2-18&bbox=-125.020833333333,24.0625,-66.479166666662,49.937500000002&width=1400&height=600&srs=EPSG:4269&format=image/png&env=the_time:2016-2-18

<layout>
  <decoration type="text" affinity="bottom,left" offset="16,6">
    <option name="message" value="Leaf Out Date: ${the_time}"/>
    <option name="font-size" value="22"/>
    <option name="font-family" value="Arial"/>
    <option name="halo-radius" value="2"/>
  </decoration>
  <decoration type="legend" affinity="bottom,right" offset="6,-6" size="0,0"/>
</layout>

For some reason, you can't name the env parameter time (I suspect some conflict with standard WMS time parameter), that's why I use the_time.

The value is a FreeMarker string, so you can use fancy templating if you want to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.