55
66Adds 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+ """ )
0 commit comments