Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Folium MarkerCluster颜色自定义_Python_Folium - Fatal编程技术网

Python Folium MarkerCluster颜色自定义

Python Folium MarkerCluster颜色自定义,python,folium,Python,Folium,我正在使用MarkerCluster在folium中创建传单图。我查阅了所有文档并搜索了一些示例,但我不知道如何自定义给定MarkerCluster或FeatureGroup的颜色(例如,设置为绿色而不是默认的蓝色) 我尝试单独创建标记,并反复将它们添加到MarkerCluster,这给了我想要的颜色,但是iFrame html表无法正常工作,弹出窗口也没有出现 我编写的代码工作得非常完美(没有提供用于弹出窗口的html表),但我确实希望能够更改一组标记的颜色,并使用代码中的方法保留弹出窗口。任

我正在使用MarkerCluster在folium中创建传单图。我查阅了所有文档并搜索了一些示例,但我不知道如何自定义给定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)

与将所有位置转储到集群中不同,您可以在它们上循环并为每个位置创建一个标记,这样您就可以设置标记的颜色。创建后,可以将标记添加到所需的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)

另一种方法是修改样式函数,如[4]和[5]所示。

谢谢!我采纳了你的建议;当我发现branca IFrame元素必须以Folium弹出窗口的形式传递给Marker时,这一切都集中到了一起:popup=Folium.popup(res_popup)——我一直试图将branca元素直接传递给Marker,但弹出表没有显示。