def create_map_figure():
from colorcet import bgy
import holoviews as hv
from holoviews.operation.datashader import datashade
import geoviews.tile_sources as gts
hv.extension('bokeh')
from datashader.geo import lnglat_to_meters
shade_pd = [["localtime", "from_lon", "from_lat", "to_lon", "to_lat"]] # TODO: create test data
# datashader and bokeh work with mercator proj
shade_pd.loc[:, 'from_lon'], shade_pd.loc[:, 'from_lat'] = lnglat_to_meters(shade_pd["from_lon"], shade_pd["from_lat"])
shade_pd.loc[:, 'to_lon'], shade_pd.loc[:, 'to_lat'] = lnglat_to_meters(shade_pd["to_lon"], shade_pd["to_lat"])
muc_coords = {"lat": 48.137154, "lon": 11.576124}
x1, y1 = lnglat_to_meters(muc_coords["lon"]-0.1, muc_coords["lat"]-0.1)
x2, y2 = lnglat_to_meters(muc_coords["lon"]+0.1, muc_coords["lat"]+0.1)
plot_width = 800
plot_height = 400
tile_opts = dict(width=plot_width, height=plot_height, xaxis=None, yaxis=None, show_grid=False)
map_tiles = gts.CartoLight.opts(style=dict(alpha=1), plot=tile_opts)
lines = hv.Curve(shade_pd[["from_lon", "from_lat", "to_lon", "to_lat"]], ["from_lon", "from_lat"],
["to_lon", "to_lat"])
routes = datashade(lines, x_sampling=2, y_sampling=2, cmap=bgy, x_range=(x1, x2), y_range=(y1, y2), alpha=50)
renderer = hv.renderer('bokeh')
return renderer.get_plot(map_tiles * routes).state
@app.route("/")
def dash():
from bokeh.embed import components
# Create the plot
plot_map = create_map_figure()
# Embed plot into HTML via Flask Render
script_map, div_map = components(plot_map)
return render_template("index.html", script_map=script_map, div_map=div_map)