我想将Google Maps Bokeh应用程序转换为允许缩放的Bokeh Server应用程序。这是我尝试修改的Bokek应用程序:
https://bokeh.pydata.org/en/latest/docs/user_guide/geo.html
这是我尝试转换为bokeh服务器应用程序的尝试:
from bokeh.io import curdoc
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap
from bokeh.models.widgets import Slider, TextInput
import random
text = TextInput(title="title", value='my sine wave')
zoom_slider = Slider(title='Zoom Level', value=11, start=0, end=20, step=1)
lat_textbox = TextInput(title='Latitude', value='30.2861')
lon_textbox = TextInput(title='Longitude', value='-97.7394')
source_gps = ColumnDataSource(data=dict(lat=[30.29, 30.20, 30.29], lon=[-97.70, -97.74, -97.78]))
source_map = ColumnDataSource(
data=dict(map_options=[GMapOptions(lat=30.2861, lng=-97.7394, map_type="roadmap", zoom=11)]))
p = gmap("YOUR GOOGLE API CREDENTIALS HERE",
source_map.data['map_options'][0], title="Austin")
p.circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8, source=source_gps)
def update_data(attrname, old, new):
zoom = zoom_slider.value
lat = float(lat_textbox.value)
lon = float(lon_textbox.value)
source_map.data = dict(map_options=[GMapOptions(lat=lat, lng=lon, map_type="roadmap", zoom=zoom)])
source_gps.data = dict(lat=[30.29 + random.random() / 10 - 0.05, 30.20, 30.29],
lon=[-97.70 + random.random() / 10 - 0.05, -97.74, -97.78])
for w in [zoom_slider, lat_textbox, lon_textbox]:
w.on_change('value', update_data)
# Set up layouts and add to document
inputs = column(zoom_slider, lat_textbox, lon_textbox)
curdoc().add_root(row(inputs, p, width=800))
curdoc().title = "Google Map"
我希望google地图能够根据缩放滑块的值进行缩放,但这是静态的。有任何想法吗?
已更新!!感谢bigreddot,这是工作代码:
from bokeh.io import curdoc
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap
from bokeh.models.widgets import Slider, TextInput
import random
text = TextInput(title="title", value='my sine wave')
zoom_slider = Slider(title='Zoom Level', value=11, start=0, end=20, step=1)
lat_textbox = TextInput(title='Latitude', value='30.2861')
lon_textbox = TextInput(title='Longitude', value='-97.7394')
source_gps = ColumnDataSource(data=dict(lat=[30.29, 30.20, 30.29], lon=[-97.70, -97.74, -97.78]))
initial_map_options = GMapOptions(lat=30.2861, lng=-97.7394, map_type="roadmap", zoom=11)
p = gmap("YOUR GOOGLE API CREDENTIALS HERE",
map_options=initial_map_options, title="Austin")
p.circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8, source=source_gps)
def update_data(attrname, old, new):
zoom = zoom_slider.value
lat = float(lat_textbox.value)
lon = float(lon_textbox.value)
source_gps.data = dict(lat=[30.29 + random.random() / 10 - 0.05, 30.20, 30.29],
lon=[-97.70 + random.random() / 10 - 0.05, -97.74, -97.78])
p.map_options = GMapOptions(lat=lat, lng=lon, map_type="roadmap", zoom=zoom)
for w in [zoom_slider, lat_textbox, lon_textbox]:
w.on_change('value', update_data)
# Set up layouts and add to document
inputs = column(zoom_slider, lat_textbox, lon_textbox)
curdoc().add_root(row(inputs, p, width=800))
curdoc().title = "Google Map"
答案 0 :(得分:1)
地图选项(即缩放级别)是 plot 的属性,而不是数据源的属性。如果要更新地图选项,则需要执行以下操作:
p.map_options = new_map_options
更新功能中的某个位置。