Search code examples
pythonfolium

Folium unable to add multiple points with "same" icon


I'm having trouble adding multiple markers with same icon style in folium.

First I declared icon:

icon_blue = folium.Icon(color='blue', icon_color='white', icon='info-sign')

Later on I wrote

folium.Marker(
    location=latlng_start,
    popup=text_start,
    tooltip=text_start,
    name=text_start,
    icon=icon_blue,
).add_to(map1)

folium.Marker(
    location=latlng_end,
    popup=text_end,
    tooltip=text_end,
    name=text_end,
    icon=icon_blue,
).add_to(map1)

And when I do this, I get output like:

enter image description here

Basically, a singleton point, with no tooltip or any data attached to it.

The issue disappears when I delete icon=icon_blue but it also disappears if I make a copy of icon_blue:

icon_blue_copy = folium.Icon(color='blue', icon_color='white', icon='info-sign')

And then for the second one write:

folium.Marker(
    location=latlng_end,
    popup=text_end,
    tooltip=text_end,
    name=text_end,
    icon=icon_blue_copy,
).add_to(map1)

To get desired output

enter image description here

The problem is, why do I need to make these copies? is this some sort of Folium bug, or is this something to do with python?


Solution

  • Instead of defining,

    icon_blue = folium.Icon(color='blue', icon_color='white', icon='info-sign')
    

    setting the icon inside the marker as,

    folium.Marker(
      location=latlng_end,
      popup=text_end,
      tooltip=text_end,
      name=text_end,
      icon=folium.Icon(color='blue', 
                       icon_color='white', 
                       icon='info-sign')
    ).add_to(map1)
    

    worked for me.