Going green: do not fail when map-config is vector-only and a layer doesn't have points

This commit is contained in:
Daniel García Aubert 2018-01-03 12:00:25 +01:00
parent 3799dd2574
commit 1c7da2c4b3
2 changed files with 84 additions and 9 deletions

View File

@ -132,7 +132,7 @@ module.exports = class AggregationMapConfigAdapter {
const result = res.rows[0] || {}; const result = res.rows[0] || {};
if (!AggregationMapConfig.supportsGeometryType(result.type)) { if (!mapConfig.isVectorOnlyMapConfig() && !AggregationMapConfig.supportsGeometryType(result.type)) {
const message = unsupportedGeometryTypeErrorMessage({ geometryType: result.type }); const message = unsupportedGeometryTypeErrorMessage({ geometryType: result.type });
const error = new Error(message); const error = new Error(message);
error.type = 'layer'; error.type = 'layer';
@ -145,6 +145,10 @@ module.exports = class AggregationMapConfigAdapter {
return callback(error); return callback(error);
} }
if (mapConfig.isVectorOnlyMapConfig() && !AggregationMapConfig.supportsGeometryType(result.type)) {
return callback(null, false);
}
if (!mapConfig.doesLayerReachThreshold(index, result.count)) { if (!mapConfig.doesLayerReachThreshold(index, result.count)) {
return callback(null, false); return callback(null, false);
} }

View File

@ -471,6 +471,8 @@ describe('aggregation', function () {
type: 'cartodb', type: 'cartodb',
options: { options: {
sql: POLYGONS_SQL_1, sql: POLYGONS_SQL_1,
cartocss: '#layer { marker-width: [value]; }',
cartocss_version: '2.3.0',
aggregation: { aggregation: {
threshold: 1 threshold: 1
} }
@ -1233,7 +1235,9 @@ describe('aggregation', function () {
}); });
}); });
it('should skip aggregation w/o failing when is Vector Only MapConfig and layer has polygons', function (done) {
it('should skip aggregation w/o failing when is Vector Only MapConfig and layer has polygons',
function (done) {
this.mapConfig = createVectorMapConfig([ this.mapConfig = createVectorMapConfig([
{ {
type: 'cartodb', type: 'cartodb',
@ -1244,6 +1248,18 @@ describe('aggregation', function () {
]); ]);
this.testClient = new TestClient(this.mapConfig); this.testClient = new TestClient(this.mapConfig);
this.testClient.getLayergroup((err, body) => {
if (err) {
return done(err);
}
assert.equal(typeof body.metadata, 'object');
assert.ok(Array.isArray(body.metadata.layers));
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.mvt));
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png));
const options = { const options = {
format: 'mvt' format: 'mvt'
}; };
@ -1255,12 +1271,67 @@ describe('aggregation', function () {
const tileJSON = tile.toJSON(); const tileJSON = tile.toJSON();
tileJSON[0].features.forEach(feature => assert.equal(typeof feature.properties.value, 'number')); tileJSON[0].features.forEach(feature => {
assert.equal(typeof feature.properties.value, 'number');
});
done(); done();
}); });
}); });
});
it('should skip aggregation for polygons (w/o failing) and aggregate when the layer has points',
function (done) {
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
options: {
sql: POLYGONS_SQL_1
}
},
{
type: 'cartodb',
options: {
sql: POINTS_SQL_1,
aggregation: {
threshold: 1
}
}
}
]);
this.testClient = new TestClient(this.mapConfig);
this.testClient.getLayergroup((err, body) => {
if (err) {
return done(err);
}
assert.equal(typeof body.metadata, 'object');
assert.ok(Array.isArray(body.metadata.layers));
assert.equal(body.metadata.layers[0].meta.aggregation.mvt, false);
assert.equal(body.metadata.layers[1].meta.aggregation.mvt, true);
const options = {
format: 'mvt'
};
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
if (err) {
return done(err);
}
const tileJSON = tile.toJSON();
tileJSON[0].features.forEach(feature => {
assert.equal(typeof feature.properties.value, 'number');
});
done();
});
});
});
}); });
}); });
}); });