Remove methods that check map-config aggregation and use the ones that MapConfig model provides

This commit is contained in:
Daniel García Aubert 2017-12-12 17:58:42 +01:00
parent 4405d61845
commit f390a10830

View File

@ -15,7 +15,7 @@ module.exports = class AggregationMapConfigAdapter {
getMapConfig (user, requestMapConfig, params, context, callback) { getMapConfig (user, requestMapConfig, params, context, callback) {
const mapConfig = new MapConfig(requestMapConfig); const mapConfig = new MapConfig(requestMapConfig);
if (!this._shouldAdaptLayers(mapConfig, requestMapConfig, params)) { if (!this._shouldAdapt(mapConfig, params)) {
return callback(null, requestMapConfig); return callback(null, requestMapConfig);
} }
@ -70,7 +70,7 @@ module.exports = class AggregationMapConfigAdapter {
return !diff.length; return !diff.length;
} }
_shouldAdaptLayers (mapConfig, requestMapConfig, params) { _shouldAdapt (mapConfig, params) {
const { aggregation } = params; const { aggregation } = params;
if (aggregation === 'false') { if (aggregation === 'false') {
@ -81,36 +81,16 @@ module.exports = class AggregationMapConfigAdapter {
return true; return true;
} }
if (aggregation === undefined && mapConfig.isVectorOnlyMapConfig()) { if (mapConfig.isAggregationMapConfig()) {
return true;
}
if (aggregation === undefined && this._hasAnyLayerAggregation(requestMapConfig)){
return true; return true;
} }
return false; return false;
} }
_hasAnyLayerAggregation (requestMapConfig) {
for (const layer of requestMapConfig.layers) {
if (this._hasLayerAggregation(layer)) {
return true;
}
}
return false;
}
_hasLayerAggregation (layer) {
const { aggregation } = layer.options;
return aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean');
}
_adaptLayers (connection, mapConfig, requestMapConfig, context, callback) { _adaptLayers (connection, mapConfig, requestMapConfig, context, callback) {
const isVectorOnlyMapConfig = mapConfig.isVectorOnlyMapConfig();
const adaptLayerPromises = requestMapConfig.layers.map((layer, index) => { const adaptLayerPromises = requestMapConfig.layers.map((layer, index) => {
return this._adaptLayer(connection, layer, index, isVectorOnlyMapConfig, mapConfig); return this._adaptLayer(connection, mapConfig, layer, index);
}); });
Promise.all(adaptLayerPromises) Promise.all(adaptLayerPromises)
@ -123,7 +103,7 @@ module.exports = class AggregationMapConfigAdapter {
if (adapted) { if (adapted) {
requestMapConfig.layers[index] = layer; requestMapConfig.layers[index] = layer;
} }
const aggregatedFormats = this._getAggregationMetadata(isVectorOnlyMapConfig, layer, adapted); const aggregatedFormats = this._getAggregationMetadata(mapConfig, layer, adapted);
context.aggregation.layers.push(aggregatedFormats); context.aggregation.layers.push(aggregatedFormats);
}); });
@ -132,9 +112,9 @@ module.exports = class AggregationMapConfigAdapter {
.catch(err => callback(err)); .catch(err => callback(err));
} }
_adaptLayer (connection, layer, index, isVectorOnlyMapConfig, mapConfig) { _adaptLayer (connection, mapConfig, layer, index) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._shouldAdaptLayer(connection, layer, isVectorOnlyMapConfig, (err, shouldAdapt) => { this._shouldAdaptLayer(connection, mapConfig, layer, index, (err, shouldAdapt) => {
if (err) { if (err) {
return reject(err); return reject(err);
} }
@ -158,10 +138,10 @@ module.exports = class AggregationMapConfigAdapter {
}); });
} }
_shouldAdaptLayer (connection, layer, isVectorOnlyMapConfig, callback) { _shouldAdaptLayer (connection, mapConfig, layer, index, callback) {
let shouldAdapt = false; let shouldAdapt = false;
if (!isVectorOnlyMapConfig && !this._hasLayerAggregation(layer)) { if (!mapConfig.isAggregationLayer(index)) {
return callback(null, shouldAdapt); return callback(null, shouldAdapt);
} }
@ -195,12 +175,12 @@ module.exports = class AggregationMapConfigAdapter {
}); });
} }
_getAggregationMetadata (isVectorOnlyMapConfig, layer, adapted) { _getAggregationMetadata (mapConfig, layer, adapted) {
if (!adapted) { if (!adapted) {
return { png: false, mvt: false }; return { png: false, mvt: false };
} }
if (isVectorOnlyMapConfig) { if (mapConfig.isVectorOnlyMapConfig()) {
return { png: false, mvt: true }; return { png: false, mvt: true };
} }