Skip to content

Commit

Permalink
Correct typing annotations in Realtime
Browse files Browse the repository at this point in the history
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 committed Jun 2, 2024
1 parent 5086929 commit 0bcd764
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 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 @@ -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

0 comments on commit 0bcd764

Please sign in to comment.