Peter Hoffmann: beautiful leaflet markers with folium and fontawesome :

Peter Hoffmann: beautiful leaflet markers with folium and fontawesome
by:
blow post content copied from  Planet Python
click here to view original post


Folium is a Python library that allows users to create and display interactive maps. The library uses the Leaflet.js library and is capable of creating powerful and visually appealing maps. Folium can be used to visualize geographical data by adding markers, polygons, heatmaps, and other geographical elements onto a map. The library is easy to use and offers a range of options for customizing the maps and the elements that are displayed on them.

Minimal marker

The minimal example just adds a marker at a specific location:

import folium
loc = [45.957916666667, 7.8123888888889]


m = folium.Map(location=loc, zoom_start=13)

folium.Marker(
    location=loc
).add_to(m)
m

Marker with a bootstrap icon

Markers can be customized through providing a Icon instance. As a default you can use bootstrap glyphicons that provide over 250 glyphs for free:

In addition you can colorize the marker. Available color names are red blue green purple orange darkred lightred beige darkblue darkgreen cadetblue darkpurple white pink lightblue lightgreen gray black lightgray .

m = folium.Map(location=loc)

folium.Marker(
    location=loc, 
    icon=folium.Icon(icon="home", 
                     color="purple",
                     icon_color="blue")
).add_to(m)

Marker with a fonteawesome icon

Font Awesome is a collection of scalable vector icons that can be customized and used in a variety of ways, such as in graphic design projects, websites, and applications. The icons are available in different styles, including Solid, Regular, and Brands, and can be easily integrated by adding the fa prefix

m = folium.Map(location=loc)
folium.Marker(
    location=loc,
    icon=folium.Icon(icon="tents", prefix='fa')
).add_to(m)

Extended Marker Customization with BeautifulIcons

The Leaflet Beautiful Icons is lightweight plugin that adds colorful iconic markers without images for Leaflet by giving full control of style to end user ( i.e. unlimited colors and many more...).

It ist exposed to folium via the Beautiful Icon plugin

Supported icon shapes are circle circle-dot doughnut rectangle rectangle-dot marker and the color be either one of the predefined or any valid hex code.

import folium.plugins as plugins

folium.Marker(
    location=loc,
    icon=plugins.BeautifyIcon(
                     icon="tent",
                     icon_shape="circle",
                     border_color='purple',
                     text_color="#007799",
                     background_color='yellow'
                 )
).add_to(m)


December 04, 2022 at 05:30AM
Click here for more details...

=============================
The original post is available in Planet Python by
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce