Remove methods that check map-config aggregation and use the ones that MapConfig model provides
This commit is contained in:
parent
4405d61845
commit
f390a10830
@ -15,7 +15,7 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
getMapConfig (user, requestMapConfig, params, context, callback) {
|
||||
const mapConfig = new MapConfig(requestMapConfig);
|
||||
|
||||
if (!this._shouldAdaptLayers(mapConfig, requestMapConfig, params)) {
|
||||
if (!this._shouldAdapt(mapConfig, params)) {
|
||||
return callback(null, requestMapConfig);
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
return !diff.length;
|
||||
}
|
||||
|
||||
_shouldAdaptLayers (mapConfig, requestMapConfig, params) {
|
||||
_shouldAdapt (mapConfig, params) {
|
||||
const { aggregation } = params;
|
||||
|
||||
if (aggregation === 'false') {
|
||||
@ -81,36 +81,16 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aggregation === undefined && mapConfig.isVectorOnlyMapConfig()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aggregation === undefined && this._hasAnyLayerAggregation(requestMapConfig)){
|
||||
if (mapConfig.isAggregationMapConfig()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
const isVectorOnlyMapConfig = mapConfig.isVectorOnlyMapConfig();
|
||||
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)
|
||||
@ -123,7 +103,7 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
if (adapted) {
|
||||
requestMapConfig.layers[index] = layer;
|
||||
}
|
||||
const aggregatedFormats = this._getAggregationMetadata(isVectorOnlyMapConfig, layer, adapted);
|
||||
const aggregatedFormats = this._getAggregationMetadata(mapConfig, layer, adapted);
|
||||
context.aggregation.layers.push(aggregatedFormats);
|
||||
});
|
||||
|
||||
@ -132,9 +112,9 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
.catch(err => callback(err));
|
||||
}
|
||||
|
||||
_adaptLayer (connection, layer, index, isVectorOnlyMapConfig, mapConfig) {
|
||||
_adaptLayer (connection, mapConfig, layer, index) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._shouldAdaptLayer(connection, layer, isVectorOnlyMapConfig, (err, shouldAdapt) => {
|
||||
this._shouldAdaptLayer(connection, mapConfig, layer, index, (err, shouldAdapt) => {
|
||||
if (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;
|
||||
|
||||
if (!isVectorOnlyMapConfig && !this._hasLayerAggregation(layer)) {
|
||||
if (!mapConfig.isAggregationLayer(index)) {
|
||||
return callback(null, shouldAdapt);
|
||||
}
|
||||
|
||||
@ -195,12 +175,12 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
_getAggregationMetadata (isVectorOnlyMapConfig, layer, adapted) {
|
||||
_getAggregationMetadata (mapConfig, layer, adapted) {
|
||||
if (!adapted) {
|
||||
return { png: false, mvt: false };
|
||||
}
|
||||
|
||||
if (isVectorOnlyMapConfig) {
|
||||
if (mapConfig.isVectorOnlyMapConfig()) {
|
||||
return { png: false, mvt: true };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user