Folium搜索插件出现问题(Data = marker_cluster)

时间:2019-04-25 13:52:32

标签: python dictionary folium

使用插件Search(marker_cluster)时,我遇到了一些麻烦 当我尝试搜索时,第一个搜索栏没有响应 第二个自定义图标和默认标记同时出现 我该如何摆脱这些默认标记?

import folium
from folium import plugins
from folium.plugins import Search

points = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "one",
'icons': 'C:\\Users\\avion\\Desktop\\pandas\\my project\\factory.png'
},
"geometry": {
"type": "Point",
"coordinates": [-71.0636, 42.3581]
}
},
{
"type": "Feature",
"properties": {
"name": "two",
'icons': 'C:\\Users\\avion\\Desktop\\pandas\\my project\\factory.png'
},
"geometry": {
"type": "Point",
"coordinates": [-74.78991444, 42.82995815]
}
},
{
"type": "Feature",
"properties": {
"name": "three",
'icons': 'C:\\Users\\avion\\Desktop\\pandas\\my project\\factory.png'
},
"geometry": {
"type": "Point",
"coordinates": [-78.56603306, 39.17929819]
}
}
]
}

m = folium.Map(
location=[42.82995815, -74.78991444],
tiles = 'cartodbpositron',
zoom_start=1
)

style_one = lambda x: {'fillColor': 'green'}
marker_cluster = folium.plugins.MarkerCluster(name = 'site location').add_to(m)
for feature in points['features']:
    lon, lat = feature['geometry']['coordinates']
    icon = feature['properties']['icons']
    name = feature['properties']['name']
    icon = folium.CustomIcon(icon_image = icon,
                                 icon_size = (30,35),
                                 icon_anchor = (0,0))
    marker =folium.Marker(location = [lat, lon] ,
                           popup = (folium.Popup(str(name))), 
                           tooltip = "<strong>"+str(name)+"</strong>",
                           icon = icon).add_to(marker_cluster)
geojson_obj = folium.GeoJson(points, style_function=style_one).add_to(marker_cluster)
statesearch = Search(layer=marker_cluster,
                     geom_type='Point',
                     placeholder="Search",
                     collapsed=True,
                     search_label='name',
                     search_zoom=14,
                     position='topright'
                    ).add_to(m)

m.save('example.html')

仅显示使用名称键和自定义图标进行搜索。

0 个答案:

没有答案