Skip to content

Commit dc79d2f

Browse files
committed
Merge pull request #437 from sanga/fullscreen_plugin
plugins: add fullscreen plugin
2 parents 7bad4ea + c44876c commit dc79d2f

12 files changed

+104
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@ ENV
5050
data.png
5151
map.html
5252

53+
# example outputs
54+
examples/*.html
55+
5356
# documentation builds
5457
docs/_build

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.3.0
2+
~~~~~
3+
4+
- Add fullscreen plugin (sanga #437)
5+
16
0.2.1
27
~~~~~
38
Bugfix release

examples/base_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
# Standard OSM.
77
map_osm = folium.Map(location=[45.5236, -122.6750])
8-
map_osm.create_map(path='osm.html')
8+
map_osm.save(outfile='osm.html')
99

1010
# Stamen Toner.
1111
stamen = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',
1212
zoom_start=13)
13-
stamen.create_map(path='stamen_toner.html')
13+
stamen.save(outfile='stamen_toner.html')

examples/choropleth_counties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def set_id(fips):
3838
key_on='feature.id',
3939
fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.3,
4040
topojson='objects.us_counties_20m')
41-
map_1.create_map(path='map_1.html')
41+
map_1.save(outfile='map_1.html')
4242

4343
# Unemployment with custom defined scale.
4444
map_2 = folium.Map(location=[40, -99], zoom_start=4)
@@ -49,7 +49,7 @@ def set_id(fips):
4949
fill_color='YlGnBu', line_opacity=0.3,
5050
legend_name='Unemployment Rate 2011 (%)',
5151
topojson='objects.us_counties_20m')
52-
map_2.create_map(path='map_2.html')
52+
map_2.save(outfile='map_2.html')
5353

5454
# Median Household income.
5555
map_3 = folium.Map(location=[40, -99], zoom_start=4)
@@ -59,4 +59,4 @@ def set_id(fips):
5959
fill_color='PuRd', line_opacity=0.3,
6060
legend_name='Median Household Income 2011 ($)',
6161
topojson='objects.us_counties_20m')
62-
map_3.create_map(path='map_3.html')
62+
map_3.save(outfile='map_3.html')

examples/choropleth_states.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
key_on='feature.id',
1919
fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,
2020
legend_name='Unemployment Rate (%)')
21-
states.create_map(path='us_state_map.html')
21+
states.save(outfile='us_state_map.html')
2222

2323
# Let's define our own scale and change the line opacity.
2424
states2 = folium.Map(location=[48, -102], zoom_start=3)
@@ -29,4 +29,4 @@
2929
fill_color='BuPu', fill_opacity=0.7, line_opacity=0.5,
3030
legend_name='Unemployment Rate (%)',
3131
reset=True)
32-
states2.create_map(path='us_state_map_2.html')
32+
states2.save(outfile='us_state_map_2.html')

examples/folium_vincent_markers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
radius=12, popup=(vis2, 'vis2.json'))
4646
buoy_map.polygon_marker(location=[46.216, -124.1280], fill_color='#43d9de',
4747
radius=12, popup=(vis3, 'vis3.json'))
48-
buoy_map.create_map(path='NOAA_buoys.html')
48+
buoy_map.save(outfile='NOAA_buoys.html')

examples/fullscreen_plugin_example.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
import folium
3+
4+
from folium.plugins import Fullscreen
5+
6+
m = folium.Map(location=[41.9, -97.3], zoom_start=4)
7+
Fullscreen().add_to(m)
8+
9+
m.save(outfile='fullscreen.html')

examples/line_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
m = folium.Map(location=[41.9, -97.3], zoom_start=4)
2929
m.line(coordinates, line_color='#FF0000', line_weight=5)
3030

31-
m.create_map(path='line_example.html')
31+
m.save(outfile='line_example.html')

examples/markers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
tiles='Stamen Terrain')
99
map_1.simple_marker([45.3288, -121.6625], popup='Mt. Hood Meadows')
1010
map_1.simple_marker([45.3311, -121.7113], popup='Timberline Lodge')
11-
map_1.create_map(path='mthood.html')
11+
map_1.save(outfile='mthood.html')
1212

1313
# Circle Markers with Stamen Toner.
1414
map_2 = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',
@@ -17,20 +17,20 @@
1717
map_2.circle_marker(location=[45.5215, -122.6261], radius=500,
1818
popup='Laurelhurst Park', line_color='#3186cc',
1919
fill_color='#3186cc')
20-
map_2.create_map(path='portland.html')
20+
map_2.save(outfile='portland.html')
2121

2222
# Lat/Lng popovers.
2323
map_3 = folium.Map(location=[46.1991, -122.1889], tiles='Stamen Terrain',
2424
zoom_start=13)
2525
map_3.lat_lng_popover()
26-
map_3.create_map(path='sthelens.html')
26+
map_3.save(outfile='sthelens.html')
2727

2828
# Click for marker.
2929
map_4 = folium.Map(location=[46.8527, -121.7649], tiles='Stamen Terrain',
3030
zoom_start=13)
3131
map_4.simple_marker(location=[46.8354, -121.7325], popup='Camp Muir')
3232
map_4.click_for_marker(popup='Waypoint')
33-
map_4.create_map(path='mtrainier.html')
33+
map_4.save(outfile='mtrainier.html')
3434

3535
# Polygon markers.
3636
map_5 = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
@@ -42,4 +42,4 @@
4242
fill_color='#769d96', num_sides=6, radius=10)
4343
map_5.polygon_marker(location=[45.5318, -122.6745], popup='Broadway Bridge',
4444
fill_color='#769d96', num_sides=8, radius=10)
45-
map_5.create_map(path='bridges.html')
45+
map_5.save(outfile='bridges.html')

folium/plugins/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
from .timestamped_geo_json import TimestampedGeoJson
1414
from .heat_map import HeatMap
1515
from .image_overlay import ImageOverlay
16+
from .fullscreen import Fullscreen
1617

1718
__all__ = ['MarkerCluster',
1819
'ScrollZoomToggler',
1920
'Terminator',
2021
'BoatMarker',
2122
'TimestampedGeoJson',
2223
'HeatMap',
23-
'ImageOverlay']
24+
'ImageOverlay',
25+
'Fullscreen']

folium/plugins/fullscreen.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Fullscreen
4+
--------------
5+
6+
https://github.com/brunob/leaflet.fullscreen
7+
8+
Adds fullscreen button to your maps.
9+
"""
10+
from jinja2 import Template
11+
12+
from branca.element import MacroElement, Figure, JavascriptLink, CssLink
13+
14+
15+
class Fullscreen(MacroElement):
16+
"""
17+
Adds a fullscreen button to your map.
18+
"""
19+
20+
def __init__(self):
21+
"""Add button to take your Folium map fullscreen"""
22+
super(Fullscreen, self).__init__()
23+
self._name = 'Fullscreen'
24+
25+
self._template = Template("""
26+
{% macro script(this, kwargs) %}
27+
L.control.fullscreen().addTo({{this._parent.get_name()}});
28+
{{this._parent.get_name()}}.on('enterFullscreen', function(){
29+
console.log('entered fullscreen');
30+
});
31+
32+
{% endmacro %}
33+
""") # noqa
34+
35+
def render(self, **kwargs):
36+
super(Fullscreen, self).render()
37+
38+
figure = self.get_root()
39+
assert isinstance(figure, Figure), ("You cannot render this Element "
40+
"if it's not in a Figure.")
41+
42+
figure.header.add_children(
43+
JavascriptLink(
44+
"https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.js"), # noqa
45+
name='Control.Fullscreen.js'
46+
)
47+
48+
figure.header.add_children(
49+
CssLink("https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.css"), # noqa
50+
name='Control.FullScreen.css'
51+
)

tests/plugins/test_fullscreen.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Test Fullscreen
4+
-----------------------
5+
"""
6+
import folium
7+
from folium import plugins
8+
9+
10+
def test_fullscreen():
11+
m = folium.Map([47, 3], zoom_start=1)
12+
fs = plugins.Fullscreen()
13+
m.add_children(fs)
14+
m._repr_html_()
15+
16+
out = m._parent.render()
17+
18+
# verify that the fullscreen control was rendered
19+
assert 'L.control.fullscreen().addTo' in out

0 commit comments

Comments
 (0)