-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
video_overlay.py
58 lines (45 loc) · 1.57 KB
/
video_overlay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
import json
from folium.map import Layer
from jinja2 import Template
class VideoOverlay(Layer):
"""
Used to load and display a video over the map.
Parameters
----------
video_url: URL of the video
bounds: list
Video bounds on the map in the form [[lat_min, lon_min],
[lat_max, lon_max]]
opacity: float, default Leaflet's default (1.0)
attr: string, default Leaflet's default ('')
"""
def __init__(self, video_url, bounds, opacity=1., attr=None,
autoplay=True, loop=True):
super(VideoOverlay, self).__init__()
self._name = 'VideoOverlay'
self.video_url = video_url
self.bounds = json.loads(json.dumps(bounds))
options = {
'opacity': opacity,
'attribution': attr,
'loop': loop,
'autoplay': autoplay,
}
self.options = json.dumps(options)
self._template = Template(u"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = L.videoOverlay(
'{{ this.video_url }}',
{{ this.bounds }},
{{ this.options }}
).addTo({{this._parent.get_name()}});
{% endmacro %}
""")
def _get_self_bounds(self):
"""
Computes the bounds of the object itself (not including it's children)
in the form [[lat_min, lon_min], [lat_max, lon_max]]
"""
return self.bounds