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 mapnik = require('windshaft').mapnik;
|
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
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('retina support', function () {
|
2015-07-08 05:46:58 +08:00
|
|
|
var layergroupId = null;
|
|
|
|
|
2018-04-16 22:16:23 +08:00
|
|
|
var server;
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2018-04-16 22:16:23 +08:00
|
|
|
before(function () {
|
|
|
|
server = cartodbServer(ServerOptions);
|
|
|
|
server.setMaxListeners(0);
|
|
|
|
});
|
2015-09-17 00:09:39 +08:00
|
|
|
|
2015-09-25 22:03:20 +08:00
|
|
|
var keysToDelete;
|
2019-10-22 01:07:24 +08:00
|
|
|
beforeEach(function (done) {
|
|
|
|
keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
2015-09-25 22:03:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var retinaSampleMapConfig = {
|
2015-07-08 05:46:58 +08:00
|
|
|
version: '1.2.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'SELECT * FROM populated_places_simple_reduced',
|
|
|
|
cartocss: '#layer { marker-fill:red; } #layer { marker-width: 2; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
geom_column: 'the_geom'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.response(server,
|
|
|
|
{
|
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(retinaSampleMapConfig)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
},
|
|
|
|
function (res, err) {
|
|
|
|
assert.ok(!err, 'Failed to create layergroup');
|
|
|
|
|
|
|
|
layergroupId = JSON.parse(res.body).layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
afterEach(function (done) {
|
2015-09-25 22:03:20 +08:00
|
|
|
keysToDelete['map_cfg|' + LayergroupToken.parse(layergroupId).token] = 0;
|
|
|
|
testHelper.deleteRedisKeys(keysToDelete, done);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function testRetinaImage (scaleFactor, responseHead, assertFn) {
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.response(server,
|
|
|
|
{
|
2019-10-02 01:34:03 +08:00
|
|
|
url: '/api/v1/map/' + layergroupId + '/0/0/0' + scaleFactor + '.png',
|
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
|
|
|
},
|
|
|
|
responseHead,
|
|
|
|
assertFn
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function testValidImageDimmensions (scaleFactor, imageSize, done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
testRetinaImage(scaleFactor,
|
|
|
|
{
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'image/png'
|
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.ok(!err, 'Failed to request 0/0/0' + scaleFactor + '.png tile');
|
|
|
|
|
|
|
|
var image = new mapnik.Image.fromBytes(new Buffer(res.body, 'binary'));
|
|
|
|
|
|
|
|
assert.equal(image.width(), imageSize);
|
|
|
|
assert.equal(image.height(), imageSize);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('image dimensions when scale factor is not defined', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
testValidImageDimmensions('', 256, done);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('image dimensions when scale factor = @1x', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
testValidImageDimmensions('@1x', 256, done);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('image dimensions when scale factor = @2x', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
testValidImageDimmensions('@2x', 512, done);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('error when scale factor is not enabled', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var scaleFactor = '@4x';
|
|
|
|
|
|
|
|
testRetinaImage(scaleFactor,
|
|
|
|
{
|
|
|
|
status: 404,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function (res, err) {
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.ok(!err, 'Failed to request 0/0/0' + scaleFactor + '.png tile');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.deepEqual(JSON.parse(res.body).errors, ['Tile with specified resolution not found']);
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|