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?