From 0bcd7641bde41b94a80a99daf2b9de5f2d48b5c3 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Sun, 2 Jun 2024 20:22:08 +0200 Subject: [PATCH] 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 d7f99594d..515b70194 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__()