Folium 中的自定义图标

问题描述 投票:0回答:0

Code sample

icons = {
    'church': folium.Icon(color='green', icon= 'church', prefix='fa'),
    'synagogue': folium.Icon(color='purple', icon='star-of-david', prefix='fa'), 
    'transport': folium.Icon(color='blue', icon='bus', prefix='fa')
}

melbourne_map = folium.Map(location=[-37.8136, 144.9631], zoom_start=13, width='100%', height='100%')

# Loop through each row in the dataframe
for index, row in combined_df_cleaned.iterrows(): 
    # Get the Landmark type for the current row 
    landmark_type = row['Landmark']
    for key, value in icons.items(): 
        if landmark_type.lower() == key.lower():
            icon = value 
            break
    
    marker = folium.Marker(
        location=[row['latitude'], row['longitude']],
        icon=icon, # Use the icon corresponding to the current Landmark type 
        popup=folium.Popup(
            f"Name: {row['name']}<br>Description: {row['description']}<br>Artist: {row['artist']}<br>Year: {row['year']}",
            max_width=400,
            style={
                'font-size': '16px',
                'line-height': '1.6',
                'padding': '10px'
            }))

    marker.add_to (melbourne_map)

# Display the map
melbourne_map

地图图片 Map Image

我正在尝试使用自定义图标,但是当我使用 icon= icon 时我没有看到任何标记,当我从代码中删除这一行时,我看到了所有标记。

Map Markers

我想看到教堂、犹太教堂等的图标,而不是蓝色标记

python pandas mapping folium
© www.soinside.com 2019 - 2024. All rights reserved.