-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Milestone
Description
When using GMapPlot with DataRange1d, the points plotted do not appear in the correct location when the data is updated. See example code below. The solution is to use Range1d. It would be helpful to give a validation error so the developer can be advised to use Range1d instead of DataRange1d.
Thanks,
Andrew
from bokeh.io import output_file, show
from bokeh.models import GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, WheelZoomTool, Select
from bokeh.plotting import curdoc
from bokeh.layouts import layout, row, widgetbox
# set up map / plot (my google maps API key: AIzaSyAh1cmN_U6smbyt5uCpMIhttQOYrE4JtLY)
map_options = GMapOptions(lat=49.74, lng=-123.117, map_type="roadmap", zoom=14)
plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options,
api_key='PUT YOUR GOOGLE MAPS API KEY HERE'
)
c=['red','green','blue']
# create an initial source object (one color and size on each point)
source = ColumnDataSource( data=dict( lat = (49.746504,49.735954,49.744864),
lon = (-123.117835,-123.114313,-123.114587),
color = c ) )
# set the circle parameters from the source elements
circle = Circle(x="lon", y="lat", fill_color="color", size=10, fill_alpha=0.5, line_color=None)
# add the source to the plot as circles
plot.add_glyph(source, circle)
# throw on some tools
plot.add_tools( WheelZoomTool() )
def update(attrname, old, new):
if color.value == 'RBG': c=['red','green','blue']
if color.value == 'Greyscale': c=['black','grey','white']
if color.value == 'CMY': c=['cyan','magenta','yellow']
# create the source object with the data to be plotted
source.data=dict( lat = (49.746504,49.735954,49.744864),
lon = (-123.117835,-123.114313,-123.114587),
color=c)
# update the plot
plot.update()
# add the selectors
color = Select(title='Color', value='None', options=['RBG','Greyscale','CMY'])
color.on_change('value', update)
# add the controls
controls = widgetbox([color], width=200)
layout = row(controls, plot)
curdoc().add_root(layout)
curdoc().title = "My Google Map"
Reactions are currently unavailable