Update location check to function
Remove property setters based on PR comments
@@ -60,6 +60,19 @@ _default_css = [
'https://rawgit.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css'), # noqa
]
+def _format_lat_lon(values):
+ """Validates and formats location values before setting"""
+ if type(values) not in [list, tuple]:
+ raise TypeError("Location is not a list, expecting ex: location=[45.523, -122.675]")
+
+ if len(values) != 2:
+ raise ValueError("Location should have two values, [lat, lon]")
+
+ try:
+ values = [float(val) for val in values]
+ except:
+ raise ValueError("Location values should be numeric, {} is not a number".format(val))
+ return value
class LegacyMap(MacroElement):
"""Create a Map with Folium and Leaflet.js
@@ -170,7 +183,7 @@ class LegacyMap(MacroElement):
self.location = [0, 0]
self.zoom_start = min_zoom
else:
- self.location = location
+ self.location = _format_lat_lon(location)
self.zoom_start = zoom_start
Figure().add_child(self)
@@ -337,28 +350,6 @@ class LegacyMap(MacroElement):
super(LegacyMap, self).render(**kwargs)
- @property
- def location(self):
- return self._location
-
- @location.setter
- def location(self, value):
- """Validates the location values before setting"""
- if type(value) not in [list, tuple]:
- raise TypeError("Location is not a list, expecting ex: location=[45.523, -122.675]")
-
- if len(value) != 2:
- raise ValueError("Location should have two values, [lat, lon]")
-
- for val in value:
- try:
- float(val)
- except:
- raise TypeError("Location values should be numeric, {} is not a number".format(val))
-
- self._location = value
-
-
class GlobalSwitches(Element):
def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):
super(GlobalSwitches, self).__init__()
