The example below is based on Ramiro's code and using his data set works perfectly :


But for some reasons when I change the json API and the SQL query it doesn't work, nor give a error message. The code below is the same as above but my carto account :


Any ideas ?

1 Answer 1


There are two things messing your code and both are located in this line of code:

subLayer.setSQL(query.replace('SELECT * FROM rohingya_entry_points_1', 'SELECT * FROM rohingya_entry_points_1 where crossing_cost < "50000"'));

The first is a typo. You need to get rid of the "...", numeric values are not strings (do notice that string values are also quoted with single marks in PostgreSQL). Secondly and more key is that the first/original piece of SQL you want to replace need to be in lowercase. Why? Because your original query is like that, as you can see when consoling log. If not, the replace js method is not going to find anything on that query string. So the right code is as follow:

subLayer.setSQL(query.replace('select * from rohingya_entry_points_1', 'select * from rohingya_entry_points_1 where crossing_cost < 250000'));

  • That full replace looks very fragile, I would try to make it more specific to only change the very bits you need, or even using some marks in the original query (in comments) to find the text to replace using regular expressions.
    – Jorge Sanz
    Dec 1, 2017 at 7:46
  • True. If I had to build the block again, I would do it quite differently. And as you said, that replace method is not the best solution... Dec 1, 2017 at 9:55
  • Ramiro , thanks for the response , it's working now! Dec 1, 2017 at 18:12

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.