Sometimes you need to enable or disable parts of a style sheet at run time. For example, you might want to use a different style for some map layers in perspective mode.

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 the framework SetStyleSheetVariable functions.


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%'/>