Skip to content

Commit a32dd82

Browse files
committed
add get_bounds
1 parent 4fcae97 commit a32dd82

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

folium/utilities.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def _parse_path(**kw):
7979
8080
"""
8181
color = kw.pop('color', '#3388ff')
82+
fill_color = kw.pop('fill_color', color)
83+
fill = False if not fill_color else True
8284
return {
8385
'stroke': kw.pop('stroke', True),
8486
'color': color,
@@ -88,8 +90,8 @@ def _parse_path(**kw):
8890
'lineJoin': kw.pop('line_join', 'round'),
8991
'dashArray': kw.pop('dash_array', None),
9092
'dashOffset': kw.pop('dash_offset', None),
91-
'fill': kw.pop('fill', False),
92-
'fillColor': kw.pop('fill_color', color),
93+
'fill': fill,
94+
'fillColor': fill_color,
9395
'fillOpacity': kw.pop('fill_opacity', 0.2),
9496
'fillRule': kw.pop('fill_rule', 'evenodd'),
9597
'bubblingMouseEvents': kw.pop('bubbling_mouse_events', True),
@@ -309,3 +311,61 @@ def mercator(x):
309311
if origin == 'upper':
310312
out = out[::-1, :, :]
311313
return out
314+
315+
316+
def none_min(x, y):
317+
if x is None:
318+
return y
319+
elif y is None:
320+
return x
321+
else:
322+
return min(x, y)
323+
324+
325+
def none_max(x, y):
326+
if x is None:
327+
return y
328+
elif y is None:
329+
return x
330+
else:
331+
return max(x, y)
332+
333+
334+
def iter_points(x):
335+
"""Iterates over a list representing a feature, and returns a list of points,
336+
whatever the shape of the array (Point, MultiPolyline, etc).
337+
"""
338+
if isinstance(x, (list, tuple)):
339+
if len(x):
340+
if isinstance(x[0], (list, tuple)):
341+
out = []
342+
for y in x:
343+
out += iter_points(y)
344+
return out
345+
else:
346+
return [x]
347+
else:
348+
return []
349+
else:
350+
raise ValueError('List/tuple type expected. Got {!r}.'.format(x))
351+
352+
353+
def get_bounds(locations):
354+
"""
355+
Computes the bounds of the object in the form
356+
[[lat_min, lon_min], [lat_max, lon_max]]
357+
358+
"""
359+
bounds = [[None, None], [None, None]]
360+
for point in iter_points(locations):
361+
bounds = [
362+
[
363+
none_min(bounds[0][0], point[0]),
364+
none_min(bounds[0][1], point[1]),
365+
],
366+
[
367+
none_max(bounds[1][0], point[0]),
368+
none_max(bounds[1][1], point[1]),
369+
],
370+
]
371+
return bounds

0 commit comments

Comments
 (0)