Skip to content

Commit 75cac11

Browse files
author
Martin Journois
committed
Fix test_terminator
1 parent bcf573e commit 75cac11

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

folium/plugins/terminator.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
66
Leaflet.Terminator is a simple plug-in to the Leaflet library to overlay day and night regions on maps.
77
"""
8-
try:
9-
from urllib.request import urlopen as _urlopen
10-
except:
11-
from urllib import urlopen as _urlopen
8+
from jinja2 import Template
129

13-
from .plugin import Plugin
10+
from folium.element import JavascriptLink, MacroElement, Figure
1411

15-
# As LO.Terminator.js is not served on both HTTP and HTTPS, we need to embed it explicitely into the code.
16-
_request = _urlopen("http://rawgithub.com/joergdietrich/Leaflet.Terminator/master/L.Terminator.js")
17-
assert _request.getcode()==200, "Error while loading Leaflet.terminator.js"
18-
_terminator_script = _request.read().decode('utf8')
19-
20-
class Terminator(Plugin):
12+
class Terminator(MacroElement):
2113
"""Leaflet.Terminator is a simple plug-in to the Leaflet library to overlay day and night regions on maps."""
2214
def __init__(self):
2315
"""Creates a Terminator plugin to append into a map with
@@ -27,12 +19,20 @@ def __init__(self):
2719
----------
2820
"""
2921
super(Terminator, self).__init__()
30-
self.plugin_name = 'Terminator'
22+
self._name = 'Terminator'
23+
24+
self._template = Template(u"""
25+
{% macro script(this, kwargs) %}
26+
L.terminator().addTo({{this._parent.get_name()}});
27+
{% endmacro %}
28+
""")
29+
def render(self,**kwargs):
30+
super(Terminator,self).render(**kwargs)
3131

32-
def render_header(self, nb):
33-
"""Generates the header part of the plugin."""
34-
return '<script type="text/javascript">'+_terminator_script+'</script>' if nb==0 else ""
32+
figure = self.get_root()
33+
assert isinstance(figure,Figure), ("You cannot render this Element "
34+
"if it's not in a Figure.")
3535

36-
def render_js(self, nb):
37-
"""Generates the Javascript part of the plugin."""
38-
return "L.terminator().addTo(map);" if nb==0 else ""
36+
figure.header.add_children(\
37+
JavascriptLink("https://rawgithub.com/joergdietrich/Leaflet.Terminator/master/L.Terminator.js"),
38+
name='markerclusterjs')

tests/test_plugins.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def test_marker_cluster(self):
3333

3434
def test_terminator(self):
3535
mapa = folium.Map([45., 3.], zoom_start=1)
36-
mapa.add_plugin(plugins.Terminator())
37-
mapa.add_plugin(plugins.ScrollZoomToggler())
38-
mapa._build_map()
36+
mapa.add_children(plugins.Terminator())
37+
mapa.add_children(plugins.ScrollZoomToggler())
38+
mapa._repr_html_()
3939

4040
def test_boat_marker(self):
4141
mapa = folium.Map([30., 0.], zoom_start=3)

0 commit comments

Comments
 (0)