@@ -275,7 +275,6 @@ class Icon(MacroElement):
275
275
var {{ this.get_name() }} = L.AwesomeMarkers.icon(
276
276
{{ this.options|tojavascript }}
277
277
);
278
- {{ this._parent.get_name() }}.setIcon({{ this.get_name() }});
279
278
{% endmacro %}
280
279
"""
281
280
)
@@ -341,7 +340,7 @@ class Marker(MacroElement):
341
340
folium.Popup or a folium.Popup instance.
342
341
tooltip: str or folium.Tooltip, default None
343
342
Display a text when hovering over the object.
344
- icon: Icon plugin
343
+ icon: Icon, CustomIcon or DivIcon, optional
345
344
the Icon plugin to use to render the marker.
346
345
draggable: bool, default False
347
346
Set to True to be able to drag the marker around the map.
@@ -372,6 +371,23 @@ class Marker(MacroElement):
372
371
"""
373
372
)
374
373
374
+ class SetIcon (MacroElement ):
375
+ """Set the icon of a marker after both are created."""
376
+
377
+ _template = Template (
378
+ """
379
+ {% macro script(this, kwargs) %}
380
+ {{ this.marker.get_name() }}.setIcon({{ this.icon.get_name() }});
381
+ {% endmacro %}
382
+ """
383
+ )
384
+
385
+ def __init__ (self , marker : "Marker" , icon : "Icon" ):
386
+ super ().__init__ ()
387
+ self ._name = "SetIcon"
388
+ self .marker = marker
389
+ self .icon = icon
390
+
375
391
def __init__ (
376
392
self ,
377
393
location : Optional [Sequence [float ]] = None ,
@@ -389,7 +405,6 @@ def __init__(
389
405
)
390
406
if icon is not None :
391
407
self .add_child (icon )
392
- self .icon = icon
393
408
if popup is not None :
394
409
self .add_child (popup if isinstance (popup , Popup ) else Popup (str (popup )))
395
410
if tooltip is not None :
@@ -406,10 +421,15 @@ def _get_self_bounds(self) -> TypeBoundsReturn:
406
421
return cast (TypeBoundsReturn , [self .location , self .location ])
407
422
408
423
def render (self ):
424
+ from .features import CustomIcon , DivIcon
425
+
409
426
if self .location is None :
410
427
raise ValueError (
411
428
f"{ self ._name } location must be assigned when added directly to map."
412
429
)
430
+ for child in list (self ._children .values ()):
431
+ if isinstance (child , (Icon , CustomIcon , DivIcon )):
432
+ self .add_child (self .SetIcon (marker = self , icon = child ))
413
433
super ().render ()
414
434
415
435
0 commit comments