我用Marker' popup'生成了地图。在Folium。
m = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner', zoom_start=13)
folium.Marker(location=[45.5244, -122.6699], popup='The Waterfront').add_to(m)
m.save('portland.html')
m
在Folium中是否可以在鼠标悬停时在标记上显示弹出窗口,而不是点击?
答案 0 :(得分:0)
我通过修改html找到了自己的解决方案。
import folium
import re
import fileinput
m = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner', zoom_start=13)
folium.Marker(location=[45.5244, -122.6699], popup='The Waterfront').add_to(m)
m.save('portland.html')
with open("portland.html") as inf:
txt = inf.read()
#Find all the markers names given by folium
markers = re.findall(r'\bmarker_\w+', txt)
markers = list(set(markers))
for linenum,line in enumerate( fileinput.FileInput("portland.html",inplace=1) ):
pattern = markers[0] + ".bindPopup"
pattern2 = markers[0] + ".on('mouseover', function (e) {this.openPopup();});"
pattern3 = markers[0] + ".on('mouseout', function (e) {this.closePopup();});"
if pattern in line:
print(line.rstrip())
print(pattern2)
print(pattern3)
else:
print(line.rstrip())