Customize label text for a single label
This tutorial will walk you through how to use expressions in the Mapbox Studio style editor to customize the label text for a single label.
Getting started
Before getting started, you will need to create a Mapbox account to use the Mapbox Studio style editor. You can create an account at mapbox.com/account.
Create a new style
Log into your Mapbox account and navigate to your Styles page. This is where all your styles are listed. A style is a set of rules for how Mapbox will draw your map on the page. It defines how all your data should be styled and includes references to your data and map images (icons, markers, patterns), fonts. For more about styles, see the Styles section of the Mapbox Studio Manual.
Go to your Styles page. Click the New style button. Find the Basic Template style and click Customize Basic. The style editor will automatically open with the Basic template style ready for editing.
Use the style editor
The Mapbox Studio style editor is a visual tool for creating custom map styles to your exact specifications. Take a look at the layers on the left side of the style editor screen. Each layer can be customized in a variety of ways including (but not limited to) changing labels.
Adjust Place labels component
In the Components tab, click on Place labels. This will open a component property panel that lists all the available properties for this component. Since you'll be focused on customizing country labels, start by hiding other place labels:
- Toggle the States property off.
- Toggle the Settlements property off.
- Toggle the Settlement subdivisions property off.
Set a manual override
If a layer property is controlled by a component, a
lock icon will appear next to the value. You can override any layer property controlled by a component by clicking the Override button.- Switch to the Layers tab.
- Click on the country-label layer.
- Click on the Text field property.
- Click Override to unlock all style options available for the Text field property.
Use expressions to edit specific labels within a layer
Click on the country-label layer to see all the options available to style this layer. To customize the country labels based on conditions and properties within the data, select Style with data conditions and choose name_en
to style the label based on the English name for the country.
In the new panel, you are prompted to fill in the details of your data condition. In the first text field, enter France
since this is the label you will be customizing. In the Text field
, add "Land in: "
and click on & to combine your two strings. As you do this, you will see the France
label change to Land in: France
on your map.
To edit another data condition, click Done in the bottom right hand corner and then Add another condition. This time, continue the travel journey by choosing the first stop on the trip. In the first text field, enter Spain
and then "First stop: "
in the Text field
box.
Repeat the previous step to continue to add more data conditions and stops on the trip. Once you are finished your map will look something like the one below.
Final product
You've updated your map using expressions to display custom labels for specific labels. To learn more about using the Mapbox Studio style editor, read the Mapbox Studio Manual.