First attempt: support buffer-size configuration for named maps

This commit is contained in:
Daniel García Aubert
2017-04-25 14:34:17 +02:00
parent 383a1a330a
commit 0c08713521
3 changed files with 261 additions and 27 deletions
+92 -26
View File
@@ -2,10 +2,35 @@ require('../support/test_helper');
var assert = require('../support/assert');
var TestClient = require('../support/test-client');
var IMAGE_TOLERANCE_PER_MIL = 20;
var IMAGE_TOLERANCE_PER_MIL = 0;
var mapnik = require('windshaft').mapnik;
function createMapConfig (bufferSize) {
var CARTOCSS_LABELS = [
'#layer {',
' polygon-fill: #374C70;',
' polygon-opacity: 0.9;',
' line-width: 1;',
' line-color: #FFF;',
' line-opacity: 0.5;',
'}',
'#layer::labels {',
' text-name: [name];',
' text-face-name: \'DejaVu Sans Book\';',
' text-size: 20;',
' text-fill: #FFFFFF;',
' text-label-position-tolerance: 0;',
' text-halo-radius: 1;',
' text-halo-fill: #6F808D;',
' text-dy: -10;',
' text-allow-overlap: true;',
' text-placement: point;',
' text-placement-type: dummy;',
'}'
].join('\n')
function createMapConfig (bufferSize, cartocss) {
cartocss = cartocss || CARTOCSS_LABELS;
return {
version: '1.6.0',
buffersize: bufferSize,
@@ -18,28 +43,7 @@ function createMapConfig (bufferSize) {
'from',
' populated_places_simple_reduced',
].join('\n'),
cartocss: [
'#layer {',
' polygon-fill: #374C70;',
' polygon-opacity: 0.9;',
' line-width: 1;',
' line-color: #FFF;',
' line-opacity: 0.5;',
'}',
'#layer::labels {',
' text-name: [name];',
' text-face-name: \'DejaVu Sans Book\';',
' text-size: 20;',
' text-fill: #FFFFFF;',
' text-label-position-tolerance: 0;',
' text-halo-radius: 1;',
' text-halo-fill: #6F808D;',
' text-dy: -10;',
' text-allow-overlap: true;',
' text-placement: point;',
' text-placement-type: dummy;',
'}'
].join('\n'),
cartocss: cartocss,
cartocss_version: '2.3.0',
interactivity: 'cartodb_id'
}
@@ -114,11 +118,73 @@ describe('buffer size per format', function () {
testClient.getTile(coords.z, coords.x, coords.y, { format: test.format }, function (err, res, tile) {
assert.ifError(err);
// To generate images use:
// tile.save(test.fixturePath);
tile.save(test.fixturePath);
test.assert(tile, function () {
testClient.drain(done);
});
});
});
});
});
});
function createBufferSizeTemplate (name, cartocss) {
cartocss = cartocss || CARTOCSS_LABELS;
return {
"version": "0.0.1",
"name": name,
"placeholders": {
"buffersize": {
"type": "number",
"default": "0"
}
},
"layergroup": {
version: '1.6.0',
buffersize: '<%= buffersize %>',
layers: [{
type: 'cartodb',
options: {
sql: [
'select',
' *',
'from',
' populated_places_simple_reduced',
].join('\n'),
cartocss: cartocss,
cartocss_version: '2.3.0',
interactivity: 'cartodb_id'
}
}]
}
}
}
describe.only('buffer size per format for named maps', function () {
var testCases = [
{
desc: 'should get png tile using buffer-size 0',
coords: { z: 7, x: 64, y: 48 },
format: 'png',
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.png',
template: createBufferSizeTemplate('named-buffer-size'),
assert: function (tile, callback) {
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
}
}
];
testCases.forEach(function (test) {
it(test.desc, function (done) {
var testClient = new TestClient(undefined, 1234, test.template);
var coords = test.coords;
testClient.getNamedTile(coords.z, coords.x, coords.y, { format: test.format }, function (err, res, tile) {
assert.ifError(err);
// To generate images use:
// tile.save('./test/fixtures/buffer-size/tile-7.64.48-buffer-size-64.png');
test.assert(tile, function () {
testClient.drain(done);
});
});
});
});
});