0

My colorramp legend's title gets set to be the layer's name. I'm wondering if I can override this and set the title explicitly. For example let's say I want to change the colorramp's title from "Spring Index, Daily Anomaly - Leaf Anomaly" to just "Leaf Anomaly".

Currently This is the WMS result I'm getting:

enter image description here

As you can see it's getting "Spring Index, Daily Anomaly - Leaf Anomaly" from the layer title:

enter image description here

Here is my layout:

<layout>
  <decoration type="text" affinity="bottom,left" offset="26,20">
    <option name="message" value="Difference from average in the timing of the Start of Spring, as estimated through an index of early-leafing plants"/>
    <option name="font-size" value="15"/>
    <option name="font-bold" value="true"/>
    <option name="font-family" value="Arial"/>
    <option name="halo-radius" value="4"/>
  </decoration>
  <decoration type="text" affinity="bottom,left" offset="26,0">
    <option name="message" value="Results Provisional  (www.usanpn.org/data/spring)"/>
    <option name="font-size" value="15"/>
    <option name="font-italic" value="true"/>
    <option name="font-family" value="Arial"/>
    <option name="halo-radius" value="4"/>
  </decoration>
  <decoration type="legend" affinity="bottom,right" offset="4,-55" size="auto"/>
</layout>

Here is my colorramp sld:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  <NamedLayer>
    <Name>days</Name>
    <UserStyle>
      <Name>days</Name>
      <Title>Days Difference</Title>
      <FeatureTypeStyle>
        <Rule>
          <RasterSymbolizer>
            <Opacity>1.0</Opacity>
            <ColorMap>         
              <ColorMapEntry color="#FFFFFF" quantity="-9999" label="Day Difference" opacity="0.0"/>
              <ColorMapEntry color="#67001f" quantity="-20"   label="20 Days Early"/>
              <ColorMapEntry color="#b2182b" quantity="-8"    label="8 Days Early"/>
              <ColorMapEntry color="#d6604d" quantity="-6"    label="6 Days Early"/>
              <ColorMapEntry color="#f4a582" quantity="-4"    label="4 Days Early"/>
              <ColorMapEntry color="#fddbc7" quantity="-2"    label="2 Days Early"/>
              <ColorMapEntry color="#f7f7f7" quantity="0"     label="No Difference"/>
              <ColorMapEntry color="#d1e5f0" quantity="2"     label="2 Days Later"/>
              <ColorMapEntry color="#92c5de" quantity="4"     label="4 Days Late"/>
              <ColorMapEntry color="#4393c3" quantity="6"     label="6 Days Late"/>
              <ColorMapEntry color="#2166ac" quantity="8"     label="8 Days Late"/>
              <ColorMapEntry color="#053061" quantity="20"    label="20 Days Later"/>
            </ColorMap>
          </RasterSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>
2

I just found the answer by digging into the LegendDecoration source found here: https://fossies.org/dox/geoserver-2.8.2/LegendDecoration_8java_source.html

The solution is to set the sldTitle option to "true" like so:

<decoration type="legend" affinity="bottom,right" offset="4,-55" size="auto">
    <option name="sldTitle" value="true"/>
  </decoration>

Then the title will come from the title attribute in your style sld (in my case it changed the title to "Days Difference" as per the below sld:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  <NamedLayer>
    <Name>days</Name>
    <UserStyle>
      <Name>days</Name>
      <Title>Days Difference</Title>

If sldTitle is not set, Geoserver pulls the title from the layer title.

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.