I currently have a map created entirely in the CartoDB editor, including custom map. For some reason it doesn't allow you to add an attribution in the editor but thats a different problem.
So my map has a custom baselayer and 3 toggleable layers. Here is the code.
<script>
function main() {
cartodb.createVis('map', 'https://paulm.cartodb.com/api/v2/viz/5fd91fc8/viz.json', {
})
.done(function(vis, layers) {
window.layers = layers;
})
.error(function(err) {
console.log(err);
});
}
window.onload = main;
</script>
I know that I could replace the current base map by adding
.done(function(vis, layers) {
var basemap = layers[0];
basemap.setUrl('http://{s}.tile.osm.org/{z}/{x}/{y}.png');
})
However im not sure if its possible to enable a base map switcher, or if I need to add it as a new layer completely will I need to do that via the code. Adding in a whole new set of tiles seems to be more of a basemap switch than just a data layer.