0

I’m generating a view using the query like this in CartoDB

SELECT table1.cartodb_id, table2.data_count, table2.event, table1.the_geom_webmercator FROM table1 JOIN table2 ON table1.data_id = table2.data_id

In my CartoCSS, I want to set the torque marker color conditionally. Both of the following fail.

['table2.data_count' < 10]{ marker-fill: #D6301D; } [data_count < 10]{ marker-fill: #D6301D; }

How can I set the CartoCSS to set marker color based on table2.data_count

1

CartoCSS, when used when Torque, doesn't know about your columns data. Filters cannot be used like your example:

['table2.data_count' < 10]{ marker-fill: #D6301D; }

in Torque because the different values you have wouldn't make sense for it.

The way that Torque works is with the aggregation function, that by default counts the number of events in the same location:

Map {
  -torque-aggregation-function:"count(cartodb_id)";
  -torque-resolution: 2;
}

The result of the torque-aggregation-function is the only variable that Torque knows about, the variable value that you can see if you apply a Torque Category map. In your case, you would have to replace this aggregation function by something that gives you the values of your load column.

This value variable can go from 0 to 255 because of certain limitations, so make sure that the aggregation function will return something bounded by these values.

If your "load" column does not exceed 255, you could try something like:

  -torque-aggregation-function:"round(avg(data_count))";

and then you should be able to use your filters like:

#table_11
  [value <10] { marker-fill: #000; }
#table_11
  [value < 8] { marker-fill: #400; }
#table_11
  [value < 3] { marker-fill: #800; }
#table_11
  [value <= 1] { marker-fill: #F00; }

You can learn about the details on how spatial aggregation works here.

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.