Skip to content

added default options to tile_layer #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def __init__(self, location=None, width='100%', height='100%',
self.template_vars.setdefault('tile_layers', [])

@iter_obj('simple')
def add_tile_layer(self, tile_name=None, tile_url=None, active=False):
def add_tile_layer(self, tile_name=None, tile_url=None, active=False, minZoom=0,
maxZoom=18, tms=False, continuousWorld=False, noWrap=False, zoomOffset=0,
zoomReverse=False, opacity=1, attribution='Leaflet'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attribution should be a string about the source of the layer, correct? Leave the default equal to None.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ozak can you write some docstring regarding these options?

"""Adds a simple tile layer.

Parameters
Expand All @@ -236,9 +238,17 @@ def add_tile_layer(self, tile_name=None, tile_url=None, active=False):
if tile_name not in self.added_layers:
tile_name = tile_name.replace(" ", "_")
tile_temp = self.env.get_template('tile_layer.js')

tile = tile_temp.render({'tile_name': tile_name,
'tile_url': tile_url})
'tile_url': tile_url,
'minZoom': minZoom,
'maxZoom': maxZoom,
'tms': str(tms).lower(),
'continuousWorld': str(continuousWorld).lower(),
'noWrap': str(noWrap).lower(),
'zoomOffset': zoomOffset,
'zoomReverse': str(zoomReverse).lower(),
'opacity': opacity,
})

self.template_vars.setdefault('tile_layers', []).append((tile))

Expand Down
6 changes: 6 additions & 0 deletions folium/templates/leaflet-dvf.markers.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion folium/templates/tile_layer.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
var {{ tile_name }} = L.tileLayer('{{ tile_url }}');
var {{ tile_name }} = L.tileLayer('{{ tile_url }}',{
'minZoom': {{minZoom}},
'maxZoom': {{maxZoom}},
'tms': {{tms}},
'continuousWorld': {{continuousWorld}},
'noWrap': {{noWrap}},
'zoomOffset': {{zoomOffset}},
'zoomReverse': {{zoomReverse}},
'opacity': {{opacity}}
});
32 changes: 32 additions & 0 deletions tests/folium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,38 @@ def test_wms_layer(self):
'wms_transparent': 'true'})
assert map.template_vars['wms_layers'][0] == wms

def test_add_tile_layer(self):
'''Test add_layer URLs'''

map = folium.Map(location=[44, -73], zoom_start=3)
tile_name = "Temperature"
tile_url = 'http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/'
tile_url += 'MapServer/WMSServer'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of these options specific to a WMS version? If so we have to document it!

minZoom = 1
maxZoom = 5
tms = True
continuousWorld = False
noWrap = True
zoomOffset = 1
zoomReverse = True
opacity = 2
map.add_tile_layer(tile_name=tile_name, tile_url=tile_url, active=True, minZoom=minZoom,
maxZoom=maxZoom, tms=tms, continuousWorld=continuousWorld, noWrap=noWrap, zoomOffset=zoomOffset,
zoomReverse=zoomReverse, opacity=opacity, attribution='Leaflet')
tile_temp = self.env.get_template('tile_layer.js')
tile = tile_temp.render({'tile_name': tile_name,
'tile_url': tile_url,
'minZoom': minZoom,
'maxZoom': maxZoom,
'tms': str(tms).lower(),
'continuousWorld': str(continuousWorld).lower(),
'noWrap': str(noWrap).lower(),
'zoomOffset': zoomOffset,
'zoomReverse': str(zoomReverse).lower(),
'opacity': opacity,
})
assert map.template_vars['tile_layers'][0] == tile

def test_simple_marker(self):
'''Test simple marker addition'''

Expand Down