Improved layergroup instantiation to filter non visible layers
This commit is contained in:
parent
ee46549e04
commit
6a7613de6b
@ -473,25 +473,30 @@ o.instance = function(template, params) {
|
|||||||
all_params[k] = val;
|
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));
|
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]) {
|
if (params.styles && params.styles[i]) {
|
||||||
// dynamic styling for this layer
|
// dynamic styling for this layer
|
||||||
lyropt.cartocss = params.styles[i];
|
layer.options.cartocss = params.styles[i];
|
||||||
} else if ( lyropt.cartocss ) {
|
} else if (layer.options.cartocss) {
|
||||||
lyropt.cartocss = _replaceVars(lyropt.cartocss, all_params);
|
layer.options.cartocss = _replaceVars(layer.options.cartocss, all_params);
|
||||||
}
|
|
||||||
if ( lyropt.sql) {
|
|
||||||
lyropt.sql = _replaceVars(lyropt.sql, all_params);
|
|
||||||
}
|
|
||||||
// Anything else ?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layergroup.layers = layergroup.layers.filter(function (layer) {
|
if (layer.options.sql) {
|
||||||
return layer.options.visibility !== false;
|
layer.options.sql = _replaceVars(layer.options.sql, all_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
return layer;
|
||||||
|
})
|
||||||
|
.filter(function (layer) {
|
||||||
|
return !!layer;
|
||||||
});
|
});
|
||||||
|
|
||||||
// extra information about the template
|
// extra information about the template
|
||||||
|
Loading…
Reference in New Issue
Block a user