I am trying to access the coordinates pertaining to the bounding box of a Plotly Mapbox figure (essentially the min and max latitude and longitude in view at any given time). Does anyone know how such information about the figure might be accessed? I am working in Python + Dash, and am thinking a callback will need to be constructed to retrieve this information when a user either pans or zooms in on the Mapbox figure.
Any help would be greatly appreciated!
Minimal working example (will require a mapbox token)
import plotly.graph_objects as go
from jupyter_dash import JupyterDash
import dash_core_components as dcc
import dash_html_components as html
fig = go.Figure()
fig.add_trace(go.Scattermapbox(mode = "markers+lines"))
fig.update_layout(
autosize=True,
hovermode='closest',
showlegend=True,
margin=dict(t=20, b=0, l=0, r=0),
mapbox=dict(
# Access token comes from https://docs.mapbox.com/help/glossary/access-token/
accesstoken= "Insert MapBox Token Key Here",
bearing=0,
pitch=0,
zoom=3,
style="satellite-streets"
),
)
app = JupyterDash(__name__)
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(mode="jupyterlab",debug=True)
Thanks for the information @pfussee.
I have tried your method and have a couple of follow-up questions.
Do you know how to get the bounding box coordinates initially (i.e. after the mapbox was first rendered and without user interaction (pan or zoom) yet)?
Second, upon zooming, relayoutData only contains the new zoom value but does not contain the new mapbox._derived[âcoordinatesâ] values. Do you know happen to know a way to derive new bounding coordinates using a new zoom value?