如何将folium.icon与fontawesome一起使用 [英] How to use folium.icon with fontawesome

查看:393
本文介绍了如何将folium.icon与fontawesome一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用自定义的字体图标thx.

我想使用字体很棒的图标从folium.icon更改图标.

例如,我要更改此内容:

     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
 

来自fontawesome的汉堡图标,如下所示:

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

但这对我不起作用!

非常感谢!!!!

解决方案

修订版

我先前的回答被忽略了此有关Folium和Leaflet的问题:添加了图标目前,Fontawesome v5中的 not 不会在Folium或Leaflet中进行渲染,而Folium则是从此叶上生成的.在实现后,作为Fontawesome v4一部分的字体(例如"truck")可以很好地工作.因此,您必须等待"hamburger"或在 Fontawesome v4列表中找到另一个标记起作用.

请记住,如果您不能这样做,则始终可以使用 Bootstrap图标作为替代方法通过Fontawesome找到您想要的东西.


下面提供的信息仅对Fontawesome v4.x图标有效

欢迎光临!您应该能够在对图标构造函数稍加修改的情况下呈现图标.在正常使用情况下,icon参数将指向Bootstrap中的标准 glyphicons .如果要使用Fontawesome图标,请在图标名称前添加前缀(例如,仅"hamburger"而不带"fa-"),然后为Fontawesome添加prefix关键字参数,即fa.

所以在您的情况下,它看起来像这样:

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

也请参见此问题.

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!!!!

解决方案

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.

这篇关于如何将folium.icon与fontawesome一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆