Encapsulate threshold layer validation in aggregation-mapconfig

This commit is contained in:
Daniel García Aubert
2017-12-18 18:43:14 +01:00
parent 81e0c3a098
commit 47e4b9da0d
2 changed files with 9 additions and 5 deletions
@@ -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);
@@ -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);
}