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