Mapbox events capture

Is it possible to capture a mouse click or other mouse events to grab a lat, long coordinate from MapBox?

Hi @WigWug,

Thanks for reaching out! Is the selectedPoint property (or hoveredOverPoint) helpful?

I don't think so. These are for points that are already on the map? I want to be able to click on a location and retrieve the lat & long of that point. Looking for events to "listen" to for this info? I see in the bottom left corner of the control the lat & long displays as you move the mouse over the map but I don't see any way of capturing the data to a variable? Actually, need to grab the lat & long of the location where the mouse is clicked.

Anything further on this?

Hi @WigWug Thanks for checking in! My apologies, I didn't realize you were referring to lat/long outside of the designated points already on the map. You're correct, the selectedPoint property wouldn't be helpful for your use case. It doesn't look like we have natively supported properties for capturing hover/click latitude & longitude outside of the marked points.

As a workaround, a number of people have set up a custom component 1 to display maps. Mapbox themselves have a nice quickstart here 1 that you can explore.

I copied this Mapbox code into a custom component (and added lines 34-36, 56-58) to create an example of getting the clicked latitude & longitude in Retool. You can check it out in the attached JSON (by importing it into your Retool account).

Hopefully that's helpful, but let me know if you have any questions getting set up! Otherwise, we can let you know here if we do include click handlers for the built-in component

1 Like