2016-01-20 02:31:43 +08:00
|
|
|
var queue = require('queue-async');
|
2016-01-20 19:44:00 +08:00
|
|
|
var _ = require('underscore');
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-21 19:03:50 +08:00
|
|
|
function MapConfigOverviewsAdapter(overviewsApi) {
|
2016-01-20 02:31:43 +08:00
|
|
|
this.overviewsApi = overviewsApi;
|
|
|
|
}
|
|
|
|
|
2016-01-21 19:03:50 +08:00
|
|
|
module.exports = MapConfigOverviewsAdapter;
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-21 19:03:50 +08:00
|
|
|
MapConfigOverviewsAdapter.prototype.getLayers = function(username, layers, callback) {
|
2016-01-20 20:12:45 +08:00
|
|
|
var self = this;
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-20 19:44:00 +08:00
|
|
|
if (!layers) {
|
|
|
|
return callback(null);
|
|
|
|
}
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-20 19:44:00 +08:00
|
|
|
var augmentLayersQueue = queue(layers.length);
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-20 19:44:00 +08:00
|
|
|
function augmentLayer(layer, done) {
|
2016-01-20 20:12:45 +08:00
|
|
|
self.overviewsApi.getOverviewsMetadata(username, layer.options.sql, function(err, metadata){
|
2016-01-21 01:09:00 +08:00
|
|
|
if (err) {
|
|
|
|
done(err, layer);
|
|
|
|
} else {
|
|
|
|
if ( !_.isEmpty(metadata) ) {
|
2016-01-21 17:58:50 +08:00
|
|
|
layer = _.extend({}, layer, { overviews: metadata });
|
2016-01-21 01:09:00 +08:00
|
|
|
}
|
|
|
|
done(null, layer);
|
2016-01-20 19:44:00 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-20 19:44:00 +08:00
|
|
|
function layersAugmentQueueFinish(err, layers) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
2016-01-20 18:51:46 +08:00
|
|
|
}
|
2016-01-20 02:31:43 +08:00
|
|
|
|
2016-01-20 19:44:00 +08:00
|
|
|
if (!layers || layers.length === 0) {
|
|
|
|
return callback(new Error('Missing layers array from layergroup config'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return callback(null, layers);
|
|
|
|
}
|
|
|
|
|
|
|
|
layers.forEach(function(layer) {
|
|
|
|
augmentLayersQueue.defer(augmentLayer, layer);
|
|
|
|
});
|
|
|
|
augmentLayersQueue.awaitAll(layersAugmentQueueFinish);
|
|
|
|
|
2016-01-20 02:31:43 +08:00
|
|
|
};
|