diff --git a/lib/cartodb/models/aggregation/aggregation-map-config.js b/lib/cartodb/models/aggregation/aggregation-map-config.js index 4411002a..379d7739 100644 --- a/lib/cartodb/models/aggregation/aggregation-map-config.js +++ b/lib/cartodb/models/aggregation/aggregation-map-config.js @@ -22,6 +22,16 @@ module.exports = class AggregationMapConfig extends MapConfig { return 1; } + static get SUPPORTED_GEOMETRY_TYPES () { + return [ + 'ST_Point' + ]; + } + + static supportsGeometryType(geometryType) { + return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType); + } + constructor (config, datasource) { super(config, datasource); diff --git a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js index f3f13828..a99eeaef 100644 --- a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js @@ -2,7 +2,8 @@ const AggregationMapConfig = require('../../aggregation/aggregation-map-config') const queryUtils = require('../../../utils/query-utils'); const unsupportedGeometryTypeErrorMessage = ctx => -`Unsupported geometry type: ${ctx.geometryType}. Aggregation is available only for geometry type: ST_Point`; +`Unsupported geometry type: ${ctx.geometryType}. ` + +`Aggregation is available only for geometry type: ${AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES}`; const invalidAggregationParamValueErrorMessage = ctx => `Invalid value for 'aggregation' query param: ${ctx.value}. Valid ones are 'true' or 'false'`; @@ -116,16 +117,13 @@ module.exports = class AggregationMapConfigAdapter { } const result = res.rows[0] || {}; - const estimatedFeatureCount = result.count; - if (!mapConfig.doesLayerReachThreshold(index, estimatedFeatureCount)) { + if (!mapConfig.doesLayerReachThreshold(index, result.count)) { return callback(null, shouldAdapt); } - const geometryType = result.type; - - if (geometryType !== 'ST_Point') { - return callback(new Error(unsupportedGeometryTypeErrorMessage({ geometryType }))); + if (!AggregationMapConfig.supportsGeometryType(result.type)) { + return callback(new Error(unsupportedGeometryTypeErrorMessage({ geometryType: result.type }))); } shouldAdapt = true;