Label Placement¶
LabelLayer places text labels using a
simulated-annealing algorithm with overlap avoidance via
shapely.STRtree. The text column is passed as column; the
remaining keyword arguments map directly to
LabelConfig.
from mappyng import Map, BasemapLayer, LabelLayer
m = Map(gdf, width=800, height="auto")
m.add(BasemapLayer())
m.add(LabelLayer(
gdf_villes,
column="nom",
priority_col="population",
max_labels=25,
font_size=9,
font_weight="bold",
halo_color="#ffffff",
halo_width=2.0,
leader_lines=True,
avoid_overlap=True,
n_sweeps=80,
seed=42,
))
# Numbered circles mode (for dense datasets)
m.add(LabelLayer(
gdf_villes,
column="nom",
numbered_above=15,
numbered_legend_position={"x": 0.75, "y": 0.1},
priority_col="population",
))
Appearance¶
Parameter |
Default |
Description |
|---|---|---|
|
10.0 |
Label font size in SVG px. |
|
|
Label font family. |
|
|
Label font weight. |
|
|
Label text color. |
|
|
Text halo color. Set to |
|
2.0 |
Halo stroke width in SVG px. |
Filtering¶
Parameter |
Default |
Description |
|---|---|---|
|
|
Column used for rank ordering (higher value = placed first). |
|
|
Rows below this value are skipped. |
|
|
Hard cap on the number of labels placed. |
Placement¶
Parameter |
Default |
Description |
|---|---|---|
|
|
Starting candidate direction. One of |
|
all 8 |
List of candidate directions tried by the annealing. |
|
4.0 |
Distance from anchor point to label edge (SVG px). |
|
40.0 |
Maximum total displacement before a label is hidden (SVG px). |
|
|
Enable label-label overlap energy. |
|
|
Allow labels to be hidden when placement fails. |
|
|
Wrap long labels at dashes (French typographic convention). |
|
12 |
Characters per line before wrapping. |
|
|
Viewport: |
Leader lines¶
Parameter |
Default |
Description |
|---|---|---|
|
|
Draw leader lines when label is displaced. |
|
1.5 |
Minimum displacement (× label height) that triggers a leader line. |
|
|
Leader line color. |
|
0.5 |
Leader line stroke width (SVG px). |
Numbered-circles mode¶
When the number of features exceeds numbered_above, labels are replaced
by numbered circles on the map and a legend box listing the names.
Parameter |
Default |
Description |
|---|---|---|
|
|
Switch to numbered mode when label count exceeds this value. |
|
|
Legend position |
|
5.0 |
Circle radius in SVG px. |
|
|
Circle fill color. |
|
|
Circle stroke color. |
|
|
Legend box background color. |
|
0.88 |
Legend box background opacity. |
|
|
Legend box border color. |
|
|
Legend box title text. |
Simulated annealing¶
Parameter |
Default |
Description |
|---|---|---|
|
50 |
Number of annealing sweeps (more = better quality, slower). |
|
1.0 |
Starting annealing temperature. |
|
0.01 |
Ending annealing temperature. |
|
42 |
Random seed. Set to |
Energy weights (advanced)¶
These control the relative importance of each penalty term. Increase a weight to make the placer prioritize avoiding that conflict.
Parameter |
Default |
Description |
|---|---|---|
|
30.0 |
Label-label overlap energy. |
|
25.0 |
Label-obstacle overlap energy (proportional symbols, markers). |
|
100.0 |
Label-chrome overlap energy (title, scale bar, source). |
|
30.0 |
Label-anchor overlap energy. |
|
1.0 |
Distance from anchor penalty. |
|
3.0 |
Orientation bias (prefer NE over other positions). |
|
1000.0 |
Out-of-bounds penalty. |