react-leaflet icon indicating copy to clipboard operation
react-leaflet copied to clipboard

Centralize all markers automatically

Open titxoo opened this issue 10 years ago • 7 comments

Hello everybody.

I have two markers , one in the United States and the other in Brazil , I can not center the map with all the markers automatically.

Expected behavior

### Actual behavior

Here is an example of code

https://jsfiddle.net/hqjv5utx/

titxoo avatar Jul 15 '16 01:07 titxoo

Hi, The map's center is applied as expected, there is no "automatic" center, it's up to your application to set it. You probably want to use something like Leaflet's latLngBounds() to create the bounds to inject to the map.

PaulLeCam avatar Jul 15 '16 09:07 PaulLeCam

@PaulLeCam What would be the best way to achieve this with the code below ?

https://jsfiddle.net/hqjv5utx/

titxoo avatar Jul 15 '16 13:07 titxoo

Hi @tiagocedrim, As your code above, you could use bounds to achieve your expectation https://jsfiddle.net/4p7u56wy/ FYI

bounds: bounds (optional): A rectangle for the map to contain. It will be centered, and the map will zoom in as close as it can while still showing the full bounds. This property is dynamic, if you change it it will be reflected on the map.

nguyendh2601 avatar Jul 18 '16 10:07 nguyendh2601

@PaulLeCam Thanks, worked perfectly :metal:

titxoo avatar Jul 18 '16 13:07 titxoo

Thanks, works great!

ihor-doroschenko avatar Feb 12 '20 13:02 ihor-doroschenko

THANKS A LOT!!! @nguyendh2601

QauseenMZ avatar Mar 28 '20 00:03 QauseenMZ

@nguyendh2601 Thx! Save my day!

atefBB avatar Jan 11 '21 15:01 atefBB