Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Get the Scroll Wheel Zoom Value on MAPBOX

He guys,
I´m using scattermapbox for plotting maps. Is there a way to get the scroll zoom (by the mouse) value?

For example, every time the use use the scroll mouse to change the zoom, I can see the zoom value on the console.

thanks always for all the help.

Hey @luquezsantiago

In short, I think the answer is YES, although I’ve not tested this for scattermapbox.

I’m using choroplethmapbox which should be pretty similar, and I can return a whole bunch of attributes about the current state of the map. I achieved it using a callback. I’m not sure if you can trigger the callback from the mousewheel ‘event’, but you probably can.

First ensure you import dash dependencies:

from dash.dependencies import Input, Output, State

To return map state variables for a given call back, you can:

Add your scattermapbox figure as a State to the given call-back declaration e.g.:

@app.callback(Output(), Input(blah),
State(“yourscattermapboxid”, “figure”))
def your_callback(blah, state)

Then inside the callback code itself you can access a ton of parameters about the figure state (including zoom) from within the variable you have ascribed to the figure state. This is a dictionary so what I usually do is just print it out to see what’s in it.

From your callback:


Then find out the zoom level, and you’re sorted. For me, it looks something like this:

zoom = state[“layout”][“mapbox”][“zoom”]

You will still need to find a way to trigger the callback if you want to grab the zoom level the moment the user moves the mouse, but otherwise, you can grab it anytime a given callback is run using the approach above.

Hope that helps :slight_smile:

I believe the relayoutData property should do this.

thanks!!! I will give it a try!