CartoCSS: Disable marker for certain selectors

I am experimenting with rendering arrows in my CartoCSS stylesheet. I render zero, one or two arrows per line by setting styles on the ::forward and `:backward attachments.

Right now the arrows are rendered at all zoom levels (even when its corresponding line is not actually rendered). I want to configure minimum zoom levels for the markers, and these need to depend on the tags of the way (in particular on the highway type).

I can think of two general approaches how to implement this. One is to enable the markers only for certain selectors. Since it seems like any marker style property enables the rendering of markers for that way, it would mean that I need to repeat all marker style properties in each selector where I want to enable markers. Setting common marker styles in a broader selector is not possible, since it would enable markers for all ways that fit the selector. This would make my code very verbose. The other approach is to disable the markers only for certain selectors. This would make my code much cleaner. I have experimented with this by disabling markers on footpaths for zoom levels <= 15, but I am failing to get it to work.

I have tried different options:

  • Setting marker: none in the selectors where I want to disable markers does not seem to do anything. In fact, I cannot make marker: none work anywhere, it’s like the property is not supported.
  • Setting marker-opacity: 0 makes tile rendering extremely slow, presumably because it enables markers for all footpaths at all zoom levels (even the ones that should not have arrows). Rendering is so slow that I cannot even find out whether the property works as intended.
  • Setting marker-width: 0 does not change anything. The markers are still rendered with the default marker width.
  • Setting marker-width: 1 causes a one-pixel marker to be rendered on all footpaths at all zoom levels (also the ones that shouldn’t have arrows), but still one the ones that should have arrows, those arrows are unaffected by it and still rendered at all zoom levels.

It seems that I am fundamentally misunderstanding something. How can I disable markers altogether for certain selectors?

One option (not really a direct answer to the question, but probably the easiest solution) is to do it in lua not CartoCSS. This would work if you have control of the schema; but wouldn’t if you don’t.

That way you can check of an explicit tag (that you have made up) in here rather than applying it to everything.

I haven’t fully grasped the problem, but this doesn’t sound difficult to achieve. The normal approach would be along the lines:

[feature = X][zoom >= 10],
[feature = Y][zoom >=11] {
  <common styling>
  [feature = X][zoom >= 15] { <do this instead>}
  [feature = X][sub_feature = Z] { <do this instead>}
}

I wouldn’t try to “disable” rendering of a selected feature.

A certain amount of repetition may be inevitable, especially if using attachments. Do you really need them? Unless you need all one aspect of rendering to be fully completed before another, you can use things like

  <main feature rendering>
  [is_left = 'yes'][zoom >= 16] { left/<do something> }
  [is_right = 'yes'][zoom >= 16] { right/<do something> }