2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2017-04-25 00:56:15 +08:00
|
|
|
|
2017-04-28 20:46:36 +08:00
|
|
|
var fs = require('fs');
|
2017-04-25 00:56:15 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var TestClient = require('../support/test-client');
|
2019-10-07 16:10:51 +08:00
|
|
|
var serverOptions = require('../../lib/server-options');
|
2017-04-28 20:46:36 +08:00
|
|
|
var mapnik = require('windshaft').mapnik;
|
2017-04-26 01:27:31 +08:00
|
|
|
var IMAGE_TOLERANCE_PER_MIL = 5;
|
2017-04-25 00:56:15 +08:00
|
|
|
|
2017-04-25 20:34:17 +08:00
|
|
|
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;',
|
|
|
|
'}'
|
2017-04-25 23:54:31 +08:00
|
|
|
].join('\n');
|
2017-04-25 20:34:17 +08:00
|
|
|
|
|
|
|
function createMapConfig (bufferSize, cartocss) {
|
|
|
|
cartocss = cartocss || CARTOCSS_LABELS;
|
|
|
|
|
2017-04-25 00:56:15 +08:00
|
|
|
return {
|
|
|
|
version: '1.6.0',
|
|
|
|
buffersize: bufferSize,
|
|
|
|
layers: [{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
2017-04-25 00:56:15 +08:00
|
|
|
options: {
|
|
|
|
sql: [
|
|
|
|
'select',
|
|
|
|
' *',
|
|
|
|
'from',
|
2019-10-22 01:07:24 +08:00
|
|
|
' populated_places_simple_reduced'
|
2017-04-25 00:56:15 +08:00
|
|
|
].join('\n'),
|
2017-04-25 20:34:17 +08:00
|
|
|
cartocss: cartocss,
|
2017-04-25 00:56:15 +08:00
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
interactivity: 'cartodb_id'
|
2017-04-26 01:27:31 +08:00
|
|
|
}
|
2017-04-25 00:56:15 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-25 00:57:20 +08:00
|
|
|
describe('buffer size per format', function () {
|
2018-10-17 16:06:48 +08:00
|
|
|
let testClient;
|
|
|
|
|
2017-04-25 00:56:15 +08:00
|
|
|
var testCases = [
|
|
|
|
{
|
2017-04-25 16:43:07 +08:00
|
|
|
desc: 'should get png tile using buffer-size 0',
|
2017-04-25 00:56:15 +08:00
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
2017-04-25 16:43:07 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.png',
|
|
|
|
mapConfig: createMapConfig({ png: 0, 'grid.json': 0 }),
|
2017-04-25 00:56:15 +08:00
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get png tile using buffer-size 128',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png',
|
|
|
|
mapConfig: createMapConfig({ png: 128, 'grid.json': 128 }),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-04-25 16:43:07 +08:00
|
|
|
desc: 'should get mvt tile using buffer-size 0',
|
2017-04-25 00:56:15 +08:00
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'mvt',
|
2017-04-28 20:46:36 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.mvt',
|
2017-04-25 16:43:07 +08:00
|
|
|
mapConfig: createMapConfig({ mvt: 0 }),
|
2017-04-25 00:56:15 +08:00
|
|
|
assert: function (tile, callback) {
|
|
|
|
var tileJSON = tile.toJSON();
|
|
|
|
var features = tileJSON[0].features;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(features.length, 1);
|
2017-04-26 02:40:17 +08:00
|
|
|
callback();
|
2017-04-25 00:56:15 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get mvt tile using buffer-size 128',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'mvt',
|
2017-04-28 20:46:36 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.mvt',
|
2017-04-25 00:56:15 +08:00
|
|
|
mapConfig: createMapConfig({ mvt: 128 }),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
var tileJSON = tile.toJSON();
|
2017-04-25 23:54:31 +08:00
|
|
|
var features = tileJSON[0].features;
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(features.length, 9);
|
2017-04-26 02:40:17 +08:00
|
|
|
callback();
|
2017-04-25 00:56:15 +08:00
|
|
|
}
|
2017-05-03 17:17:51 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get grid.json tile using buffer-size 0 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'grid.json',
|
2017-05-17 17:40:53 +08:00
|
|
|
layers: [0],
|
2017-05-03 17:17:51 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-grid.json.7.64.48-buffer-size-0.grid.json',
|
|
|
|
mapConfig: createMapConfig({ 'grid.json': 0 }),
|
|
|
|
assert: function (tile, callback) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(tile, this.fixturePath, 2, callback);
|
2017-05-03 17:17:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get grid.json tile using buffer-size 128 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'grid.json',
|
2017-05-17 17:40:53 +08:00
|
|
|
layers: [0],
|
2017-05-03 17:17:51 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.grid.json',
|
|
|
|
mapConfig: createMapConfig({ 'grid.json': 128 }),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.utfgridEqualsFile(tile, this.fixturePath, 2, callback);
|
|
|
|
}
|
2017-04-25 00:56:15 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2018-10-17 16:06:48 +08:00
|
|
|
if (testClient) {
|
|
|
|
return testClient.drain(done);
|
2017-10-06 23:53:47 +08:00
|
|
|
}
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
|
2017-10-09 21:42:24 +08:00
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
2018-10-17 16:06:48 +08:00
|
|
|
after(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
2018-10-17 16:08:55 +08:00
|
|
|
var testFn = (test) => {
|
|
|
|
it(test.desc, function (done) {
|
|
|
|
testClient = new TestClient(test.mapConfig, 1234);
|
|
|
|
var coords = test.coords;
|
|
|
|
var options = {
|
|
|
|
format: test.format,
|
|
|
|
layers: test.layers
|
|
|
|
};
|
|
|
|
testClient.getTile(coords.z, coords.x, coords.y, options, function (err, res, tile) {
|
|
|
|
assert.ifError(err);
|
|
|
|
// To generate images use:
|
|
|
|
// tile.save(test.fixturePath);
|
|
|
|
test.assert(tile, done);
|
2017-04-25 20:34:17 +08:00
|
|
|
});
|
2018-10-17 16:08:55 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-10-17 16:25:18 +08:00
|
|
|
testCases.filter(test => test.format !== 'mvt').forEach(function (test) {
|
|
|
|
testFn(test);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('using mapnik mvt renderer', function () {
|
2018-10-17 16:25:18 +08:00
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = false;
|
|
|
|
});
|
|
|
|
testCases.filter(test => test.format === 'mvt').forEach(function (test) {
|
2018-10-17 16:08:55 +08:00
|
|
|
testFn(test);
|
2018-10-17 16:25:18 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('using postgis mvt renderer', function () {
|
2018-10-17 16:25:18 +08:00
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = true;
|
|
|
|
});
|
|
|
|
testCases.filter(test => test.format === 'mvt').forEach(function (test) {
|
|
|
|
testFn(test);
|
|
|
|
});
|
2017-04-25 20:34:17 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-25 23:54:31 +08:00
|
|
|
function createBufferSizeTemplate (name, buffersize, placeholders, cartocss) {
|
2017-04-25 20:34:17 +08:00
|
|
|
cartocss = cartocss || CARTOCSS_LABELS;
|
2017-04-25 23:54:31 +08:00
|
|
|
|
2017-04-25 20:34:17 +08:00
|
|
|
return {
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '0.0.1',
|
|
|
|
name: name,
|
|
|
|
placeholders: placeholders || {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
2017-04-25 20:34:17 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
layergroup: createMapConfig(buffersize)
|
2017-04-26 01:41:30 +08:00
|
|
|
};
|
2017-04-25 20:34:17 +08:00
|
|
|
}
|
|
|
|
|
2017-04-26 01:27:31 +08:00
|
|
|
describe('buffer size per format for named maps', function () {
|
2017-04-25 20:34:17 +08:00
|
|
|
var testCases = [
|
|
|
|
{
|
2017-04-25 21:48:23 +08:00
|
|
|
desc: 'should get png tile using buffer-size 0 (default value in template)',
|
2017-04-25 20:34:17 +08:00
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
template: createBufferSizeTemplate('named-default-buffer-size', { png: '<%= buffersize %>' }),
|
2017-04-25 21:48:23 +08:00
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get png tile using buffer-size 128 (placehoder value)',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
|
|
|
placeholders: { buffersize: 128 },
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
template: createBufferSizeTemplate('named-custom-buffer-size', { png: '<%= buffersize %>' }),
|
2017-04-25 20:34:17 +08:00
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
2017-04-25 23:54:31 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get png tile using buffer-size 0 (default value in template by format)',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
2017-04-26 01:27:31 +08:00
|
|
|
placeholders: { buffersize_png: 0 },
|
2017-04-25 23:54:31 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.png',
|
2017-04-26 01:27:31 +08:00
|
|
|
template: createBufferSizeTemplate('named-default-buffer-size-by-format', {
|
|
|
|
png: '<%= buffersize_png %>'
|
2017-04-25 23:54:31 +08:00
|
|
|
}, {
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize_png: {
|
|
|
|
type: 'number',
|
|
|
|
default: '0'
|
2017-04-25 23:54:31 +08:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get png tile using buffer-size 128 (placehoder value in template by format)',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
2017-04-26 01:27:31 +08:00
|
|
|
placeholders: { buffersize_png: 128 },
|
2017-04-25 23:54:31 +08:00
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png',
|
2017-04-26 01:27:31 +08:00
|
|
|
template: createBufferSizeTemplate('named-custom-buffer-size-by-format', {
|
|
|
|
png: '<%= buffersize_png %>'
|
2017-04-25 23:54:31 +08:00
|
|
|
}, {
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize_png: {
|
|
|
|
type: 'number',
|
|
|
|
default: '0'
|
2017-04-25 23:54:31 +08:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
2017-05-03 17:17:51 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get grid.json tile using buffer-size 0 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'grid.json',
|
2017-05-17 17:40:53 +08:00
|
|
|
layers: [0],
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: { buffersize_gridjson: 0 },
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-grid.json.7.64.48-buffer-size-0.grid.json',
|
|
|
|
template: createBufferSizeTemplate('named-default-buffer-size-by-format-gridjson', {
|
|
|
|
'grid.json': '<%= buffersize_gridjson %>'
|
|
|
|
}, {
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize_gridjson: {
|
|
|
|
type: 'number',
|
|
|
|
default: '0'
|
2017-05-03 17:17:51 +08:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
assert: function (tile, callback) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(tile, this.fixturePath, 2, callback);
|
2017-05-03 17:17:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get grid.json tile using buffer-size 128 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'grid.json',
|
2017-05-17 17:40:53 +08:00
|
|
|
layers: [0],
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: { buffersize_gridjson: 128 },
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.grid.json',
|
|
|
|
template: createBufferSizeTemplate('named-custom-buffer-size-by-format-gridjson', {
|
|
|
|
'grid.json': '<%= buffersize_gridjson %>'
|
|
|
|
}, {
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize_gridjson: {
|
|
|
|
type: 'number',
|
|
|
|
default: '0'
|
2017-05-03 17:17:51 +08:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.utfgridEqualsFile(tile, this.fixturePath, 2, callback);
|
|
|
|
}
|
2017-04-25 20:34:17 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2017-10-07 00:17:26 +08:00
|
|
|
if (this.testClient) {
|
|
|
|
return this.testClient.drain(done);
|
|
|
|
}
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
|
2017-04-25 20:34:17 +08:00
|
|
|
testCases.forEach(function (test) {
|
|
|
|
it(test.desc, function (done) {
|
2017-10-07 00:17:26 +08:00
|
|
|
this.testClient = new TestClient(test.template, 1234);
|
2017-04-25 20:34:17 +08:00
|
|
|
var coords = test.coords;
|
2017-04-26 01:27:31 +08:00
|
|
|
var options = {
|
|
|
|
format: test.format,
|
2017-05-17 17:40:53 +08:00
|
|
|
placeholders: test.placeholders,
|
|
|
|
layers: test.layers
|
2017-04-26 01:27:31 +08:00
|
|
|
};
|
2017-10-07 00:17:26 +08:00
|
|
|
this.testClient.getTile(coords.z, coords.x, coords.y, options, function (err, res, tile) {
|
2017-04-25 20:34:17 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
// To generate images use:
|
2019-10-22 01:07:24 +08:00
|
|
|
// tile.save('./test/fixtures/buffer-size/tile-7.64.48-buffer-size-0-test.png');
|
2017-10-07 00:17:26 +08:00
|
|
|
test.assert(tile, done);
|
2017-04-25 00:56:15 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-04-25 20:34:17 +08:00
|
|
|
});
|
2017-04-28 20:46:36 +08:00
|
|
|
|
2017-05-18 21:49:57 +08:00
|
|
|
describe('buffer size per format for named maps w/o placeholders', function () {
|
2018-10-17 16:33:12 +08:00
|
|
|
let testClient;
|
|
|
|
|
2017-04-28 20:46:36 +08:00
|
|
|
var testCases = [
|
|
|
|
{
|
|
|
|
desc: 'should get png tile using buffer-size 0 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: {
|
2017-04-28 20:46:36 +08:00
|
|
|
buffersize: {
|
|
|
|
png: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.png',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-png-0', {}, {}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get png tile using buffer-size 128 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: {
|
2017-04-28 20:46:36 +08:00
|
|
|
buffersize: {
|
|
|
|
png: 128
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.png',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-png-128', {}, {}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get mvt tile using buffer-size 0 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'mvt',
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: {
|
2017-04-28 20:46:36 +08:00
|
|
|
buffersize: {
|
|
|
|
mvt: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-mvt-7.64.48-buffer-size-0.mvt',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-mvt', {}, {}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
var tileJSON = tile.toJSON();
|
|
|
|
var features = tileJSON[0].features;
|
|
|
|
|
|
|
|
var dataFixture = fs.readFileSync(this.fixturePath);
|
|
|
|
var vtile = new mapnik.VectorTile(this.coords.z, this.coords.x, this.coords.y);
|
|
|
|
vtile.setDataSync(dataFixture);
|
|
|
|
var vtileJSON = vtile.toJSON();
|
|
|
|
var vtileFeatures = vtileJSON[0].features;
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(features.length, vtileFeatures.length);
|
2017-04-28 20:46:36 +08:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get mvt tile using buffer-size 128 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'mvt',
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: {
|
2017-04-28 20:46:36 +08:00
|
|
|
buffersize: {
|
|
|
|
mvt: 128
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-mvt-7.64.48-buffer-size-128.mvt',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-mvt-128', {}, {}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
var tileJSON = tile.toJSON();
|
|
|
|
var features = tileJSON[0].features;
|
|
|
|
|
|
|
|
var dataFixture = fs.readFileSync(this.fixturePath);
|
|
|
|
var vtile = new mapnik.VectorTile(this.coords.z, this.coords.x, this.coords.y);
|
|
|
|
vtile.setDataSync(dataFixture);
|
|
|
|
var vtileJSON = vtile.toJSON();
|
|
|
|
var vtileFeatures = vtileJSON[0].features;
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(features.length, vtileFeatures.length);
|
2017-04-28 20:46:36 +08:00
|
|
|
callback();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get grid.json tile using buffer-size 0 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'grid.json',
|
2017-05-17 17:40:53 +08:00
|
|
|
layers: [0],
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: {
|
2017-04-28 20:46:36 +08:00
|
|
|
buffersize: {
|
|
|
|
'grid.json': 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-grid.json.7.64.48-buffer-size-0.grid.json',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-grid-json-0', {}, {}),
|
|
|
|
assert: function (tile, callback) {
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.utfgridEqualsFile(tile, this.fixturePath, 2, callback);
|
2017-04-28 20:46:36 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'should get grid.json tile using buffer-size 128 overriden by template params',
|
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'grid.json',
|
2017-05-17 17:40:53 +08:00
|
|
|
layers: [0],
|
2017-05-03 17:17:51 +08:00
|
|
|
placeholders: {
|
2017-04-28 20:46:36 +08:00
|
|
|
buffersize: {
|
|
|
|
'grid.json': 128
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-128.grid.json',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-grid-json-128', {}, {}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.utfgridEqualsFile(tile, this.fixturePath, 2, callback);
|
|
|
|
}
|
2017-05-18 21:41:41 +08:00
|
|
|
},
|
|
|
|
{
|
2017-05-18 21:49:57 +08:00
|
|
|
desc: 'should get png tile using buffer-size 0' +
|
|
|
|
' overriden by template params with no buffersize in mapconfig',
|
2017-05-18 21:41:41 +08:00
|
|
|
coords: { z: 7, x: 64, y: 48 },
|
|
|
|
format: 'png',
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
png: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fixturePath: './test/fixtures/buffer-size/tile-7.64.48-buffer-size-0.png',
|
|
|
|
template: createBufferSizeTemplate('named-no-buffer-size-mapconfig-png-0', undefined, {}),
|
|
|
|
assert: function (tile, callback) {
|
|
|
|
assert.imageIsSimilarToFile(tile, this.fixturePath, IMAGE_TOLERANCE_PER_MIL, callback);
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-05-18 21:41:41 +08:00
|
|
|
|
2017-04-28 20:46:36 +08:00
|
|
|
];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2018-10-17 16:33:12 +08:00
|
|
|
if (testClient) {
|
|
|
|
return testClient.drain(done);
|
2017-10-07 00:17:26 +08:00
|
|
|
}
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
|
2017-10-09 21:42:24 +08:00
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
2018-10-17 16:33:12 +08:00
|
|
|
after(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
var testFn = (test) => {
|
|
|
|
it(test.desc, function (done) {
|
|
|
|
test.template.name += '_1';
|
|
|
|
testClient = new TestClient(test.template, 1234);
|
|
|
|
var coords = test.coords;
|
|
|
|
var options = {
|
|
|
|
format: test.format,
|
|
|
|
placeholders: test.placeholders,
|
|
|
|
layers: test.layers
|
|
|
|
};
|
|
|
|
testClient.getTile(coords.z, coords.x, coords.y, options, function (err, res, tile) {
|
|
|
|
assert.ifError(err);
|
|
|
|
// To generate images use:
|
2019-10-22 01:07:24 +08:00
|
|
|
// tile.save(test.fixturePath);
|
2018-10-17 16:33:12 +08:00
|
|
|
// require('fs').writeFileSync(test.fixturePath, JSON.stringify(tile));
|
|
|
|
// require('fs').writeFileSync(test.fixturePath, tile.getDataSync());
|
|
|
|
test.assert(tile, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
testCases.filter(test => test.format !== 'mvt').forEach(function (test) {
|
|
|
|
testFn(test);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('using mapnik mvt renderer', function () {
|
2018-10-17 16:33:12 +08:00
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = false;
|
|
|
|
});
|
|
|
|
testCases.filter(test => test.format === 'mvt').forEach(function (test) {
|
|
|
|
testFn(test);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('using postgis mvt renderer', function () {
|
2018-10-17 16:33:12 +08:00
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = true;
|
|
|
|
});
|
|
|
|
testCases.filter(test => test.format === 'mvt').forEach(function (test) {
|
|
|
|
testFn(test);
|
|
|
|
});
|
2017-04-28 20:46:36 +08:00
|
|
|
});
|
|
|
|
});
|