2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
var testHelper = require('../../support/test-helper');
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var _ = require('underscore');
|
|
|
|
var fs = require('fs');
|
2019-10-07 15:40:50 +08:00
|
|
|
var cartodbServer = require('../../../lib/server');
|
2019-10-07 16:44:45 +08:00
|
|
|
var ServerOptions = require('./support/ported-server-options');
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2019-10-07 15:40:50 +08:00
|
|
|
var LayergroupToken = require('../../../lib/models/layergroup-token');
|
2015-09-17 00:09:39 +08:00
|
|
|
|
2015-07-08 05:46:58 +08:00
|
|
|
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 85;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('server_png8_format', function () {
|
2018-04-16 22:16:23 +08:00
|
|
|
var serverPng32;
|
|
|
|
var serverPng8;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
var serverOptionsPng32 = ServerOptions;
|
|
|
|
serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore);
|
|
|
|
serverOptionsPng32.grainstore.mapnik_tile_format = 'png32';
|
|
|
|
serverPng32 = cartodbServer(serverOptionsPng32);
|
|
|
|
serverPng32.setMaxListeners(0);
|
|
|
|
|
|
|
|
var serverOptionsPng8 = ServerOptions;
|
|
|
|
serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore);
|
|
|
|
serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h';
|
|
|
|
serverPng8 = cartodbServer(serverOptionsPng8);
|
|
|
|
serverPng8.setMaxListeners(0);
|
|
|
|
});
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
var layergroupId;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
before(function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var testPngFilesDir = __dirname + '/../../results/png';
|
|
|
|
fs.readdirSync(testPngFilesDir)
|
2019-10-22 01:07:24 +08:00
|
|
|
.filter(function (fileName) {
|
2015-07-08 05:46:58 +08:00
|
|
|
return /.*\.png$/.test(fileName);
|
|
|
|
})
|
2019-10-22 01:07:24 +08:00
|
|
|
.map(function (fileName) {
|
2015-07-08 05:46:58 +08:00
|
|
|
return testPngFilesDir + '/' + fileName;
|
|
|
|
})
|
|
|
|
.forEach(fs.unlinkSync);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2015-09-25 22:09:41 +08:00
|
|
|
var keysToDelete;
|
2019-10-22 01:07:24 +08:00
|
|
|
beforeEach(function () {
|
2015-09-25 22:09:41 +08:00
|
|
|
keysToDelete = {
|
|
|
|
'user:localhost:mapviews:global': 5
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2015-09-25 22:09:41 +08:00
|
|
|
testHelper.deleteRedisKeys(keysToDelete, done);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function testOutputForPng32AndPng8 (desc, tile, callback) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var bufferPng32,
|
|
|
|
bufferPng8;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it(desc + '; tile: ' + JSON.stringify(tile), function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.response(
|
|
|
|
serverPng32,
|
|
|
|
{
|
2019-10-02 01:34:03 +08:00
|
|
|
url: '/api/v1/map',
|
2015-07-08 05:46:58 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2018-03-17 02:56:34 +08:00
|
|
|
host: 'localhost',
|
2015-07-08 05:46:58 +08:00
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
data: JSON.stringify(layergroup)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
2015-07-08 05:46:58 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
layergroupId = JSON.parse(res.body).layergroupid;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var tilePartialUrl = _.template('/<%= z %>/<%= x %>/<%= y %>.png', tile);
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
var requestPayload = {
|
2019-10-02 01:34:03 +08:00
|
|
|
url: '/api/v1/map/' + layergroupId + tilePartialUrl,
|
2015-07-08 05:46:58 +08:00
|
|
|
method: 'GET',
|
2018-03-17 02:56:34 +08:00
|
|
|
encoding: 'binary',
|
|
|
|
headers: {
|
|
|
|
host: 'localhost'
|
|
|
|
}
|
2015-07-08 05:46:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
var requestHeaders = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'image/png'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(serverPng32, requestPayload, requestHeaders, function (responsePng32) {
|
|
|
|
assert.equal(responsePng32.headers['content-type'], 'image/png');
|
2015-07-08 05:46:58 +08:00
|
|
|
bufferPng32 = responsePng32.body;
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.response(serverPng8, requestPayload, requestHeaders, function (responsePng8) {
|
|
|
|
assert.equal(responsePng8.headers['content-type'], 'image/png');
|
2015-07-08 05:46:58 +08:00
|
|
|
bufferPng8 = responsePng8.body;
|
|
|
|
assert.ok(bufferPng8.length < bufferPng32.length);
|
2016-02-22 23:02:15 +08:00
|
|
|
assert.imageBuffersAreSimilar(bufferPng32, bufferPng8, IMAGE_EQUALS_TOLERANCE_PER_MIL,
|
2019-10-22 01:07:24 +08:00
|
|
|
function (err, imagePaths, similarity) {
|
2015-09-25 22:09:41 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(layergroupId).token] = 0;
|
|
|
|
|
|
|
|
callback(err, imagePaths, similarity, done);
|
2015-07-08 05:46:58 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var currentLevel = 3;
|
|
|
|
var allLevelTiles = [];
|
|
|
|
var maxLevelTile = Math.pow(2, currentLevel);
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
for (var i = 0; i < maxLevelTile; i++) {
|
|
|
|
for (var j = 0; j < maxLevelTile; j++) {
|
|
|
|
allLevelTiles.push({
|
|
|
|
z: currentLevel,
|
|
|
|
x: i,
|
|
|
|
y: j
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var layergroup = {
|
2015-07-08 05:46:58 +08:00
|
|
|
version: '1.3.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'SELECT * FROM populated_places_simple_reduced',
|
|
|
|
cartocss: [
|
|
|
|
'#populated_places_simple_reduced {',
|
2019-10-22 01:07:24 +08:00
|
|
|
'marker-fill: #FFCC00;',
|
|
|
|
'marker-width: 10;',
|
|
|
|
'marker-line-color: #FFF;',
|
|
|
|
'marker-line-width: 1.5;',
|
|
|
|
'marker-line-opacity: 1;',
|
|
|
|
'marker-fill-opacity: 0.9;',
|
|
|
|
'marker-comp-op: multiply;',
|
|
|
|
'marker-type: ellipse;',
|
|
|
|
'marker-placement: point;',
|
|
|
|
'marker-allow-overlap: true;',
|
|
|
|
'marker-clip: false;',
|
2015-07-08 05:46:58 +08:00
|
|
|
'}'
|
|
|
|
].join(' '),
|
|
|
|
cartocss_version: '2.0.1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var allImagePaths = [];
|
|
|
|
var similarities = [];
|
|
|
|
allLevelTiles.forEach(function (tile) {
|
|
|
|
testOutputForPng32AndPng8('intensity visualization', tile, function (err, imagePaths, similarity, done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
allImagePaths.push(imagePaths);
|
|
|
|
similarities.push(similarity);
|
|
|
|
var transformPaths = [];
|
|
|
|
for (var i = 0, len = allImagePaths.length; i < len; i++) {
|
|
|
|
if (similarities[i] > 0.075) {
|
|
|
|
transformPaths.push({
|
|
|
|
passive: allImagePaths[i][0],
|
|
|
|
active: allImagePaths[i][1],
|
|
|
|
similarity: similarities[i]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var output = 'handleResults(' + JSON.stringify(transformPaths) + ');';
|
|
|
|
fs.writeFileSync('test/results/png/results.js', output);
|
|
|
|
assert.ifError(err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|