4

Is it possible to render a background color for text labels in geoserver? My current style is this:

  <TextSymbolizer>
    <Label>
      <ogc:PropertyName>fahrznr</ogc:PropertyName>
    </Label>
    <Font>
      <CssParameter name="font-family">Arial</CssParameter>
      <CssParameter name="font-style">Normal</CssParameter>
      <CssParameter name="font-size">12</CssParameter>
    </Font>
    <LabelPlacement>
      <PointPlacement>
        <AnchorPoint>
          <AnchorPointX>0.5</AnchorPointX>
          <AnchorPointY>-1</AnchorPointY>
        </AnchorPoint>
      </PointPlacement>
    </LabelPlacement>
  </TextSymbolizer>

Which produces the following text (with transparent background): enter image description here

But what I want is the following (with green background): enter image description here

Is this somehow possible with geoserver style? I tried

<CssParameter name="fill">#00FF00</CssParameter>
<CssParameter name="fill-opacity">0.7</CssParameter>

And

<CssParameter name="background">#00FF00</CssParameter>

Both do not work.

2

In GeoServer's SLD you can specify a graphic element for your label. You will also want to set graphic-resize and graphic-margin elements to control how the graphic fits your label.

So your SLD will become something like:

 <TextSymbolizer>
    <Label>
      <ogc:PropertyName>fahrznr</ogc:PropertyName>
    </Label>
    <Font>
      <CssParameter name="font-family">Arial</CssParameter>
      <CssParameter name="font-style">Normal</CssParameter>
      <CssParameter name="font-size">12</CssParameter>
    </Font>
    <LabelPlacement>
      <PointPlacement>
        <AnchorPoint>
          <AnchorPointX>0.5</AnchorPointX>
          <AnchorPointY>-1</AnchorPointY>
        </AnchorPoint>
      </PointPlacement>
    </LabelPlacement>
    <Graphic>
       <Mark>
         <WellKnownName>Square</WellKnownName>
         <Fill>
            <CssParameter name="fill">#00FF00</CssParameter>
            <CssParameter name="fill-opacity">0.7</CssParameter>
         </Fill>
         <Size>10</Size>
       </Mark>

    </Graphic>
    <VendorOption name="graphic-resize">stretch</VendorOption>
    <VendorOption name="graphic-margin">2</VendorOption>
  </TextSymbolizer>

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.