I making an interactive map so users can select a location to get data for a crop yield tool. I have the map and I have sliders showing the latitude and longitude and the initial point shows up but when I move the sliders the point disappears
Shortened version:
globe_points = {'x':[list of latitudes], 'y':[list of longitudes]} # each is ~27500 long
web_points = {'x':[list of lats converted to web mercator],
'y':[list of long converted to web mercator]}
web_plot = ColumnDataSource(data=web_points)
globe_loc = ColumnDataSource(data=globe_points)
latitude_slider = Slider(start=min_lat, end=max_lat,
value=globe_points['x'][14250],
step=.1,
title="Latitude")
longitude_slider = Slider(start=min_long, end=max_long,
value=globe_points['y'][10000],
step=.1, title="Longitude")
#x and y coordinates for the point on the map
source = {'x':[web_plot.data['x'][14250]],
'y':[web_plot.data['y'][10000]]} #starting plot point
#The below creates the bounding box for the map
pts = [(min_lat, min_long), (max_lat, max_long)]
bbox = [ ]
#convert from lat/long to web mercator using pyproj
for pt in transformer.itransform(pts):
bbox.append(pt)
#Use the bounding box to identify the map plot area
p = figure(x_range=(bbox[0][0], bbox[1][0]),
y_range=(bbox[0][1], bbox[1][1]),
x_axis_type="mercator", y_axis_type="mercator")
#add the map from the Bokeh map vendor in this case Stamen_Terrain
p.add_tile(tile_provider)
#plots the initial point we want the user to move
p.circle('x','y',source=source, color= "blue")
callback = CustomJS(args=dict(source=source,
web_plot=web_plot,
globe_loc=globe_loc,
latitude_slider=latitude_slider,
longitude_slider=longitude_slider),
code="""
const data = source.data;
const web = web_plot.data
const globe = globe_loc.data;
const X = latitude_slider.value;
const Y = longitude_slider.value;
var idx_lat = globe.x.indexOf(X);
var idx_long = globe.y.indexOf(Y);
data.x[0]=web.x[idx_lat]
data.y[0]=web.y[idx_long]
source.change.emit();
""")
latitude_slider.js_on_change('value', callback)
longitude_slider.js_on_change('value', callback)
layout = row(p, column(latitude_slider, longitude_slider))
show(layout)