Folium Search Plugin No Results for FeatureGroup

馋奶兔 提交于 2020-01-23 03:30:11

问题


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.

来源:https://stackoverflow.com/questions/57468332/folium-search-plugin-no-results-for-featuregroup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!