only list map records that include tile data in ZXYStream()
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
node_modules
|
||||
test/fixtures/non_existent.mbtiles
|
||||
test/fixtures/empty.mbtiles
|
||||
test/fixtures/output
|
||||
|
||||
@@ -31,7 +31,10 @@ ZXYStream.prototype._read = function() {
|
||||
|
||||
// Prepare sql statement
|
||||
if (!stream.statement) {
|
||||
stream.statement = this.source._db.prepare('SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM ' + this.table, function(err) {
|
||||
var query = 'SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM ' + this.table;
|
||||
if (this.table === 'map') query += ' WHERE tile_id is not null';
|
||||
|
||||
stream.statement = this.source._db.prepare(query, function(err) {
|
||||
if (err && err.code === 'SQLITE_ERROR' && /no such table/.test(err.message)) return stream.push(null);
|
||||
return stream._read();
|
||||
});
|
||||
|
||||
BIN
test/fixtures/some-empty-tiles.mbtiles
vendored
Normal file
BIN
test/fixtures/some-empty-tiles.mbtiles
vendored
Normal file
Binary file not shown.
@@ -145,3 +145,20 @@ tape('zxystream empty zxystream', function(assert) {
|
||||
assert.end();
|
||||
});
|
||||
});
|
||||
|
||||
tape('zxystream ignores map coords without tile_ids', function(assert) {
|
||||
new MBTiles(__dirname + '/fixtures/some-empty-tiles.mbtiles', function(err, src) {
|
||||
if (err) throw err;
|
||||
var stream = src.createZXYStream();
|
||||
var called = 0;
|
||||
stream.on('data', function(lines) {
|
||||
lines.toString().split('\n').forEach(function(coord) {
|
||||
if (coord) called++;
|
||||
});
|
||||
});
|
||||
stream.on('end', function() {
|
||||
assert.equal(called, 11, 'found correct number of tiles');
|
||||
assert.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user