folium 绘制星形标记

folium draw star marker

我正在考虑在 folium 地图上绘制三个不同的标记:正方形、圆形和星形。 前两个是使用 BeautifyIcon 插件完成的。我在绘制星星时遇到了麻烦。 我想只画星星而不画别针。有什么建议吗?

import folium

# Make an empty map
m = folium.Map(location=[15, 0], tiles="OpenStreetMap", zoom_start=2)

# square marker
icon_square = folium.plugins.BeautifyIcon(
    icon_shape='rectangle-dot', 
    border_color='red', 
    border_width=10,
)
folium.Marker([50, -70], tooltip='square', icon=icon_square).add_to(m)

# circle marker
icon_circle = folium.plugins.BeautifyIcon(
    icon_shape='circle-dot', 
    border_color='green', 
    border_width=10,
)
folium.Marker([-20, 25], tooltip='circle', icon=icon_circle).add_to(m)

# star marker
icon_star = folium.Icon(
    prefix='fa', 
    icon='star', 
    icon_color='blue',
)
folium.Marker([60, 125], tooltip='star', icon=icon_star).add_to(m)


m.save('markers_on_folium_map.html')

只需努力 BeautifyIcon options 就可以满足您的需求:

import folium
from folium.plugins import BeautifyIcon

# Make an empty map
m = folium.Map(location=[15, 0], tiles="OpenStreetMap", zoom_start=2)

# square marker
icon_square = BeautifyIcon(
    icon_shape='rectangle-dot', 
    border_color='red', 
    border_width=10,
)
folium.Marker([50, -70], tooltip='square', icon=icon_square).add_to(m)

# circle marker
icon_circle = BeautifyIcon(
    icon_shape='circle-dot', 
    border_color='green', 
    border_width=10,
)
folium.Marker([-20, 25], tooltip='circle', icon=icon_circle).add_to(m)

# star marker
icon_star = BeautifyIcon(
    icon='star',
    inner_icon_style='color:blue;font-size:30px;',
    background_color='transparent',
    border_color='transparent',
)

folium.Marker([60, 125], tooltip='star', icon=icon_star).add_to(m)

m.save('markers_on_folium_map.html')

你得到: