Programmatically zoom into map / automatically change range of plot

Hello,

I created a small dashboard, which contains a map, set up like this:

tools_to_show = “pan, wheel_zoom, box_select,lasso_select,hover”
tooltips = [(“id”, “@sensor_id”), (“sensor type”, “@sensor_type”),(“mean value”, “@P1”)]
p_map = figure(x_range=(-2500000, 5000000), y_range=(3000000, 9000000),
x_axis_type=“mercator”, y_axis_type=“mercator”,
tools=tools_to_show, toolbar_location=“above”,
tooltips=tooltips)
p_map.xaxis.visible = False
p_map.yaxis.visible = False
p_map.add_tile(CARTODBPOSITRON)

``

Now I added a new functionality to the dashboard, where user can choose an area (City, Country) of interest and only get data from that area.

This is done via the text input widget

def search(attrname, old, new):
global df
q = “https://nominatim.openstreetmap.org/search?q={}&format=json”.format(search_box.value)
r = requests.get(q)
bb = r.json()[0][“boundingbox”]
min_lon, min_lat = transform(prj_wgs, prj_itm, bb[2], bb[0])
max_lon, max_lat = transform(prj_wgs, prj_itm, bb[3], bb[1])
df = df_full[(df_full[“lat”] >= min_lat)&(df_full[“lat”] <= max_lat)&(df_full[“lon”]>=min_lon)&(df_full[“lon”]<=max_lon)]
new_data = ColumnDataSource(df[df[“date”] == slider.value])
src.data.update(new_data.data)

search_box = TextInput(value="", title=“Area:”)
search_box.on_change(‘value’, search)

``

This works so far.

Additionally, I want the map to automatically zoom into the chosen area.

This is were I run into problems.

At first, I thought I only have to change x_range and y_range of p_map, but this doesn’t update the plot.

I couldn’t find anything relating to my problem in the documentation either.

Is there a way to achieve this programmatically?

How did you try changing the ranges? E.g. rather than trying to replace the entire ranges, you should definitely prefer updating the .start and .end of the existing range.

Bryan

···

On Sep 11, 2018, at 05:36, [email protected] wrote:

Hello,

I created a small dashboard, which contains a map, set up like this:
tools_to_show = "pan, wheel_zoom, box_select,lasso_select,hover"
tooltips = [("id", "@sensor_id"), ("sensor type", "@sensor_type"),("mean value", "@P1")]
p_map = figure(x_range=(-2500000, 5000000), y_range=(3000000, 9000000),
           x_axis_type="mercator", y_axis_type="mercator",
           tools=tools_to_show, toolbar_location="above",
           tooltips=tooltips)
p_map.xaxis.visible = False
p_map.yaxis.visible = False
p_map.add_tile(CARTODBPOSITRON)

Now I added a new functionality to the dashboard, where user can choose an area (City, Country) of interest and only get data from that area.
This is done via the text input widget
def search(attrname, old, new):
    global df
    q = “https://nominatim.openstreetmap.org/search?q={}&format=json”.format(search_box.value)
    r = requests.get(q)
    bb = r.json()[0][“boundingbox”]
    min_lon, min_lat = transform(prj_wgs, prj_itm, bb[2], bb[0])
    max_lon, max_lat = transform(prj_wgs, prj_itm, bb[3], bb[1])
    df = df_full[(df_full[“lat”] >= min_lat)&(df_full[“lat”] <= max_lat)&(df_full[“lon”]>=min_lon)&(df_full[“lon”]<=max_lon)]
    new_data = ColumnDataSource(df[df[“date”] == slider.value])
    src.data.update(new_data.data)

search_box = TextInput(value="", title="Area:")
search_box.on_change('value', search)

This works so far.
Additionally, I want the map to automatically zoom into the chosen area.
This is were I run into problems.
At first, I thought I only have to change x_range and y_range of p_map, but this doesn't update the plot.
I couldn't find anything relating to my problem in the documentation either.

Is there a way to achieve this programmatically?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1afe904a-3fbd-4cb3-9417-7f90ddd84794%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I first tried something like p_map.y_range=(min_lat, max_lat).

Thank you, updating p_map.y_range.start and p_map.y_range.end separately works!

I also had to “p_map.add_tile(CARTODBPOSITRON)” after changing the range.

···

On Tuesday, September 11, 2018 at 5:23:49 PM UTC+2, Bryan Van de ven wrote:

How did you try changing the ranges? E.g. rather than trying to replace the entire ranges, you should definitely prefer updating the .start and .end of the existing range.

Bryan

On Sep 11, 2018, at 05:36, [email protected] wrote:

Hello,

I created a small dashboard, which contains a map, set up like this:

tools_to_show = “pan, wheel_zoom, box_select,lasso_select,hover”

tooltips = [(“id”, “@sensor_id”), (“sensor type”, “@sensor_type”),(“mean value”, “@P1”)]

p_map = figure(x_range=(-2500000, 5000000), y_range=(3000000, 9000000),

       x_axis_type="mercator", y_axis_type="mercator",
       tools=tools_to_show, toolbar_location="above",
       tooltips=tooltips)

p_map.xaxis.visible = False

p_map.yaxis.visible = False

p_map.add_tile(CARTODBPOSITRON)

Now I added a new functionality to the dashboard, where user can choose an area (City, Country) of interest and only get data from that area.

This is done via the text input widget

def search(attrname, old, new):

global df
q = "[https://nominatim.openstreetmap.org/search?q={}&format=json](https://nominatim.openstreetmap.org/search?q=%7B%7D&format=json)".format(search_box.value)
r = requests.get(q)
bb = r.json()[0]["boundingbox"]
min_lon, min_lat = transform(prj_wgs, prj_itm, bb[2], bb[0])
max_lon, max_lat = transform(prj_wgs, prj_itm, bb[3], bb[1])
df = df_full[(df_full["lat"] >= min_lat)&(df_full["lat"] <= max_lat)&(df_full["lon"]>=min_lon)&(df_full["lon"]<=max_lon)]
new_data = ColumnDataSource(df[df["date"] == slider.value])
src.data.update(new_data.data)

search_box = TextInput(value="", title=“Area:”)

search_box.on_change(‘value’, search)

This works so far.

Additionally, I want the map to automatically zoom into the chosen area.

This is were I run into problems.
At first, I thought I only have to change x_range and y_range of p_map, but this doesn’t update the plot.

I couldn’t find anything relating to my problem in the documentation either.

Is there a way to achieve this programmatically?


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1afe904a-3fbd-4cb3-9417-7f90ddd84794%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.