Is there any way to use a regular expression to filter a string when using CartoCSS expressions? I have geojson of some ways and route relations I obtained using Overpass Turbo. When creating a new vector tile source from this geojson, Mapbox Studio flattens the nested @relations property to a string. I'd like to use one of the relation's tags for labeling, but it appears I'll need a regular expression to extract it from the flattened string. Is this possible, or are only simple expressions supported? If not possible does anyone have suggestions on dealing with relations in CartoCSS (perhaps some imposm pre-processing is necessary but I'd like to avoid it if possible).
1 Answer
Yes, regex is supported with the =~
operator. For example,
[name=~'^.{12,}$'] {
text-name: '';
}
will remove labels above a certain length.
You can find this and more examples in this Advanced CartoCSS techniques slide deck.
-
Thanks for the reference to that presentation, it looks like a great resource. I was aware regex was supported for filtering. I should have clarified, my question pertains to using regex in [shield-name]github.com/mapbox/carto/blob/master/docs/… or text-name calculations Commented Jan 23, 2015 at 2:27
-
Sorry about that - I should have read a little more carefully!– jmcbroomCommented Jan 23, 2015 at 2:45