folium icon indicating copy to clipboard operation
folium copied to clipboard

Adding multiple Custom Icon in Folium

Open shubham039 opened this issue 8 years ago • 7 comments

I am creating a Custom Icon in folium, and displaying it on a map, but when i try to add another coordinate with the same Icon, it fails.

import folium
map_osm = folium.Map(location=[45.3288, -121.6625])
icon_url = 'https://cdn1.iconfinder.com/data/icons/maps-locations-2/96/Geo2-Number-512.png'
icon = folium.features.CustomIcon(icon_url,icon_size=(28, 30))  # Creating a custom Icon
folium.Marker(location=[45.3288, -121.6625],icon=icon).add_to(map_osm)  #adding it to the map
map_osm

image

Now adding another location with the same icon

folium.Marker(location=[46.3288, -122.6625],icon=icon).add_to(map_osm)
map_osm

image

[The map_osm points to new location with its default icon, and the previous pin is removed.]

Expected Output should have been two map pins with the same icon.

folium.__version__ = '0.5.0'

shubham039 avatar Oct 12 '17 06:10 shubham039

I got this solved, it needs icon to be initialised everytime you add a marker.

icon = folium.features.CustomIcon(icon_url,icon_size=(28, 30))
folium.Marker(location=[46.3288, -122.6625],icon=icon).add_to(map_osm)
map_osm

shubham039 avatar Oct 12 '17 06:10 shubham039

When icon have to be initialised everytime we got huge file. It's a bug.

ninabel avatar Nov 09 '18 09:11 ninabel

I guess you're right @ninabel, do you want to look into this and open a PR? I'm thinking now we should let an element have multiple parents in a way, but render it only once. Or something.

Conengmo avatar Nov 09 '18 12:11 Conengmo

Was this ever addressed in another issue? Because I notice the bug mentioned above by @ninabel still persists.

hbarovertwo avatar Mar 22 '21 23:03 hbarovertwo

The bug is still persisting. It has not been solved yet. @hbarovertwo

hbshrestha avatar Jan 19 '22 21:01 hbshrestha

I managed to solved this problem by initiliasing the custom icon within a for loop. Example below:

df = {'Lat': [22.50, 63.21, -13.21, 33.46],
                'Lon': [43.91, -22.22, 77.11, 22.11],
                'Color': ['red', 'yellow', 'orange', 'blue']
              }
      

data = pd.DataFrame(df)

   world = folium.Map(
    zoom_start=2
    )

    x = data[['Lat', 'Lon', 'Color']].copy()

    for index, row in x.iterrows():
         pushpin = folium.features.CustomIcon('/content/drive/My Drive/Colab Notebooks/pushpin.png', icon_size=(30,30))
         folium.Marker([row['Lat'], row['Lon']],
                                    icon=pushpin,
                                    popup=row['Color'],
                                   ).add_to(world)


    world
Screenshot 2022-10-26 at 20 02 30

lowdowner avatar Oct 26 '22 19:10 lowdowner

Is this issue fix or is there a good work-around that does not load redundant copies of the same image, thus slowing the server?

MiusR avatar Apr 18 '24 13:04 MiusR