Skip to content

Commit 01ad4b1

Browse files
committed
use get_bounds in GeoJSON
1 parent 0d5cd52 commit 01ad4b1

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

folium/features.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from branca.utilities import (_locations_tolist, _parse_size, image_to_url, iter_points, none_max, none_min) # noqa
1818

1919
from folium.map import FeatureGroup, Icon, Layer, Marker
20-
from folium.utilities import _parse_wms
20+
from folium.utilities import _parse_wms, get_bounds
2121
from folium.vector_layers import PolyLine
2222

2323
from jinja2 import Template
@@ -510,37 +510,13 @@ def style_data(self):
510510
feature.setdefault('properties', {}).setdefault('highlight', {}).update(self.highlight_function(feature)) # noqa
511511
return json.dumps(self.data, sort_keys=True)
512512

513-
def get_bounds(self):
513+
def _get_self_bounds(self):
514514
"""
515515
Computes the bounds of the object itself (not including it's children)
516-
in the form [[lat_min, lon_min], [lat_max, lon_max]]
516+
in the form [[lat_min, lon_min], [lat_max, lon_max]].
517517
518518
"""
519-
if not self.embed:
520-
raise ValueError('Cannot compute bounds of non-embedded GeoJSON.')
521-
522-
if 'features' not in self.data.keys():
523-
# Catch case when GeoJSON is just a single Feature or a geometry.
524-
if not (isinstance(self.data, dict) and 'geometry' in self.data.keys()): # noqa
525-
# Catch case when GeoJSON is just a geometry.
526-
self.data = {'type': 'Feature', 'geometry': self.data}
527-
self.data = {'type': 'FeatureCollection', 'features': [self.data]}
528-
529-
bounds = [[None, None], [None, None]]
530-
for feature in self.data['features']:
531-
for point in iter_points(feature.get('geometry', {}).get('coordinates', {})): # noqa
532-
bounds = [
533-
[
534-
none_min(bounds[0][0], point[1]),
535-
none_min(bounds[0][1], point[0]),
536-
],
537-
[
538-
none_max(bounds[1][0], point[1]),
539-
none_max(bounds[1][1], point[0]),
540-
],
541-
]
542-
return bounds
543-
519+
return get_bounds(self.data, lonlat=True)
544520

545521
class TopoJson(Layer):
546522
"""

0 commit comments

Comments
 (0)