Mapbox-gl-js: Better error when providing NaN/null camera settings

Created on 28 Apr 2015  路  12Comments  路  Source: mapbox/mapbox-gl-js

2015-04-28 at 1 53 pm

cause is in getProjTransform: https://github.com/mapbox/mapbox-gl-js/blob/master/js/geo/transform.js#L336-L357 which is returning an array of NaNs.

feature

Most helpful comment

I am getting this again in 0.23.0 when ever i do fitBounds().

https://gist.github.com/eatpurely/d7e8cd8e76695472d87d828fc60645a4

All 12 comments

map.transform:

{"tileSize":512,"_minZoom":0,"_maxZoom":20,"latRange":[-85.05113,85.05113],"width":407,"height":701,"_zoom":11.237981760650836,"scale":2415.2917653027107,"tileZoom":11,"zoomFraction":0.2379817606508361,"center":{"lat":37.76860424585354,"lng":-122.40030284531892},"angle":0,"_altitude":1.5,"_pitch":0}
{"tileSize":512,"_minZoom":0,"_maxZoom":20,"latRange":[-85.05113,85.05113],"width":1011,"height":353,"_zoom":0,"scale":1,"tileZoom":0,"zoomFraction":0,"center":{"lat":0,"lng":0},"angle":0,"_altitude":1.5,"_pitch":null}

The result I got was because the app was calling setView without a pitch argument which is now required in master: issue for that is https://github.com/mapbox/mapbox-gl-js/issues/1051

This is still triggerable without misusing the API like I was doing: just use shift-drag zooming in the /debug page.

I am getting this again in 0.23.0 when ever i do fitBounds().

https://gist.github.com/eatpurely/d7e8cd8e76695472d87d828fc60645a4

Same here :/

@eatpurely what are the values of addressLocation and driverLocation that result in an error?

@ansis These errors are almost certainly related to #2414.

Comment from the commit above:

It turns out that a null bearing is the cause of the 'Failed to invert matrix' error, rather than the format or order of latitude and longitude coordinates: mapbox/mapbox-gl-js#1189

I was getting this error too from the fitBounds() method, however I later realized I had just a few values switched so it was not able to make a proper box and got messed up. I wish that the method could accept an object with {ne: {lon: 0, lat: 0}, sw: {lon: 0, lat:0}} so you don't have to know the order that the lat and lons should be placed in an array, more explicit when they are named.

We're seeing the failed to invert matrix error when a user navigates to a map that renders 2 or more markers that have the exact same LngLat. We see it's because fitBounds does not have two different points to draw a box, but we were wondering if there is a method in the API to easily check whether the bounds are equal, and to only perform fitBounds if they are not equal. For now we are using this:

if(!(bounds._ne.lat === bounds._sw.lat && bounds._ne.lng === bounds._sw.lng)){ map.fitBounds(bounds) }

@daschi unfortunately we don't have a check like you're describing built into the API. Fortunately, this should be fixed when https://github.com/mapbox/mapbox-gl-js/pull/3683 merges.

@stuyam fitBounds at a single point is included in #3683 as well.

This error is much much rarer now 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronlidman picture aaronlidman  路  3Comments

iamdenny picture iamdenny  路  3Comments

BernhardRode picture BernhardRode  路  3Comments

mollymerp picture mollymerp  路  3Comments

Scarysize picture Scarysize  路  3Comments