I have create a visualisation in cartodb with 4 layers. The resulting viz.json is added to a leaflet map as follows:
cartodb.createLayer(cartomap, [url], {https:true})
.addTo(cartomap)
.on('done', function(layer) {
// add individual layers
}
I want to accomplish that all 4 layers in the viz.json can be toggled separatly in the layer control (switching both the markers/features and the legend)
The layer in on('done') is a valid leaflet layer and can be added to the Layer Control. However, it contains all sublayers which can then not be toggled individually.
The layer also contains an array with all the "sub" layers in there, but these are not valid Leaflet layers (onAdd function is missing), so these can not be added to the layerControl individually. The layer.getSubLayer(i) also returns a not valid Leaflet layer.