question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Markers only work with URLs

See original GitHub issue

It seems that custom markers only work with URLs and not local image files.

This works:

icon = folium.features.CustomIcon('http://www.pngall.com/wp-content/uploads/2016/05/Iron-Man.png', icon_size=(50,50))
folium.Marker([43, -79],
              popup='Iron Man',
              icon=icon
              ).add_to(geo_map)

This does not work:

icon = folium.features.CustomIcon('Iron-Man.png', icon_size=(50,50))
folium.Marker([43, -79],
              popup='Iron Man',
              icon=icon
              ).add_to(geo_map)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
davidolmocommented, Feb 26, 2019

Ok I see. It seems like the utility function that parses images for CustomIcon (image_to_url) no longer supports BytesIO format in the current version. However, it supports the path! (so it will transform the file automatically to Bytes for you). What I did is directly pass the path of the image:

icon_path = r"C:\some_path\icon.png" icon = folium.features.CustomIcon(icon_image=icon_path ,icon_size=icons_size)

marker=folium.Marker([row["coord"].y,row["coord"].x],popup=popup,icon=icon).add_to(feature_groups[alert_icon_name])

2reactions
dvu4commented, May 19, 2018

@nanodan this code will work with local image file.

import base64

encoded = base64.b64encode(open('Iron-Man.png', 'rb').read())
decoded = base64.b64decode(encoded)
icon_url = BytesIO(decoded)
icon = folium.features.CustomIcon(icon_url, icon_size=(50,50))
folium.Marker([43, -79],
              popup='Iron Man',
              icon=icon
              ).add_to(geo_map)

but for list of markers, the code only shows the first icon. 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Markers | Maps JavaScript API - Google Developers
This tutorial teaches you how to change the icon of a Google maps marker. It is beneficial to know the basics of creating...
Read more >
Add custom markers in Mapbox GL JS | Help
In this tutorial, you will learn how to build an interactive web map that adds custom markers at specified locations using Mapbox GL...
Read more >
Custom marker icons in Google Static Map URL don't show up
As this answer said: Static Maps service allows up to five unique custom icons per request. Note that each of these unique icons...
Read more >
link to url from marker click - mutiple markers - Google Groups
The goal is simple each marker on the map will have a different URL to link to when clicked. The information is in...
Read more >
Registering Custom Markers in PyTest - Numpy Ninja
Optionally specify a reason for better reporting and run=False if you don't even want to execute the tes t function. If only specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found