This sample demonstrates how to paint decluttered labels for points, polylines and polygons. The sample uses three layers with vector data from the US. Each of these layers uses a separate painter that defines the specific styling that should be applied to the vector data.
To paint labels, every painter overrides the
FeaturePainter.paintLabel()
method and uses the
LabelCanvas
to paint labels. Depending on the properties of a feature, different styling for both the label and its shape is
applied.
The state labels are repositioned whenever a previous label location becomes invisible in the current view. You
can deactivate this behavior for in-path labeling by using
InPathLabelStyle
with the
inView
property set to false. In this case, the labels are placed in the center of the shape. They are not redrawn if a
label threatens to go off-screen. Additionally labels for the River layer are repeated along polyline geometries
using
OnPathLabelStyle
.
In addition, the state labels are drawn with the
InPathLabelStyle#restrictToBounds
style property. The flag indicates if the label should be painted outside of the bounds of its painted shape or
not.