2

Here is my code:

    cartodb.createVis(map, 'https://blahblah/viz.json')
      .done(function(vis, layers) {
        console.log("Layers has " + layers.length + " layers.");
        layers(1).setInteraction(true)
        ...

when it gets to the last line, I get the error above. Is the syntax wrong or something? I am inexperienced with js and html. The previous line resolves fine, I get the message "Layers has 3 layers" in the console.

I am including cartodb.js 3.15.8.

1 Answer 1

2

The correct syntax is with brackets, not parens. In other words the correct syntax is:

layers[1].setInteraction(true)

not

layers(1).setInteraction(true)
1
  • 1
    That's it. If you check your viz.json, you can learn more about the layers structure. In a viz, regularly layers[0] is the basemap, and layers[1] are the data layers. Other layer types such as Torque layers would come as another independent layer such as layers[2].
    – iriberri
    Nov 18, 2015 at 10:50

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.