Folium Search Plugin No Results for FeatureGroup

2020-07-20 04:39发布

问题:

I'm trying to add search functionality to a map I'm generating in Python with Folium. I see there is a handy Search plugin available and able to implement it successfully and get it added to the map. Unfortunately, using a FeatureGroup as the layer my FeatureGroup filled with markers can't seem to get the search to bring back results.

My assumption is that the search function would query the tooltip and/or popup attributes of the markers to return the lat/lon as the search value. I've tried manually supplying the value 'tooltip' to the search_label option of the Search function, but no luck.

import pandas as pd
import folium
from folium.plugins import Search

def mapGenerator(data):
    map = folium.Map()
    fg = folium.FeatureGroup()

    for index, row in data.iterrows():
        marker = folium.Marker(location=[row['lat'], row['lon']],
                               popup=row['name'])
        marker.add_to(fg)

    fg.add_to(map)
    Search(fg).add_to(map)

    map.save('map.html')

data = pd.DataFrame({'name': ['first', 'second', 'third'], 'lat': [28.27724, 48.52228, 22.43949],
                    'lon':[-9.72904, 34.77667, 102.49105]})

mapGenerator(data)

This code produces a map that plots some random points and then adds a search box. My expected and the desired result is that the search bar will zoom in on the coordinate with the name 'first' if I search 'first', or even if I searched 'fir' (or some variation), but currently, no results are found no matter what.