From 73ae73660367bf96b2e366841b4b1c39576878a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 30 Nov 2017 19:02:30 +0100 Subject: [PATCH] Add aggregation proxy --- .../models/aggregation/aggregation-proxy.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/cartodb/models/aggregation/aggregation-proxy.js diff --git a/lib/cartodb/models/aggregation/aggregation-proxy.js b/lib/cartodb/models/aggregation/aggregation-proxy.js new file mode 100644 index 00000000..0985ec8d --- /dev/null +++ b/lib/cartodb/models/aggregation/aggregation-proxy.js @@ -0,0 +1,43 @@ +const RasterAggregation = require('./raster-aggregation'); +const VectorAggregation = require('./vector-aggregation'); +const RASTER_AGGREGATION = 'RasterAggregation'; +const VECTOR_AGGREGATION = 'VectorAggregation'; + +module.exports = class AggregationProxy { + constructor (mapconfig, resolution = 256, threshold = 10e5, placement = 'centroid') { + this.mapconfig = mapconfig; + this.resolution = resolution; + this.threshold = threshold; + this.placement = placement; + this.implementation = this._getAggregationImplementation(); + } + + _getAggregationImplementation () { + let implementation = null; + + switch (this._getAggregationType()) { + case VECTOR_AGGREGATION: + implementation = new VectorAggregation(this.resolution, this.threshold, this.placement); + break; + case RASTER_AGGREGATION: + implementation = new RasterAggregation(this.resolution, this.threshold, this.placement); + break; + default: + throw new Error('Unsupported aggregation type'); + } + + return implementation; + } + + _getAggregationType () { + if (this.mapconfig.isVetorLayergroup()) { + return VECTOR_AGGREGATION; + } + + return RASTER_AGGREGATION; + } + + sql () { + return this.implementation.sql(); + } +};