Skip to content
Advertisement

Get Bounds with Leaflet

I have a DC.JSc Charts which are filtering my icons on my Leaflet Map. Basically, when I’m filtering I want my map to zoom on my selected icons.

JavaScript

I’ve tried:

JavaScript

Also tried :

JavaScript

Error: Object doesn’t support property or method ‘getBounds’

Any ideas?

Found my own solution: map.fitBounds(clusterLayer.getBounds());

Advertisement

Answer

You’re almost there, but have several mistakes: you’re trying to getBounds within forEach loop, you’re trying to getBounds from the wrong object.

Please see and run the snippet below click FILTER button, read comments in JS code.

I omitted the filtering part, left zooming only:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement