Customize label text for a single label

7 mins remaining
Customize label text for a single label
Beginner
codeNo code

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.

The final product will show adjusted country label tags as seen below:

Getting started

There are 2 resources you will need to follow along with this guide:

  • Mapbox account - Sign up for a free account on Mapbox.
  • How to Video - The following video instructions to follow with for this tutorial:

Create a new style

Let's create a new style in Mapbox Studio. A style is a set of rules for how Mapbox will draw your map and its data on the page.

  1. Log into your Mapbox account and navigate to your Styles page, where all your styles are listed.
  2. Click the New style button.
  • The style editor will automatically open with the Basic template style ready for editing.
Learn more about styles

A style 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.

Adjust Place labels component

The Mapbox Studio style editor is a visual tool for creating custom map styles, for example adjusting place label components.

For this tutorial, we'll adjust the country labels, so let's start by focusing your style on the country layer of labels:

  1. Click the blue Plus button under the Layers tab.
  2. In the menu that appears, click Components > Place labels.
  3. Toggle off the Continents, States/Provinces, Settlements, and Settlement subdivisions properties.

Now with these adjustments, you should only see country labels on the globe.

Use expressions to edit specific labels within a layer

You can customize the country labels based on conditions and properties within the data by doing the following:

  1. Click on the country-label layer to see all the options available to style this layer.
  2. Select Style with data conditions and choose name_en to style the label based on the English name for the country.
  3. In the new panel that appears, type in France and click + use France at the bottom of the prompt
    • This is the country label you will be customizing.
  4. Next in the Text field, before coalesce, add "Land in: " and click on & to combine your two strings.

Now you will see the France label change to Land in: France on your map.

Adding additional data conditions

  1. To edit another data condition, click Done in the bottom right hand corner of the panel and then Add another condition.
  2. 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.
  3. 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.

Next steps

To learn more about using the Mapbox Studio style editor, read the Mapbox Studio Manual.

Was this tutorial helpful?