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">
           <CssParameter name="fill">#40FF40</CssParameter>
           <CssParameter name="stroke">#FFFFFF</CssParameter>
           <CssParameter name="stroke-width">2</CssParameter>
          <ogc:Function name="centroid">
           <CssParameter name="font-family">Arial</CssParameter>
           <CssParameter name="font-size">11</CssParameter>
           <CssParameter name="font-style">normal</CssParameter>
           <CssParameter name="font-weight">bold</CssParameter>
           <CssParameter name="fill">#000000</CssParameter>
         <VendorOption name="autoWrap">100</VendorOption>
         <VendorOption name="maxDisplacement">50</VendorOption>
         <VendorOption name="repeat">1</VendorOption>
  • 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.