Skip to content

Commit 121508a

Browse files
author
Martin Journois
committed
Fix test_scroll_zoom_toggler
1 parent 859d7b8 commit 121508a

2 files changed

Lines changed: 53 additions & 47 deletions

File tree

folium/plugins/scroll_zoom_toggler.py

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,54 @@
55
66
Adds a button to enable/disable zoom scrolling.
77
"""
8-
from .template_plugin import TemplatePlugin
9-
10-
class ScrollZoomToggler(TemplatePlugin):
11-
"""Adds a button to enable/disable zoom scrolling."""
12-
template = """
13-
{% set plugin_name = "ScrollZoomToggler" %}
14-
{% macro css(nb) %}
15-
#ScrollZoomToggler_{{nb}} {
16-
position:absolute;
17-
width:35px;
18-
bottom:10px;
19-
height:35px;
20-
left:10px;
21-
background-color:#fff;
22-
text-align:center;
23-
line-height:35px;
24-
vertical-align: middle;
25-
}
26-
{% endmacro %}
27-
28-
{% macro html(nb) %}
29-
<img id="ScrollZoomToggler_{{nb}}" alt="scroll"
30-
src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/1.5.2/png/512/arrow-move.png"
31-
onclick="toggleScroll()"></img>
32-
{% endmacro %}
33-
34-
{% macro js(nb) %}
35-
{% if nb==0 %}
36-
map.scrollEnabled = true;
37-
38-
var toggleScroll = function() {
39-
if (map.scrollEnabled) {
40-
map.scrollEnabled = false;
41-
map.scrollWheelZoom.disable();
42-
}
43-
else {
44-
map.scrollEnabled = true;
45-
map.scrollWheelZoom.enable();
46-
}
47-
};
48-
49-
toggleScroll();
50-
{% endif %}
51-
{% endmacro %}
52-
"""
8+
from jinja2 import Template
9+
10+
from folium.element import MacroElement, Figure, Element
11+
12+
class ScrollZoomToggler(MacroElement):
13+
def __init__(self):
14+
"""TODO docstring here.
15+
"""
16+
super(ScrollZoomToggler, self).__init__()
17+
self._name = 'ScrollZoomToggler'
18+
19+
self._template = Template("""
20+
{% macro header(this,kwargs) %}
21+
<style>
22+
#{{this.get_name()}} {
23+
position:absolute;
24+
width:35px;
25+
bottom:10px;
26+
height:35px;
27+
left:10px;
28+
background-color:#fff;
29+
text-align:center;
30+
line-height:35px;
31+
vertical-align: middle;
32+
}
33+
</style>
34+
{% endmacro %}
35+
36+
{% macro html(this,kwargs) %}
37+
<img id="{{this.get_name()}}" alt="scroll"
38+
src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/1.5.2/png/512/arrow-move.png"
39+
onclick="{{this._parent.get_name()}}.toggleScroll()"></img>
40+
{% endmacro %}
41+
42+
{% macro script(this,kwargs) %}
43+
{{this._parent.get_name()}}.scrollEnabled = true;
44+
45+
{{this._parent.get_name()}}.toggleScroll = function() {
46+
if (this.scrollEnabled) {
47+
this.scrollEnabled = false;
48+
this.scrollWheelZoom.disable();
49+
}
50+
else {
51+
this.scrollEnabled = true;
52+
this.scrollWheelZoom.enable();
53+
}
54+
};
55+
56+
{{this._parent.get_name()}}.toggleScroll();
57+
{% endmacro %}
58+
""")

tests/test_plugins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class TestPlugins(object):
1717

1818
def test_scroll_zoom_toggler(self):
1919
mapa = folium.Map([45., 3.], zoom_start=4)
20-
mapa.add_plugin(plugins.ScrollZoomToggler())
21-
mapa._build_map()
20+
mapa.add_children(plugins.ScrollZoomToggler())
21+
mapa._repr_html_()
2222

2323
def test_marker_cluster(self):
2424
N = 100

0 commit comments

Comments
 (0)