Improved layergroup instantiation to filter non visible layers
This commit is contained in:
parent
ee46549e04
commit
6a7613de6b
@ -473,26 +473,31 @@ o.instance = function(template, params) {
|
||||
all_params[k] = val;
|
||||
});
|
||||
|
||||
// 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;
|
||||
// // NOTE: we're deep-cloning the layergroup here
|
||||
var layergroup = JSON.parse(JSON.stringify(template.layergroup));
|
||||
|
||||
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 ?
|
||||
}
|
||||
layergroup.layers = layergroup.layers
|
||||
.map(function (layer, i) {
|
||||
if (layer.options.visibility === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
layergroup.layers = layergroup.layers.filter(function (layer) {
|
||||
return layer.options.visibility !== false;
|
||||
});
|
||||
if (params.styles && params.styles[i]) {
|
||||
// dynamic styling for this layer
|
||||
layer.options.cartocss = params.styles[i];
|
||||
} else if (layer.options.cartocss) {
|
||||
layer.options.cartocss = _replaceVars(layer.options.cartocss, all_params);
|
||||
}
|
||||
|
||||
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
|
||||
layergroup.template = {
|
||||
|
Loading…
Reference in New Issue
Block a user