Skip to content

Commit d73fa29

Browse files
committed
Add icon also via add_to and add_child
1 parent a53a7b7 commit d73fa29

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

folium/map.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ def __init__(
408408
# this attribute is not used by Marker, but by GeoJson
409409
self.icon = None
410410
if icon is not None:
411-
self.add_child(icon)
412-
self.icon = icon
411+
self.set_icon(icon)
413412
if popup is not None:
414413
self.add_child(popup if isinstance(popup, Popup) else Popup(str(popup)))
415414
if tooltip is not None:
@@ -434,6 +433,19 @@ def render(self):
434433
self.add_child(self.SetIcon(marker=self, icon=self.icon))
435434
super().render()
436435

436+
def set_icon(self, icon: Union[Icon, "CustomIcon", "DivIcon"]):
437+
"""Set the icon for this Marker"""
438+
super().add_child(icon)
439+
self.icon = icon
440+
441+
def add_child(self, child, name=None, index=None):
442+
import folium.features as features
443+
444+
if isinstance(child, (Icon, features.CustomIcon, features.DivIcon)):
445+
self.set_icon(child)
446+
else:
447+
super().add_child(child, name, index)
448+
437449

438450
class Popup(MacroElement):
439451
"""Create a Popup instance that can be linked to a Layer.

0 commit comments

Comments
 (0)