How to use folium.icon with fontawesome

99封情书 提交于 2020-02-25 12:53:06

问题


I am looking to use a custom fontawesome icon, thx.

I would like to change the icon from folium.icon using fontawesome icons.

For example, I want to change this:

    import folium

    m = folium.Map(location=(25.0431, 121.539723), zoom_start=12,tiles='Cartodb Positron')

    folium.Marker(
        location=[25.0431, 121.539723], 
        icon=folium.Icon(color="red",icon="fa-truck", prefix='fa')).add_to(m)

    m

To a burger icon from fontawesome as shown below:

    folium.Marker(
        location=[25.0431, 121.539723], 
        icon=folium.Icon(color="red",icon="fa-hamburger", prefix='fa')).add_to(m)

But it does not work for me!

Many thanks!!!!


回答1:


Revised

My earlier response neglected this issue with Folium and Leaflet: icons added in Fontawesome v5 do not currently render in Folium or Leaflet, upon which Folium is derived. Fonts that were part of Fontawesome v4, such as "truck" work just fine as you implemented. So you'll have to wait on "hamburger" or find another marker in the Fontawesome v4 list that does work.

Remember, you can always use Bootstrap icons as an alternative if you can't find what you want with Fontawesome.


The info provided below only valid for Fontawesome v4.x icons

Welcome! You should be able to render the icon with a slight modification to your icon constructor. In normal usage, the icon argument will point to standard glyphicons from Bootstrap. If you want to use Fontawesome icons, you put in the icon's name without the prefix (e.g. just "hamburger" without "fa-" in front), then add the prefix keyword argument for Fontawesome, which is fa.

So in your case it would look like this:

folium.Marker(
    location=[25.0431, 121.539723], 
    icon=folium.Icon(color="red",icon="hamburger", prefix='fa')
).add_to(m)

See this question as well.



来源:https://stackoverflow.com/questions/58607693/how-to-use-folium-icon-with-fontawesome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!