Compare commits

...

2 Commits

Author SHA1 Message Date
Raul Ochoa
f3e4a79529 Merge branch 'master' into tile-size
Conflicts:
	lib/torque/renderer/point.js
2016-08-03 17:57:58 +02:00
Raul Ochoa
5bdabbd921 Add support for different tile sizes 2016-06-02 01:42:45 +02:00
4 changed files with 55 additions and 31 deletions

View File

@ -74,7 +74,7 @@ var CartoDatasource = require('./datasource');
this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass}); this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass});
this.style = this.options.cartocss || DEFAULT_CARTOCSS; this.style = this.options.cartocss || DEFAULT_CARTOCSS;
this.setCartoCSS(this.style); this.setCartoCSS(this.style);
this.TILE_SIZE = 256; this.TILE_SIZE = options.tileSize || 256;
this._style = null; this._style = null;
this._gradients = {}; this._gradients = {};

View File

@ -10,7 +10,6 @@ var IMAGE_DIFF_TOLERANCE = 4 / 100;
// Once you have a valid canvas and no errors, it's possible to write to disk the canvas buffer as a png image with: // Once you have a valid canvas and no errors, it's possible to write to disk the canvas buffer as a png image with:
// require('fs').writeFileSync('/tmp/torque-acceptance-test-tile.png', canvas.toBuffer(), {encoding: null}); // require('fs').writeFileSync('/tmp/torque-acceptance-test-tile.png', canvas.toBuffer(), {encoding: null});
asyncTest('navy example', function(assert) {
var cartocss = [ var cartocss = [
'Map {', 'Map {',
' -torque-time-attribute: "date";', ' -torque-time-attribute: "date";',
@ -35,6 +34,7 @@ asyncTest('navy example', function(assert) {
'}' '}'
].join('\n'); ].join('\n');
asyncTest('navy example', function(assert) {
var step = 300; var step = 300;
pointRenderer.getTile('default_navy_3-3-2.torque.json', cartocss, 3, 3, 2, step, function(err, canvas) { pointRenderer.getTile('default_navy_3-3-2.torque.json', cartocss, 3, 3, 2, step, function(err, canvas) {
@ -45,6 +45,22 @@ asyncTest('navy example', function(assert) {
}); });
}); });
asyncTest('tileSize = 512', function(assert) {
var step = 300;
var tileSize = 512;
var options = {
tileSize: tileSize
};
pointRenderer.getTile('default_navy_3-3-2.torque.json', cartocss, 3, 3, 2, step, options, function(err, canvas) {
assert.ok(!err, 'no error while getting tile');
var img = image.getImage(canvas.toBuffer());
assert.equal(img.width(), tileSize);
assert.equal(img.height(), tileSize);
QUnit.start();
});
});
asyncTest('basic heatmap', function(assert) { asyncTest('basic heatmap', function(assert) {
var cartocss = [ var cartocss = [
'Map {', 'Map {',

View File

@ -1,9 +1,13 @@
var mapnik = require('mapnik'); var mapnik = require('mapnik');
function getImage(buffer) {
return new mapnik.Image.fromBytesSync(buffer);
}
function compare(buffer, fixtureRelPath) { function compare(buffer, fixtureRelPath) {
save(__dirname + '/../results/' + fixtureRelPath, buffer); save(__dirname + '/../results/' + fixtureRelPath, buffer);
var img = new mapnik.Image.fromBytesSync(buffer); var img = getImage(buffer);
var reference = new mapnik.Image.openSync(__dirname + '/../fixtures/image/' + fixtureRelPath); var reference = new mapnik.Image.openSync(__dirname + '/../fixtures/image/' + fixtureRelPath);
return img.compare(reference) / (reference.width() * reference.height()); return img.compare(reference) / (reference.width() * reference.height());
} }
@ -14,6 +18,7 @@ function save(path, buffer) {
} }
module.exports = { module.exports = {
getImage: getImage,
compare: compare, compare: compare,
save: save save: save
}; };

View File

@ -6,13 +6,15 @@ var fs = require('fs');
var torque = require('../../lib/torque/index'); var torque = require('../../lib/torque/index');
function getTile(jsonRelPath, cartocss, z, x, y, step, callback) { function getTile(jsonRelPath, cartocss, z, x, y, step, options, callback) {
step = step || 0; if (!callback) {
callback = options;
options = {};
}
var cartoCssOptions = torque.common.TorqueLayer.optionsFromCartoCSS(cartocss); var cartoCssOptions = torque.common.TorqueLayer.optionsFromCartoCSS(cartocss);
var provider = new torque.providers.windshaft(_.extend({ no_fetch_map: true }, cartoCssOptions)); var provider = new torque.providers.windshaft(_.extend({ no_fetch_map: true }, cartoCssOptions));
var rendererOptions = _.extend({cartocss: cartocss}, cartoCssOptions, { var rendererOptions = _.extend(options, {cartocss: cartocss}, cartoCssOptions, {
canvasClass: Canvas, canvasClass: Canvas,
imageClass: Canvas.Image, imageClass: Canvas.Image,
setImageSrc: function(img, url, callback) { setImageSrc: function(img, url, callback) {
@ -42,7 +44,8 @@ function getTile(jsonRelPath, cartocss, z, x, y, step, callback) {
var rows = JSON.parse(fs.readFileSync(__dirname + '/../fixtures/json/' + jsonRelPath)); var rows = JSON.parse(fs.readFileSync(__dirname + '/../fixtures/json/' + jsonRelPath));
var canvas = new Canvas(256, 256); var tileSize = options.tileSize || 256;
var canvas = new Canvas(tileSize, tileSize);
var pointRenderer = new torque.renderer.Point(canvas, rendererOptions); var pointRenderer = new torque.renderer.Point(canvas, rendererOptions);
pointRenderer.renderTile(provider.proccessTile(rows, {x: x, y: y}, z), step, function(err) { pointRenderer.renderTile(provider.proccessTile(rows, {x: x, y: y}, z), step, function(err) {