我正在使用MarkerCluster在大叶中创建传单地图。我遍历了文档,并搜索了示例,但是我无法弄清楚如何为给定的MarkerCluster或FeatureGroup(例如,一组设置为绿色而不是默认的蓝色)自定义颜色。
我尝试单独创建标记并将其迭代添加到MarkerCluster中,这给了我我想要的颜色,但是iFrame html表无法正常运行,并且没有出现弹出窗口。
我编写的代码可以正常工作(不提供用于弹出窗口的html表),但我真的很希望能够更改一组标记的颜色并使用我的方法保留弹出窗口码。任何指导将不胜感激!
or_map = folium.Map(location=OR_COORDINATES, zoom_start=8)
res_popups, res_locations = [], []
com_popups, com_locations = [], []
for idx, row in geo.iterrows():
if row['Type'] == 'Residential':
res_locations.append([row['geometry'].y, row['geometry'].x])
property_type = row['Type']
property_name = row['Name']
address = row['address']
total_units = row['Total Unit']
iframe = folium.IFrame(table(property_type, property_name,
address, total_units), width=width,
height=height)
res_popups.append(iframe)
else:
com_locations.append([row['geometry'].y, row['geometry'].x])
property_type = row['Type']
property_name = row['Name']
address = row['address']
total_units = row['Total Unit']
iframe = folium.IFrame(table(property_type, property_name, address,
total_units), width=width,
height=height)
com_popups.append(iframe)
r = folium.FeatureGroup(name='UCPM Residential Properties')
r.add_child(MarkerCluster(locations=res_locations, popups=res_popups))
or_map.add_child(r)
c = folium.FeatureGroup(name='UCPM Commercial Properties')
c.add_child(MarkerCluster(locations=com_locations, popups=com_popups))
or_map.add_child(c)
display(or_map)
答案 0 :(得分:1)
您不仅可以将所有位置转储到群集中,还可以在它们上循环并为每个位置创建一个标记-这样就可以设置标记的颜色。创建后,可以将标记添加到所需的MarkerCluster。
for com_location, com_popup in zip(com_locations, com_popups):
folium.Marker(com_location,
popup=com_popup
icon=folium.Icon(color='red', icon='info-sign')
).add_to(cluster)
另一种方法是修改样式功能,如here(In [4]和In [5])。