我正在使用MarkerCluster在folium中创建一个leaflet地图。我查看了所有文档并搜索了示例,但是我无法弄清楚如何为给定的MarkerCluster或FeatureGroup自定义颜色(例如,将其设置为绿色而不是默认蓝色)。
我尝试逐个创建标记并将它们迭代地添加到MarkerCluster中,这样可以给我想要的颜色,但是iFrame html表格无法正常工作,弹出窗口也没有出现。
我编写的代码运行完美(用于弹出窗口的html表格未提供),但我真的很想能够更改一组标记的颜色并使用我的代码中的方法保留弹出窗口。任何指导都将不胜感激!
我尝试逐个创建标记并将它们迭代地添加到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)