New text placement system
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 svn.mapnik.org/branches/textplacement.
In the second half of summer of code I will add text formating capabilities to mapnik as described in an older post.Posted by Herman Kraus on 13 July 2011.