我写了一些python代码,使用bokeh在地图上显示点。但是现在有一些超链接在鼠标悬停在点上时显示在工具提示上。但是由于这是工具提示,因此我无法单击超链接来导航到其他页面。有没有机会这样做。
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions,HoverTool,CustomJS
import bokeh.plotting as plotting
from bokeh import events
from bokeh.plotting import gmap
import tkinter as tk
screenInfo=tk.Tk()
map_options = GMapOptions(lat=26.366314, lng= 77.016513, map_type="roadmap", zoom=5)
source = ColumnDataSource(df)
TOOLTIPS = """
<div id="Tooltip">
<div>
<span style="font-size: 17px; font-weight: bold;">@Place</span>
</div>
<div>
<span style="font-size: 15px; color: #966;">@Title<a href="@Link">Click here for more details</a></span>
</div>
</div>
"""
HoverCallback=CustomJS(code="""
""")
# For GMaps to function, Google requires you obtain and enable an API key:
#
# https://developers.google.com/maps/documentation/javascript/get-api-key
#
# Replace the value below with your personal API key:
p = gmap(API_key, map_options, title="The Hindu",plot_width=screenInfo.winfo_screenwidth()-100, plot_height=screenInfo.winfo_screenheight()-150)
p.circle(x="lat", y="lon", size=15,fill_color="blue",fill_alpha=0.8, source=source)
p.add_tools( HoverTool(tooltips=TOOLTIPS,callback=HoverCallback))
plotting.output_file('gmap.html')
show(p)
答案 0 :(得分:0)
您将永远无法单击工具提示本身,因为工具提示始终位于鼠标旁边,而不是鼠标下方。最好的选择是同时配置TapTool
和OpenURL
回调,以在单击字形时打开相同的URL。这是Bokeh 0.13.0
的完整示例:
from bokeh.models import OpenURL, TapTool
from bokeh.plotting import figure, show
url = "http://www.colors.commutercreative.com/@color/"
tooltips = 'Click the circle to go to:<br /><a href="{url}">{url}</a>'.format(url=url)
p = figure(tooltips=tooltips) # "easy" tooltips requires Bokeh >= 0.13.0
data = dict(x=[1, 2, 3], y=[2, 6, 4], color=['firebrick', 'navy', 'olive'])
r = p.circle('x', 'y', color='color', size=25, source=data)
# these lines prevent greying out untapped circles, remove them
# to have default selection/non-selection appearance
r.selection_glyph = None
r.nonselection_glyph = None
tap = TapTool(callback=OpenURL(url=url))
p.add_tools(tap)
show(p)