Skip to content

Commit

Permalink
Correct type annotations in Realtime (#1960)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
hansthen authored Jun 18, 2024
1 parent 721dfa1 commit 8bc6b02
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions folium/plugins/beautify_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(
inner_icon_style="",
spin=False,
number=None,
**kwargs
**kwargs,
):
super().__init__()
self._name = "BeautifyIcon"
Expand All @@ -111,5 +111,5 @@ def __init__(
spin=spin,
isAlphaNumericIcon=number is not None,
text=number,
**kwargs
**kwargs,
)
10 changes: 5 additions & 5 deletions folium/plugins/realtime.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -42,7 +42,7 @@ class Realtime(JSCSSMixin, MacroElement):
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
Expand Down Expand Up @@ -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__()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
branca>=0.6.0
fiona
jinja2>=2.9
numpy
requests
Expand Down

0 comments on commit 8bc6b02

Please sign in to comment.