From 20bafc32dc791d6aa6296886cf6aebe7d00137f7 Mon Sep 17 00:00:00 2001 From: Frank <33519926+Conengmo@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:49:25 +0100 Subject: [PATCH 1/4] fix geojson marker icon --- folium/map.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/folium/map.py b/folium/map.py index b10b27fae6..b9557b33f4 100644 --- a/folium/map.py +++ b/folium/map.py @@ -403,8 +403,11 @@ def __init__( self.options = remove_empty( draggable=draggable or None, autoPan=draggable or None, **kwargs ) + # this attribute is not used by Marker, but by GeoJson + self.icon: Optional[Icon] = None if icon is not None: self.add_child(icon) + self.icon = icon if popup is not None: self.add_child(popup if isinstance(popup, Popup) else Popup(str(popup))) if tooltip is not None: From 4d06b527db8e897a188c7349dcaa23b1c37fbe5e Mon Sep 17 00:00:00 2001 From: Frank <33519926+Conengmo@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:52:34 +0100 Subject: [PATCH 2/4] mypy --- folium/map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folium/map.py b/folium/map.py index b9557b33f4..7163784211 100644 --- a/folium/map.py +++ b/folium/map.py @@ -404,7 +404,7 @@ def __init__( draggable=draggable or None, autoPan=draggable or None, **kwargs ) # this attribute is not used by Marker, but by GeoJson - self.icon: Optional[Icon] = None + self.icon: Union[Icon, "CustomIcon", "DivIcon", None] = None if icon is not None: self.add_child(icon) self.icon = icon From 89d1a0b32484673b23bc659b190c8181e208acd5 Mon Sep 17 00:00:00 2001 From: Frank <33519926+Conengmo@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:57:02 +0100 Subject: [PATCH 3/4] ruff --- folium/map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folium/map.py b/folium/map.py index 7163784211..83bacd42cf 100644 --- a/folium/map.py +++ b/folium/map.py @@ -404,7 +404,7 @@ def __init__( draggable=draggable or None, autoPan=draggable or None, **kwargs ) # this attribute is not used by Marker, but by GeoJson - self.icon: Union[Icon, "CustomIcon", "DivIcon", None] = None + self.icon = None if icon is not None: self.add_child(icon) self.icon = icon From df180b306d7ce50a2a5956ca6258f46995b8f54e Mon Sep 17 00:00:00 2001 From: Hans Then Date: Wed, 26 Feb 2025 21:44:38 +0100 Subject: [PATCH 4/4] After review comments --- folium/map.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/folium/map.py b/folium/map.py index 83bacd42cf..e922906713 100644 --- a/folium/map.py +++ b/folium/map.py @@ -424,15 +424,12 @@ def _get_self_bounds(self) -> TypeBoundsReturn: return cast(TypeBoundsReturn, [self.location, self.location]) def render(self): - from .features import CustomIcon, DivIcon - if self.location is None: raise ValueError( f"{self._name} location must be assigned when added directly to map." ) - for child in list(self._children.values()): - if isinstance(child, (Icon, CustomIcon, DivIcon)): - self.add_child(self.SetIcon(marker=self, icon=child)) + if self.icon: + self.add_child(self.SetIcon(marker=self, icon=self.icon)) super().render()