Mapnik 3.1.0 Release Jan 08, 2021 | Artem Pavlenko
Mapnik 3.0.24 Release Jan 05, 2021 | Artem Pavlenko
Mapnik 3.0.23 Release Jan 18, 2020 | Artem Pavlenko
Mapnik 3.0.22 Release Jan 22, 2019 | Artem Pavlenko
Mapnik 3.0.21 Release Oct 08, 2018 | Artem Pavlenko
Mapnik 3.0.20 Release Apr 12, 2018 | Artem Pavlenko
Mapnik 3.0.19 Release Mar 06, 2018 | Artem Pavlenko
Mapnik 3.0.18 Release Jan 26, 2018 | Artem Pavlenko
Mapnik 3.0.16 Release Nov 16, 2017 | Artem Pavlenko
Mapnik 3.0.12 Release Sep 08, 2016 | Artem Pavlenko
Mapnik 3.0.10 Release Feb 29, 2016 | Artem Pavlenko
Node Mapnik 3.5.0 Release Feb 29, 2016 | Sam Matthews

latest news

New text placement system

Jul 13, 2011

BY:   Herman Kraus

The first part of my Google Summer of Code project is completed now.

As a result one can choose arbitrary alternative placements for TextSymbolizers if the default placement fails. However this is no longer limited to placements, but one can also change text, font size, color, etc. Everything is fully configurable now.

When two labels are too close to each other normally one label is placed and the other one is simply ignored. This can lead to undesirable results. Look at the following sample image:


With the new placement system one can tell Mapnik to try different placement options. In this example I defined the following parameters:

  • First try to place the label below the number with font size 16 (color: blue)
  • Then try to place it above with font size 10 (color: red)
  • Last try to use a shortened label text (color: green)

The syntax to configure this is pretty easy:

<TextSymbolizer name="'Long'+[nr]"  face-name="DejaVu Sans Book" size="16"  placement="point" dy="8" fill="blue" />


<TextSymbolizer name="'Long'+[nr]"   face-name="DejaVu Sans Book" size="16"   placement="point" dy="8" fill="blue"   placement-type="list">    <Placement size="10" dy="-8" fill="red"/>    <Placement name="'S'+[nr]" fill="green"/></TextSymbolizer>

One can add as many placement options as one wants. Each attribute has the same name as in TextSymbolizer (in fact they share the parser). Each placement inherits all attributes from the previous one. Therefore it is not required to add 'size="10"' in the second Placement tag.

The code is not already included in trunk, but is available in the branch

In the second half of summer of code I will add text formating capabilities to mapnik as described in an older post.

Copyright © 2018 Artem Pavlenko | Downloads | License | Media