0

I saw an example to add numbers inside markers using plugins.BeautifyIcon here - Folium markers with numbers inside.

But I need an alternate solution to add numbers without using plugins.BeautifyIcon.

import folium
from folium.plugins import MarkerCluster


m = folium.Map(location=[44, -73], zoom_start=5)

marker_cluster = MarkerCluster().add_to(m)


folium.Marker(
    location=[40.67, -73.94],
    popup="Add popup text here.",
    icon=folium.Icon(color="green", icon="", prefix='fa'),
).add_to(marker_cluster)

folium.Marker(
    location=[44.67, -73.94],
    popup="Add popup text here.",
    icon=folium.Icon(color="red", icon="", prefix='fa'),
).add_to(marker_cluster)

folium.Marker(
    location=[44.67, -71.94],
    popup="Add popup text here.",
    icon=folium.Icon(color="blue", icon="", prefix='fa'),
).add_to(marker_cluster)

m

enter image description here

Is it possible to customize the marker styles and add numbers inside like the below examples??

enter image description here

enter image description here

Ailurophile
  • 2,552
  • 7
  • 21
  • 46

1 Answers1

0

The following works for numbers from 0 to 9

As described in the documentation, icon style can be picked from bootstrap or, when using prefix=fa, also from fontawesome (see example below)

m = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles="Stamen Terrain")

folium.Marker(
    location=[45.3288, -121.6625],
    popup="Mt. Hood Meadows",
    icon=folium.Icon(icon='1', prefix='fa'),  # choose your fontawesome icon style like this
).add_to(m)

folium.Marker(
    location=[45.3288, -121.7625],
    popup="Mt. Hood Meadows",
    icon=folium.Icon(icon='2', prefix='fa', color='red'),  # choose your fontawesome icon style like this
).add_to(m)

m

map

With your code snippet:

map from your code

flipSTAR
  • 579
  • 1
  • 4
  • 18
  • `bootstrap icon style` didn't work for me. Blank marker – Ailurophile Feb 14 '23 at 16:44
  • I understand your problem - It seems to be just a subset of the bootstrap icons, sorry for that. I corrected the bootstrap link and removed the non working example. Added the resulting map from the fontawesome example, hope that will help. – flipSTAR Feb 15 '23 at 08:36
  • `folium.Icon(icon='2', prefix='fa', color='red')` still blank marker – Ailurophile Feb 15 '23 at 17:03
  • If I use the code from your question and add the numbers to icon (eg icon="2") it shows the numbers. Which folium version do you use? I am with 0.14.0 – flipSTAR Feb 16 '23 at 08:39
  • yeah upgrading helps, i was on folium-0.12.1.post1 version $ pip install folium --upgrade – Mantej Singh Jun 26 '23 at 19:07