0

I generated map with Marker 'popup' in 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

Is it possible in Folium that a popup will appear over a marker on mouse-over, not on click?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Duc Vu
  • 59
  • 1
  • 6

1 Answers1

0

I found my own solution by modifying the 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())
Duc Vu
  • 59
  • 1
  • 6