zcreativelabs / react-simple-maps

Beautiful React SVG maps with d3-geo and topojson using a declarative api.
https://www.react-simple-maps.io/
MIT License
3.12k stars 426 forks source link

Zooming map to show two points #255

Open jnhfmn opened 3 years ago

jnhfmn commented 3 years ago

Hi guys,

I'm working on project with your library and this is what I got

https://codesandbox.io/s/react-simple-maps-switching-topojson-on-zoom-forked-1s4qh?file=/src/index.js

As you can see I'm trying to maximally zoom the map to show two points based on their coordinates

What is a problem, when you click on 2 the zooming work properly, but on 1 the map is zoomed to far - I'm trying to figure out what is wrong witch my calculation that it work only in some cases.

As you can see in function calcZoom I'm calculating zoom based on centroid of this two coordinates and bbox.

If someone can help be would be greatfull.

Best!