Skip to content

Commit df33b82

Browse files
committed
Merge pull request #59 from ocefpaf/fix_wms_layer_py3k
Fix wms layer py3k
2 parents 453c40e + cff8555 commit df33b82

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

folium/folium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def add_layers_to_map(self):
243243

244244
data_string = ''
245245
for i, layer in enumerate(self.added_layers):
246-
name = layer.keys()[0]
246+
name = list(layer.keys())[0]
247247
data_string+='\"'
248248
data_string+=name
249249
data_string+='\"'

tests/folium_tests.py

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ def setup_data():
2323
county_codes = [x['id'] for x in get_id['features']]
2424
county_df = pd.DataFrame({'FIPS_Code': county_codes}, dtype=str)
2525

26-
#Read into Dataframe, cast to string for consistency
26+
# Read into Dataframe, cast to string for consistency.
2727
df = pd.read_csv('us_county_data.csv', na_values=[' '])
2828
df['FIPS_Code'] = df['FIPS_Code'].astype(str)
2929

30-
#Perform an inner join, pad NA's with data from nearest county
30+
# Perform an inner join, pad NA's with data from nearest county.
3131
merged = pd.merge(df, county_df, on='FIPS_Code', how='inner')
3232
return merged.fillna(method='pad')
3333

@@ -107,13 +107,36 @@ def test_custom_tile(self):
107107
assert map.template_vars['Tiles'] == url
108108
assert map.template_vars['attr'] == attr
109109

110+
def test_wms_layer(self):
111+
'''Test wms layer URLs'''
112+
113+
map = folium.Map(location=[44, -73], zoom_start=3)
114+
wms_url = 'http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/'
115+
wms_url += 'MapServer/WMSServer'
116+
wms_name = "Temperature"
117+
wms_layers = 16
118+
wms_format = "image/png"
119+
map.add_wms_layer(wms_name=wms_name,
120+
wms_url=wms_url,
121+
wms_format=wms_format,
122+
wms_layers=wms_layers,
123+
wms_transparent=True)
124+
125+
wms_temp = self.env.get_template('wms_layer.js')
126+
wms = wms_temp.render({'wms_name': wms_name,
127+
'wms_url': wms_url,
128+
'wms_format': wms_format,
129+
'wms_layer_names': wms_layers,
130+
'wms_transparent': 'true'})
131+
assert map.template_vars['wms_layers'][0] == wms
132+
110133
def test_simple_marker(self):
111134
'''Test simple marker addition'''
112135

113136
mark_templ = self.env.get_template('simple_marker.js')
114137
popup_templ = self.env.get_template('simple_popup.js')
115138

116-
#Single Simple marker
139+
# Single Simple marker.
117140
self.map.simple_marker(location=[45.50, -122.7])
118141
mark_1 = mark_templ.render({'marker': 'marker_1', 'lat': 45.50,
119142
'lon': -122.7,
@@ -123,7 +146,7 @@ def test_simple_marker(self):
123146
assert self.map.template_vars['custom_markers'][0][1] == mark_1
124147
assert self.map.template_vars['custom_markers'][0][2] == popup_1
125148

126-
#Test Simple marker addition
149+
# Test Simple marker addition.
127150
self.map.simple_marker(location=[45.60, -122.8], popup='Hi')
128151
mark_2 = mark_templ.render({'marker': 'marker_2', 'lat': 45.60,
129152
'lon': -122.8,
@@ -134,16 +157,17 @@ def test_simple_marker(self):
134157
assert self.map.template_vars['custom_markers'][1][1] == mark_2
135158
assert self.map.template_vars['custom_markers'][1][2] == popup_2
136159

137-
#Test no popup
160+
# Test no popup.
138161
self.map.simple_marker(location=[45.60, -122.8], popup_on=False)
139-
assert self.map.template_vars['custom_markers'][2][2] == 'var no_pop = null;'
162+
nopopup = 'var no_pop = null;'
163+
assert self.map.template_vars['custom_markers'][2][2] == nopopup
140164

141165
def test_circle_marker(self):
142166
'''Test circle marker additions'''
143167

144168
circ_templ = self.env.get_template('circle_marker.js')
145169

146-
#Single Circle marker
170+
# Single Circle marker.
147171
self.map.circle_marker(location=[45.60, -122.8], popup='Hi')
148172
circle_1 = circ_templ.render({'circle': 'circle_1', 'lat': 45.60,
149173
'lon': -122.8, 'radius': 500,
@@ -152,7 +176,7 @@ def test_circle_marker(self):
152176
'fill_opacity': 0.6})
153177
assert self.map.template_vars['markers'][0][0] == circle_1
154178

155-
#Second circle marker
179+
# Second circle marker.
156180
self.map.circle_marker(location=[45.70, -122.9], popup='Hi')
157181
circle_2 = circ_templ.render({'circle': 'circle_2', 'lat': 45.70,
158182
'lon': -122.9, 'radius': 500,
@@ -191,14 +215,14 @@ def test_latlng_pop(self):
191215
def test_click_for_marker(self):
192216
'''Test click for marker functionality'''
193217

194-
#lat/lng popover
218+
# Lat/lon popover.
195219
self.map.click_for_marker()
196220
click_templ = self.env.get_template('click_for_marker.js')
197221
click = click_templ.render({'popup': ('"Latitude: " + lat + "<br>'
198222
'Longitude: " + lng ')})
199223
assert self.map.template_vars['click_pop'] == click
200224

201-
#Custom popover
225+
# Custom popover.
202226
self.map.click_for_marker(popup='Test')
203227
click_templ = self.env.get_template('click_for_marker.js')
204228
click = click_templ.render({'popup': '"Test"'})
@@ -209,7 +233,8 @@ def test_vega_popup(self):
209233

210234
vis = vincent.Bar(width=675 - 75, height=350 - 50, no_data=True)
211235

212-
self.map.simple_marker(location=[45.60, -122.8], popup=(vis, 'vis.json'))
236+
self.map.simple_marker(location=[45.60, -122.8],
237+
popup=(vis, 'vis.json'))
213238
popup_temp = self.env.get_template('vega_marker.js')
214239
vega = popup_temp.render({'mark': 'marker_1', 'div_id': 'vis',
215240
'width': 675, 'height': 350,
@@ -224,7 +249,7 @@ def test_geo_json(self):
224249
path = 'us-counties.json'
225250
geo_path = ".defer(d3.json, '{0}')".format(path)
226251

227-
#No data binding
252+
# No data binding.
228253
self.map.geo_json(geo_path=path)
229254
geo_path = ".defer(d3.json, '{0}')".format(path)
230255
map_var = 'gjson_1'
@@ -246,14 +271,14 @@ def test_geo_json(self):
246271
assert templ['gjson_layers'][0] == layer
247272
assert templ['json_paths'][0] == geo_path
248273

249-
#Data binding incorrect color value error
274+
# Data binding incorrect color value error.
250275
data = setup_data()
251276
nt.assert_raises(ValueError, self.map.geo_json,
252277
path, data=data,
253278
columns=['FIPS_Code', 'Unemployed_2011'],
254279
key_on='feature.id', fill_color='blue')
255280

256-
#Data binding threshold_scale too long
281+
# Data binding threshold_scale too long.
257282
data = setup_data()
258283
nt.assert_raises(ValueError, self.map.geo_json,
259284
path, data=data,
@@ -262,7 +287,7 @@ def test_geo_json(self):
262287
threshold_scale=[1, 2, 3, 4, 5, 6, 7],
263288
fill_color='YlGnBu')
264289

265-
#With DataFrame data binding, default threshold scale
290+
# With DataFrame data binding, default threshold scale.
266291
self.map.geo_json(geo_path=path, data=data,
267292
columns=['FIPS_Code', 'Unemployed_2011'],
268293
key_on='feature.id', fill_color='YlGnBu',
@@ -299,16 +324,16 @@ def test_geo_json(self):
299324
assert templ['json_paths'] == [data_path, geo_path]
300325
assert templ['color_scales'][0] == scale
301326

302-
#Adding TopoJSON as additional layer
327+
# Adding TopoJSON as additional layer.
303328
path_2 = 'or_counties_topo.json'
304329
self.map.geo_json(geo_path=path_2, topojson='objects.or_counties_geo')
305330
geo_path_2 = ".defer(d3.json, '{0}')".format(path_2)
306331
map_var_2 = 'tjson_2'
307332
layer_var_2 = 'topo_2'
308333
topo_func = ('topo_2 = topojson.feature(tjson_2,'
309334
' tjson_2.objects.or_counties_geo);')
310-
layer_2 = ('gJson_layer_{0} = L.geoJson({1}, {{style: {2}}}).addTo(map)'
311-
.format(2, layer_var_2, 'style_2'))
335+
fmt = 'gJson_layer_{0} = L.geoJson({1}, {{style: {2}}}).addTo(map)'
336+
layer_2 = fmt.format(2, layer_var_2, 'style_2')
312337

313338
templ = self.map.template_vars
314339
assert templ['func_vars'] == [data_var, map_var, map_var_2]
@@ -319,13 +344,13 @@ def test_geo_json(self):
319344
def test_map_build(self):
320345
'''Test map build'''
321346

322-
#Standard map
347+
# Standard map.
323348
self.map._build_map()
324349
html_templ = self.env.get_template('fol_template.html')
325350

326351
tmpl = {'Tiles': 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
327352
'attr': ('Map data (c) <a href="http://openstreetmap.org">'
328-
'OpenStreetMap</a> contributors'),
353+
'OpenStreetMap</a> contributors'),
329354
'map_id': 'folium_' + '0' * 32,
330355
'lat': 45.5236, 'lon': -122.675, 'max_zoom': 20,
331356
'size': 'style="width: 900px; height: 400px"',

0 commit comments

Comments
 (0)