diff --git a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js index 94092bda..3ef4e391 100644 --- a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js @@ -142,10 +142,6 @@ module.exports = class AggregationMapConfigAdapter { return resolve({ layer, index, adapted: false }); } - const threshold = layer.options.aggregation && layer.options.aggregation.threshold ? - layer.options.aggregation.threshold : - 1e5; - const aggregationMetadata = queryUtils.getAggregationMetadata({ query: layer.options.sql }); connection.query(aggregationMetadata, (err, res) => { @@ -154,6 +150,11 @@ module.exports = class AggregationMapConfigAdapter { } const estimatedFeatureCount = res.rows[0].count; + + const threshold = layer.options.aggregation && layer.options.aggregation.threshold ? + layer.options.aggregation.threshold : + 1e5; + const geometryType = res.rows[0].type; if (estimatedFeatureCount < threshold) {