Mapbox-gl-js: Display an error message when fitBounds' padding is larger than map

Created on 1 Dec 2015  路  3Comments  路  Source: mapbox/mapbox-gl-js

Due to some imperfect CSS, the page I was loading had a map that was 34px wide and 640px tall. I tried calling the following:

map.fitBounds(myBounds, { padding: 20 });

which was blowing up with:

Error: Invalid LngLat object: (NaN, NaN)

I traced that down to the fact that inside fitBounds(), scaleX was coming out to -0.02134339601961903. That's because the width is smaller than twice the padding, which you can see here will be a problem: https://github.com/mapbox/mapbox-gl-js/blob/d1e521322da88b81f143190a0b79eab28ca99aaf/js/ui/camera.js#L361

There should probably be some kind of rescue for these calculations with a default value for situations like these.

Hope that's enough info to get by on!

feature good first issue

Most helpful comment

Having the same issue! Any plans to have this one fixed soon?

Thanks for Mapbox GL!

All 3 comments

Having the same issue! Any plans to have this one fixed soon?

Thanks for Mapbox GL!

I just added a better warning for this error in #3890 馃樃

Looks like this was addressed sufficiently in #3890.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

foundryspatial-duncan picture foundryspatial-duncan  路  3Comments

iamdenny picture iamdenny  路  3Comments

rigoneri picture rigoneri  路  3Comments

mapcarta picture mapcarta  路  3Comments

samanpwbb picture samanpwbb  路  3Comments