MCPcopy
hub / github.com/python-visualization/folium / Realtime

Class Realtime

folium/plugins/realtime.py:10–118  ·  view source on GitHub ↗

Put realtime data on a Leaflet map: live tracking GPS units, sensor data or just about anything. Based on: https://github.com/perliedman/leaflet-realtime Parameters ---------- source: str, dict, JsCode The source can be one of: * a string with the URL to get da

Source from the content-addressed store, hash-verified

8
9
10class Realtime(JSCSSMixin, FeatureGroup):
11 """Put realtime data on a Leaflet map: live tracking GPS units,
12 sensor data or just about anything.
13
14 Based on: https://github.com/perliedman/leaflet-realtime
15
16 Parameters
17 ----------
18 source: str, dict, JsCode
19 The source can be one of:
20
21 * a string with the URL to get data from
22 * a dict that is passed to javascript's `fetch` function
23 for fetching the data
24 * a `folium.JsCode` object in case you need more freedom.
25 start: bool, default True
26 Should automatic updates be enabled when layer is added
27 on the map and stopped when layer is removed from the map
28 interval: int, default 60000
29 Automatic update interval, in milliseconds
30 get_feature_id: str or JsCode, optional
31 A JS function with a geojson `feature` as parameter
32 default returns `feature.properties.id`
33 Function to get an identifier to uniquely identify a feature over time
34 update_feature: str or JsCode, optional
35 A JS function with a geojson `feature` as parameter
36 Used to update an existing feature's layer;
37 by default, points (markers) are updated, other layers are discarded
38 and replaced with a new, updated layer.
39 Allows to create more complex transitions,
40 for example, when a feature is updated
41 remove_missing: bool, default False
42 Should missing features between updates been automatically
43 removed from the layer
44 container: FeatureGroup or GeoJson, default GeoJson
45 The container will typically be a `FeatureGroup`, `MarkerCluster` or
46 `GeoJson`, but it can be anything that generates a javascript
47 L.LayerGroup object, i.e. something that has the methods
48 `addLayer` and `removeLayer`.
49
50 Other keyword arguments are passed to the GeoJson layer, so you can pass
51 `style`, `point_to_layer` and/or `on_each_feature`. Make sure to wrap
52 Javascript functions in the JsCode class.
53
54 Examples
55 --------
56 >>> from folium import JsCode
57 >>> m = folium.Map(location=[40.73, -73.94], zoom_start=12)
58 >>> rt = Realtime(
59 ... "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/subway_stations.geojson",
60 ... get_feature_id=JsCode("(f) => { return f.properties.objectid; }"),
61 ... point_to_layer=JsCode(
62 ... "(f, latlng) => { return L.circleMarker(latlng, {radius: 8, fillOpacity: 0.2})}"
63 ... ),
64 ... interval=10000,
65 ... )
66 >>> rt.add_to(m)
67 """

Callers 1

test_realtimeFunction · 0.90

Calls 1

TemplateClass · 0.90

Tested by 1

test_realtimeFunction · 0.72