1
- from typing import Optional , Union
1
+ from typing import Union
2
2
3
3
from branca .element import MacroElement
4
4
from jinja2 import Template
@@ -27,11 +27,11 @@ class Realtime(JSCSSMixin, MacroElement):
27
27
on the map and stopped when layer is removed from the map
28
28
interval: int, default 60000
29
29
Automatic update interval, in milliseconds
30
- get_feature_id: JsCode, optional
30
+ get_feature_id: str or JsCode, optional
31
31
A JS function with a geojson `feature` as parameter
32
32
default returns `feature.properties.id`
33
33
Function to get an identifier to uniquely identify a feature over time
34
- update_feature: JsCode, optional
34
+ update_feature: str or JsCode, optional
35
35
A JS function with a geojson `feature` as parameter
36
36
Used to update an existing feature's layer;
37
37
by default, points (markers) are updated, other layers are discarded
@@ -44,7 +44,8 @@ class Realtime(JSCSSMixin, MacroElement):
44
44
45
45
46
46
Other keyword arguments are passed to the GeoJson layer, so you can pass
47
- `style`, `point_to_layer` and/or `on_each_feature`.
47
+ `style`, `point_to_layer` and/or `on_each_feature`. Make sure to wrap
48
+ Javascript functions in the JsCode class.
48
49
49
50
Examples
50
51
--------
@@ -95,8 +96,8 @@ def __init__(
95
96
source : Union [str , dict , JsCode ],
96
97
start : bool = True ,
97
98
interval : int = 60000 ,
98
- get_feature_id : Optional [JsCode ] = None ,
99
- update_feature : Optional [JsCode ] = None ,
99
+ get_feature_id : Union [JsCode , str , None ] = None ,
100
+ update_feature : Union [JsCode , str , None ] = None ,
100
101
remove_missing : bool = False ,
101
102
** kwargs
102
103
):
@@ -107,9 +108,9 @@ def __init__(
107
108
kwargs ["start" ] = start
108
109
kwargs ["interval" ] = interval
109
110
if get_feature_id is not None :
110
- kwargs ["get_feature_id" ] = get_feature_id
111
+ kwargs ["get_feature_id" ] = JsCode ( get_feature_id )
111
112
if update_feature is not None :
112
- kwargs ["update_feature" ] = update_feature
113
+ kwargs ["update_feature" ] = JsCode ( update_feature )
113
114
kwargs ["remove_missing" ] = remove_missing
114
115
115
116
# extract JsCode objects
0 commit comments