By Graham Asher on 16 November 2009
A problem that arose with the CityMap product, developed in partnership with Greys Mead Ltd., was the need for various different style sheets, both for different variants of the product, and within a particular product, to suppress parts of the style sheet while drawing a perspective map, for speed. While it's possible to solve the problem using several different style sheets, it is much easier to put everything into one style sheet and select different features at run-time using conditional compilation controlled by parameters set by the application.
You can select any part of a style sheet (that is, any balanced XML) using
<if exp="integer expression"> ... </if>
If the expression's value is non-zero the section is compiled, otherwise it is ignored. The operators 'and', 'or', 'lt', 'le', 'eq' or '==', 'ge', 'gt', '+', '-' (unary and binary), '!', '*' and '/' are supported, and also bracketed sub-expressions using ( ... ). Operator precedence follows C++. (The operators &&, ||, <, <=, >= and > are also legal but cannot easily be used because of conflicts with XML syntax.) The variable 'scale' is built-in. Other variables can be set using CMap::SetStyleSheetVariable.
Example:
in the app code:
cur_map->SetStyleSheetVariable("HIGHLIGHTING",1); // variables can be u/c or l/c or mixed and are case-sensitive
in the style sheet:
<condition test='RoadType#F80=#400'>
<line fill='khaki'/>
<if exp="HIGHLIGHTING and scale lt 25000">
<highlight fill='green' width='70%,1' opacity='50%' distance='-40%'/>
</if>
</condition>