@@ -382,7 +382,9 @@ class SetIcon(MacroElement):
382382 """
383383 )
384384
385- def __init__ (self , marker : "Marker" , icon : "Icon" ):
385+ def __init__ (
386+ self , marker : "Marker" , icon : Union [Icon , "CustomIcon" , "DivIcon" ]
387+ ):
386388 super ().__init__ ()
387389 self ._name = "SetIcon"
388390 self .marker = marker
@@ -406,8 +408,7 @@ def __init__(
406408 # this attribute is not used by Marker, but by GeoJson
407409 self .icon = None
408410 if icon is not None :
409- self .add_child (icon )
410- self .icon = icon
411+ self .set_icon (icon )
411412 if popup is not None :
412413 self .add_child (popup if isinstance (popup , Popup ) else Popup (str (popup )))
413414 if tooltip is not None :
@@ -432,6 +433,19 @@ def render(self):
432433 self .add_child (self .SetIcon (marker = self , icon = self .icon ))
433434 super ().render ()
434435
436+ def set_icon (self , icon ):
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+
435449
436450class Popup (MacroElement ):
437451 """Create a Popup instance that can be linked to a Layer.
0 commit comments