Is is possible to use Font Awesome icons in Mapbox Markers?

混江龙づ霸主 提交于 2019-12-21 21:13:12

问题


I'm using the Maki set of icons, but they are very limited and would like to be able to use Font Awesome icons. Is this possible?

Here's the code I'm using to set up the marker icons.

marker.setIcon(L.mapbox.marker.icon({
    'title': jobid,
    'marker-color': '#e32f2f',
    'marker-symbol': 'square'
}));

回答1:


If you've included the font awesome CSS on your page, you can use the L.DivIcon constructor to create custom icon.

<style>
/*
 * Unlike other icons, you can style `L.divIcon` instances with CSS.
 * These styles make each marker a circle with a border and centered
 * text
 */
.fa-icon {color: red;}
</style>
<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
    .setView([45.52245801087795, -122.67773866653444], 3);

L.marker([45.52245801087795, -122.67773866653444], {
    icon: L.divIcon({
        // specify a class name that we can refer to in styles, as we
        // do above.
        className: 'fa-icon',
        // html here defines what goes in the div created for each marker
        html: '<i class="fa fa-camera-retro fa-3x"></i>',
        // and the marker width and height
        iconSize: [40, 40]
    })
}).addTo(map);

Here's a full example: http://jsbin.com/tiyote/1/




回答2:


Thanks for the help. Based on your example I was able to update my original code to use L.divIcon instead of L.mapbox.marker.icon.

marker.setIcon(L.divIcon({
    className: 'count-icon-emergency',
    html: '<i class="fa fa-check"></i>',
    iconSize: [40, 40]
}));


来源:https://stackoverflow.com/questions/24897823/is-is-possible-to-use-font-awesome-icons-in-mapbox-markers

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