1

When creating labels using centroids of a polygon layer, I'm facing the problem that some of them are missing. Eg:

Missing labels

Ok, I can make it reappear by using "maxDisplacement" vendor option, but, using this option labels appear displaced. Some to the right, some to the left.

Displaced labels

How can I render all the labels propperly in the centroid of the polygons?

Here is the SLD code I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<sld:UserStyle 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">
  <sld:Title/>
  <FeatureTypeStyle>
     <Rule>
       <PolygonSymbolizer>
         <Fill>
           <CssParameter name="fill">#40FF40</CssParameter>
         </Fill>
         <Stroke>
           <CssParameter name="stroke">#FFFFFF</CssParameter>
           <CssParameter name="stroke-width">2</CssParameter>
         </Stroke>
       </PolygonSymbolizer>
       <TextSymbolizer>
        <sld:Geometry>
          <ogc:Function name="centroid">
            <ogc:PropertyName>geom</ogc:PropertyName>
          </ogc:Function>
        </sld:Geometry>
         <Label>
           <ogc:PropertyName>cod_25000</ogc:PropertyName>
         </Label>
         <Font>
           <CssParameter name="font-family">Arial</CssParameter>
           <CssParameter name="font-size">11</CssParameter>
           <CssParameter name="font-style">normal</CssParameter>
           <CssParameter name="font-weight">bold</CssParameter>
         </Font>
         <LabelPlacement>
           <PointPlacement>
             <AnchorPoint>
               <AnchorPointX>0.5</AnchorPointX>
               <AnchorPointY>0.5</AnchorPointY>
             </AnchorPoint>
           </PointPlacement>
         </LabelPlacement>
         <Fill>
           <CssParameter name="fill">#000000</CssParameter>
         </Fill>
         <VendorOption name="autoWrap">100</VendorOption>
         <VendorOption name="maxDisplacement">50</VendorOption>
         <VendorOption name="repeat">1</VendorOption>
       </TextSymbolizer>
     </Rule>
   </FeatureTypeStyle>
</sld:UserStyle>
  • 2
    turn off tiling for your labels layer. – Ian Turton May 25 '15 at 13:16
  • Thanks iant! I've changed in openlayers the TileWMS layer to ImageWMS and now displays correcly. This layer is not complex and renders fast, but in case I have a complex layer and I need tiling to improve performance, wich should be the proper way to display the labels? Maybe creating a point layer using polygon centroids? (Maybe I should edit my question...) – cag May 27 '15 at 7:29

Your Answer

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

Browse other questions tagged or ask your own question.