0

I liked the part in the advanced label styling about randomly asigning a 0 or 1 to control label placement and then using as a conditional

#labels {
  text-name: "[name]";
  text-face-name: "OpenSans Regular";
  text-placement-type: simple;
  text-placements: "E,NE,SE,W,NW,SW";
  [dir=1] { text-placements: "W,NW,SW,E,NE,SE"; }
}

Rather than create a new variable, could I just use my FID and detect whether or not it is odd/even? Is there a way to detect this property in the CartoCSS?

1

This is possible if the ID is exposed as a regular data column, but CartoCSS has no way to access any internal ID stucture a particular data format might make use of.

If you have an appropriate column to filter on, you can then use a regular expression filter to divide up the features. Eg:

#labels {
  text-name: "[name]";
  text-face-name: "OpenSans Regular";
  text-placement-type: simple;
  text-placements: "E,NE,SE,W,NW,SW";
  [ID=~'.*[02468]$'] { text-placements: "W,NW,SW,E,NE,SE"; }
}

The nested filter checks if the last character of the id is an even digit (which will therefore mean the whole number is even) and alters the text-placements for them.

|improve this answer|||||

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.