メインコンテンツまでスキップ

Apply conditional labels

  • This is a modified version of the Streets template style.

  • The data used in this example comes from the mapbox-streets-v8 tileset.

  • The airport-label layer, a symbol layer, has been modified using an Override.

  • Airport labels are styled using property expressions to style features with a data condition. Labels will include both the full name and the short code if the short code is available.

About this style

  • Label data: The data for airport labels comes from the mapbox-streets-v8 tileset. The ref field contains short identifier codes for many airports, but not all airports. Read more about Mapbox Streets in the vector tile documentation.
  • Override: In the Streets template style, the text-field for the airport-label layer is controlled by a component. To make these changes, switch to Layers tab, find the airport-label layer, and use the Override button to customize the style of the text-field for this layer.
  • Styling with expressions: In this example, the airport labels are styled using property expressions to style features using a data condition. Open the airport-label layer to see how to check whether a data property exists (in this case the ref property). If the property does exist, the label displays the full name (name) along with the ref. If the ref property does not exist, the label displays the name value. Read more about styling with data conditions in the Mapbox Style Specification.

Looking for more guidance? Read our tutorials.

このexampleは役に立ちましたか?