Optimize map label placement
Map labels are applied to Mapbox GL maps as features in symbol layers. Symbol layers are the most complex layer type in the Mapbox Style Specification. The symbol layer type offers detailed typographic styling options for your labels and map data.
This guide will walk through a subset of layout properties that are relevant to label placement. You can see the complete list of layout and paint properties for symbol layers, including those responsible for label language, style, and more, in the Mapbox Style Specification.
Label collision
Collision detection is the process of preventing labels on a map from overlapping each other. Styles use four properties to prevent label collision:
- By default
icon-allow-overlapandtext-allow-overlapare set tofalse. If set totrue, the icon or text will be visible even if it collides with other symbols drawn before. - By default
icon-ignore-placementandtext-ignore-placementare set tofalse. If set totrue, other symbols can be visible even if they collide with the text or icon.
For reliable collision detection across layers that come from different data sources, use source compositing. Source compositing happens by default for new styles created in Mapbox Studio. If you are adding sources on the client, they will not be composited.
While detecting and preventing label collision helps improve map legibility, it can result in many hidden labels. Use collision detection and variable label placement to keep labels legible while increasing the density of labels displayed on the map.
Label density
Variable label placement is a map design concept in which more than one placement option is attempted for each label. This maximizes the chances that the map will show each label. Variable label placement is powered by three layout properties in the Mapbox Style Specification: text-variable-anchor, text-radial-offset, and text-justify.
The diagram below illustrates each possible position relative to the data point:
bottom-rightrightbottomcenterbottom-leftleftrightrightcentercenterleftlefttop-rightrighttopcentertop-leftleft