@@ -23,11 +23,11 @@ def setup_data():
23
23
county_codes = [x ['id' ] for x in get_id ['features' ]]
24
24
county_df = pd .DataFrame ({'FIPS_Code' : county_codes }, dtype = str )
25
25
26
- #Read into Dataframe, cast to string for consistency
26
+ # Read into Dataframe, cast to string for consistency.
27
27
df = pd .read_csv ('us_county_data.csv' , na_values = [' ' ])
28
28
df ['FIPS_Code' ] = df ['FIPS_Code' ].astype (str )
29
29
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.
31
31
merged = pd .merge (df , county_df , on = 'FIPS_Code' , how = 'inner' )
32
32
return merged .fillna (method = 'pad' )
33
33
@@ -107,13 +107,36 @@ def test_custom_tile(self):
107
107
assert map .template_vars ['Tiles' ] == url
108
108
assert map .template_vars ['attr' ] == attr
109
109
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
+
110
133
def test_simple_marker (self ):
111
134
'''Test simple marker addition'''
112
135
113
136
mark_templ = self .env .get_template ('simple_marker.js' )
114
137
popup_templ = self .env .get_template ('simple_popup.js' )
115
138
116
- #Single Simple marker
139
+ # Single Simple marker.
117
140
self .map .simple_marker (location = [45.50 , - 122.7 ])
118
141
mark_1 = mark_templ .render ({'marker' : 'marker_1' , 'lat' : 45.50 ,
119
142
'lon' : - 122.7 ,
@@ -123,7 +146,7 @@ def test_simple_marker(self):
123
146
assert self .map .template_vars ['custom_markers' ][0 ][1 ] == mark_1
124
147
assert self .map .template_vars ['custom_markers' ][0 ][2 ] == popup_1
125
148
126
- #Test Simple marker addition
149
+ # Test Simple marker addition.
127
150
self .map .simple_marker (location = [45.60 , - 122.8 ], popup = 'Hi' )
128
151
mark_2 = mark_templ .render ({'marker' : 'marker_2' , 'lat' : 45.60 ,
129
152
'lon' : - 122.8 ,
@@ -134,16 +157,17 @@ def test_simple_marker(self):
134
157
assert self .map .template_vars ['custom_markers' ][1 ][1 ] == mark_2
135
158
assert self .map .template_vars ['custom_markers' ][1 ][2 ] == popup_2
136
159
137
- #Test no popup
160
+ # Test no popup.
138
161
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
140
164
141
165
def test_circle_marker (self ):
142
166
'''Test circle marker additions'''
143
167
144
168
circ_templ = self .env .get_template ('circle_marker.js' )
145
169
146
- #Single Circle marker
170
+ # Single Circle marker.
147
171
self .map .circle_marker (location = [45.60 , - 122.8 ], popup = 'Hi' )
148
172
circle_1 = circ_templ .render ({'circle' : 'circle_1' , 'lat' : 45.60 ,
149
173
'lon' : - 122.8 , 'radius' : 500 ,
@@ -152,7 +176,7 @@ def test_circle_marker(self):
152
176
'fill_opacity' : 0.6 })
153
177
assert self .map .template_vars ['markers' ][0 ][0 ] == circle_1
154
178
155
- #Second circle marker
179
+ # Second circle marker.
156
180
self .map .circle_marker (location = [45.70 , - 122.9 ], popup = 'Hi' )
157
181
circle_2 = circ_templ .render ({'circle' : 'circle_2' , 'lat' : 45.70 ,
158
182
'lon' : - 122.9 , 'radius' : 500 ,
@@ -191,14 +215,14 @@ def test_latlng_pop(self):
191
215
def test_click_for_marker (self ):
192
216
'''Test click for marker functionality'''
193
217
194
- #lat/lng popover
218
+ # Lat/lon popover.
195
219
self .map .click_for_marker ()
196
220
click_templ = self .env .get_template ('click_for_marker.js' )
197
221
click = click_templ .render ({'popup' : ('"Latitude: " + lat + "<br>'
198
222
'Longitude: " + lng ' )})
199
223
assert self .map .template_vars ['click_pop' ] == click
200
224
201
- #Custom popover
225
+ # Custom popover.
202
226
self .map .click_for_marker (popup = 'Test' )
203
227
click_templ = self .env .get_template ('click_for_marker.js' )
204
228
click = click_templ .render ({'popup' : '"Test"' })
@@ -209,7 +233,8 @@ def test_vega_popup(self):
209
233
210
234
vis = vincent .Bar (width = 675 - 75 , height = 350 - 50 , no_data = True )
211
235
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' ))
213
238
popup_temp = self .env .get_template ('vega_marker.js' )
214
239
vega = popup_temp .render ({'mark' : 'marker_1' , 'div_id' : 'vis' ,
215
240
'width' : 675 , 'height' : 350 ,
@@ -224,7 +249,7 @@ def test_geo_json(self):
224
249
path = 'us-counties.json'
225
250
geo_path = ".defer(d3.json, '{0}')" .format (path )
226
251
227
- #No data binding
252
+ # No data binding.
228
253
self .map .geo_json (geo_path = path )
229
254
geo_path = ".defer(d3.json, '{0}')" .format (path )
230
255
map_var = 'gjson_1'
@@ -246,14 +271,14 @@ def test_geo_json(self):
246
271
assert templ ['gjson_layers' ][0 ] == layer
247
272
assert templ ['json_paths' ][0 ] == geo_path
248
273
249
- #Data binding incorrect color value error
274
+ # Data binding incorrect color value error.
250
275
data = setup_data ()
251
276
nt .assert_raises (ValueError , self .map .geo_json ,
252
277
path , data = data ,
253
278
columns = ['FIPS_Code' , 'Unemployed_2011' ],
254
279
key_on = 'feature.id' , fill_color = 'blue' )
255
280
256
- #Data binding threshold_scale too long
281
+ # Data binding threshold_scale too long.
257
282
data = setup_data ()
258
283
nt .assert_raises (ValueError , self .map .geo_json ,
259
284
path , data = data ,
@@ -262,7 +287,7 @@ def test_geo_json(self):
262
287
threshold_scale = [1 , 2 , 3 , 4 , 5 , 6 , 7 ],
263
288
fill_color = 'YlGnBu' )
264
289
265
- #With DataFrame data binding, default threshold scale
290
+ # With DataFrame data binding, default threshold scale.
266
291
self .map .geo_json (geo_path = path , data = data ,
267
292
columns = ['FIPS_Code' , 'Unemployed_2011' ],
268
293
key_on = 'feature.id' , fill_color = 'YlGnBu' ,
@@ -299,16 +324,16 @@ def test_geo_json(self):
299
324
assert templ ['json_paths' ] == [data_path , geo_path ]
300
325
assert templ ['color_scales' ][0 ] == scale
301
326
302
- #Adding TopoJSON as additional layer
327
+ # Adding TopoJSON as additional layer.
303
328
path_2 = 'or_counties_topo.json'
304
329
self .map .geo_json (geo_path = path_2 , topojson = 'objects.or_counties_geo' )
305
330
geo_path_2 = ".defer(d3.json, '{0}')" .format (path_2 )
306
331
map_var_2 = 'tjson_2'
307
332
layer_var_2 = 'topo_2'
308
333
topo_func = ('topo_2 = topojson.feature(tjson_2,'
309
334
' 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' )
312
337
313
338
templ = self .map .template_vars
314
339
assert templ ['func_vars' ] == [data_var , map_var , map_var_2 ]
@@ -319,13 +344,13 @@ def test_geo_json(self):
319
344
def test_map_build (self ):
320
345
'''Test map build'''
321
346
322
- #Standard map
347
+ # Standard map.
323
348
self .map ._build_map ()
324
349
html_templ = self .env .get_template ('fol_template.html' )
325
350
326
351
tmpl = {'Tiles' : 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ,
327
352
'attr' : ('Map data (c) <a href="http://openstreetmap.org">'
328
- 'OpenStreetMap</a> contributors' ),
353
+ 'OpenStreetMap</a> contributors' ),
329
354
'map_id' : 'folium_' + '0' * 32 ,
330
355
'lat' : 45.5236 , 'lon' : - 122.675 , 'max_zoom' : 20 ,
331
356
'size' : 'style="width: 900px; height: 400px"' ,
0 commit comments