Skip to content

Commit 38e2348

Browse files
author
Lo Conti Francesco
committed
SideBySideLayers plugin minor updates
1 parent f9f2e78 commit 38e2348

File tree

3 files changed

+127
-23
lines changed

3 files changed

+127
-23
lines changed

examples/SideBySideLayers.ipynb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# SideBySideLayers Demo"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import os\n",
17+
"import folium\n",
18+
"from folium.plugins import SideBySideLayers"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"create a map and two layers"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"m = folium.Map(location=(30, 20), zoom_start=4)\n",
35+
"\n",
36+
"layer_right = folium.TileLayer('openstreetmap')\n",
37+
"layer_left = folium.TileLayer('cartodbpositron')"
38+
]
39+
},
40+
{
41+
"cell_type": "markdown",
42+
"metadata": {},
43+
"source": [
44+
"create an instance of `SideBySideLayers` based on two"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"sbs = SideBySideLayers(layer_left=layer_left, layer_right=layer_right)"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {},
59+
"source": [
60+
"add layers and SideBySideLayers instance to the map"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"layer_left.add_to(m)\n",
70+
"layer_right.add_to(m)\n",
71+
"sbs.add_to(m)"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": null,
77+
"metadata": {},
78+
"outputs": [],
79+
"source": [
80+
"m"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"m.save(os.path.join('results', 'SideBySide.html'))"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {},
96+
"outputs": [],
97+
"source": []
98+
}
99+
],
100+
"metadata": {
101+
"kernelspec": {
102+
"display_name": "Python 3",
103+
"language": "python",
104+
"name": "python3"
105+
},
106+
"language_info": {
107+
"codemirror_mode": {
108+
"name": "ipython",
109+
"version": 3
110+
},
111+
"file_extension": ".py",
112+
"mimetype": "text/x-python",
113+
"name": "python",
114+
"nbconvert_exporter": "python",
115+
"pygments_lexer": "ipython3",
116+
"version": "3.6.2"
117+
}
118+
},
119+
"nbformat": 4,
120+
"nbformat_minor": 2
121+
}

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.polyline_text_path import PolyLineTextPath
3030
from folium.plugins.scroll_zoom_toggler import ScrollZoomToggler
3131
from folium.plugins.search import Search
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
@@ -56,6 +57,7 @@
5657
'PolyLineOffset',
5758
'ScrollZoomToggler',
5859
'Search',
60+
'SideBySideLayers',
5961
'StripePattern',
6062
'Terminator',
6163
'TimeSliderChoropleth',

folium/plugins/side_by_side.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class SideBySideLayers(Layer):
1111
"""
1212
Creates a SideBySideLayers that takes two Layers and adds a sliding
1313
control with the leaflet-side-by-side plugin.
14+
15+
Uses the Leaflet leaflet-side-by-side plugin https://github.com/digidem/leaflet-side-by-side
16+
1417
Parameters
1518
----------
1619
layer_left: Layer.
@@ -29,30 +32,8 @@ class SideBySideLayers(Layer):
2932
Whether the layer will be shown on opening (only for overlays).
3033
Examples
3134
--------
32-
>>> layer_left = WmsTileLayer(
33-
... 'http://this.wms.server/ncWMS/wms',
34-
... name='Test WMS Data',
35-
... styles='',
36-
... fmt='image/png',
37-
... transparent=True,
38-
... layers='test_data',
39-
... COLORSCALERANGE='0,10',
40-
...)
41-
>>> layer_left.add_to(m)
42-
>>> layer_right = WmsTileLayer(
43-
... 'http://this.wms.server/ncWMS/wms',
44-
... name='Test WMS Data',
45-
... styles='',
46-
... fmt='image/png',
47-
... transparent=True,
48-
... layers='test_data_2',
49-
... COLORSCALERANGE='0,5',
50-
...)
51-
>>> layer_right.add_to(m)
52-
>>> # Add layers to sidebyside control.
5335
>>> sidebyside = SideBySideLayers(layer_left, layer_right)
5436
>>> sidebyside.add_to(m)
55-
See https://github.com/digidem/leaflet-side-by-side for more information.
5637
"""
5738

5839
_template = Template(u"""
@@ -80,5 +61,5 @@ def render(self, **kwargs):
8061
'if it is not in a Figure.')
8162

8263
figure.header.add_child(
83-
JavascriptLink('http://lab.digital-democracy.org/leaflet-side-by-side/leaflet-side-by-side.js'), # noqa
64+
JavascriptLink('https://raw.githack.com/digidem/leaflet-side-by-side/gh-pages/leaflet-side-by-side.js'), # noqa
8465
name='leaflet.sidebyside')

0 commit comments

Comments
 (0)