Improved layergroup instantiation to filter non visible layers

This commit is contained in:
Daniel García Aubert 2016-08-26 14:42:22 +02:00
parent ee46549e04
commit 6a7613de6b

View File

@ -473,25 +473,30 @@ o.instance = function(template, params) {
all_params[k] = val;
});
// NOTE: we're deep-cloning the layergroup here
// // NOTE: we're deep-cloning the layergroup here
var layergroup = JSON.parse(JSON.stringify(template.layergroup));
for (var i=0; i<layergroup.layers.length; ++i) {
var lyropt = layergroup.layers[i].options;
layergroup.layers = layergroup.layers
.map(function (layer, i) {
if (layer.options.visibility === false) {
return;
}
if (params.styles && params.styles[i]) {
// dynamic styling for this layer
lyropt.cartocss = params.styles[i];
} else if ( lyropt.cartocss ) {
lyropt.cartocss = _replaceVars(lyropt.cartocss, all_params);
}
if ( lyropt.sql) {
lyropt.sql = _replaceVars(lyropt.sql, all_params);
}
// Anything else ?
layer.options.cartocss = params.styles[i];
} else if (layer.options.cartocss) {
layer.options.cartocss = _replaceVars(layer.options.cartocss, all_params);
}
layergroup.layers = layergroup.layers.filter(function (layer) {
return layer.options.visibility !== false;
if (layer.options.sql) {
layer.options.sql = _replaceVars(layer.options.sql, all_params);
}
return layer;
})
.filter(function (layer) {
return !!layer;
});
// extra information about the template