0

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

http://bl.ocks.org/Pabloska/a860115cc78515291688ca4491f3ba09

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 :

http://bl.ocks.org/Pabloska/b7a9f6a052d8d7b91c6595cc38086113

Any ideas ?

1 Answer 1

0

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'));

3
  • 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
    Commented 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... Commented Dec 1, 2017 at 9:55
  • Ramiro , thanks for the response , it's working now! Commented 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.