Skip to content

Commit d204712

Browse files
authored
Merge pull request #508 from ocefpaf/continuousWorld
continuousWorld
2 parents a425353 + 2cbbd09 commit d204712

File tree

5 files changed

+233
-29
lines changed

5 files changed

+233
-29
lines changed

CHANGES.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
0.3.0
22
~~~~~
33

4-
- Added fullscreen plugin (sanga #437)
5-
- Added ColorLine object (bibmartin #449)
6-
- Added smooth_factor option to GeoJSON, TopoJSON and Choropleth (JamesGardiner #428)
7-
- Added options to fullscreen plugin (qingkaikong #468)
8-
- Added options to LayerControl (qingkaikong #473)
9-
- Added text path (talespaiva #451 and #474)
4+
- Added `continuous_world`, `world_copy_jump`, and `no_wrap` options (ocefpaf #508)
105
- Update font-awesome to 4.6.3 (ocefpaf #478)
11-
- Add highlight function to GeoJSON, and Chrorpleth (JoshuaCano #341)
6+
- Added text path (talespaiva #451 and ocefpaf #474)
7+
- More options to `LayerControl` (qingkaikong #473)
8+
- More options to `fullscreen` plugin (qingkaikong #468)
9+
- Added `ColorLine` object (bibmartin #449)
10+
- Add highlight function to `GeoJSON`, and `Chrorpleth` (JoshuaCano #341)
11+
- Added `fullscreen` plugin (sanga #437)
12+
- Added `smooth_factor `option to `GeoJSON`, `TopoJSON` and `Choropleth` (JamesGardiner #428)
1213

1314
Bug Fixes
1415

examples/ContinuousWorld.ipynb

Lines changed: 176 additions & 0 deletions
Large diffs are not rendered by default.

folium/map.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from branca.six import text_type, binary_type
1818
from branca.utilities import _parse_size
19-
from branca.element import Element, Figure, MacroElement, Html, JavascriptLink, CssLink
19+
from branca.element import (Element, Figure, MacroElement, Html,
20+
JavascriptLink, CssLink)
2021

2122
ENV = Environment(loader=PackageLoader('folium', 'templates'))
2223

@@ -135,8 +136,9 @@ class LegacyMap(MacroElement):
135136
def __init__(self, location=None, width='100%', height='100%',
136137
left="0%", top="0%", position='relative',
137138
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
138-
zoom_start=10, attr=None, min_lat=-90, max_lat=90,
139-
min_lon=-180, max_lon=180, detect_retina=False,
139+
zoom_start=10, continuous_world=False, world_copy_jump=False,
140+
no_wrap=False, attr=None, min_lat=-90, max_lat=90,
141+
min_lon=-180, max_lon=180, max_bounds=True, detect_retina=False,
140142
crs='EPSG3857', control_scale=False):
141143
super(LegacyMap, self).__init__()
142144
self._name = 'Map'
@@ -163,14 +165,18 @@ def __init__(self, location=None, width='100%', height='100%',
163165
self.max_lat = max_lat
164166
self.min_lon = min_lon
165167
self.max_lon = max_lon
168+
self.max_bounds = max_bounds
169+
self.continuous_world = continuous_world
170+
self.no_wrap = no_wrap
171+
self.world_copy_jump = world_copy_jump
166172

167173
self.crs = crs
168174
self.control_scale = control_scale
169175

170176
if tiles:
171177
self.add_tile_layer(tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom,
172-
attr=attr, API_key=API_key,
173-
detect_retina=detect_retina)
178+
continuous_world=continuous_world, no_wrap=no_wrap,
179+
attr=attr, API_key=API_key, detect_retina=detect_retina)
174180

175181
self._template = Template(u"""
176182
{% macro header(this, kwargs) %}
@@ -189,20 +195,26 @@ def __init__(self, location=None, width='100%', height='100%',
189195
190196
{% macro script(this, kwargs) %}
191197
192-
var southWest = L.latLng({{ this.min_lat }}, {{ this.min_lon }});
193-
var northEast = L.latLng({{ this.max_lat }}, {{ this.max_lon }});
194-
var bounds = L.latLngBounds(southWest, northEast);
195-
196-
var {{this.get_name()}} = L.map('{{this.get_name()}}', {
197-
center:[{{this.location[0]}},{{this.location[1]}}],
198-
zoom: {{this.zoom_start}},
199-
maxBounds: bounds,
200-
layers: [],
201-
crs: L.CRS.{{this.crs}}
202-
});
198+
{% if this.max_bounds %}
199+
var southWest = L.latLng({{ this.min_lat }}, {{ this.min_lon }});
200+
var northEast = L.latLng({{ this.max_lat }}, {{ this.max_lon }});
201+
var bounds = L.latLngBounds(southWest, northEast);
202+
{% else %}
203+
var bounds = null;
204+
{% endif %}
205+
206+
var {{this.get_name()}} = L.map(
207+
'{{this.get_name()}}',
208+
{center: [{{this.location[0]}},{{this.location[1]}}],
209+
zoom: {{this.zoom_start}},
210+
maxBounds: bounds,
211+
layers: [],
212+
worldCopyJump: {{this.world_copy_jump.__str__().lower()}},
213+
crs: L.CRS.{{this.crs}}
214+
});
203215
{% if this.control_scale %}L.control.scale().addTo({{this.get_name()}});{% endif %}
204216
{% endmacro %}
205-
""")
217+
""") # noqa
206218

207219
def _repr_html_(self, **kwargs):
208220
"""Displays the Map in a Jupyter notebook.
@@ -217,8 +229,10 @@ def _repr_html_(self, **kwargs):
217229

218230
def add_tile_layer(self, tiles='OpenStreetMap', name=None,
219231
API_key=None, max_zoom=18, min_zoom=1,
220-
attr=None, tile_name=None, tile_url=None,
221-
active=False, detect_retina=False, **kwargs):
232+
continuous_world=False, attr=None,
233+
tile_name=None, tile_url=None,
234+
active=False, detect_retina=False, no_wrap=False,
235+
**kwargs):
222236
"""Add a tile layer to the map.
223237
224238
See TileLayer for options."""
@@ -232,7 +246,9 @@ def add_tile_layer(self, tiles='OpenStreetMap', name=None,
232246
tile_layer = TileLayer(tiles=tiles, name=name,
233247
min_zoom=min_zoom, max_zoom=max_zoom,
234248
attr=attr, API_key=API_key,
235-
detect_retina=detect_retina)
249+
detect_retina=detect_retina,
250+
continuous_world=continuous_world,
251+
no_wrap=no_wrap)
236252
self.add_child(tile_layer, name=tile_layer.tile_name)
237253

238254
def render(self, **kwargs):
@@ -333,7 +349,8 @@ class TileLayer(Layer):
333349
"""
334350
def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18,
335351
attr=None, API_key=None, detect_retina=False,
336-
name=None, overlay=False, control=True):
352+
continuous_world=False, name=None, overlay=False,
353+
control=True, no_wrap=False):
337354
self.tile_name = (name if name is not None else
338355
''.join(tiles.lower().strip().split()))
339356
super(TileLayer, self).__init__(name=self.tile_name, overlay=overlay,
@@ -343,6 +360,8 @@ def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18,
343360

344361
self.min_zoom = min_zoom
345362
self.max_zoom = max_zoom
363+
self.no_wrap = no_wrap
364+
self.continuous_world = continuous_world
346365

347366
self.detect_retina = detect_retina
348367

@@ -374,6 +393,8 @@ def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18,
374393
{
375394
maxZoom: {{this.max_zoom}},
376395
minZoom: {{this.min_zoom}},
396+
continuousWorld: {{this.continuous_world.__str__().lower()}},
397+
noWrap: {{this.no_wrap.__str__().lower()}},
377398
attribution: '{{this.attr}}',
378399
detectRetina: {{this.detect_retina.__str__().lower()}}
379400
}

folium/templates/fol_template.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
zoom: {{ zoom_level }},
6767
maxBounds: bounds,
6868
layers: [],
69+
worldCopyJump: {{ world_copy_jump.__str__().lower() }},
6970
crs: L.CRS.{{crs}}
7071
});
7172

@@ -75,6 +76,8 @@
7576
{
7677
maxZoom: {{tile['max_zoom']}},
7778
minZoom: {{tile['min_zoom']}},
79+
continuousWorld: {{tile['continuous_world'].__str__().lower()}},
80+
noWrap: {{tile['no_wrap'].__str__().lower()}},
7881
attribution: '{{tile['attr']}}',
7982
detectRetina: {{tile['detect_retina'].__str__().lower()}}
8083
}

tests/test_folium.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ def test_geo_json_simple(self):
434434
[71.285909, -66.979601]], bounds
435435

436436
def test_geo_json_str(self):
437-
# No data binding.
438437
self.map = folium.Map([43, -100], zoom_start=4)
438+
# No data binding.
439439
path = os.path.join(rootpath, 'us-counties.json')
440440

441441
data = json.load(open(path))
@@ -635,6 +635,8 @@ def test_map_build(self):
635635
'max_zoom': 20,
636636
'min_zoom': 1,
637637
'detect_retina': False,
638+
'no_wrap': False,
639+
'continuous_world': False
638640
}]
639641
tmpl = {'map_id': 'map_' + '0' * 32,
640642
'lat': 45.5236, 'lon': -122.675,
@@ -646,6 +648,7 @@ def test_map_build(self):
646648
'max_lon': 180,
647649
'tile_layers': tile_layers,
648650
'crs': 'EPSG3857',
651+
'world_copy_jump': False
649652
}
650653
HTML = html_templ.render(tmpl, plugins={})
651654

0 commit comments

Comments
 (0)