Support default full-sample aggregation for postgis vector renderer
This commit is contained in:
@@ -7,6 +7,17 @@ const {
|
||||
createAggregationColumnsValidator
|
||||
} = aggregationValidator;
|
||||
|
||||
const SubstitutionTokens = require('../../utils/substitution-tokens');
|
||||
|
||||
function prepareSql(sql) {
|
||||
return sql && SubstitutionTokens.replace(sql, {
|
||||
bbox: 'ST_MakeEnvelope(0,0,0,0)',
|
||||
scale_denominator: '0',
|
||||
pixel_width: '1',
|
||||
pixel_height: '1'
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = class AggregationMapConfig extends MapConfig {
|
||||
static get AGGREGATIONS () {
|
||||
return aggregationQuery.SUPPORTED_AGGREGATE_FUNCTIONS;
|
||||
@@ -132,7 +143,9 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
const sql = limitedQuery({ query: layer.options.sql });
|
||||
const sql = limitedQuery({
|
||||
query: prepareSql(layer.options.sql)
|
||||
});
|
||||
|
||||
connection.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
@@ -141,7 +154,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
||||
|
||||
let columns = result.fields || [];
|
||||
|
||||
columns = columns.map(({ name, type }) => ({ name, type }));
|
||||
columns = columns.map(({ name }) => name);
|
||||
|
||||
if (skipGeoms) {
|
||||
columns = columns.filter((column) => !geomColumns.includes(column));
|
||||
@@ -152,16 +165,25 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
||||
});
|
||||
}
|
||||
|
||||
isDefaultAggregation (index) {
|
||||
isDefaultLayerAggregation (index) {
|
||||
const aggregation = this.getAggregation(index);
|
||||
return !aggregation || (
|
||||
!aggregation.placement &&
|
||||
this._isEmptyParameter(aggregation.columns) &&
|
||||
this._isEmptyParameter(aggregation.dimensions)
|
||||
);
|
||||
|
||||
return (this.isVectorOnlyMapConfig() && !this.hasLayerAggregation(index)) ||
|
||||
aggregation === true ||
|
||||
this._isEmptyAggregation(aggregation);
|
||||
}
|
||||
|
||||
_isEmptyParameter (parameter) {
|
||||
return !parameter || Object.keys(parameter).length === 0;
|
||||
_isEmptyAggregation (aggregation) {
|
||||
return aggregation.placement === undefined &&
|
||||
aggregation.columns === undefined &&
|
||||
this._isEmptyParameter(aggregation.dimensions);
|
||||
}
|
||||
|
||||
_isEmptyParameter(parameter) {
|
||||
return parameter === undefined || parameter === null || this._isEmptyObject(parameter);
|
||||
}
|
||||
|
||||
_isEmptyObject (parameter) {
|
||||
return typeof parameter === 'object' && Object.keys(parameter).length === 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,32 +89,34 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
if (shouldAdapt) {
|
||||
const sqlQueryWrap = layer.options.sql_wrap;
|
||||
if (!shouldAdapt) {
|
||||
return resolve({ layer, index, adapted: shouldAdapt });
|
||||
}
|
||||
|
||||
let aggregationSql = mapConfig.getAggregatedQuery(index);
|
||||
const sqlQueryWrap = layer.options.sql_wrap;
|
||||
|
||||
if (sqlQueryWrap) {
|
||||
aggregationSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, aggregationSql);
|
||||
let aggregationSql = mapConfig.getAggregatedQuery(index);
|
||||
|
||||
if (sqlQueryWrap) {
|
||||
aggregationSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, aggregationSql);
|
||||
}
|
||||
|
||||
if (!mapConfig.isDefaultLayerAggregation(index)) {
|
||||
layer.options.sql = aggregationSql;
|
||||
return resolve({ layer, index, adapted: shouldAdapt });
|
||||
}
|
||||
|
||||
const skipGeoms = true;
|
||||
mapConfig.getLayerColumns(index, skipGeoms, (err, columns) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
layer.options.sql = aggregationSql;
|
||||
layer.options.columns = columns;
|
||||
|
||||
if (mapConfig.isDefaultAggregation(index)) {
|
||||
const skipGeoms = true;
|
||||
mapConfig.getLayerColumns(index, skipGeoms, (err, columns) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
layer.options.columns = columns;
|
||||
|
||||
return resolve({ layer, index, adapted: shouldAdapt });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return resolve({ layer, index, adapted: shouldAdapt });
|
||||
return resolve({ layer, index, adapted: shouldAdapt });
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user