Skip to content

Commit 91c59c4

Browse files
FabeGConengmo
authored andcommitted
Fix broken attribution for built-in tiles. (#1128)
- Fix broken attribution for builtin tiles. - Change a little the attribution text ((c) replaced by ©) - Corrected a dead link in mapbox attribution.
1 parent 99449e2 commit 91c59c4

File tree

12 files changed

+42
-34
lines changed

12 files changed

+42
-34
lines changed

folium/raster_layers.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ def __init__(self, tiles='OpenStreetMap', min_zoom=0, max_zoom=18,
9090
self._name = 'TileLayer'
9191
self._env = ENV
9292

93-
self.options = parse_options(
94-
min_zoom=min_zoom,
95-
max_zoom=max_zoom,
96-
max_native_zoom=max_native_zoom or max_zoom,
97-
no_wrap=no_wrap,
98-
attribution=attr,
99-
subdomains=subdomains,
100-
detect_retina=detect_retina,
101-
tms=tms,
102-
opacity=opacity,
103-
**kwargs
104-
)
10593
tiles_flat = ''.join(tiles.lower().strip().split())
10694
if tiles_flat in ('cloudmade', 'mapbox') and not API_key:
10795
raise ValueError('You must pass an API key if using Cloudmade'
@@ -113,12 +101,24 @@ def __init__(self, tiles='OpenStreetMap', min_zoom=0, max_zoom=18,
113101

114102
if tile_template in templates and attr_template in templates:
115103
self.tiles = self._env.get_template(tile_template).render(API_key=API_key) # noqa
116-
self.attr = self._env.get_template(attr_template).render()
104+
attr = self._env.get_template(attr_template).render()
117105
else:
118106
self.tiles = tiles
119107
if not attr:
120108
raise ValueError('Custom tiles must have an attribution.')
121-
self.attr = attr
109+
110+
self.options = parse_options(
111+
min_zoom=min_zoom,
112+
max_zoom=max_zoom,
113+
max_native_zoom=max_native_zoom or max_zoom,
114+
no_wrap=no_wrap,
115+
attribution=attr,
116+
subdomains=subdomains,
117+
detect_retina=detect_retina,
118+
tms=tms,
119+
opacity=opacity,
120+
**kwargs
121+
)
122122

123123

124124
class WmsTileLayer(Layer):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(c) <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors (c) <a href="http://cartodb.com/attributions">CartoDB</a>, CartoDB <a href ="http://cartodb.com/attributions">attributions</a>
1+
&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="http://cartodb.com/attributions">CartoDB</a>, CartoDB <a href ="http://cartodb.com/attributions">attributions</a>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(c) <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors (c) <a href="http://cartodb.com/attributions">CartoDB</a>, CartoDB <a href ="http://cartodb.com/attributions">attributions</a>
1+
&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="http://cartodb.com/attributions">CartoDB</a>, CartoDB <a href ="http://cartodb.com/attributions">attributions</a>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery (c) <a href="http://cloudmade.com">CloudMade</a>
1+
Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery &copy; <a href="http://cloudmade.com">CloudMade</a>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map tiles by <a href="http://www.mapbox.com/m">Mapbox</a> Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
1+
Map tiles by &copy; <a href="http://www.mapbox.com/about/maps">Mapbox</a> Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map tiles by <a href="http://www.mapbox.com/m">Mapbox</a> Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
1+
Map tiles by &copy; <a href="http://www.mapbox.com/about/maps">Mapbox</a> Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map tiles by <a href="http://www.mapbox.com/m">Mapbox</a> Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
1+
Map tiles by &copy; <a href="http://www.mapbox.com/about/maps">Mapbox</a> Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.
1+
Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
1+
Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.
1+
Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.
1+
Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.

tests/test_folium.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import folium
1515
from folium.features import GeoJson, Choropleth
16-
from folium.utilities import normalize
1716

1817
import jinja2
1918
from jinja2 import Environment, PackageLoader
19+
from jinja2.utils import htmlsafe_json_dumps
2020

2121
import numpy as np
2222
import pandas as pd
@@ -114,40 +114,48 @@ def test_init(self):
114114
'name': 'TileLayer',
115115
'id': '00000000000000000000000000000000',
116116
'children': {}
117-
}
118117
}
119118
}
119+
}
120120

121121
def test_builtin_tile(self):
122122
"""Test custom maptiles."""
123123

124-
default_tiles = ['OpenStreetMap', 'Stamen Terrain', 'Stamen Toner']
124+
default_tiles = [
125+
"OpenStreetMap",
126+
"Stamen Terrain",
127+
"Stamen Toner",
128+
"Mapbox Bright",
129+
"Mapbox Control Room",
130+
"CartoDB positron",
131+
"CartoDB dark_matter",
132+
]
125133
for tiles in default_tiles:
126134
m = folium.Map(location=[45.5236, -122.6750], tiles=tiles)
127-
tiles = ''.join(tiles.lower().strip().split())
128-
url = 'tiles/{}/tiles.txt'.format
129-
attr = 'tiles/{}/attr.txt'.format
135+
tiles = "".join(tiles.lower().strip().split())
136+
url = "tiles/{}/tiles.txt".format
137+
attr = "tiles/{}/attr.txt".format
130138
url = m._env.get_template(url(tiles)).render()
131139
attr = m._env.get_template(attr(tiles)).render()
132140

133141
assert m._children[tiles].tiles == url
134-
assert m._children[tiles].attr == attr
142+
assert htmlsafe_json_dumps(attr) in m._parent.render()
135143

136144
bounds = m.get_bounds()
137145
assert bounds == [[None, None], [None, None]], bounds
138146

139147
def test_custom_tile(self):
140148
"""Test custom tile URLs."""
141149

142-
url = 'http://{s}.custom_tiles.org/{z}/{x}/{y}.png'
143-
attr = 'Attribution for custom tiles'
150+
url = "http://{s}.custom_tiles.org/{z}/{x}/{y}.png"
151+
attr = "Attribution for custom tiles"
144152

145153
with pytest.raises(ValueError):
146154
folium.Map(location=[45.5236, -122.6750], tiles=url)
147155

148156
m = folium.Map(location=[45.52, -122.67], tiles=url, attr=attr)
149157
assert m._children[url].tiles == url
150-
assert m._children[url].attr == attr
158+
assert attr in m._parent.render()
151159

152160
bounds = m.get_bounds()
153161
assert bounds == [[None, None], [None, None]], bounds

0 commit comments

Comments
 (0)