1

I am trying todispatch events from external javascript to open tooltips or infowindows from feature points.

What I am doing using google maps api is something like this:

function myClick(id){
        google.maps.event.trigger(markers[id], 'click');
}
  1. Could it be possible using Cartodb.js api or I need to keep track all feature points in an external array?
1

When you create your CartoDBLayer you need to specify the interactivity and the fields that will be returned on click or other events. The example below adds interactivity to the click event for features and returns variables (columns) called idNumber and idName.

exampleLayer = new CartoDBLayer({
    map_canvas: 'map',
    map: map,
    user_name: 'test',
    table_name: 'testTable',
    query: "SELECT * FROM testTable",
    interactivity: "idNumber,idName",
    featureClick: function (ev, latlng, pos, data) {
       console.log('the id number is '+data.idNumber'and the data is '+data.idName)   
    }
});

For more info see the cartodb.js docs here

You could easily get all the visible features shown on a map using a cartodb.SQL query. Since that is a separate question I suggest you post another question and I will help you out.

  • Thank you for your response, but what I want to do is to dispatch the click event over an specific marker from a javascript function. Here you can find a jsfiddle with the behaviour I want to get using cartodb jsfiddle – nachoorme Jan 3 '14 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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