0

I know how to set a specific color for a specific value (here specific_string) of a specific field (here field1)

#mydataset[field1="specific_string"] {
   marker-fill: #000000;

But what if I want to set this color for all the elements where field1 CONTAINS a specific string?

#mydataset[field1 ??CONTAINS?? "specific_string"] {
   marker-fill: #000000;

How do I write that please?

1

You are looking for using regular expressions on your filters, here's the official documentation of the CartoCSS language regarding filters.

Example from documentation:

/* a regular expression over name */
#world[name =~ "A.*"]

With the data you provided it's working as expected

enter image description here

I changed slightly the code to have a default marker fill value (#fabada). Then you can see how some dots are in blue as they contain the string Diversité offre.

#l {
   marker-fill: #fabada;
   marker-fill-opacity: 0.9;
   marker-line-color: #FFF;
   marker-line-width: 0.5;
   marker-line-opacity: 1;
   marker-placement: point;
   marker-type: ellipse;
   marker-width: [pertinence]*5;
   marker-allow-overlap: true;
}

#l[recurrence=~"Diversité offre"] {
   marker-fill: #A6CEE3;
}

There is an important caveat you need to take into account. Because you are having tags and looking for occurrences, the last rules will override any previous match. So if you have a point that matches more than one rule, only the last one will be rendered. To fix that you should work more in the SQL part to unnest your rows by tag, and then maybe use something like the stacking chips hack to render the different values.

  • Thank you. I tried that but it doesn't look to work for me. I have a column called "recurrence" in which I have TAGS separated by the "|" symbol (smal vertical bar). Please see here the link of the .carto map : n.fonty.free.fr/divers/… – Nicolas Fonty Mar 6 '18 at 17:37
  • I've added more details to my answer based in your data – Jorge Sanz Mar 6 '18 at 18:36
  • Thank you Jorge. If you look at the 3 pink points on the bottom left corner of your map, you will see that 2 of them are tagged "Diversité offre" and are still pink. – Nicolas Fonty Mar 7 '18 at 7:41
  • Please see image on this link to spot the 2 points : n.fonty.free.fr/divers/CN2AT.jpg – Nicolas Fonty Mar 7 '18 at 7:49
  • What is the problem with those 2 points? (in fact, I am seeing 3) – ramiroaznar Mar 7 '18 at 11:38

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.