Skip to content

Commit 8bc6b02

Browse files
authored
Correct type annotations in Realtime (#1960)
* 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.
1 parent 721dfa1 commit 8bc6b02

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

folium/plugins/beautify_icon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(
9595
inner_icon_style="",
9696
spin=False,
9797
number=None,
98-
**kwargs
98+
**kwargs,
9999
):
100100
super().__init__()
101101
self._name = "BeautifyIcon"
@@ -111,5 +111,5 @@ def __init__(
111111
spin=spin,
112112
isAlphaNumericIcon=number is not None,
113113
text=number,
114-
**kwargs
114+
**kwargs,
115115
)

folium/plugins/realtime.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from typing import Optional, Union
22

3-
from branca.element import MacroElement
43
from jinja2 import Template
54

65
from folium.elements import JSCSSMixin
7-
from folium.map import Layer
6+
from folium.features import GeoJson
7+
from folium.map import FeatureGroup
88
from folium.utilities import JsCode, camelize, parse_options
99

1010

11-
class Realtime(JSCSSMixin, MacroElement):
11+
class Realtime(JSCSSMixin, FeatureGroup):
1212
"""Put realtime data on a Leaflet map: live tracking GPS units,
1313
sensor data or just about anything.
1414
@@ -42,7 +42,7 @@ class Realtime(JSCSSMixin, MacroElement):
4242
remove_missing: bool, default False
4343
Should missing features between updates been automatically
4444
removed from the layer
45-
container: Layer, default GeoJson
45+
container: FeatureGroup or GeoJson, default GeoJson
4646
The container will typically be a `FeatureGroup`, `MarkerCluster` or
4747
`GeoJson`, but it can be anything that generates a javascript
4848
L.LayerGroup object, i.e. something that has the methods
@@ -109,7 +109,7 @@ def __init__(
109109
get_feature_id: Union[JsCode, str, None] = None,
110110
update_feature: Union[JsCode, str, None] = None,
111111
remove_missing: bool = False,
112-
container: Optional[Layer] = None,
112+
container: Optional[Union[FeatureGroup, GeoJson]] = None,
113113
**kwargs
114114
):
115115
super().__init__()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
branca>=0.6.0
2+
fiona
23
jinja2>=2.9
34
numpy
45
requests

0 commit comments

Comments
 (0)