From 0bcd7641bde41b94a80a99daf2b9de5f2d48b5c3 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 2 Jun 2024 20:22:08 +0200 Subject: [PATCH 1/3] Correct typing annotations in Realtime 1. Realtime superclass in leaflet is GeoJson (which is a subclass of featuregroup). In Folium I cannot make Realtime a subclass of GeoJson since GeoJson requires features to be present before rendering. I made it a subclass of FeatureGroup to more clearly document that features can be added to a Realtime layer. 2. The container parameter for Realtime cannot just be any `L.Layer`. It must be a `FeatureGroup` or something that allows adding features. I created type annotations to reflect this on the Folium side. --- folium/plugins/realtime.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/folium/plugins/realtime.py b/folium/plugins/realtime.py index d7f99594da..515b701949 100644 --- a/folium/plugins/realtime.py +++ b/folium/plugins/realtime.py @@ -1,14 +1,14 @@ from typing import Optional, Union -from branca.element import MacroElement from jinja2 import Template from folium.elements import JSCSSMixin -from folium.map import Layer +from folium.features import GeoJson +from folium.map import FeatureGroup from folium.utilities import JsCode, camelize, parse_options -class Realtime(JSCSSMixin, MacroElement): +class Realtime(JSCSSMixin, FeatureGroup): """Put realtime data on a Leaflet map: live tracking GPS units, sensor data or just about anything. @@ -109,7 +109,7 @@ def __init__( get_feature_id: Union[JsCode, str, None] = None, update_feature: Union[JsCode, str, None] = None, remove_missing: bool = False, - container: Optional[Layer] = None, + container: Optional[Union[FeatureGroup, GeoJson]] = None, **kwargs ): super().__init__() From fa3fe548d65224568c83e594fb4db63582e176a4 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 16 Jun 2024 16:33:42 +0200 Subject: [PATCH 2/3] Based on review comments --- folium/plugins/realtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folium/plugins/realtime.py b/folium/plugins/realtime.py index 515b701949..7944e3fe10 100644 --- a/folium/plugins/realtime.py +++ b/folium/plugins/realtime.py @@ -42,7 +42,7 @@ class Realtime(JSCSSMixin, FeatureGroup): remove_missing: bool, default False Should missing features between updates been automatically removed from the layer - container: Layer, default GeoJson + container: FeatureGroup or GeoJson, default GeoJson The container will typically be a `FeatureGroup`, `MarkerCluster` or `GeoJson`, but it can be anything that generates a javascript L.LayerGroup object, i.e. something that has the methods From 064bfffdbd81e9bf5d16945d551d4632460892ac Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 16 Jun 2024 21:12:31 +0200 Subject: [PATCH 3/3] Try with explicit fiona import --- folium/plugins/beautify_icon.py | 4 ++-- requirements.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/folium/plugins/beautify_icon.py b/folium/plugins/beautify_icon.py index d45e9eb583..99a8e1e6cb 100644 --- a/folium/plugins/beautify_icon.py +++ b/folium/plugins/beautify_icon.py @@ -95,7 +95,7 @@ def __init__( inner_icon_style="", spin=False, number=None, - **kwargs + **kwargs, ): super().__init__() self._name = "BeautifyIcon" @@ -111,5 +111,5 @@ def __init__( spin=spin, isAlphaNumericIcon=number is not None, text=number, - **kwargs + **kwargs, ) diff --git a/requirements.txt b/requirements.txt index dff8e41f47..bebfd7dae9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ branca>=0.6.0 +fiona jinja2>=2.9 numpy requests