How can I activate interactivity on cartoDB.js with createLayer?

المشرف العام

Administrator
طاقم الإدارة
I've made a map with cartoDB.js with the createLayer method. I've defined the sublayers,inside a variables called layerSource, giving them an interactivity field like this:

sublayers:[ {sql: "SELECT * FROM db_name",interactivity: "cartodb_id",cartocss: "styles"},...more sublayers...After this I've added the layers to the map

cartodb.createLayer(map,layerSource) .addTo(map) .done(function(layer) { for (var i = 0; i < layer.getSubLayerCount(); i++) { sublayers = layer.getSubLayer(i); } }) .error(function(err) { console.log("error: " + err); });But the sublayers are not interactive. I've seen in the documentation that I have to enable the interactivity with setInteraction:true, but where I should activate this option?? Inside the createLayer (as an argument?), inside the .done??.. I assume this should be something very obvious but I'm new to javaScript and not being able to get this done.



أكثر...
 
أعلى