0

How can the user be redirected if he clicks on a marker in CartoDB?

I have a dataset with the markers — the geometry and inside of the description-field the URL to redirect the user. I know I can redirect the user by calling on('featureClick') and then change the window.location … but how can I change the window.location to set it to the description-value of my dataset? I've tried with sql.execute but failed (Access-Control-Allow-Origin………). Any Ideas?

My Example: (not working)

      var d = layers[1].getSubLayer(2),
          d2 = layers[1].getSubLayer(3);

      d.setInteraction(true);
      d.infowindow.set({sanitizeTemplate:false});
      d.infowindow.set('template',$('#infowindow_template').html());

      d2.setInteraction(true);
      d2.on('featureClick', function(e, latlng, pos, data) {
        cartodb.log.log(data.url);
        //window.location = data.url;
      });

                 });
1

I have an example here that uses window.open:

You can enable the description column in your infowindows in order to retrieve the data from there and avoid the SQL query.

 layer.on('featureClick', function(e, pos, latlng, data) {
        cartodb.log.log(e, pos, latlng, data);
        window.open(data.url);
      });
  • What could be the problem if I can't retrieve the data? «data» still only contains «cartodb_id» … but nothing else. The columns are enabled in the infowindow-editor — and the viz and dataset have even been set to «public»… – albuvee Jun 30 '15 at 13:36
  • I'd need to check your viz.json in order to know more :) – iriberri Jun 30 '15 at 15:09
  • 4e5848f6-084e-11e5-aae7-0e49835281d6 – albuvee Jul 1 '15 at 8:36
  • Why are you getting the second layer of the viz.json in the "d" variable and then using "d2"? According to your viz.json, your first 2 layers only have cartodb_id enabled in the infowindows, so I think that you could be referring to another layer which is not the one you want :) – iriberri Jul 1 '15 at 12:39
  • d revers to layer 3, d2 to layer 4 (sorry, had deleted to much code in my example — but updated it right now) … I know there is only cartodb_id in the viz.json — thats the problem since in the editor actually ALL columns are enabled! Thats why I'm so irritated… – albuvee Jul 2 '15 at 6:02

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.