mapbox/geojson-vt

Add warning for not Number type (debug mode)

korywka opened this issue ยท 2 comments

GeoJSONVT.prototype.getTile = function (z, x, y) {

If x, y, z are string type, getTile returns null. Wasted a lot of time to find it out ๐Ÿ™„

Or at least please add it to README.
Thanks.

oh boy, I too spent a lot of time scratching my head wondering why this wasn't working. For the most part JS will naturally convert to a number for most of the code when doing arithmetic, except at

geojson-vt/src/index.js

Lines 194 to 196 in aa2522b

function toID(z, x, y) {
return (((1 << z) * y + x) * 32) + z;
}

It decides to concatenate numbers first, so the results are completely messed up.

I've proposed #128 as a fix, I'd rather getTile just fix up any numbers passed as strings.

๐Ÿ‘(personally, I prefer more obviously conversion with Number() ๐Ÿ™„)