2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
2016-03-09 03:06:43 +08:00
|
|
|
|
|
|
|
var IMAGE_TOLERANCE_PER_MIL = 20;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function imageCompareFn (fixture, done) {
|
|
|
|
return function (err, res, image) {
|
2016-03-09 03:06:43 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.imageIsSimilarToFile(image, './test/fixtures/' + fixture, IMAGE_TOLERANCE_PER_MIL, done);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function makeMapconfig (cartocss) {
|
2016-03-09 03:06:43 +08:00
|
|
|
return {
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '1.4.0',
|
|
|
|
layers: [
|
2016-03-09 03:06:43 +08:00
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
sql: [
|
2016-03-09 03:06:43 +08:00
|
|
|
'SELECT test_table.*, _prices.price FROM test_table JOIN (' +
|
|
|
|
' SELECT 1 AS cartodb_id, 10.00 AS price',
|
2018-07-17 18:43:29 +08:00
|
|
|
' UNION ALL',
|
2016-03-09 03:06:43 +08:00
|
|
|
' SELECT 2, 10.50',
|
2018-07-17 18:43:29 +08:00
|
|
|
' UNION ALL',
|
2016-03-09 03:06:43 +08:00
|
|
|
' SELECT 3, 11.00',
|
2018-07-17 18:43:29 +08:00
|
|
|
' UNION ALL',
|
2016-03-09 03:06:43 +08:00
|
|
|
' SELECT 4, 12.00',
|
2018-07-17 18:43:29 +08:00
|
|
|
' UNION ALL',
|
2016-03-09 03:06:43 +08:00
|
|
|
' SELECT 5, 21.00',
|
|
|
|
') _prices ON _prices.cartodb_id = test_table.cartodb_id'
|
|
|
|
].join('\n'),
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: cartocss
|
2016-03-09 03:06:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('turbo-carto for anonymous maps', function () {
|
2016-03-09 03:06:43 +08:00
|
|
|
describe('parsing ramp function with colorbrewer for greens and mapnik renderer', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
var turboCartocss = '#layer { marker-fill: ramp([price], colorbrewer(Greens)); }';
|
|
|
|
this.testClient = new TestClient(makeMapconfig(turboCartocss));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
it('should get a tile with turbo-carto parsed properly', function (done) {
|
|
|
|
var fixturePath = 'test_turbo_carto_greens_13_4011_3088.png';
|
2016-03-09 03:06:43 +08:00
|
|
|
this.testClient.getTile(13, 4011, 3088, imageCompareFn(fixturePath, done));
|
|
|
|
});
|
2016-05-19 21:54:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should work for different char case in quantification names', function (done) {
|
2016-05-19 21:54:58 +08:00
|
|
|
this.testClient = new TestClient(
|
|
|
|
makeMapconfig('#layer { marker-fill: ramp([price], colorbrewer(Greens, 3), jeNkS); }')
|
|
|
|
);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup(function (err, layergroup) {
|
2016-05-19 21:54:58 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('errors'));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-03-09 03:06:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('parsing ramp function with colorbrewer for reds and mapnik renderer', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
var turboCartocss = '#layer { marker-fill: ramp([price], colorbrewer(Reds)); }';
|
|
|
|
this.testClient = new TestClient(makeMapconfig(turboCartocss));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
it('should get a tile with turbo-carto parsed properly', function (done) {
|
|
|
|
var fixtureFileName = 'test_turbo_carto_reds_13_4011_3088.png';
|
2016-03-09 03:06:43 +08:00
|
|
|
this.testClient.getTile(13, 4011, 3088, imageCompareFn(fixtureFileName, done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('parsing ramp function with colorbrewer for greens and toque renderer', function () {
|
|
|
|
var mapConfig = {
|
|
|
|
version: '1.2.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'torque',
|
|
|
|
options: {
|
2019-10-22 01:07:24 +08:00
|
|
|
sql: 'SELECT * FROM populated_places_simple_reduced where the_geom' +
|
|
|
|
' && ST_MakeEnvelope(-90, 0, 90, 65)',
|
2016-03-09 03:06:43 +08:00
|
|
|
cartocss: [
|
|
|
|
'Map {',
|
|
|
|
' buffer-size:0;',
|
|
|
|
' -torque-frame-count:1;',
|
|
|
|
' -torque-animation-duration:30;',
|
|
|
|
' -torque-time-attribute:"cartodb_id";',
|
|
|
|
' -torque-aggregation-function:"count(cartodb_id)";',
|
|
|
|
' -torque-resolution:1;',
|
|
|
|
' -torque-data-aggregation:linear;',
|
|
|
|
'};',
|
|
|
|
'#populated_places_simple_reduced {',
|
|
|
|
' comp-op: multiply;',
|
|
|
|
' marker-fill-opacity: 1;',
|
|
|
|
' marker-line-color: #FFF;',
|
|
|
|
' marker-line-width: 0;',
|
|
|
|
' marker-line-opacity: 1;',
|
|
|
|
' marker-type: rectangle;',
|
|
|
|
' marker-width: 3;',
|
|
|
|
' marker-fill: ramp([pop_max], colorbrewer(Greens));',
|
|
|
|
'};'
|
|
|
|
].join(' '),
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
it('should get a tile with turbo-carto parsed properly', function (done) {
|
2016-03-09 03:06:43 +08:00
|
|
|
var z = 2;
|
|
|
|
var x = 2;
|
|
|
|
var y = 1;
|
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
var pngFixture = 'torque/populated_places_simple_reduced-turbo-carto-' + [z, x, y].join('.') + '.png';
|
2016-03-09 03:06:43 +08:00
|
|
|
|
|
|
|
this.testClient.getTile(z, x, y, { layers: 0, format: 'torque.png' }, imageCompareFn(pngFixture, done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|