Comparing version 4.2.2 to 4.3.0
@@ -15,2 +15,4 @@ var tilelive = require('..'); | ||
this.job = job; | ||
this.formats = []; | ||
this.cache = { tile: {}, grid: {} }; | ||
this.initialize(from, to); | ||
@@ -69,3 +71,8 @@ } | ||
CopyTask.prototype.pause = function(callback) { | ||
// Don't call the callback if already pausing as callers often | ||
// expect they are the only ones doing teardown operations. | ||
if (this.pausing) return; | ||
var task = this; | ||
this.pausing = true; | ||
@@ -109,9 +116,29 @@ this.scheme.once('paused', function() { | ||
task.source = source; | ||
tilelive.load(task.to, function(err, sink) { | ||
source.getInfo(function(err, info) { | ||
if (err) return callback(err); | ||
task.sink = sink; | ||
task.sink.startWriting(function(err) { | ||
// @TODO the tilelive API currently has no standard way | ||
// of determining whether a tilesource has tiles, grids | ||
// or both. See issue #44. | ||
task.formats.push('tile'); | ||
// Use template as an indicator that grids are present. | ||
if (info.template) { | ||
task.formats.push('grid'); | ||
task.stats.total = (task.stats.total || 0) * 2; | ||
} | ||
tilelive.load(task.to, function(err, sink) { | ||
if (err) return callback(err); | ||
task.scheme.start(); | ||
callback(null); | ||
task.sink = sink; | ||
task.sink.startWriting(function(err) { | ||
if (err) return callback(err); | ||
// It is possible for a CopyTask to be paused before it | ||
// ever starts (SIGINT, exceptions, etc.) In these cases | ||
// respect the pause rather than forging ahead. | ||
if (task.pausing) return callback(null); | ||
task.scheme.start(); | ||
callback(null); | ||
}); | ||
}); | ||
@@ -122,6 +149,12 @@ }); | ||
CopyTask.prototype.render = function(tile) { | ||
CopyTask.prototype.render = function(tile, type) { | ||
var get = type === 'grid' ? 'getGrid' : 'getTile'; | ||
var put = type === 'grid' ? 'putGrid' : 'putTile'; | ||
var task = this; | ||
if (tile.key !== false) { | ||
task.sink.putDuplicateTile(tile.z, tile.x, tile.y, tile.key, function(err) { | ||
// If tile key is set and we have cached its buffer in memory, | ||
// skip rendering and use the existing buffer. | ||
if (tile.key !== false && task.cache[type][tile.key]) { | ||
var data = task.cache[type][tile.key]; | ||
task.sink[put](tile.z, tile.x, tile.y, data, function(err) { | ||
if (err) { | ||
@@ -134,36 +167,50 @@ task.emit('error', err, tile); | ||
}); | ||
// Render the tile. | ||
} else { | ||
task.source.getTile(tile.z, tile.x, tile.y, function(err, data) { | ||
task.source[get](tile.z, tile.x, tile.y, function(err, data) { | ||
if (err) { | ||
task.emit('error', err, tile); | ||
task.scheme.error(tile); | ||
} else { | ||
if (data.solid) { | ||
var color = data.solid.split(','); | ||
if (color[3] === '0') { | ||
tile.key = 0; | ||
} else { | ||
tile.key = -(color[0]*(1<<24) + ((color[1]<<16) | (color[2]<<8) | color[3])); | ||
} | ||
data.key = tile.key; | ||
return; | ||
} | ||
if (data.solid) switch(type) { | ||
case 'grid': | ||
// Empty grid. | ||
if (data.solid === '0') { | ||
data.key = tile.key = 0; | ||
// String grid key. | ||
} else { | ||
data.key = tile.key = data.solid; | ||
} | ||
if (tile.key === 0) { | ||
task.scheme.skip(tile); | ||
task.cache[type][tile.key] = data; | ||
break; | ||
case 'tile': | ||
var color = data.solid.split(','); | ||
// Empty tile. | ||
if (color[3] === '0') { | ||
data.key = tile.key = 0; | ||
// Negative encoded RGBA value. | ||
} else { | ||
task.sink.putTile(tile.z, tile.x, tile.y, data, function(err) { | ||
if (err) { | ||
task.emit('error', err, tile); | ||
task.scheme.error(tile); | ||
} | ||
else if (tile.key === false) { | ||
// This is a unique tile | ||
task.scheme.unique(tile); | ||
} else { | ||
task.scheme.duplicate(tile); | ||
} | ||
}); | ||
data.key = tile.key = -(color[0]*(1<<24) + ((color[1]<<16) | (color[2]<<8) | color[3])); | ||
} | ||
task.cache[type][tile.key] = data; | ||
break; | ||
} | ||
if (tile.key === 0) { | ||
task.scheme.skip(tile); | ||
} else { | ||
task.sink[put](tile.z, tile.x, tile.y, data, function(err) { | ||
if (err) { | ||
task.emit('error', err, tile); | ||
task.scheme.error(tile); | ||
} else if (tile.key === false) { | ||
// This is a unique tile | ||
task.scheme.unique(tile); | ||
} else { | ||
task.scheme.duplicate(tile); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}; |
@@ -36,6 +36,9 @@ var fs = require('fs'); | ||
FileScheme.prototype.next = function() { | ||
var formats = (this.task.formats && this.task.formats.length > 0) ? this.task.formats : ['tile']; | ||
while (!this.paused && this.list.length && this.pending.length < this.concurrency) { | ||
var tile = this.list.shift(); | ||
this.addPending(tile); | ||
this.task.render(tile); | ||
for (var key in formats) { | ||
this.addPending(tile); | ||
this.task.render(tile,formats[key]); | ||
} | ||
} | ||
@@ -42,0 +45,0 @@ |
@@ -76,2 +76,3 @@ var Scheme = require('./scheme'); | ||
// all of its members. | ||
var formats = (this.task.formats && this.task.formats.length > 0) ? this.task.formats : ['tile']; | ||
while (!this.finished && !this.paused && (this.pending.length < this.concurrency || this.box.length)) { | ||
@@ -105,4 +106,6 @@ var tile; | ||
if (tile) { | ||
this.addPending(tile); | ||
this.task.render(tile); | ||
for (var key in formats) { | ||
this.addPending(tile); | ||
this.task.render(tile,formats[key]); | ||
} | ||
} | ||
@@ -109,0 +112,0 @@ } |
@@ -177,2 +177,3 @@ var sm = new (require('sphericalmercator')); | ||
// all of its members. | ||
var formats = (this.task.formats && this.task.formats.length > 0) ? this.task.formats : ['tile']; | ||
while (!this.finished && !this.paused && (this.pending.length < this.concurrency || this.box.length)) { | ||
@@ -195,4 +196,6 @@ var tile; | ||
if (tile) { | ||
this.addPending(tile); | ||
this.task.render(tile); | ||
for (var key in formats) { | ||
this.addPending(tile); | ||
this.task.render(tile,formats[key]); | ||
} | ||
} | ||
@@ -199,0 +202,0 @@ } |
@@ -27,6 +27,6 @@ var Statistics = require('./statistics'); | ||
Scheme.prototype.started = false; | ||
Scheme.prototype.finished = false; | ||
Scheme.prototype.paused = true; | ||
Scheme.prototype.initialize = function() { | ||
@@ -42,2 +42,3 @@ this.pending = []; | ||
this.paused = false; | ||
this.started = true; | ||
this.next(); | ||
@@ -53,2 +54,4 @@ } | ||
} | ||
} else if (!this.started) { | ||
this.emit('paused'); | ||
} | ||
@@ -55,0 +58,0 @@ }; |
{ | ||
"name" : "tilelive", | ||
"version" : "4.2.2", | ||
"version" : "4.3.0", | ||
"main" : "./lib/tilelive.js", | ||
@@ -5,0 +5,0 @@ "description" : "Frontend for various tile backends, mapnik and mbtiles", |
@@ -77,2 +77,11 @@ # tilelive.js | ||
## 4.3.0 | ||
* Bug fixes for CopyTask. | ||
* Removes use of `putDuplicateTile` from TileSink interface. | ||
## 4.2.0 | ||
* Rewritten copy command with swappable schemes. | ||
## 4.1.0 | ||
@@ -79,0 +88,0 @@ |
@@ -14,2 +14,3 @@ var assert = require('assert'); | ||
'plain_4': 'mbtiles://' + __dirname + '/fixtures/plain_4.mbtiles', | ||
'resume': 'mbtiles://' + __dirname + '/fixtures/resume.mbtiles', | ||
'mapquest': 'tilejson://' + __dirname + '/fixtures/mapquest.tilejson' | ||
@@ -16,0 +17,0 @@ }, sources); |
@@ -95,2 +95,16 @@ var assert = require('assert'); | ||
legend: null | ||
}, | ||
{ | ||
scheme: 'tms', | ||
basename: 'resume.mbtiles', | ||
id: 'resume', | ||
filesize: 16384, | ||
name: '', | ||
description: '', | ||
version: '1.0.0', | ||
legend: null, | ||
minzoom: 0, | ||
maxzoom: 22, | ||
bounds: [ -180, -85.05112877980659, 180, 85.05112877980659 ], | ||
center: null | ||
} | ||
@@ -97,0 +111,0 @@ ]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2259459
35
2016
131
6