Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct type annotations in Realtime #1960

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
hansthen committed Jun 2, 2024
commit 0bcd7641bde41b94a80a99daf2b9de5f2d48b5c3
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.

@@ -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,
hansthen marked this conversation as resolved.
Show resolved Hide resolved
**kwargs
):
super().__init__()