Retrieve lat long after box zoom

What are you trying to do?
I am trying to retrieve the ranges of the latitude (y-axis) and longitude (x-axis) after the user employs a box zoom. So I can then use these new ranges to retrieve data

What have you tried that did NOT work as expected?
I have looked through the community forum and seen similar requests but they involved getting the points in a box select and I can’t find documentation for the JSCallback for the map ranges.

If this is a question about Bokeh code, please post a Minimal, Reproducible Example so that reviewers can test and see what you see. A guide to do this is here: https://stackoverflow.com/help/minimal-reproducible-example

Minimal reproducible example of the map with box zoom

TOOLS = ['box_zoom','undo','redo','reset']
p = figure(x_range=(-350656.39,2098372.401 ),y_range=(1271821.69 , 2722973.976),x_axis_type="mercator", y_axis_type="mercator", 
           tools=TOOLS)
#add the map form the Bokeh map vendor in this case Stamen_Terrain --- see documentation
p.add_tile(tile_provider)


show(p, notebook_handle=True)

Notebook comms (i.e. notebook_handle=True) can only push change to the JS side. If your want to get information back to a notebook Python kernel, you will have to use a Bokeh server application inside the notebook. Then you could examine the range start/end after the zoom event in a Python callback.

1 Like

@Bryan Good to know, thanks. I can’t use a server because we are trying to link with binder to make a skill scalable app. However, I used a patch plot and ipywidgets so users can customize the box with sliders. Thanks again, I am sure that would have been hours of wasted effort if you had to let me know.

FWIW there are potentially hacky options e.g. using kernel.execute in Bokeh CustomJS callbacks, but I don’t really recommend them.

1 Like