Fix support of boolean aggregation layer option

This commit is contained in:
Javier Goizueta
2019-03-06 18:14:15 +01:00
parent cf193a71b2
commit 113b3728b1
@@ -49,6 +49,10 @@ module.exports = class AggregationMapConfig extends MapConfig {
];
}
static get HAS_AGGREGATION_DISABLED () {
return null;
}
static supportsGeometryType(geometryType) {
return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType);
}
@@ -103,19 +107,17 @@ module.exports = class AggregationMapConfig extends MapConfig {
});
}
isAggregationMapConfig () {
return this.isVectorOnlyMapConfig() || this.hasAnyLayerAggregation();
}
isAggregationLayer (index) {
return this.isVectorOnlyMapConfig() || this.hasLayerAggregation(index);
let hasAggregation = this.hasLayerAggregation(index);
// for vector-only MapConfig are aggregated unless explicitly disabled
return hasAggregation || (this.isVectorOnlyMapConfig() && hasAggregation !== AggregationMapConfig.HAS_AGGREGATION_DISABLED);
}
hasAnyLayerAggregation () {
isAggregationMapConfig () {
const layers = this.getLayers();
for (let index = 0; index < layers.length; index++) {
if (this.hasLayerAggregation(index)) {
if (this.isAggregationLayer(index)) {
return true;
}
}
@@ -123,22 +125,32 @@ module.exports = class AggregationMapConfig extends MapConfig {
return false;
}
/* Three possible return values:
* * true: explicit aggregation ({}, true)
* * false: no aggregation (undefined)
* * AggregationMapConfig.HAS_AGGREGATION_DISABLED: explicitly disabled aggregation (false)
*/
hasLayerAggregation (index) {
const layer = this.getLayer(index);
const { aggregation } = layer.options;
if (aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean')) {
if (aggregation === false) {
return AggregationMapConfig.HAS_AGGREGATION_DISABLED;
}
return true;
}
return false;
return aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean');
}
getAggregation (index) {
if (this.isVectorOnlyMapConfig() && !this.hasLayerAggregation(index)) {
return {};
}
const { aggregation } = this.getLayer(index).options;
if (typeof aggregation === 'boolean') {
return {};
if (this.isAggregationLayer(index)) {
if (typeof aggregation === 'boolean' || !aggregation) {
return {};
}
}
return aggregation;
@@ -221,10 +233,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
_isDefaultLayerAggregation (index) {
const aggregation = this.getAggregation(index);
return (this.isVectorOnlyMapConfig() && !this.hasLayerAggregation(index)) ||
aggregation === true ||
this._isDefaultAggregation(aggregation);
return aggregation && this._isDefaultAggregation(aggregation);
}
_isDefaultAggregation (aggregation) {