diff --git a/lib/cartodb/models/aggregation/aggregation-map-config.js b/lib/cartodb/models/aggregation/aggregation-map-config.js index 26f62b17..4411002a 100644 --- a/lib/cartodb/models/aggregation/aggregation-map-config.js +++ b/lib/cartodb/models/aggregation/aggregation-map-config.js @@ -89,6 +89,14 @@ module.exports = class AggregationMapConfig extends MapConfig { return aggregation; } + doesLayerReachThreshold(index, featureCount) { + const threshold = this.getAggregation(index) && this.getAggregation(index).threshold ? + this.getAggregation(index).threshold : + AggregationMapConfig.THRESHOLD; + + return featureCount >= threshold; + } + validate () { const validate = aggregationValidator(this); const numberValidator = createNumberValidator(this); diff --git a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js index 2572ecdf..f3f13828 100644 --- a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js @@ -118,11 +118,7 @@ module.exports = class AggregationMapConfigAdapter { const result = res.rows[0] || {}; const estimatedFeatureCount = result.count; - const threshold = layer.options.aggregation && layer.options.aggregation.threshold ? - layer.options.aggregation.threshold : - AggregationMapConfig.THRESHOLD; - - if (estimatedFeatureCount < threshold) { + if (!mapConfig.doesLayerReachThreshold(index, estimatedFeatureCount)) { return callback(null, shouldAdapt); }