Python 单击按钮时,标记会出现在叶状图上
我正在folium中实现一个映射,从数据帧df获取信息。I包含经度、纬度、名称和地区信息。 使用我在这里获取的GeoJson文件:,我能够在英国定义区域,在鼠标指针悬停时突出显示它们,并显示一些信息。我想为每个区域创建一个带有按钮的弹出窗口。如果单击该按钮,df中位于该区域的所有条目将显示为标记。可能吗?我现在使用的代码如下:Python 单击按钮时,标记会出现在叶状图上,python,dataframe,mapping,folium,Python,Dataframe,Mapping,Folium,我正在folium中实现一个映射,从数据帧df获取信息。I包含经度、纬度、名称和地区信息。 使用我在这里获取的GeoJson文件:,我能够在英国定义区域,在鼠标指针悬停时突出显示它们,并显示一些信息。我想为每个区域创建一个带有按钮的弹出窗口。如果单击该按钮,df中位于该区域的所有条目将显示为标记。可能吗?我现在使用的代码如下: ...operations on df and definition of the map m... width = 10 heigth = 4 resolution
...operations on df and definition of the map m...
width = 10
heigth = 4
resolution = 75
def style_function(feature):
return {
'fillColor': '#ffaf00',
'color': 'grey',
'weight': 1.5,
'dashArray': '5, 5'
}
def highlight_function(feature):
return {
'fillColor': '#ffaf00',
'color': 'black',
'weight': 3,
'dashArray': '5, 5'
}
c = folium.GeoJson(geojsonFile,
name = 'Highlight',
overlay=True,
style_function = style_function,
highlight_function = highlight_function)
html = '{}<br> Info: {} <br> <buttononclick="window.location.reload()">Reload</button>'.format
frame = IFrame(html(name, info), width=(width*resolution)+20, height=(height*resolution)+20)
popup_text = folium.Popup(iframe, max_width=2650)
c.add_child(folium.Popup(popup_text))
c.add_to(m)
单击按钮时将运行的。我正在寻找的最终效果应该是:打开地图,单击选定区域,单击按钮,区域上的标记出现。但是我还没有找到任何解决方案(我尝试过烧瓶,但没有成功)。您好,如果您能够实现这一点,我正在寻找一个类似的功能,以便在folium上显示鼠标单击事件,请您帮助我示例代码。谢谢
def testFunction(df, region):
markerCluster = folium.plugins.MarkerCluster().add_to(map)
for index, row in df.iterrows():
if row['region'] == region:
folium.Marker([row['lat'], row['lon']], popup='some text').add_to(markerCluster)