Skip to content

Commit 0c8dd3c

Browse files
authored
Merge pull request #468 from qingkaikong/add_options_to_fullscreen_plugin
add options to fullscreen plugin
2 parents a52e6d7 + ab09288 commit 0c8dd3c

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

examples/fullscreen_plugin_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from folium.plugins import Fullscreen
55

66
m = folium.Map(location=[41.9, -97.3], zoom_start=4)
7-
Fullscreen().add_to(m)
7+
Fullscreen(position='topright', title='Expand me', titleCancel='Exit me',
8+
forceSeparateButton=True).add_to(m)
89

910
m.save(outfile='fullscreen.html')

folium/plugins/fullscreen.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,42 @@
1515
class Fullscreen(MacroElement):
1616
"""
1717
Adds a fullscreen button to your map.
18+
19+
Parameters
20+
----------
21+
position : str
22+
change the position of the button can be:
23+
'topleft', 'topright', 'bottomright' or 'bottomleft'
24+
default: 'topleft'
25+
title : str
26+
change the title of the button,
27+
default: 'Full Screen'
28+
titleCancel : str
29+
change the title of the button when fullscreen is on,
30+
default: 'Exit Full Screen'
31+
forceSeparateButton : boolean
32+
force seperate button to detach from zoom buttons,
33+
default: False
1834
"""
1935

20-
def __init__(self):
36+
def __init__(self, position='topleft', title='Full Screen',
37+
titleCancel='Exit Full Screen', forceSeparateButton=False):
2138
"""Add button to take your Folium map fullscreen"""
2239
super(Fullscreen, self).__init__()
2340
self._name = 'Fullscreen'
41+
self.position = position
42+
self.title = title
43+
self.titleCancel = titleCancel
44+
self.forceSeparateButton = str(forceSeparateButton).lower()
2445

2546
self._template = Template("""
2647
{% macro script(this, kwargs) %}
27-
L.control.fullscreen().addTo({{this._parent.get_name()}});
48+
L.control.fullscreen({
49+
position: '{{this.position}}',
50+
title: '{{this.title}}',
51+
titleCancel: '{{this.titleCancel}}',
52+
forceSeparateButton: {{this.forceSeparateButton}},
53+
}).addTo({{this._parent.get_name()}});
2854
{{this._parent.get_name()}}.on('enterFullscreen', function(){
2955
console.log('entered fullscreen');
3056
});

tests/plugins/test_fullscreen.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import folium
77
from folium import plugins
8+
from jinja2 import Template
89

910

1011
def test_fullscreen():
@@ -16,4 +17,16 @@ def test_fullscreen():
1617
out = m._parent.render()
1718

1819
# verify that the fullscreen control was rendered
19-
assert 'L.control.fullscreen().addTo' in out
20+
tmpl = Template("""
21+
L.control.fullscreen({
22+
position: '{{this.position}}',
23+
title: '{{this.title}}',
24+
titleCancel: '{{this.titleCancel}}',
25+
forceSeparateButton: {{this.forceSeparateButton}},
26+
}).addTo({{this._parent.get_name()}});
27+
{{this._parent.get_name()}}.on('enterFullscreen', function(){
28+
console.log('entered fullscreen');
29+
});
30+
""")
31+
32+
assert ''.join(tmpl.render(this=fs).split()) in ''.join(out.split())

0 commit comments

Comments
 (0)