Show a list of point in mapbox from a Retool database table

Hi there!

I'm absolutely new to the platform...

I'd like to show a number of points on a mapbox with it's coords coming from a Retool database table.
My table has columns "lat" and "long" with the correct values (as float8). I use this query to retrieve the data:

SELECT "b".name AS "id", "b".long AS "longitude", "b".lat AS "latitude" FROM "myBuildingList" AS "b" WHERE "b".long <> 0 ORDER BY ID

and I get this result:

image

How can assign this to mapbox as Points?

Thanks!

You probably only want the lat and long values so you can just pull those values from that data set or you can use a Query with JSON to pull the long and lat from it....
select longitude, latitude from {{yourdataset.data)) so that you have something like:

{{[
    { longitude: '-122.4194', latitude: '37.7949' },
    { longitude: '-122.4794', latitude: '37.7749' },
    { longitude: '-122.4194', latitude: '37.7049' },
]}}

Thanks, @ScottR for writing!

I'm not sure I understood. The result from my dataset.data is:

How can I transform it to use it in the Points property of mapbox? Something like "transpose"?

Use a transformer and you can map from your initial data like so:

return {{ formatDataAsArray(yourQueryName.data) }}.map((row) => {
  return {
    longitude: row.longitude,
    latitude: row.latitude,
  }
})

Screenshot 2023-09-21 at 12.42.02 PM

1 Like

@ScottR Thank you so much! I could transform the data directly in the resource query using your hint and it works like a charm!

1 Like