react-map-gl icon indicating copy to clipboard operation
react-map-gl copied to clipboard

Post 1.6.0, fitBounds method returns a NaN zoom value

Open srikanthnarayan opened this issue 10 years ago • 5 comments

This seems to possibly coincide with the MapboxGL 0.24 upgrade. Using fitBounds, and applying the returned values on to map props would cause the map component to fail.

srikanthnarayan avatar Sep 23 '16 23:09 srikanthnarayan

Having a similar issue here, did you ever get to the bottom of this?

Appears tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)); being passed tr.scale = 1, scaleX = 35.78821257289714, scaleY = -36.83207022162391

screen shot 2016-10-30 at 08 09 33

I'm guessing because it's taking the negative point from the min() call before going to tr.scaleZoom(), but I've a limited understanding here of why exactly since the returned lat/long coord is correct, just the zoom that is wrong.

gaving avatar Oct 30 '16 08:10 gaving

This seems to be due to passing a negative value to the scaleZoom method in some cases. If the line is changed to const zoom = tr.scaleZoom(tr.scale * Math.abs(Math.min(scaleX, scaleY))); it works as expected again.

jwarning avatar Nov 26 '16 23:11 jwarning

Hey guys. Were you able to come up with a solution for this - if so, can you drop a PR?

abmai avatar Dec 06 '16 23:12 abmai

Yeah I could probably do so. The fix relies on ensuring that the scale passed to the scaleZoom method is not negative. The line I posted above fixes the issue.

jwarning avatar Dec 06 '16 23:12 jwarning

Resolved by #159.

balthazar avatar Dec 09 '16 21:12 balthazar