Layer Toggle Control

Allow users to turn off and on different vector or raster layers on your map.

This feature adds an area for users to turn off and on different layers on your map, as defined in your Mapbox Studio Style or in your Custom Style JSON. This is available only with Maplibre or Mapbox maps. See an example here.

To use this, go to Controls and look for the Layer Control. In the left-hand side text area, you can enter layers on each line that you want to turn off and on when the user toggles them. You can add multiple layers to each line by separating them using commas, such as

country-label, admin-0-boundary

Make sure these layers correspond correctly to the layer names you've given in Mapbox Studio -- otherwise your map will have an error!

On the right hand side, add the text that you want to show for each of the toggles.

Finally, you can choose the Checkbox Type, which can be switches, checkboxes, or radio buttons. Radio buttons mean that only a single set of layers can be shown at once. If you select this, make sure that only one of your layers is visible on the map load, otherwise the control may turn layers off by accident.

Last updated