Skip to content

Commit 8abfe0a

Browse files
committed
Add value checking for location #625
Using property decorators.
1 parent 5d1c722 commit 8abfe0a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

folium/map.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from __future__ import unicode_literals
12-
12+
import numbers
1313
import json
1414
from collections import OrderedDict
1515

@@ -297,6 +297,26 @@ def render(self, **kwargs):
297297
'</style>'), name='map_style')
298298

299299
super(LegacyMap, self).render(**kwargs)
300+
301+
@property
302+
def location(self):
303+
return self._location
304+
305+
@location.setter
306+
def location(self, value):
307+
"""Validates the location values before setting"""
308+
if type(value) not in [list, tuple]:
309+
raise TypeError("Location is not a list, expecting ex: location=[45.523, -122.675]")
310+
311+
if len(value) != 2:
312+
raise ValueError("Location should have two values, [lat, lon]")
313+
314+
for val in value:
315+
if not isinstance(val, numbers.Rational):
316+
raise TypeError("Location values should be numeric, {val} is not a number".format(val))
317+
318+
319+
self._location = value
300320

301321

302322
class GlobalSwitches(Element):

0 commit comments

Comments
 (0)