Mapbox Conditional Map Marker

Hey y’all, just started experimenting with Retool and am loving it. I’m testing it out by rendering a Mapbox map of saved locations, as a replacement for Google My Maps (which is lacking in a lot ways…).

This isn’t particularly high priority, but as a QOL improvement, is it possible to conditionally specify the marker instead of just supplying a single static marker?

In my case, I’m supplying data following this format: { latitude, longitude, type, ... }

And I roughly imagined that I could supply a JS function like so:

{{ row => { "National Park": "🏞️", "Hike": "🥾", ... }[row.type] }}

Or alternatively, this function could be executed as a Transformer on the Query itself and the marker value stored as a column. In that case, being able to specify a column name would work perfectly.

Hey @colin, and welcome to the community! You can write JS anywhere in Retool, so in the Latitude / Longitude form fields in the Mapbox settings, you can write {{ any JS here }} to dynamically set those values. A common pattern is to use ternary operators (?) in there. You can also use a JS function (create a new query and choose “run JS code”) and reference the .data property of that function if you have more complex logic. Does that make sense / help?

Hey Justin, thanks for the quick response!

I'm specifically referring to the Marker field here:

Screen Shot 2020-06-29 at 7.38.51 AM

Given that I have various points on the Map, is there a way to give each point a different Marker?

Ahhhh I gotcha now. Will share with the team :slight_smile:

You can set “marker” additionally to latitude and longitude.

For example,
{
“latitude”: 45.92,
“longitude”: 132.23,
“marker” : “:mans_shoe:
}

5 Likes

Amazing :clap: Thank you!

2 Likes

This is reaaaaaaly helpful! But where/how did you find out this?

1 Like

Tinkering!

have you found something more available?