I enabled a tooltip on my viz using the code below.
cartodb.createVis('map', vizUrl, {
center_lat: 16.55,
center_lon: -106.5,
zoom: 6
})
.done(function (vis, layers) {
spillLayer = layers[1];
layers[1].getSubLayer(1).setInteraction(true);
layers[1].getSubLayer(1).setInteractivity('v1');
vis.addOverlay({
layer: spillLayer,
type: 'tooltip',
template: '<p>{{v1}} gallons</p>'
});
})
I am now in a situation where I need to load the viz after a L.Map has already been created. How would I enable the tooltip in this situation? When I run the code below I get an error like
cartodb.createLayer(map, vizUrl)
.addTo(map)
.done(function (vis, layer) {
spillLayer = layer[1];
layers[1].getSubLayer(1).setInteraction(true);
layers[1].getSubLayer(1).setInteractivity('v1');
vis.addOverlay({
layer: spillLayer,
type: 'tooltip',
template: '<p>{{v1}} gallons</p>'
});
)}