5

Does GeoServer have a way to display polygon's labels, in a centralized way and moving it to the center of displayed polygon at that "screen moment", dynamically?

I'm trying to make labels visible, always in the polygon's centralized position, independent of the zoom level and the screen position related to the polygon's itself:

Image 1.Image 2

Here's the code:

   <TextSymbolizer>
      <Geometry>
        <ogc:Function name="centroid">
        <ogc:PropertyName>the_geom</ogc:PropertyName>
        </ogc:Function>
      </Geometry>
     <Label>
       <ogc:PropertyName>Nome_V2</ogc:PropertyName>
     </Label>
     <Halo>
       <Radius>1.5</Radius>
       <Fill>
         <CssParameter name="fill">#ffffff</CssParameter>
       </Fill>
     </Halo>
     <Font>
       <CssParameter name="font-family">Arial</CssParameter>
       <CssParameter name="font-size">10</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">60</VendorOption>
     <VendorOption name="maxDisplacement">150</VendorOption>
   </TextSymbolizer>

2 Answers 2

5

You just need to remove this bit forcing the label in the centroid:

<Geometry>
  <ogc:Function name="centroid">
    <ogc:PropertyName>the_geom</ogc:PropertyName>
  </ogc:Function>
</Geometry>
7
  • though then you will get duplicated labels if you are using tiles
    – Ian Turton
    Dec 19, 2017 at 11:13
  • And if you use metatiles during seeding then the label may stay in place while panning because the labeled tile and it's neighbors are already in the cache.
    – user30184
    Dec 19, 2017 at 11:25
  • I've done it, Andrea, but as Ian said, the labels get duplicated. Can you guys be more specific were I can activate metatilling? Thanks. Dec 19, 2017 at 11:36
  • 1
    Sorry, I assumed from the above it was an un-tiled request. The only other option I can think of is to tile only the geometry rendering, and make a separate un-tiled layer for labels, computed on the fly on the current map position every time. If that is not acceptable, you'll have to choose between repeated labels or labels not centered in the view. Dec 19, 2017 at 12:08
  • And do not forget to consider using single-tile mode.
    – user30184
    Dec 19, 2017 at 15:03
3

If you want to use tiling but have labels dynamically centered, you can:

  • setup a layer with only geometry rendering (no labels), request it as tiled
  • make a separate layer for labels, which contains only the text symbolizer, and request it from the client as un-tiled

This will provide most of the benefits of tiling, but allow to get dynamically centered labels every time the user moves them map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.