Deindent post tapification.
This commit is contained in:
@@ -6,25 +6,25 @@ var MBTiles = require('..');
|
|||||||
var fixtureDir = __dirname + '/fixtures/output';
|
var fixtureDir = __dirname + '/fixtures/output';
|
||||||
var image = fs.readFileSync(__dirname + '/fixtures/images/plain_1_0_0_0.png');
|
var image = fs.readFileSync(__dirname + '/fixtures/images/plain_1_0_0_0.png');
|
||||||
|
|
||||||
tape('setup', function(assert) {
|
tape('setup', function(assert) {
|
||||||
// Recreate output directory to remove previous tests.
|
// Recreate output directory to remove previous tests.
|
||||||
try { fs.unlinkSync(fixtureDir + '/commit_1.mbtiles'); } catch(err) {}
|
try { fs.unlinkSync(fixtureDir + '/commit_1.mbtiles'); } catch(err) {}
|
||||||
try { fs.mkdirSync(fixtureDir, 0755); } catch(err) {}
|
try { fs.mkdirSync(fixtureDir, 0755); } catch(err) {}
|
||||||
assert.end();
|
assert.end();
|
||||||
});
|
});
|
||||||
tape('test mbtiles commit lock', function(assert) {
|
tape('test mbtiles commit lock', function(assert) {
|
||||||
var remaining = 10;
|
var remaining = 10;
|
||||||
new MBTiles('mbtiles://' + fixtureDir + '/commit_1.mbtiles?batch=1', function(err, mbtiles) {
|
new MBTiles('mbtiles://' + fixtureDir + '/commit_1.mbtiles?batch=1', function(err, mbtiles) {
|
||||||
assert.ifError(err, 'new MBTiles');
|
assert.ifError(err, 'new MBTiles');
|
||||||
mbtiles.startWriting(function(err) {
|
mbtiles.startWriting(function(err) {
|
||||||
assert.ifError(err, 'startWriting');
|
assert.ifError(err, 'startWriting');
|
||||||
for (var i = 0; i < remaining; i++) mbtiles.putTile(0,0,0,image,putcb);
|
for (var i = 0; i < remaining; i++) mbtiles.putTile(0,0,0,image,putcb);
|
||||||
assert.equal(mbtiles._committing, true, 'Sets committing lock');
|
assert.equal(mbtiles._committing, true, 'Sets committing lock');
|
||||||
assert.equal(mbtiles._events.commit.length, 19, 'Queues commits');
|
assert.equal(mbtiles._events.commit.length, 19, 'Queues commits');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
function putcb(err) {
|
|
||||||
assert.ifError(err, 'putTile');
|
|
||||||
if (!--remaining) assert.end();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
function putcb(err) {
|
||||||
|
assert.ifError(err, 'putTile');
|
||||||
|
if (!--remaining) assert.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -8,86 +8,85 @@ var fixtures = {
|
|||||||
empty: __dirname + '/fixtures/empty.mbtiles'
|
empty: __dirname + '/fixtures/empty.mbtiles'
|
||||||
};
|
};
|
||||||
|
|
||||||
try { fs.unlinkSync(fixtures.empty); } catch (err) {}
|
try { fs.unlinkSync(fixtures.empty); } catch (err) {}
|
||||||
|
|
||||||
tape('get metadata', function(assert) {
|
tape('get metadata', function(assert) {
|
||||||
new MBTiles(fixtures.plain_1, function(err, mbtiles) {
|
new MBTiles(fixtures.plain_1, function(err, mbtiles) {
|
||||||
|
assert.ifError(err);
|
||||||
|
|
||||||
|
mbtiles.getInfo(function(err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
mbtiles.getInfo(function(err, data) {
|
assert.deepEqual({
|
||||||
assert.ifError(err);
|
name: 'plain_1',
|
||||||
|
description: 'demo description',
|
||||||
|
version: '1.0.3',
|
||||||
|
scheme: 'tms',
|
||||||
|
minzoom: 0,
|
||||||
|
maxzoom: 4,
|
||||||
|
formatter: null,
|
||||||
|
center: [ 0, 7.500000001278025, 2 ],
|
||||||
|
bounds: [ -179.9999999749438, -69.99999999526695, 179.9999999749438, 84.99999999782301 ],
|
||||||
|
// Test that json data is merged in.
|
||||||
|
level1: { level2: 'property' },
|
||||||
|
// These aren't part of TileJSON, but exist in an MBTiles file.
|
||||||
|
filesize: 561152,
|
||||||
|
type: 'baselayer',
|
||||||
|
id: 'plain_1',
|
||||||
|
basename: 'plain_1.mbtiles'
|
||||||
|
}, data);
|
||||||
|
|
||||||
assert.deepEqual({
|
assert.end();
|
||||||
name: 'plain_1',
|
|
||||||
description: 'demo description',
|
|
||||||
version: '1.0.3',
|
|
||||||
scheme: 'tms',
|
|
||||||
minzoom: 0,
|
|
||||||
maxzoom: 4,
|
|
||||||
formatter: null,
|
|
||||||
center: [ 0, 7.500000001278025, 2 ],
|
|
||||||
bounds: [ -179.9999999749438, -69.99999999526695, 179.9999999749438, 84.99999999782301 ],
|
|
||||||
// Test that json data is merged in.
|
|
||||||
level1: { level2: 'property' },
|
|
||||||
// These aren't part of TileJSON, but exist in an MBTiles file.
|
|
||||||
filesize: 561152,
|
|
||||||
type: 'baselayer',
|
|
||||||
id: 'plain_1',
|
|
||||||
basename: 'plain_1.mbtiles'
|
|
||||||
}, data);
|
|
||||||
|
|
||||||
assert.end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
tape('get/put metadata from empty file', function(assert) {
|
});
|
||||||
var info = {
|
tape('get/put metadata from empty file', function(assert) {
|
||||||
version: '1.0.0',
|
var info = {
|
||||||
level1: { level2: 'property' },
|
version: '1.0.0',
|
||||||
custom: [ 'custom list' ]
|
level1: { level2: 'property' },
|
||||||
};
|
custom: [ 'custom list' ]
|
||||||
|
};
|
||||||
|
|
||||||
new MBTiles(fixtures.empty, function(err, mbtiles) {
|
new MBTiles(fixtures.empty, function(err, mbtiles) {
|
||||||
|
assert.ifError(err);
|
||||||
|
|
||||||
|
mbtiles.getInfo(function(err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
mbtiles.getInfo(function(err, data) {
|
assert.deepEqual({
|
||||||
assert.ifError(err);
|
basename: "empty.mbtiles",
|
||||||
|
filesize: 0,
|
||||||
|
id: "empty",
|
||||||
|
scheme: "tms"
|
||||||
|
}, data);
|
||||||
|
|
||||||
assert.deepEqual({
|
mbtiles.putInfo(info, function(err) {
|
||||||
basename: "empty.mbtiles",
|
assert.ok(err);
|
||||||
filesize: 0,
|
assert.equal(err.message, 'MBTiles not in write mode');
|
||||||
id: "empty",
|
|
||||||
scheme: "tms"
|
|
||||||
}, data);
|
|
||||||
|
|
||||||
mbtiles.putInfo(info, function(err) {
|
mbtiles.startWriting(function(err) {
|
||||||
assert.ok(err);
|
assert.ifError(err);
|
||||||
assert.equal(err.message, 'MBTiles not in write mode');
|
|
||||||
|
|
||||||
mbtiles.startWriting(function(err) {
|
mbtiles.putInfo(info, function(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
mbtiles.putInfo(info, function(err) {
|
mbtiles.stopWriting(function(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
mbtiles.stopWriting(function(err) {
|
mbtiles.getInfo(function(err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
mbtiles.getInfo(function(err, data) {
|
assert.deepEqual({
|
||||||
assert.ifError(err);
|
basename: "empty.mbtiles",
|
||||||
|
filesize: 0,
|
||||||
|
id: "empty",
|
||||||
|
scheme: "tms",
|
||||||
|
version: "1.0.0",
|
||||||
|
level1: { level2: "property" },
|
||||||
|
custom: [ 'custom list' ]
|
||||||
|
}, data);
|
||||||
|
|
||||||
assert.deepEqual({
|
assert.end();
|
||||||
basename: "empty.mbtiles",
|
|
||||||
filesize: 0,
|
|
||||||
id: "empty",
|
|
||||||
scheme: "tms",
|
|
||||||
version: "1.0.0",
|
|
||||||
level1: { level2: "property" },
|
|
||||||
custom: [ 'custom list' ]
|
|
||||||
}, data);
|
|
||||||
|
|
||||||
assert.end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -95,3 +94,4 @@ var fixtures = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ var fixtures = {
|
|||||||
doesnotexist: __dirname + '/doesnotexist'
|
doesnotexist: __dirname + '/doesnotexist'
|
||||||
};
|
};
|
||||||
|
|
||||||
try { fs.unlinkSync(fixtures.doesnotexist); } catch (err) {}
|
try { fs.unlinkSync(fixtures.doesnotexist); } catch (err) {}
|
||||||
|
|
||||||
tape('list', function(assert) {
|
tape('list', function(assert) {
|
||||||
MBTiles.list(fixtures.doesnotexist, function(err, list) {
|
MBTiles.list(fixtures.doesnotexist, function(err, list) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.deepEqual(list, {});
|
assert.deepEqual(list, {});
|
||||||
assert.end();
|
assert.end();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -22,121 +22,121 @@ function yieldsError(assert, error, msg, callback) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var loaded = {};
|
var loaded = {};
|
||||||
|
|
||||||
try { fs.unlinkSync(fixtures.non_existent); } catch (err) {}
|
try { fs.unlinkSync(fixtures.non_existent); } catch (err) {}
|
||||||
|
|
||||||
tape('setup', function(assert) {
|
tape('setup', function(assert) {
|
||||||
var queue = Object.keys(fixtures);
|
var queue = Object.keys(fixtures);
|
||||||
var load = function() {
|
var load = function() {
|
||||||
if (!queue.length) return assert.end();
|
if (!queue.length) return assert.end();
|
||||||
var key = queue.shift();
|
var key = queue.shift();
|
||||||
new MBTiles(fixtures[key], function(err, mbtiles) {
|
new MBTiles(fixtures[key], function(err, mbtiles) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
loaded[key] = mbtiles;
|
loaded[key] = mbtiles;
|
||||||
load();
|
load();
|
||||||
});
|
|
||||||
};
|
|
||||||
load();
|
|
||||||
});
|
|
||||||
|
|
||||||
fs.readdirSync(__dirname + '/fixtures/images/').forEach(function(file) {
|
|
||||||
var coords = file.match(/^plain_1_(\d+)_(\d+)_(\d+).png$/);
|
|
||||||
if (!coords) return;
|
|
||||||
|
|
||||||
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
|
||||||
coords = [ coords[3], coords[1], coords[2] ];
|
|
||||||
coords[2] = Math.pow(2, coords[0]) - 1 - coords[2];
|
|
||||||
tape('tile ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.plain_1.getTile(coords[0] | 0, coords[1] | 0, coords[2] | 0, function(err, tile, headers) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.deepEqual(tile, fs.readFileSync(__dirname + '/fixtures/images/' + file));
|
|
||||||
assert.equal(headers['Content-Type'], 'image/png');
|
|
||||||
assert.ok(!isNaN(Date.parse(headers['Last-Modified'])));
|
|
||||||
assert.ok(/\d+-\d+/.test(headers['ETag']));
|
|
||||||
assert.end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
tape('grid ' + coords.join('/'), function(assert) {
|
};
|
||||||
loaded.plain_1.getGrid(coords[0] | 0, coords[1] | 0, coords[2] | 0, yieldsError(assert, 'error', 'Grid does not exist', assert.end));
|
load();
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.readdirSync(__dirname + '/fixtures/images/').forEach(function(file) {
|
||||||
|
var coords = file.match(/^plain_1_(\d+)_(\d+)_(\d+).png$/);
|
||||||
|
if (!coords) return;
|
||||||
|
|
||||||
|
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
||||||
|
coords = [ coords[3], coords[1], coords[2] ];
|
||||||
|
coords[2] = Math.pow(2, coords[0]) - 1 - coords[2];
|
||||||
|
tape('tile ' + coords.join('/'), function(assert) {
|
||||||
|
loaded.plain_1.getTile(coords[0] | 0, coords[1] | 0, coords[2] | 0, function(err, tile, headers) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.deepEqual(tile, fs.readFileSync(__dirname + '/fixtures/images/' + file));
|
||||||
|
assert.equal(headers['Content-Type'], 'image/png');
|
||||||
|
assert.ok(!isNaN(Date.parse(headers['Last-Modified'])));
|
||||||
|
assert.ok(/\d+-\d+/.test(headers['ETag']));
|
||||||
|
assert.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
[ [0,1,0],
|
tape('grid ' + coords.join('/'), function(assert) {
|
||||||
[-1,0,0],
|
loaded.plain_1.getGrid(coords[0] | 0, coords[1] | 0, coords[2] | 0, yieldsError(assert, 'error', 'Grid does not exist', assert.end));
|
||||||
[0,0,1],
|
|
||||||
[3,1,-1],
|
|
||||||
[2,-3,3],
|
|
||||||
[18,2,262140],
|
|
||||||
[4,0,15]
|
|
||||||
].forEach(function(coords) {
|
|
||||||
tape('tile ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.plain_1.getTile(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Tile does not exist', assert.end));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
[ [0,1,0],
|
||||||
|
[-1,0,0],
|
||||||
|
[0,0,1],
|
||||||
|
[3,1,-1],
|
||||||
|
[2,-3,3],
|
||||||
|
[18,2,262140],
|
||||||
|
[4,0,15]
|
||||||
|
].forEach(function(coords) {
|
||||||
|
tape('tile ' + coords.join('/'), function(assert) {
|
||||||
|
loaded.plain_1.getTile(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Tile does not exist', assert.end));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
fs.readdirSync(__dirname + '/fixtures/grids/').forEach(function(file) {
|
fs.readdirSync(__dirname + '/fixtures/grids/').forEach(function(file) {
|
||||||
var coords = file.match(/^plain_2_(\d+)_(\d+)_(\d+).json$/);
|
var coords = file.match(/^plain_2_(\d+)_(\d+)_(\d+).json$/);
|
||||||
if (!coords) return;
|
if (!coords) return;
|
||||||
|
|
||||||
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
||||||
coords = [ coords[3], coords[1], coords[2] ];
|
coords = [ coords[3], coords[1], coords[2] ];
|
||||||
coords[2] = Math.pow(2, coords[0]) - 1 - coords[2];
|
coords[2] = Math.pow(2, coords[0]) - 1 - coords[2];
|
||||||
tape('grid ' + coords.join('/'), function(assert) {
|
tape('grid ' + coords.join('/'), function(assert) {
|
||||||
loaded.plain_2.getGrid(coords[0] | 0, coords[1] | 0, coords[2] | 0, function(err, grid, headers) {
|
loaded.plain_2.getGrid(coords[0] | 0, coords[1] | 0, coords[2] | 0, function(err, grid, headers) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8'));
|
assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8'));
|
||||||
assert.equal(headers['Content-Type'], 'text/javascript');
|
assert.equal(headers['Content-Type'], 'text/javascript');
|
||||||
assert.ok(!isNaN(Date.parse(headers['Last-Modified'])));
|
assert.ok(!isNaN(Date.parse(headers['Last-Modified'])));
|
||||||
assert.ok(/\d+-\d+/.test(headers['ETag']));
|
assert.ok(/\d+-\d+/.test(headers['ETag']));
|
||||||
assert.end();
|
assert.end();
|
||||||
});
|
|
||||||
});
|
|
||||||
tape('grid alt ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.plain_4.getGrid(coords[0] | 0, coords[1] | 0, coords[2] | 0, function(err, grid, headers) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8'));
|
|
||||||
assert.equal(headers['Content-Type'], 'text/javascript');
|
|
||||||
assert.ok(!isNaN(Date.parse(headers['Last-Modified'])));
|
|
||||||
assert.ok(/\d+-\d+/.test(headers['ETag']));
|
|
||||||
assert.end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
[ [0,1,0],
|
tape('grid alt ' + coords.join('/'), function(assert) {
|
||||||
[-1,0,0],
|
loaded.plain_4.getGrid(coords[0] | 0, coords[1] | 0, coords[2] | 0, function(err, grid, headers) {
|
||||||
[0,0,1],
|
if (err) throw err;
|
||||||
[3,1,-1],
|
assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8'));
|
||||||
[2,-3,3],
|
assert.equal(headers['Content-Type'], 'text/javascript');
|
||||||
[18,2,262140],
|
assert.ok(!isNaN(Date.parse(headers['Last-Modified'])));
|
||||||
[4,0,15]
|
assert.ok(/\d+-\d+/.test(headers['ETag']));
|
||||||
].forEach(function(coords) {
|
assert.end();
|
||||||
tape('grid ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.plain_2.getGrid(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Grid does not exist', assert.end));
|
|
||||||
});
|
|
||||||
tape('grid alt ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.plain_4.getGrid(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Grid does not exist', assert.end));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
[ [0,1,0],
|
});
|
||||||
[-1,0,0],
|
[ [0,1,0],
|
||||||
[0,0,-1],
|
[-1,0,0],
|
||||||
[3,1,8],
|
[0,0,1],
|
||||||
[2,-3,0],
|
[3,1,-1],
|
||||||
[18,2,3],
|
[2,-3,3],
|
||||||
[4,0,0],
|
[18,2,262140],
|
||||||
[4,3,8],
|
[4,0,15]
|
||||||
[4,4,8],
|
].forEach(function(coords) {
|
||||||
[4,5,8],
|
tape('grid ' + coords.join('/'), function(assert) {
|
||||||
[4,13,4],
|
loaded.plain_2.getGrid(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Grid does not exist', assert.end));
|
||||||
[4,0,14],
|
|
||||||
[3,0,7],
|
|
||||||
[3,6,2]
|
|
||||||
].forEach(function(coords) {
|
|
||||||
tape('dne ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.non_existent.getTile(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Tile does not exist', assert.end));
|
|
||||||
});
|
|
||||||
tape('corrupt ' + coords.join('/'), function(assert) {
|
|
||||||
loaded.corrupt.getTile(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'SQLITE_CORRUPT: database disk image is malformed', assert.end));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
tape('grid alt ' + coords.join('/'), function(assert) {
|
||||||
|
loaded.plain_4.getGrid(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Grid does not exist', assert.end));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
[ [0,1,0],
|
||||||
|
[-1,0,0],
|
||||||
|
[0,0,-1],
|
||||||
|
[3,1,8],
|
||||||
|
[2,-3,0],
|
||||||
|
[18,2,3],
|
||||||
|
[4,0,0],
|
||||||
|
[4,3,8],
|
||||||
|
[4,4,8],
|
||||||
|
[4,5,8],
|
||||||
|
[4,13,4],
|
||||||
|
[4,0,14],
|
||||||
|
[3,0,7],
|
||||||
|
[3,6,2]
|
||||||
|
].forEach(function(coords) {
|
||||||
|
tape('dne ' + coords.join('/'), function(assert) {
|
||||||
|
loaded.non_existent.getTile(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'Tile does not exist', assert.end));
|
||||||
|
});
|
||||||
|
tape('corrupt ' + coords.join('/'), function(assert) {
|
||||||
|
loaded.corrupt.getTile(coords[0], coords[1], coords[2], yieldsError(assert, 'error', 'SQLITE_CORRUPT: database disk image is malformed', assert.end));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,58 +5,58 @@ var tape = require('tape');
|
|||||||
var MBTiles = require('..');
|
var MBTiles = require('..');
|
||||||
var fixtureDir = __dirname + '/fixtures/output';
|
var fixtureDir = __dirname + '/fixtures/output';
|
||||||
|
|
||||||
// Recreate output directory to remove previous tests.
|
// Recreate output directory to remove previous tests.
|
||||||
try { fs.unlinkSync(fixtureDir + '/write_1.mbtiles'); } catch(err) {}
|
try { fs.unlinkSync(fixtureDir + '/write_1.mbtiles'); } catch(err) {}
|
||||||
try { fs.mkdirSync(fixtureDir, 0755); } catch(err) {}
|
try { fs.mkdirSync(fixtureDir, 0755); } catch(err) {}
|
||||||
|
|
||||||
tape('test mbtiles file creation', function(assert) {
|
tape('test mbtiles file creation', function(assert) {
|
||||||
var completed = { written: 0, read: 0 };
|
var completed = { written: 0, read: 0 };
|
||||||
new MBTiles(fixtureDir + '/write_1.mbtiles', function(err, mbtiles) {
|
new MBTiles(fixtureDir + '/write_1.mbtiles', function(err, mbtiles) {
|
||||||
completed.open = true;
|
completed.open = true;
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
mbtiles.startWriting(function(err) {
|
||||||
|
completed.started = true;
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
mbtiles.startWriting(function(err) {
|
fs.readdirSync(__dirname + '/fixtures/images/').forEach(insertTile);
|
||||||
completed.started = true;
|
|
||||||
if (err) throw err;
|
|
||||||
|
|
||||||
fs.readdirSync(__dirname + '/fixtures/images/').forEach(insertTile);
|
|
||||||
});
|
|
||||||
|
|
||||||
function insertTile(file) {
|
|
||||||
var coords = file.match(/^plain_1_(\d+)_(\d+)_(\d+).png$/);
|
|
||||||
if (!coords) return;
|
|
||||||
|
|
||||||
// Flip Y coordinate because file names are TMS, but .putTile() expects XYZ.
|
|
||||||
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
|
||||||
|
|
||||||
var tile = fs.readFileSync(__dirname + '/fixtures/images/' + file);
|
|
||||||
mbtiles.putTile(coords[3] | 0, coords[1] | 0, coords[2] | 0, tile, function(err) {
|
|
||||||
if (err) throw err;
|
|
||||||
completed.written++;
|
|
||||||
if (completed.written === 285) {
|
|
||||||
mbtiles.stopWriting(function(err) {
|
|
||||||
completed.stopped = true;
|
|
||||||
if (err) throw err;
|
|
||||||
verifyWritten();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function verifyWritten() {
|
|
||||||
fs.readdirSync(__dirname + '/fixtures/images/').forEach(function(file) {
|
|
||||||
var coords = file.match(/^plain_1_(\d+)_(\d+)_(\d+).png$/);
|
|
||||||
if (coords) {
|
|
||||||
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
|
||||||
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
|
||||||
mbtiles.getTile(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, tile) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.deepEqual(tile, fs.readFileSync(__dirname + '/fixtures/images/' + file));
|
|
||||||
completed.read++;
|
|
||||||
if (completed.read === 285) assert.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function insertTile(file) {
|
||||||
|
var coords = file.match(/^plain_1_(\d+)_(\d+)_(\d+).png$/);
|
||||||
|
if (!coords) return;
|
||||||
|
|
||||||
|
// Flip Y coordinate because file names are TMS, but .putTile() expects XYZ.
|
||||||
|
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
||||||
|
|
||||||
|
var tile = fs.readFileSync(__dirname + '/fixtures/images/' + file);
|
||||||
|
mbtiles.putTile(coords[3] | 0, coords[1] | 0, coords[2] | 0, tile, function(err) {
|
||||||
|
if (err) throw err;
|
||||||
|
completed.written++;
|
||||||
|
if (completed.written === 285) {
|
||||||
|
mbtiles.stopWriting(function(err) {
|
||||||
|
completed.stopped = true;
|
||||||
|
if (err) throw err;
|
||||||
|
verifyWritten();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyWritten() {
|
||||||
|
fs.readdirSync(__dirname + '/fixtures/images/').forEach(function(file) {
|
||||||
|
var coords = file.match(/^plain_1_(\d+)_(\d+)_(\d+).png$/);
|
||||||
|
if (coords) {
|
||||||
|
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
||||||
|
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
||||||
|
mbtiles.getTile(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, tile) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.deepEqual(tile, fs.readFileSync(__dirname + '/fixtures/images/' + file));
|
||||||
|
completed.read++;
|
||||||
|
if (completed.read === 285) assert.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -5,58 +5,58 @@ var tape = require('tape');
|
|||||||
var MBTiles = require('..');
|
var MBTiles = require('..');
|
||||||
var fixtureDir = __dirname + '/fixtures/output';
|
var fixtureDir = __dirname + '/fixtures/output';
|
||||||
|
|
||||||
// Recreate output directory to remove previous tests.
|
// Recreate output directory to remove previous tests.
|
||||||
try { fs.unlinkSync(fixtureDir + '/write_2.mbtiles'); } catch(err) {}
|
try { fs.unlinkSync(fixtureDir + '/write_2.mbtiles'); } catch(err) {}
|
||||||
try { fs.mkdirSync(fixtureDir, 0755); } catch(err) {}
|
try { fs.mkdirSync(fixtureDir, 0755); } catch(err) {}
|
||||||
|
|
||||||
tape('test mbtiles file creation', function(assert) {
|
tape('test mbtiles file creation', function(assert) {
|
||||||
var completed = { written: 0, read: 0 };
|
var completed = { written: 0, read: 0 };
|
||||||
new MBTiles(fixtureDir + '/write_2.mbtiles', function(err, mbtiles) {
|
new MBTiles(fixtureDir + '/write_2.mbtiles', function(err, mbtiles) {
|
||||||
completed.open = true;
|
completed.open = true;
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
mbtiles.startWriting(function(err) {
|
||||||
|
completed.started = true;
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
mbtiles.startWriting(function(err) {
|
fs.readdirSync(__dirname + '/fixtures/grids/').forEach(insertGrid);
|
||||||
completed.started = true;
|
|
||||||
if (err) throw err;
|
|
||||||
|
|
||||||
fs.readdirSync(__dirname + '/fixtures/grids/').forEach(insertGrid);
|
|
||||||
});
|
|
||||||
|
|
||||||
function insertGrid(file) {
|
|
||||||
var coords = file.match(/^plain_2_(\d+)_(\d+)_(\d+).json$/);
|
|
||||||
if (!coords) return;
|
|
||||||
|
|
||||||
// Flip Y coordinate because file names are TMS, but .putGrid() expects XYZ.
|
|
||||||
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
|
||||||
|
|
||||||
var grid = fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8');
|
|
||||||
mbtiles.putGrid(coords[3] | 0, coords[1] | 0, coords[2] | 0, JSON.parse(grid), function(err) {
|
|
||||||
if (err) throw err;
|
|
||||||
completed.written++;
|
|
||||||
if (completed.written === 241) {
|
|
||||||
mbtiles.stopWriting(function(err) {
|
|
||||||
completed.stopped = true;
|
|
||||||
if (err) throw err;
|
|
||||||
verifyWritten();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function verifyWritten() {
|
|
||||||
fs.readdirSync(__dirname + '/fixtures/grids/').forEach(function(file) {
|
|
||||||
var coords = file.match(/^plain_2_(\d+)_(\d+)_(\d+).json$/);
|
|
||||||
if (coords) {
|
|
||||||
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
|
||||||
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
|
||||||
mbtiles.getGrid(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, grid) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8'));
|
|
||||||
completed.read++;
|
|
||||||
if (completed.read === 241) assert.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function insertGrid(file) {
|
||||||
|
var coords = file.match(/^plain_2_(\d+)_(\d+)_(\d+).json$/);
|
||||||
|
if (!coords) return;
|
||||||
|
|
||||||
|
// Flip Y coordinate because file names are TMS, but .putGrid() expects XYZ.
|
||||||
|
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
||||||
|
|
||||||
|
var grid = fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8');
|
||||||
|
mbtiles.putGrid(coords[3] | 0, coords[1] | 0, coords[2] | 0, JSON.parse(grid), function(err) {
|
||||||
|
if (err) throw err;
|
||||||
|
completed.written++;
|
||||||
|
if (completed.written === 241) {
|
||||||
|
mbtiles.stopWriting(function(err) {
|
||||||
|
completed.stopped = true;
|
||||||
|
if (err) throw err;
|
||||||
|
verifyWritten();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyWritten() {
|
||||||
|
fs.readdirSync(__dirname + '/fixtures/grids/').forEach(function(file) {
|
||||||
|
var coords = file.match(/^plain_2_(\d+)_(\d+)_(\d+).json$/);
|
||||||
|
if (coords) {
|
||||||
|
// Flip Y coordinate because file names are TMS, but .getTile() expects XYZ.
|
||||||
|
coords[2] = Math.pow(2, coords[3]) - 1 - coords[2];
|
||||||
|
mbtiles.getGrid(coords[3] | 0, coords[1] | 0, coords[2] | 0, function(err, grid) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.deepEqual(JSON.stringify(grid), fs.readFileSync(__dirname + '/fixtures/grids/' + file, 'utf8'));
|
||||||
|
completed.read++;
|
||||||
|
if (completed.read === 241) assert.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user