Robert Smith
Robert Smith

Reputation: 779

Set sld font based on map scale - geoserver/sld

I am using GeoServer environment. I am trying to setup font size using sld based on scale. So far I have the following:

<CssParameter name="font-size">
  <ogc:Mult>
    <ogc:Function name="env">
      <ogc:Literal>wms_scale_denominator</ogc:Literal>
    </ogc:Function>
    <ogc:Literal>.001</ogc:Literal>
  </ogc:Mult>
</CssParameter>

But am getting a log error in GeoServer : "Null font size specified". Why is the multiplication function not working to set a font size?

Update: No need to use the multiplication function to set font size based on scale. Use instead the Categorize function as seen in below example.

Upvotes: 1

Views: 1880

Answers (1)

Robert Smith
Robert Smith

Reputation: 779

Dont ask me how this worked but it works perfect!

<CssParameter name="font-size">
  <ogc:Function name="Categorize">
    <!-- Value to transform -->
    <ogc:Function name="env">
      <ogc:Literal>wms_scale_denominator</ogc:Literal>
    </ogc:Function>
    <!-- Output values and thresholds -->
    <!-- Font Size Range [<= 5000]=14, [5000-10000]=10, and [>10000]=6 -->
    <ogc:Literal>14</ogc:Literal>
    <ogc:Literal>5000</ogc:Literal>
    <ogc:Literal>10</ogc:Literal>
    <ogc:Literal>10000</ogc:Literal>
    <ogc:Literal>6</ogc:Literal>
  </ogc:Function>
</CssParameter>

Note: Adjust the font size/range based on your scale denominators.

Upvotes: 3

Related Questions