diff --git a/folium/map.py b/folium/map.py index 95d7fa7786..62bdf50ad8 100644 --- a/folium/map.py +++ b/folium/map.py @@ -347,6 +347,8 @@ class Icon(MacroElement): 'darkpurple', 'white', 'pink', 'lightblue', 'lightgreen', 'gray', 'black', 'lightgray'] + or a hex color code such as '#00A6A6'. + icon_color : str, default 'white' The color of the drawing on the marker. You can use colors above, or an html color code. @@ -377,25 +379,24 @@ class Icon(MacroElement): {% macro header(this, kwargs) %} {% if this.is_hex %} {% endif %} @@ -436,7 +437,9 @@ def __init__( self._name = "Icon" # 1. Determine if the input is a hex color - self.is_hex = color.startswith("#") and len(color) in (4, 7) + self.is_hex = ( + isinstance(color, str) and color.startswith("#") and len(color) in (4, 7) + ) self.color = color # 2. Strip the '#' for the CSS class name generation diff --git a/tests/test_map.py b/tests/test_map.py index 551ffb2b3d..ad8d20c098 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -287,6 +287,18 @@ def test_marker_numpy_array_as_location(): Marker(np.array([0, 0])) +def test_icon_hex_marker_color(): + with warnings.catch_warnings(): + warnings.simplefilter("error") + icon = Icon(color="#00A6A6") + assert icon.options["marker_color"] == "00A6A6" + header = normalize(icon._template.module.header(this=icon, kwargs={})) + # The pin is drawn on a pseudo-element: Leaflet's inline transform on the + # marker element would override a rotation set on the element itself. + assert ".awesome-marker-icon-00A6A6::before {" in header + assert "background-color: #00A6A6;" in header + + @pytest.mark.filterwarnings("ignore::UserWarning") def test_icon_invalid_marker_colors(): pytest.warns(UserWarning, Icon, color="lila")