Skip to content

Commit

Permalink
hardlink empty vector tiles to a common file
Browse files Browse the repository at this point in the history
While at it calculate the filename of the new vector file only once.
  • Loading branch information
DerDakon committed Mar 24, 2016
1 parent a40b922 commit 4a56fe9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions emptytile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"features":[],"granularity":10}
28 changes: 23 additions & 5 deletions tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Tile.prototype =
}

var filepath = configuration.vtiledir+'/'+this.z+'/'+this.x+'/';
var file = this.y+'.json';
var file = filepath + this.y + '.json';

this.debug('Creating path '+filepath+'...');
var self = this;
Expand All @@ -155,19 +155,37 @@ Tile.prototype =
});
}

self.debug('Created path. Saving vector tile at path: '+filepath+file);
fs.writeFile(filepath+file, JSON.stringify(self.data), {mode: 0666}, function(err)
if (self.data.features.length === 0)
{
self.debug('Created path. Linking empty vector tile to: ' + file);
fs.link('emptytile.json', file, function(err)
{
if (!err)
self.debug('Empty vector tile was stored.');
else
self.debug('Could not link empty vector file.');

return process.nextTick(function()
{
callback(true);
});
});
}

self.debug('Created path. Saving vector tile at path: ' + file);
fs.unlinkSync(file);
fs.writeFile(file, JSON.stringify(self.data), {mode: 0666}, function(err)
{
if (err)
{
self.error('Cannot save vector tile at path: '+filepath+file);
self.error('Cannot save vector tile at path: ' + file);
return process.nextTick(function()
{
callback(err);
});
}

self.debug('Saved vector tile at path: '+filepath+file);
self.debug('Saved vector tile at path: ' + file);
return process.nextTick(function()
{
callback(false);
Expand Down

0 comments on commit 4a56fe9

Please sign in to comment.