[GIS] Hide layers by default on CartoDB visualization

cartocarto-js

I'm loading a CartoDB visualization and I want all layers to be switched off as the default setting, so users have to switch them on using the layer selector loaded with the visualization.

I'm reallly new on leaflet and cartodbjs so not sure where to begin to dive in the code. I think is related with this question but it doesn't have any answer.

I have a sample code on gist (demo).

Best Answer

find attached some example code. You can access the layers/sublayers through the javascript API layer[0] is the basemap and layer1 is the main layer with your two sublayers.

Anyway I recommend you creating this visualization with CreateLayer as when hiding the sublayers the toggle layers controls won't update.

Cheers

Related Question