3

I want to create a CartoDB viz where the where parameter in my SQL statement changes dynamically at runtime.

When I share my CartoDB viz from the dashboard, I can't help but notice the the SQL statement is passed as a URL var.

I thought that was an easy way to dynamically change the where clause. After playing around though, I found out that the parameter is ignored (and for good reason, to guard against SQL injection), though other parms like showing the title/desc and the ne/sw latlongs are processed.

So I'm now trying to create a viz using the CartoDB API.

But for some reason, I can't get the creating visualizations at runtime example to work.

3
  • could you include the relevant lines of code in your non-working example? Here it is working fine, cartodb.github.io/cartodb.js/examples/leaflet_multilayer.html Commented Jan 15, 2014 at 15:12
  • as a side comment, SQL is not being accepted as a param because there could be more than one sublayer in the visualization so it's not possible to know to what layer apply it Commented Jan 15, 2014 at 17:06
  • Thanks! RTFM. Didn't realize that the inline examples were just code fragments. Still, you may want to consider adding the inline example in GitHub as well. Commented Jan 15, 2014 at 21:36

1 Answer 1

1

you can do easier with viz.json, taking this example (https://github.com/CartoDB/cartodb.js/blob/develop/examples/easy.html) as starting point you can do:

  cartodb.createVis('map', 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json', {
        //options 
  })
  .done(function(vis, layers) {
     layers[1].getSubLayer(SUBLAYER_NUMBER).setSQL(YOUR_SQL)   
  })

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.