|
60 | 60 | 'https://rawgit.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css'), # noqa
|
61 | 61 | ]
|
62 | 62 |
|
| 63 | +def _validate_location(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 values |
| 76 | + |
63 | 77 |
|
64 | 78 | class LegacyMap(MacroElement):
|
65 | 79 | """Create a Map with Folium and Leaflet.js
|
@@ -170,7 +184,7 @@ def __init__(self, location=None, width='100%', height='100%',
|
170 | 184 | self.location = [0, 0]
|
171 | 185 | self.zoom_start = min_zoom
|
172 | 186 | else:
|
173 |
| - self.location = location |
| 187 | + self.location = _validate_location(location) |
174 | 188 | self.zoom_start = zoom_start
|
175 | 189 |
|
176 | 190 | Figure().add_child(self)
|
@@ -337,7 +351,6 @@ def render(self, **kwargs):
|
337 | 351 |
|
338 | 352 | super(LegacyMap, self).render(**kwargs)
|
339 | 353 |
|
340 |
| - |
341 | 354 | class GlobalSwitches(Element):
|
342 | 355 | def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):
|
343 | 356 | super(GlobalSwitches, self).__init__()
|
|
0 commit comments