Skip to content

Commit

Permalink
do not tile empty geojson, close #40
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Sep 22, 2015
1 parent 76140fe commit 7cfb639
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ function GeoJSONVT(data, options) {
features = wrap(features, options.buffer / options.extent, intersectX);

// start slicing from the top tile down
this.splitTile(features, 0, 0, 0);
if (features.length) this.splitTile(features, 0, 0, 0);

if (debug) {
console.log('features: %d, points: %d', this.tiles[0].numFeatures, this.tiles[0].numPoints);
if (features.length) console.log('features: %d, points: %d', this.tiles[0].numFeatures, this.tiles[0].numPoints);
console.timeEnd('generate tiles');
console.log('tiles generated:', this.total, JSON.stringify(this.stats));
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "FeatureCollection",
"features": []
}
5 changes: 5 additions & 0 deletions test/test-full.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function testTiles(inputFile, expectedFile, maxZoom, maxPoints) {
});
}

test('empty geojson', function (t) {
t.same(genTiles(getJSON('empty.json')), {});
t.end();
});

function getJSON(name) {
return JSON.parse(fs.readFileSync(path.join(__dirname, '/fixtures/' + name)));
}

0 comments on commit 7cfb639

Please sign in to comment.