From 47e4b9da0d8e45ce626167f6ab536f95f80f694b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 18 Dec 2017 18:43:05 +0100 Subject: [PATCH] Encapsulate threshold layer validation in aggregation-mapconfig --- lib/cartodb/models/aggregation/aggregation-map-config.js | 8 ++++++++ .../mapconfig/adapter/aggregation-mapconfig-adapter.js | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) 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); }