0

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 enter image description here

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>'
        });

)}

1 Answer 1

1

I believe you are mixing up the createViz and createLayer methods. With createViz you get back a viz element, since it sets up the map etc for you, with createLayer you only get back a layers element. Change this line,

.done(function (vis, layer) {

to

.done(function (layer) {
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.