MCPcopy Create free account
hub / github.com/python-visualization/folium / Timeline

Class Timeline

folium/plugins/timeline.py:12–128  ·  view source on GitHub ↗

Create a layer from GeoJSON with time data to add to a map. To add time data, you need to do one of the following: * Add a 'start' and 'end' property to each feature. The start and end can be any comparable item. Alternatively, you can provide a `get_interval` function.

Source from the content-addressed store, hash-verified

10
11
12class Timeline(GeoJson):
13 """
14 Create a layer from GeoJSON with time data to add to a map.
15
16 To add time data, you need to do one of the following:
17
18 * Add a 'start' and 'end' property to each feature. The start and end
19 can be any comparable item.
20
21 Alternatively, you can provide a `get_interval` function.
22
23 * This function should be a JsCode object and take as parameter
24 a GeoJson feature and return a dict containing values for
25 'start', 'end', 'startExclusive' and 'endExcusive' (or false if no
26 data could be extracted from the feature).
27 * 'start' and 'end' can be any comparable items
28 * 'startExclusive' and 'endExclusive' should be boolean values.
29
30 Parameters
31 ----------
32 data: file, dict or str.
33 The geojson data you want to plot.
34
35 get_interval: JsCode, optional
36 Called for each feature, and should return either a time range for the
37 feature or `false`, indicating that it should not be included in the
38 timeline. The time range object should have 'start' and 'end' properties.
39 Optionally, the boolean keys 'startExclusive' and 'endExclusive' allow the
40 interval to be considered exclusive.
41
42 If `get_interval` is not provided, 'start' and 'end' properties are
43 assumed to be present on each feature.
44
45 Examples
46 --------
47 >>> from folium.plugins import Timeline, TimelineSlider
48 >>> m = folium.Map()
49
50 >>> data = requests.get(
51 ... "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson"
52 ... ).json()
53
54 >>> timeline = Timeline(
55 ... data,
56 ... get_interval=JsCode(
57 ... '''
58 ... function (quake) {
59 ... // earthquake data only has a time, so we\'ll use that as a "start"
60 ... // and the "end" will be that + some value based on magnitude
61 ... // 18000000 = 30 minutes, so a quake of magnitude 5 would show on the
62 ... // map for 150 minutes or 2.5 hours
63 ... return {
64 ... start: quake.properties.time,
65 ... end: quake.properties.time + quake.properties.mag * 1800000,
66 ... };
67 ... };
68 ... '''
69 ... ),

Callers

nothing calls this directly

Calls 1

TemplateClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…