Merge pull request #835 from CartoDB/skip-polygon-layer-vector-map-config
In vector-only map-config, only aggregate layers with points
This commit is contained in:
commit
5e9b326d03
1
NEWS.md
1
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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user