diff --git a/lib/cartodb/backends/cluster.js b/lib/cartodb/backends/cluster.js index da468177..62ef86a9 100644 --- a/lib/cartodb/backends/cluster.js +++ b/lib/cartodb/backends/cluster.js @@ -5,6 +5,9 @@ const dbParamsFromReqParams = require('../utils/database-params'); const debug = require('debug')('backend:cluster'); const AggregationMapConfig = require('../models/aggregation/aggregation-mapconfig'); +const windshaftUtils = require('windshaft').utils; +const wmh = new windshaftUtils.WebMercatorHelper(); + module.exports = class ClusterBackend { getClusterFeatures (mapConfigProvider, params, callback) { mapConfigProvider.getMapConfig((err, _mapConfig) => { @@ -156,8 +159,8 @@ const clusterFeaturesQuery = ctx => ` `; const gridResolution = ctx => { - const minimumResolution = 2*Math.PI*6378137/Math.pow(2,38); - return `${256/ctx.res} * GREATEST(!pixel_height!, ${minimumResolution})::numeric`; + const zoom_resolution = wmh.getResolution({ z : Math.min(38, ctx.zoom) }); + return `${256/ctx.res} * (${zoom_resolution})::double precision`; }; const aggregationQuery = ctx => ` diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 55bdf7f0..52778443 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -429,7 +429,7 @@ SELECT * FROM OFFSET 0 ) __cdb_src_get_x_y, __cdb_grid_params WHERE cdb_x < __cdb_grid_params.cdb_xmax AND cdb_y < __cdb_grid_params.cdb_ymax - ) __cdb_src_gridded, __cdb_grid_params + ) __cdb_src_gridded GROUP BY cdb_pos_grid_x, cdb_pos_grid_y ${dimensionNames(ctx)} ${havingClause(ctx)} ) __cdb_aggregation_src