Any way to see the latitude range and longitude range for a given zoom level in Mapbox Scatter?

I am trying to get a dynamically zooming mapbox plot, but it would be much easier to write a function for this if there was some way to access the full range of lat and lon that is being displayed at a given zoom.

This is all for the basic projection, I am not well versed in the geometry of spheres transposed to rectangles, so please allow for any misconceptions I have but,

e.g. I set a plot to zoom at 4, what is the range of this plots lat and lon?
If I set it to 3, then what is the range?

If there are any accessible attributes relating to the full display of the mapbox at a given zoom level that I could pull, e.g. Layout.mapbox.max_lat or Layout.mapbox.min_lon – something like that would be immensely useful.

Thanks for any help

1 Like

It looks like Mapboxes inherently have a ‘bounds’ property for latitude and longitude but how can these be accessed from a plotly Scattermapbox instance?

From the mapbox docs:

which isn’t a great description. I don’t know if there’s a simple relationship between zoom level and longitude and latitude range. The viewbox size might have to be considered.

I think something like this might do the trick:

var gd = document.getElementById('graph')
Plotly.newPlot(gd, data, layout).then(() => {
  var bounds = gd._fullLayout.mapbox._subplot.map.fitBounds
})

Do you know how I might use etienne’s solution in Python? I’m using plot.ly in Python and am not sure how to make use of Javascript code.

Any solution? Same problem rn

Would love to be able to set the bounds in Python rather than relying on zoom!

I’m using react-plotly.js and I tried this method, but I’m not able to find the fitBounds attribute in _fullLayout.mapbox._subplot.map