0

for several hours Im trying to create a multiline label for a line. I use Geoserver 2.5, the line is in postGIS, the style is very simple :

<?xml version="1.0" encoding="UTF-8"?> <sld:StyledLayerDescriptor 

xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">   <sld:NamedLayer>
        <sld:Name>Borders_1fe760e8</sld:Name>
        <sld:UserStyle>
          <sld:Name>Borders_1fe760e8</sld:Name>
          <sld:Title>Borders</sld:Title>
          <sld:IsDefault>1</sld:IsDefault>
          <sld:FeatureTypeStyle>
            <sld:Name>name</sld:Name>
            <sld:Rule>
              <sld:Name>rule1</sld:Name>
              <sld:Title>Title 1</sld:Title>
              <sld:Abstract>-</sld:Abstract>
              <sld:LineSymbolizer>
                <sld:Stroke>
                  <sld:CssParameter name="stroke">#FF0000</sld:CssParameter>
                  <sld:CssParameter name="stroke-width">2</sld:CssParameter>
                </sld:Stroke>
              </sld:LineSymbolizer>
              <sld:TextSymbolizer>
                <Label>
                  <ogc:PropertyName>Name_1</ogc:PropertyName><![CDATA[
]]><ogc:PropertyName>Name_2</ogc:PropertyName>
                </Label>
                <sld:Font>
                  <sld:CssParameter name="font-family">Tahoma</sld:CssParameter>
                  <sld:CssParameter name="font-size">16</sld:CssParameter>
                  <sld:CssParameter name="font-style">normal</sld:CssParameter>
                  <sld:CssParameter name="font-weight">normal</sld:CssParameter>
                </sld:Font>
                <sld:LabelPlacement>
                  <sld:PointPlacement>
                    <sld:AnchorPoint>
                      <sld:AnchorPointX>0.0</sld:AnchorPointX>
                      <sld:AnchorPointY>0.5</sld:AnchorPointY>
                    </sld:AnchorPoint>
                    </sld:PointPlacement>
                </sld:LabelPlacement>
                <sld:Fill>
                  <sld:CssParameter name="fill">#FF0000</sld:CssParameter>
                </sld:Fill>
                <sld:VendorOption name="followLine">true</sld:VendorOption>
              </sld:TextSymbolizer>
            </sld:Rule>
          </sld:FeatureTypeStyle>
        </sld:UserStyle>   </sld:NamedLayer> </sld:StyledLayerDescriptor>

yet I am unable to see the lables 1 and 2 on two lines - they always end up on the same line. I tried :

  • SLD - CDATA with line break (as seen above)
  • SLD - CDATA with <BR> tag
  • SLD - use only one field, POSTGIS field value with \n (value1\nvalue2)
  • SLD - use only one field, POSTGIS field value with <br> tag (value1<br>value2)

and many other permutations of above, i copy-pasted the code, typed it, used geoserver style editor, typed it manually into xml file directly on the server, but I wasnt able to produce two line label. I did try all the tricks I was able to find via google.

What am I doing wrong ? Or is it some known Geoserver bug ?

  • I have an SLD that works fine for me on geoserver 2.5 – MickyInTheSky May 5 '14 at 10:36
  • Can you please share ? or is it same as I already tried ? – Radek May 5 '14 at 10:39
2

Here some snippets of my SLD on geoserver 2.5:

<?xml version="1.0" encoding="ISO-8859-1"?>

--header

<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
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">

--Rule

<Rule>
      <Name>Rule 1</Name>
      <Title>title</Title>
      <Abstract>theme</Abstract>
      <MaxScaleDenominator>120000</MaxScaleDenominator>
      <TextSymbolizer>
        <Label>
          <ogc:PropertyName>nome_1</ogc:PropertyName><![CDATA[
       ]]> (<ogc:PropertyName>nome_2</ogc:PropertyName>)
        </Label>
        <Font>
          <CssParameter name="font-family">Arial</CssParameter>
          <CssParameter name="font-weight">bold</CssParameter>
          <CssParameter name="font-size">10</CssParameter>
        </Font>

--vendor options

        <VendorOption name="conflictResolution">false</VendorOption>
        <VendorOption name="maxDisplacement">20</VendorOption>
      </TextSymbolizer>
1

Here is answer to my question

http://ehc.ac/p/geoserver/mailman/message/31520843/

it is NOT POSSIBLE to do multiline label with <sld:VendorOption name="followLine">true</sld:VendorOption> :( Disabling this option and using sld:LabelPlacement makes it work, but the label is not following the line.

1

I solved this with some CDATA and a zero-width space, like this;

            <se:Label>
                <ogc:PropertyName>region_name</ogc:PropertyName>
                <ogc:Literal></ogc:Literal>
                <![CDATA[​
]]>
                <ogc:PropertyName>population_change_count</ogc:PropertyName>
            </se:Label>

What you can't see above is the zero-width space character immediately after the CDATA[. Search 'copy zero width space to clipboard' to help you.

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.