Highlight and zoom to a point on a map but do not filter

Update: Further below you will find that I suggest applying a factor to one of the calculations. This has been identified to be version related. In Tableau 2021.3 (the version I created my file with) using a buffer on the marks layer results in a lesser zoom extend. In 2021.4 this behaviour is not observed anymore.

Recently a colleague asked how he could enable searching a point on the map (search entry) highlight it and zoom there without filtering the view. The use case was for addresses in a city.

From my research it seems this is neither discussed in any blogs ( I am not claiming I searched everything there is, just some quick google searches) nor is it a standard function in Tableau. The resources provided show how to zoom by filtering which is exactly what we did not want to do.

Update: of course someone has written on the topic, see Jeff Shaffer over on dataplusscience.com. Anyways, let’s just add this post as well and give the topic a bit more visibility

You can filter, but then everything else is gone and that might be something your customers don’t want. Or you can use the inbuilt highlight function but that won’t zoom to the specified selection, just highlight it and so you might still have to search for it if you have many points on your map.

Example for using the inbuilt highlighter. No zoom at all

four+ different options

I have come up with four different versions that do what we intend though they are all pretty closely related.

General preparation for all approaches

The approaches only differ in their fine tuning so let’s first set the scene.

A word of caution upfront: your data source will need to have the latitude and longitude be available in itself. It does not work with auto-generated lat/lon values which is why for my example I extracted the latitudes and longitudes for the cities from sample superstore.

Here is the preparation (some calcs are split for easier reference and might be merged in one step in your case).

  1. create a parameter p.city. It must be a string parameter that allows all values. You might think using a list but a list won’t allow you to select nothing which is what you want to do if not searching for a specific space
  2. For options 2 and 3 create one more parameter p.zoom
  3. create calculations:
//Selected City
IF CONTAINS(UPPER([City]), UPPER([p.City])) THEN [City] END
//SELECTED LAT
IF [City] = [Selected City] THEN [Latitude] END
//SELECTED LON
IF [City] = [Selected City] THEN [Longitude] END
//Makepoint City
MAKEPOINT([Selected LAT], [Selected LON])

This will give us the point for the selected city.

//Coloring
IF [p.City] = "" THEN FALSE
ELSEIF
[City] = [Selected City] THEN TRUE ELSE FALSE
END

This may seem somewhat repetitive (why not leave out the first part?) but in order to only have two colors (selected and not selected) we need to expressly check also for the blank parameter value.

For options two and three we need one more calculation

//buffer
BUFFER(MAKEPOINT([Selected LAT], [Selected LON]),[p.zoom],'kilometers')

Note that the kilometres in the last calculation can be whatever suits your case best but since we are showcasing on cities kilometres seems reasonable.

From the above you will already see why we need the latitude and longitude fields to be available in the data source. We cannot use auto-generated values in calculated fields.

Version 1 – Dual axis

This version is also viable for those users still on rather old versions of Tableau where the map layers are not available.

Put your latitude on rows and longitude on columns. Set both to average.

Split your data by moving [city] onto the details shelf. Add the [Makepoint City] field also onto details. Add [Coloring] calculation onto color.

Duplicate your latitude fields and create a dual axis.

On the secondary latitude field, remove everything and add the [buffer] calculated field. Note that both mark types need to be set to Map. If you set either of them to something different, the zoom will break.

Now you can adjust the coloring on the secondary axis as you please. Sometimes, it can be handy to show the buffer, in other cases you may not want to do it.

Notice that the zoom resulting from the buffer is pretty perfectly aligned with your selected zoom kilometers. In this screen I have 20km inserted in the parameter and when we use the radius drawing tool we get about 22km when touching the outer bounds:

So this is a plus. However, downside to this is:

We cannot change the size of the selected city and make it even more visible. Since we have to use Map as mark type, all dots are the same size. As soon as we change either of the axis away from maps, the zoom will collapse, leaving us with the zoomed out version of the map

Version 2 -Using maplayers w/o buffer

With the 2020.4 Tableau map layers feature we have more options at hand now

Start again putting lat and long on rows and columns.

Move [City] onto the canvas and select circle as marks type. Now you can also add [Coloring] to size and color. Since we are using circles, this time the sizing effect takes place.

Now in order to have a map, move [Makepoint City] onto the canvas, place it on the “new map layer” symbol.

Select map as mark type.

Next, deselect “add to zoom extent” on the cities layer and hide the Makepoint City layer lke this:

Result: We can see already some zooming effect

Version 3 – including buffer

Update: I noticed that the below described disparity between the zoom factors using dual axis vs map layers does not exist on Tableau Public. I have no idea why that is as the problem remains when using Tableau Desktop. I asked to see if someone has experienced the same and as per this writing, no responses.

Now we include our [buffer] field on the map layers in addition.

Remove “add to zoom extent” from our Makepoint City field but keep it on the buffer layer. Also, you can consider disabling the selection option:

Ad this is our result:

As we can see, the zoom is much better but as highlighted, we now have about 2.1x our intended zoom (compare the blue circle with the smaller inner circle which is our buffer that was set to 20km).

Version 3b – adjusted buffer

We can make use of the factor and simply adjust our buffer calculation by including a division within it:

//buffer adjusted
BUFFER(
    MAKEPOINT([Selected LAT], [Selected LON]),
[p.zoom]/2.1,
'kilometers'
)

Use this one on the map layers instead of the previous [buffer] field

I would strongly argue to hide this map layer because since you just have more or less halfed your buffer it will otherwise be very confusing for the userif he enters 20km, then sees a buffer and the shown radius is actually only around 10km. However, now the zoomed in part fits the parameter:

Version 4 – somewhat unneeded but lets take it anyways

The last idea I want to discuss is not using a buffer calculation but instead using two more fake points and/or a line based on these points.

Tableau always tries to center so when we simply add a line that consists of two fake points that have our actual selected city as their middle then we can have it center.

So, here is what we use:

//fakeline
MAKELINE( MAKEPOINT([Selected LAT]-[p.lat_lon_adjuster], [Selected LON]),MAKEPOINT([Selected LAT] +[p.lat_lon_adjuster], [Selected LON]) )

The parameter will allow the user to also use his zoom level. Basically, all we do is create two points on the same longitude as our selected city and the latitude being slightly increase or decreased and then create a line between these two.

The [fakeline] layer will be your zoom extent.

In the screen I am showing the line, in reality obviously you would hide it:

And that’s it for today. If you like to check out the workbook find it on my tableau public.

I hope you found that useful.

As always appreciate your feedback.

Until next time.

Steffen

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 )

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