Skip to content

Commit 2ac2628

Browse files
committed
Update location check to function
Remove property setters based on PR comments
1 parent d36233e commit 2ac2628

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

folium/map.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060
'https://rawgit.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css'), # noqa
6161
]
6262

63+
def _format_lat_lon(values):
64+
"""Validates and formats location values before setting"""
65+
if type(values) not in [list, tuple]:
66+
raise TypeError("Location is not a list, expecting ex: location=[45.523, -122.675]")
67+
68+
if len(values) != 2:
69+
raise ValueError("Location should have two values, [lat, lon]")
70+
71+
try:
72+
values = [float(val) for val in values]
73+
except:
74+
raise ValueError("Location values should be numeric, {} is not a number".format(val))
75+
return value
6376

6477
class LegacyMap(MacroElement):
6578
"""Create a Map with Folium and Leaflet.js
@@ -170,7 +183,7 @@ def __init__(self, location=None, width='100%', height='100%',
170183
self.location = [0, 0]
171184
self.zoom_start = min_zoom
172185
else:
173-
self.location = location
186+
self.location = _format_lat_lon(location)
174187
self.zoom_start = zoom_start
175188

176189
Figure().add_child(self)
@@ -336,28 +349,6 @@ def render(self, **kwargs):
336349
'</style>'), name='map_style')
337350

338351
super(LegacyMap, self).render(**kwargs)
339-
340-
@property
341-
def location(self):
342-
return self._location
343-
344-
@location.setter
345-
def location(self, value):
346-
"""Validates the location values before setting"""
347-
if type(value) not in [list, tuple]:
348-
raise TypeError("Location is not a list, expecting ex: location=[45.523, -122.675]")
349-
350-
if len(value) != 2:
351-
raise ValueError("Location should have two values, [lat, lon]")
352-
353-
for val in value:
354-
try:
355-
float(val)
356-
except:
357-
raise TypeError("Location values should be numeric, {} is not a number".format(val))
358-
359-
self._location = value
360-
361352

362353
class GlobalSwitches(Element):
363354
def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):

0 commit comments

Comments
 (0)