Talk:MapCSS/0.2/RoleBasedSelectors

From OpenStreetMap Wiki
Jump to: navigation, search

MapCSS and Role Based Selectors

The current MapCSS specification states that relation member roles can be tested with a attribute selector using the pseudo-tag role, like so

   /* 
    * renders "proposed" ways in a route in blue
    */
   relation[type=route] way[role=proposed] { color: blue; }

To the best of our knowledge, current MapCSS implementation do not support this feature yet. bk and Gubaer are currently working on integrating it into JOSM.

We propose to express role-based test expressions with a slightly different syntax.

   /* 
    * renders "proposed" ways in a route in blue
    */
   relation[type=route] >[role=proposed] way { color: blue; }

Rationale

CSS has descendent selector and child selectors. In my opinion, only the child selector is useful in the context of osm map rendering. The decendant selector is hard to implement (both the parser and the underlying logic) and I haven't seen a use case for it so far. This is why we concentrate on the child selector syntax for now. (Last paragraph by Bk)

Details

  • the condition selector between the parent and the child selector is placed after >.
  • only the attribute role is allowed
  • the following test expressions are supported
  /* is 'role' equal to 'a role' ? */
  relation >[role = "a role"] way { ... }   /* long form */
  relation >["a role"]        way { ... }   /* short form */
  /* is 'role' not equal to 'a role' ? */
  relation >[role != "a role"] way { ... }  /* long form */
  relation >[!"a role"]        way { ... }  /* short form */
  /* does 'role' match the regular expression 'a regexp' ? */
  relation >[role ~= /a regexp/] way { ... } /* long form */
  relation >[/a regexp/]         way { ... } /* short form */