Skip to content

Commit dbd6a96

Browse files
fralcLo Conti FrancescoConengmo
authored
Add SideBySide plugin (#1292)
* Add SideBySide plugin * removed unused import * SideBySideLayers plugin minor updates * adding SideBySideLayers entry into Plugin notebook * Update Plugins.ipynb * update JS dependency * Update Plugins.ipynb * disable layer control for plugin Co-authored-by: Lo Conti Francesco <[email protected]> Co-authored-by: Frank <[email protected]>
1 parent 4e6e6e4 commit dbd6a96

File tree

3 files changed

+3971
-38
lines changed

3 files changed

+3971
-38
lines changed

examples/Plugins.ipynb

Lines changed: 3923 additions & 38 deletions
Large diffs are not rendered by default.

folium/plugins/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from folium.plugins.scroll_zoom_toggler import ScrollZoomToggler
3030
from folium.plugins.search import Search
3131
from folium.plugins.semicircle import SemiCircle
32+
from folium.plugins.side_by_side import SideBySideLayers
3233
from folium.plugins.terminator import Terminator
3334
from folium.plugins.time_slider_choropleth import TimeSliderChoropleth
3435
from folium.plugins.timestamped_geo_json import TimestampedGeoJson
@@ -60,6 +61,7 @@
6061
'ScrollZoomToggler',
6162
'Search',
6263
'SemiCircle',
64+
'SideBySideLayers',
6365
'StripePattern',
6466
'TagFilterButton',
6567
'Terminator',

folium/plugins/side_by_side.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from folium.elements import JSCSSMixin
2+
from folium.map import Layer
3+
4+
from jinja2 import Template
5+
6+
7+
class SideBySideLayers(JSCSSMixin, Layer):
8+
"""
9+
Creates a SideBySideLayers that takes two Layers and adds a sliding
10+
control with the leaflet-side-by-side plugin.
11+
12+
Uses the Leaflet leaflet-side-by-side plugin https://github.com/digidem/leaflet-side-by-side
13+
14+
Parameters
15+
----------
16+
layer_left: Layer.
17+
The left Layer within the side by side control.
18+
Must be created and added to the map before being passed to this class.
19+
layer_right: Layer.
20+
The left Layer within the side by side control.
21+
Must be created and added to the map before being passed to this class.
22+
23+
Examples
24+
--------
25+
>>> sidebyside = SideBySideLayers(layer_left, layer_right)
26+
>>> sidebyside.add_to(m)
27+
"""
28+
29+
_template = Template(u"""
30+
{% macro script(this, kwargs) %}
31+
var {{ this.get_name() }} = L.control.sideBySide(
32+
{{ this.layer_left.get_name() }}, {{ this.layer_right.get_name() }}
33+
).addTo({{ this._parent.get_name() }});
34+
{% endmacro %}
35+
""")
36+
37+
default_js = [
38+
('leaflet.sidebyside',
39+
'https://cdn.jsdelivr.net/gh/digidem/leaflet-side-by-side@gh-pages/leaflet-side-by-side.min.js'),
40+
]
41+
42+
def __init__(self, layer_left, layer_right):
43+
super().__init__(control=False)
44+
self._name = 'SideBySideLayers'
45+
self.layer_left = layer_left
46+
self.layer_right = layer_right

0 commit comments

Comments
 (0)