diff --git a/NEWS.md b/NEWS.md index 87e8909f..acf57fa9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## 4.6.1 Released 2018-mm-dd + - Allow to create vector map-config for layers that doesn't have points. Layers with lines or polygons won't be aggregated by default. ## 4.6.0 diff --git a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js index 28cbffc9..6aa0eaf2 100644 --- a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js @@ -132,7 +132,7 @@ module.exports = class AggregationMapConfigAdapter { const result = res.rows[0] || {}; - if (!AggregationMapConfig.supportsGeometryType(result.type)) { + if (!mapConfig.isVectorOnlyMapConfig() && !AggregationMapConfig.supportsGeometryType(result.type)) { const message = unsupportedGeometryTypeErrorMessage({ geometryType: result.type }); const error = new Error(message); error.type = 'layer'; @@ -145,6 +145,10 @@ module.exports = class AggregationMapConfigAdapter { return callback(error); } + if (mapConfig.isVectorOnlyMapConfig() && !AggregationMapConfig.supportsGeometryType(result.type)) { + return callback(null, false); + } + if (!mapConfig.doesLayerReachThreshold(index, result.count)) { return callback(null, false); } diff --git a/test/acceptance/aggregation.js b/test/acceptance/aggregation.js index 30cfd9db..ce6eabb4 100644 --- a/test/acceptance/aggregation.js +++ b/test/acceptance/aggregation.js @@ -471,6 +471,8 @@ describe('aggregation', function () { type: 'cartodb', options: { sql: POLYGONS_SQL_1, + cartocss: '#layer { marker-width: [value]; }', + cartocss_version: '2.3.0', aggregation: { threshold: 1 } @@ -1233,6 +1235,99 @@ describe('aggregation', function () { }); }); + + it('should skip aggregation w/o failing when is Vector Only MapConfig and layer has polygons', + function (done) { + this.mapConfig = createVectorMapConfig([ + { + type: 'cartodb', + options: { + sql: POLYGONS_SQL_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)); + + body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.mvt)); + body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png)); + + const options = { + format: 'mvt' + }; + + this.testClient.getTile(0, 0, 0, options, (err, res, tile) => { + if (err) { + return done(err); + } + + const tileJSON = tile.toJSON(); + + assert.equal(tileJSON[0].features.length, 7); + + 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(); + + assert.equal(tileJSON[0].features.length, 7); + + done(); + }); + }); + }); }); }); });