I make a tourist map with CartoCSS in TileMill. There are several zooms and I would like to show markers of the objects on 15 zoom and their labels (names) on 16 or 17 zoom. If the number of symbols in name is too much (for ex., more than 10) I want to label them on 17 zoom, if there are less than 10 symbols, I want to label them on 16 zoom.

Could any one help how to set the restriction on the number of symbols either in CartoCSS or sql?

1 Answer 1


You can't calculate string length with CartoCSS directly, but you can preprocess the data. If you're reading from a PostGIS database, add a new field for label length using the char_length() function in Postgres (docs).

If you data is another format (e.g. shapefile), you'd have to do the calculation in another program (e.g. qGIS).

Then, use a CartoCSS filter (for example, name your calculated field char_count):

#label-layer[zoom=16][char_count < 10],

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.