Skip to content

Fix wms layer py3k #59

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

Merged
merged 2 commits into from
Dec 4, 2014
Merged
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
2 changes: 1 addition & 1 deletion folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def add_layers_to_map(self):

data_string = ''
for i, layer in enumerate(self.added_layers):
name = layer.keys()[0]
name = list(layer.keys())[0]
data_string+='\"'
data_string+=name
data_string+='\"'
Expand Down
65 changes: 45 additions & 20 deletions tests/folium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def setup_data():
county_codes = [x['id'] for x in get_id['features']]
county_df = pd.DataFrame({'FIPS_Code': county_codes}, dtype=str)

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

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

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

def test_wms_layer(self):
'''Test wms layer URLs'''

map = folium.Map(location=[44, -73], zoom_start=3)
wms_url = 'http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/'
wms_url += 'MapServer/WMSServer'
wms_name = "Temperature"
wms_layers = 16
wms_format = "image/png"
map.add_wms_layer(wms_name=wms_name,
wms_url=wms_url,
wms_format=wms_format,
wms_layers=wms_layers,
wms_transparent=True)

wms_temp = self.env.get_template('wms_layer.js')
wms = wms_temp.render({'wms_name': wms_name,
'wms_url': wms_url,
'wms_format': wms_format,
'wms_layer_names': wms_layers,
'wms_transparent': 'true'})
assert map.template_vars['wms_layers'][0] == wms

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

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

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

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

#Test no popup
# Test no popup.
self.map.simple_marker(location=[45.60, -122.8], popup_on=False)
assert self.map.template_vars['custom_markers'][2][2] == 'var no_pop = null;'
nopopup = 'var no_pop = null;'
assert self.map.template_vars['custom_markers'][2][2] == nopopup

def test_circle_marker(self):
'''Test circle marker additions'''

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

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

#Second circle marker
# Second circle marker.
self.map.circle_marker(location=[45.70, -122.9], popup='Hi')
circle_2 = circ_templ.render({'circle': 'circle_2', 'lat': 45.70,
'lon': -122.9, 'radius': 500,
Expand Down Expand Up @@ -191,14 +215,14 @@ def test_latlng_pop(self):
def test_click_for_marker(self):
'''Test click for marker functionality'''

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

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

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

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

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

#Data binding incorrect color value error
# Data binding incorrect color value error.
data = setup_data()
nt.assert_raises(ValueError, self.map.geo_json,
path, data=data,
columns=['FIPS_Code', 'Unemployed_2011'],
key_on='feature.id', fill_color='blue')

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

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

#Adding TopoJSON as additional layer
# Adding TopoJSON as additional layer.
path_2 = 'or_counties_topo.json'
self.map.geo_json(geo_path=path_2, topojson='objects.or_counties_geo')
geo_path_2 = ".defer(d3.json, '{0}')".format(path_2)
map_var_2 = 'tjson_2'
layer_var_2 = 'topo_2'
topo_func = ('topo_2 = topojson.feature(tjson_2,'
' tjson_2.objects.or_counties_geo);')
layer_2 = ('gJson_layer_{0} = L.geoJson({1}, {{style: {2}}}).addTo(map)'
.format(2, layer_var_2, 'style_2'))
fmt = 'gJson_layer_{0} = L.geoJson({1}, {{style: {2}}}).addTo(map)'
layer_2 = fmt.format(2, layer_var_2, 'style_2')

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

#Standard map
# Standard map.
self.map._build_map()
html_templ = self.env.get_template('fol_template.html')

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