fix handling of empty files

This commit is contained in:
Konstantin Käfer
2011-07-18 16:36:11 +02:00
parent a0c816c691
commit 64888c7e56
3 changed files with 80 additions and 34 deletions

View File

@@ -376,14 +376,23 @@ MBTiles.prototype.getInfo = function(callback) {
if (err) return callback(err);
var range = parseInt(info.maxzoom, 10) - parseInt(info.minzoom, 10);
info.minzoom = parseInt(info.minzoom, 10);
if (isNaN(info.minzoom) || typeof info.minzoom !== 'number') delete info.minzoom;
info.maxzoom = parseInt(info.maxzoom, 10);
if (isNaN(info.maxzoom) || typeof info.maxzoom !== 'number') delete info.maxzoom;
info.bounds = _((info.bounds || '').split(',')).map(parseFloat);
if (info.bounds.length !== 4 || info.bounds[0] === null) delete info.bounds;
if (info.center) info.center = _((info.center).split(',')).map(parseFloat);
if (!info.center || info.center.length !== 3) info.center = [
if ((!info.center || info.center.length !== 3) && info.bounds) info.center = [
(info.bounds[2] - info.bounds[0]) / 2 + info.bounds[0],
(info.bounds[3] - info.bounds[1]) / 2 + info.bounds[1],
(range <= 1) ? info.maxzoom : Math.floor(range * 0.5) + info.minzoom
];
if (info.center && (info.center.length !== 3 || info.center[0] === null)) {
delete info.center;
}
return callback(null, info);
});
};