From 113b3728b15366bdbf1ed754f6e6563d8ccadb23 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Wed, 6 Mar 2019 18:14:15 +0100 Subject: [PATCH] Fix support of boolean aggregation layer option --- .../aggregation/aggregation-mapconfig.js | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/cartodb/models/aggregation/aggregation-mapconfig.js b/lib/cartodb/models/aggregation/aggregation-mapconfig.js index abd53fe3..0b533acc 100644 --- a/lib/cartodb/models/aggregation/aggregation-mapconfig.js +++ b/lib/cartodb/models/aggregation/aggregation-mapconfig.js @@ -49,6 +49,10 @@ module.exports = class AggregationMapConfig extends MapConfig { ]; } + static get HAS_AGGREGATION_DISABLED () { + return null; + } + static supportsGeometryType(geometryType) { return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType); } @@ -103,19 +107,17 @@ module.exports = class AggregationMapConfig extends MapConfig { }); } - isAggregationMapConfig () { - return this.isVectorOnlyMapConfig() || this.hasAnyLayerAggregation(); - } - isAggregationLayer (index) { - return this.isVectorOnlyMapConfig() || this.hasLayerAggregation(index); + let hasAggregation = this.hasLayerAggregation(index); + // for vector-only MapConfig are aggregated unless explicitly disabled + return hasAggregation || (this.isVectorOnlyMapConfig() && hasAggregation !== AggregationMapConfig.HAS_AGGREGATION_DISABLED); } - hasAnyLayerAggregation () { + isAggregationMapConfig () { const layers = this.getLayers(); for (let index = 0; index < layers.length; index++) { - if (this.hasLayerAggregation(index)) { + if (this.isAggregationLayer(index)) { return true; } } @@ -123,22 +125,32 @@ module.exports = class AggregationMapConfig extends MapConfig { return false; } + /* Three possible return values: + * * true: explicit aggregation ({}, true) + * * false: no aggregation (undefined) + * * AggregationMapConfig.HAS_AGGREGATION_DISABLED: explicitly disabled aggregation (false) + */ hasLayerAggregation (index) { const layer = this.getLayer(index); const { aggregation } = layer.options; + if (aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean')) { + if (aggregation === false) { + return AggregationMapConfig.HAS_AGGREGATION_DISABLED; + } + return true; + } + return false; return aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean'); } getAggregation (index) { - if (this.isVectorOnlyMapConfig() && !this.hasLayerAggregation(index)) { - return {}; - } - const { aggregation } = this.getLayer(index).options; - if (typeof aggregation === 'boolean') { - return {}; + if (this.isAggregationLayer(index)) { + if (typeof aggregation === 'boolean' || !aggregation) { + return {}; + } } return aggregation; @@ -221,10 +233,7 @@ module.exports = class AggregationMapConfig extends MapConfig { _isDefaultLayerAggregation (index) { const aggregation = this.getAggregation(index); - - return (this.isVectorOnlyMapConfig() && !this.hasLayerAggregation(index)) || - aggregation === true || - this._isDefaultAggregation(aggregation); + return aggregation && this._isDefaultAggregation(aggregation); } _isDefaultAggregation (aggregation) {