Creating Custom UIs with Map Layers

Tableau’s recent release, version 2020.4, included the new Map Layers functionality, which enables you to easily layer multiple sources of spatial data on the same map. You can read more about this functionality in this blog post.

The Map Layers feature also opened up some interesting alternative uses for plotting multiple mark layers on a ‘map’, with the background map itself not in view, such that latitude and longitude are being used to position marks in the view but not in a geographical sense. This post by Jeffrey Shaffer was the first example I saw of this and there’s been various other examples since (see the resources section at the end for more).

This kind of experimentation isn’t for everyone, but I find it to be a fun and interesting way to learn more about the new functionality, how it interoperates with existing functionality and what the limits and constraints are when using it.

During the 2019.2 beta, I had some fun experimenting with custom UIs in the form of popup customisable charts:

In a blog post about the 2019.2 release, I questioned if we were moving “from dashboards to apps”, or at least seeing the possibilities to do so with the new parameter actions and collapsible containers that were added in that impactful release.

Custom UI with map Layers

In this post I’ll explore some similar, ‘app-like’ functionality, this time using map layers. Not with the map removed, however. Instead, with charts layered on top of a map, in context, next to the selected mark with the aim of revealing insights with geographic context.

Disclaimers

Much of what follows wouldn’t be considered “best practice”. It’s experimental, a bit ‘hacky’ and arguably a lot of effort for the returns on offer. That said, it’s a fun and creative way to explore and learn more about this new feature. Furthermore, I think there may even be a few applicable use cases for these techniques.

From a design perspective, I also like the idea of being able to have a map take up the full canvas of a visualisation while still being able to see charts on demand, layered on top, instead of them being separated in a side panel as might normally be the case.

Pies Charts in Context

This first example looks at how pie charts can be shown or hidden next to a selected geographic point to show metrics for that geographic entity – in this case, sales by category and sales by ship mode for the selected US state:

The pie charts are created using a MAKEPOINT calculation with the latitude and longitude being calculated as offset from the latitude and longitude of the selected state. To toggle their visibility a boolean parameter is used – if TRUE, the point is created, if not, then NULL is returned and no point in created so no pie charts are shown.

Once the point in created, the mark type of pie is selected and sales (or whichever metric) for the selected state is added to the marks card along with a dimension to create the pie segments – the below example is for the sales by category pie chart:

It’s important to note that you can’t just use the sales measure as, because everything is in the same view, that would return sales for all states. Instead, when a state is selected, this updates a parameter – p.State – that is used in a calculation to return the sales for that selected state:

Repositioning the Charts

One issue is that the pie charts might overlap other parts of the map which you are interested in viewing. To resolve this, URL-triggered parameter actions can be used to allow the repositioning of the pie charts:

These work by updating a parameter (p.Pie Position), which in turn updates the calculations used to determine the latitude and longitude used in the respective MAKEPOINT calculations for each pie chart:

One drawback with non-geographic mark types (for this use case) is that they don’t scale with the map when you zoom in and out, so if the zoom level changes outside of a given tolerance, the pies will begin to overlap:

Viz in Tooltip Options

The next example explores ways of displaying different Viz in Tooltips for the selected geographic point. Here I’ve included three Viz in Tooltip options:

  • Sales over time
  • Profit over time
  • Quantity sold over time

Viz in Tooltips are shown when a reference to a worksheet is inserted in to a tooltip for a mark. Because Map Layers has no restriction on the number of layers, we can add three buffers to the map and then insert a different Viz in Tooltip sheet to each buffer’s tooltip. The user can then hover over the one they are interested in:

Again, the buffer positions are based off of the latitude and longitude of the selected state using different parameters for positioning and spacing.  A circle mark could also be used, however, the nice thing about buffers is that they scale with the map as you zoom so we don’t get the overlapping issue as we saw with the pie charts earlier (although the text labels don’t scale).

You could argue that the three charts could all be added to a single Viz in Tooltip on the original State mark, however, that can be quite cluttered and while I’ve only shown three here, further buffer marks could be added with more visuals (for example, for sales regions within the states, or dynamically showing only for underperforming products in that region etc.). Additionally the buffers could be coloured based on a RAG rating to highlight with visuals to look at.

Visual URL Links

Menu URL actions can be added to tooltips quite easily, however, you have little control over the UX other than the text used in the URL link in the tooltip. Again, using buffers, we can add select-triggered URL actions to each buffer and thereby change the look and feel of each link – either by changing the colour of the buffer or adding custom text or a symbol. They could also be positioned around the selected mark as needed.

In this simple example there are three URL links. The first two are static URLs (to Tableau and Salesforce), the third is dynamic and appends the name of the selected state to the URL to open a Wikipedia page for the selected state:

Again, this idea focusses purely on the UX as there is no added functionality over what can (more easily) be achieved with URL actions. So it really depends on your purpose and use case as to whether you would want to make the extra effort required to create such a UX.  For an external facing dashboard where the look and feel is particularly important from a marketing perspective, it might make sense. 

Top N Pie Charts

In this more developed example, I was looking at Facebook’s Social Connected Index (SCI) data that shows the probability of having a Facebook friend in different regions across Europe at the NUTS 3 geographic level. (There is also data available for regions across the world, but I focussed on Europe for simplicity). 

Clicking on any region will select it as the source. All other regions on the map will then change colour based on the likelihood of a person in the source location having Facebook friend in that region.

The home country of the user is filtered out as the probability of having a friend there is so much higher than in other countries that it becomes hard to distinguish the range of probabilities in regions outside of the home country. The focus then becomes where are there stronger international Facebook connections between regions within Europe, which was a more interesting story.

How to Read the Visualisation

The below help overlay image shows the instructions on how to read and use the visualisation.

(If you’re interested in learning how to create one of these help overlays, see my earlier blog post).

In the example below, a region of Poland is selected. Based on the map alone, we could say that it is more likely that a Facebook user in this region has a connection to someone in one of the following countries: the UK, the Netherlands, Germany, Croatia and possibly Bulgaria.

But in which country is the highest scoring region? Or the second highest? With the map alone, it’s hard to tell without hovering over all the darkest regions to see the SCI scores. This puts a burden on short term memory making more precise comparisons difficult.

The map is a great medium for giving a general indication of where connections are stronger but not precisely.

This is where having the option to show pie charts for the selected region is helpful. Clicking the blue circle (another buffer), we can show the top 3 countries, ranked 1 to 3, with each region within them as segments of the pie chart sorted from high to low based on their SCI scores:

We can now see that the United Kingdom is the country with the highest scoring region. Followed by Germany then the Netherlands.

Hovering over the segments of the pie charts, we can also easily see the next highest ranking regions in each of those countries: 

Select a Region from the Pie Charts

The user can then select a new region directly from the pie charts instead of clicking on the map. This has two benefits:

  • Some NUTS 3 regions are very small so would require zooming in to select and then zooming back out to see the results of their selection.
  • The user can easily select the highest (or second highest etc.) scoring region from the charts because ranking is shown with a sorted position (as well as colour) within the pie chart, which is easier to navigate compared to using colour alone, as is the case with the map.

Custom Control to Move the Charts

We have the same issue mentioned earlier that the pie charts could obscure parts of the map we want to see. Again, they can be moved, but instead of menu-triggered parameter actions as used previously, I’ve created a custom control with four buffers. Clicking one of the grey buffers will move the pie charts in the respective direction of where that buffer is placed (above, below, to the left or right). The controls themselves are also repositioned when the pie charts move:

This works using parameter actions. One ad-hoc text calculation (“Above”, “Below”, “Left” or “Right”) is placed on each of the buffers. A separate parameter action then passes the value of the buffer that is clicked on to a parameter.  That parameter is used in various calculations to position the charts and the buffers.

I could also have used shapes, such as arrows pointing in each direction but, as mentioned earlier, buffers maintain their size relative to the map as you zoom in and out, which results in a better user experience.

Toggle the Charts On or Off

Clicking the blue buffer in the middle of the directional controls toggles the pie charts on or off using the same logic as described earlier, using a boolean parameter to determine if the buffers and pie charts are created or not.  This blue toggle buffer always remains visible and is positioned next to the selected region.

Highlight the Selected Region

To make it clear which region has been selected, another map layer is used that just draws the selected NUTS 3 region, coloured blue, on top of the map layer that draws all the other regions:

This Selected NUTS3 calculation is given a Geographic Role of NUTS Europe. When it is then added as a map layer it takes the shape of that region.

Zoomed in Map of London

The NUTS 3 regions of London are quite small so require zooming in to select a region and then zooming back out to see the connections across Europe. To avoid this, I duplicated the main map, zoomed in on London and fixed the position (by removing the map controls).

This was then added to a collapsible container in the top right. With the London map shown, the user can now select different regions in London easily and see the connection probabilities across Europe update at the same time on the larger map, which vary a lot by the region selected:

Scaling Marks and Distances

Because marks are being drawn on a map using latitude and longitude, as we move further north there is some distortion due to the projection of the map onto a 2D plane. This results in buffers being drawn larger and vertically further apart the further north we go:

This is because Tableau is, correctly, drawing the buffer with a fixed radius in relation to the map underneath it. Notice that the pie charts are not resizing because their size is not fixed relative the map’s position or level of zoom.

To account for this is I made a simple factor calculation that limits this effect. It’s not perfect by any means, but does a good enough job for the purposes of this experimentation. Below are screenshots with a region in Finland at latitude 64.6 and below that a region in Italy at latitude 38.2. The buffers now show minimal distortion:

The factor calculation used is: 30 / [p.Lat] where p.Lat is the latitude of the selected region.

Ranking Using Sets

Because the pie charts are being created in the same view as the map, it’s not possible to filter to the one country required. Therefore, to add only the relevant country and its respective regions, I used sets to first isolate the top 2, top 3 and top 4 countries based on the maximum SCI scoring regions in each country. For example:

This set is then used in a calculation to return the NUTS 3 regions ([Friend Location]) for the country with the second highest scoring region outside of the home country, i.e. where the country does not equal the selected country:

For Pie 2, it’s a little easier. If a country is in the Top 3 set but not in the Top 2 set, then it is ranked 3 (which means rank 2 outside of the selected country):

Pie 3 is a similar calculation: In the Top 4 set, but not in the Top 3 set.

A similar calculation can also be used for creating the label next to each pie chart. For example, below is the label calculation for the pie chart showing the 3rd ranked country:

Video of Dashboard in Use

You can interact with and explore the workbook on Tableau Public here.

Summary

I’ve enjoyed exploring these custom UI possibilities using Map Layers. It improved my understanding of the functionality and how it can be used in conjunction with other Tableau features and I can imagine a few use cases where I might employ some of these techniques, even if just for a simple pop-up pie chart on a map for a selected geographic point.

This was a long post so thanks for making it this far! I hope you’ve found it useful. Feel free to leave feedback or questions below or you can always contact me via twitter or LinkedIn.

More Examples of Map Layers Experimentation

As always, the Tableau Community has been very creative in exploring the different ways in which the new map layers feature can be used. Some examples are below:

Marc Reid
Twitter | LinkedIn | Tableau Public

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

WordPress.com.

Up ↑

<span>%d</span> bloggers like this: