<< Back

Allow users to show and hide map layers in Tableau

With the new addition of map layers in Tableau 2020.4, there’s an exciting level of control over maps that viz designers can exercise. The easy-to-use map layers cards almost feel like designing in GIS or Google Earth. However, there’s no native way to give your end-user the same level of control over what show and what to hide. Luckily, there’s an easy way to do empower them using Boolean parameters. Let’s walk through it using the Superstore dataset!

1. Create your parameter

Create a Boolean parameter “Show/hide cities”. For the “True” alias, enter the words “Show cities”, for the “False” alias, use “Hide cities”.

Gif showing how to create parameter

2. Create a field to control your city field using the parameter

In a new calculated field, [City switcher], create a conditional statement. When the value of [Show/hide cities] is true, then provide the [City] field.

//City switcher

If [Show/hide cities] then [City] END

You do not need to include an ELSE clause because Tableau will default the false value to NULL.

After creating the new field, change its data type to Geographic>City.

3. Build your map

Double click on your [City switcher] field to create a map of all the cities. On the marks card, change the mark colour to black. Drag [State] on to the map where you can see the box “Add a map layer” appears. Then change the mark type for state to “Map” to see the filled region for each state. Finally, make sure that your layer for [City switcher] is above that of [State] by checking to see if it is listed on top in your marks card.

Gif showing process of creating map

4. Show your parameter and test it

Right-click on your [Show/hide cities] parameter in your data pane and choose “Show parameter”. This will bring up a dropdown card on the right side of your map with the options “Show cities” and “Hide cities”. Change the dropdown selection to test if your parameter is working. Selecting “Hide cities” should remove all the city marks from the view.

Gif showing how to show parameter.

5. Add your map to a dashboard

Create a new dashboard and add your map sheet to it. The map and the parameter control for [Show/hide cities] should both appear. If not, click the more options dropdown in the corner of your map and add the parameter from the list. Voila! You’ve now given your end user control over showing the map layer. This method can be repeated for the state field and any number of other geographic fields you’d like to add. The trick is to take whichever field is on the “Detail” shelf for the layer and replace it with a parameterized version. You will want to create a separate parameter for each field you’d like to show or hide independently.

Leave a Reply

Your email address will not be published. Required fields are marked *