Sketch of using map table + map index if present for zxystream.
This commit is contained in:
+11
-1
@@ -28,7 +28,17 @@ function ZXYStream(source, options) {
|
||||
|
||||
ZXYStream.prototype._read = function() {
|
||||
var stream = this;
|
||||
this.source._db.all('SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles LIMIT ' + this.batch + ' OFFSET ' + this.offset, function(err, rows) {
|
||||
|
||||
// Check for the existence of a map table that is indexed.
|
||||
if (!stream.table) {
|
||||
return this.source._db.get("select count(1) as count from sqlite_master where type = 'index' and tbl_name = 'map';", function(err, row) {
|
||||
if (err) return stream.emit('error', err);
|
||||
stream.table = row.count === 1 ? 'map' : 'tiles';
|
||||
return stream._read();
|
||||
});
|
||||
}
|
||||
|
||||
this.source._db.all('SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM ' + this.table + ' LIMIT ' + this.batch + ' OFFSET ' + this.offset, function(err, rows) {
|
||||
if (err && err.code === 'SQLITE_ERROR' && /no such table/.test(err.message)) return stream.push(null);
|
||||
if (err) return stream.emit('error', err);
|
||||
if (!rows.length) return stream.push(null);
|
||||
|
||||
Reference in New Issue
Block a user