Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multiple Custom Icon in Folium #744

Open
shubham039 opened this issue Oct 12, 2017 · 7 comments · May be fixed by #2119
Open

Adding multiple Custom Icon in Folium #744

shubham039 opened this issue Oct 12, 2017 · 7 comments · May be fixed by #2119

Comments

@shubham039
Copy link

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
Copy link
Author

shubham039 commented Oct 12, 2017

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

@ninabel
Copy link

ninabel commented Nov 9, 2018

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

@Conengmo
Copy link
Member

Conengmo commented Nov 9, 2018

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.

@hbarovertwo
Copy link

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

@hbshrestha
Copy link

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

@lowdowner
Copy link

lowdowner commented Oct 26, 2022

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

@MiusR
Copy link

MiusR commented Apr 18, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants