Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using getBounds on geoJSON feature

I've tried map.fitBounds(geojsonFeature.getBounds()); and I get this error:

geojsonFeature.getBounds() is not a function.

Here is the code: http://jsfiddle.net/0aqxktov/

What is going wrong here?

Thanks in advance.

like image 686
Mike Johnson Jr Avatar asked Jan 27 '19 05:01

Mike Johnson Jr


Video Answer


1 Answers

Your variable geojsonFeature is just an object, there is no method named getBounds() there, as you can easily check.

Instead of that, give your geoJSON layer a name...

var feature = L.geoJson(geojsonFeature).addTo(map);

And use that to call getBounds():

map.fitBounds(feature.getBounds());

Here is the updated JSFiddle: http://jsfiddle.net/qofrgm2k/

like image 144
Gerardo Furtado Avatar answered Oct 11 '22 02:10

Gerardo Furtado