0

I wish to change label position of polygon in Geoserver layer (custom local osm map), like that: enter image description here

but I don't understand how. label-anchor: was ignored. my style:

    * {
  font-family: "DejaVu Sans";
  font-size: 8px;
  halo-color: #ffffff;
  halo-radius: 0.4;
  font-weight: normal;
  font-fill: #414142;
  font-style: normal; 
}

[@scale < 35000] [@scale > 5000] {
  fill: #ded3be;
  stroke:#C4BBA9;
  stroke-width: 0.5;
  fill-opacity: 0.4, 1;
  geometry: [offset(way, 0.5, -0.5)], [way];
}

[@scale < 5001] [@scale > 2500] {
  fill: #ded3be;
  fill-opacity: 0.4, 1;
  geometry: [offset(way, 0.4, -0.4)], [way];
  stroke: #C4BBA9;
  stroke-width: 0.5;
  font-size: 12;
  font-fill: #414142;
  font-weight: 600;
  label: ["housenumber"];
  label-anchor:  1.0 0.5;
}

[@scale < 2501] {
  fill: #ded3be;
  fill-opacity: 0.4, 1;
  stroke: #C4BBA9;
  stroke-width: 0.5;
  font-size: 12;
  font-fill:#414142;
  label: ["housenumber"];
  label-anchor: 0.5 0.0;
  font-weight: 600;
 }

how to move label to the new label position?

1 Answer 1

2

The anchor just controls the relative position of the label bbox and the label point, e.g., the label point is typically the centroid of the polygon (when it's inside the polygon), setting it to 1 0.5 means it's at the right/middle of the label bbox. Think of it as a text alignment offering more options than just "right, center, left" and "bottom, middle, top" (and it always refers to the label point, not the entire polygon).

What you may want to use there is label-offset, expressed in pixels, e.g., label-offset: 0 -20. Mind though, there is no way to ensure the resulting position will still be inside the polygon.

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.