Map objects in a single layer often have different attributes. For instance, roads are distinguished by their feature type and by other attributes indicating whether a road is one-way, private, etc. These attributes affect the way the road is drawn.

You use <condition> sections inside <layer> to treat objects with differing attributes in different ways. Each <condition> section is like an embedded <layer> section for only those objects with the specified attributes.

A <condition> section inherits all attributes defined in the containing <layer>, unless it is nested inside another condition, in which case it inherits from the containing condition. Conditions may be nested up to 15 levels deep.

You set the actual condition using a style sheet expression in the exp attribute. Expressions test integer and string attributes of map objects; if the expression is true, the object is drawn using the styles given inside the condition element

This is hard to understand without an example. Here is the mid-level road layer from the standard style sheet:

<layer name='road/mid' road='true'>
    <condition exp='@feature_type="tertiary road"'>
        <line border='dimgrey' borderWidth='8%,0.35pt,1pt' fill='orange+khaki+0.8white' width='10m@6000_40m@40000,0.3pt'/>
         <macro ref='minor-road-label'/>
         <macro color='darkkhaki' ref='one-way-arrow'/>
         <macro ref='standard-bridge'/>
         <macro ref='grey-tunnel'/>
    <condition exp='@feature_type in { "secondary road", "secondary road link" }'>
        <line border='dimgrey' borderWidth='8%,0.35pt,1pt' fill='orange+khaki+0.6white' width='10m@6000_40m@40000,0.6pt'/>
        <scale max='40000'>
            <label case='assume-title' color='dimgrey' font-size='75%,5pt,18pt' glow='white' glowWidth='7%,0.5pt' labelFormat=';int_name;name:en+" "ref' maxScale='75000'/>
        <macro color='darkkhaki+black' ref='one-way-arrow'/>
        <macro ref='standard-bridge'/>
        <macro ref='standard-tunnel'/>

The first condition has the test '@feature_type="tertiary road"', meaning that only tertiary roads are drawn by the specifications in this condition.

Here is an example showing the inheritance of attributes from the containing layer:

<layer name='waterway/minor'>
    <label case='assume-title' color='ncsblue' duplicate='1000m,512pt' font-family='serif' font-style='italic' glow='white' glowWidth='7%,0.5pt' position='centralpath' priority='1'/>
    <line fill='lightblue'/>
    <shape fill='lightblue'/>
    <condition exp='@feature_type="str"'>
        <line width='4m,0.3pt'/>
        <label font-size='75%,5pt,18pt'/>
    <condition exp='@feature_type="dra"'>
        <line width='2m,0.3pt'/>
        <label font-size='75%,5pt,18pt'/>
    <macro ref='water-minor'/>

And here is an example of nested conditions:

<layer name='pushpin'>
    <label case='assume-title' color='ncsred' colorAttrib='_color' font-size='12m,6pt,12pt' glow='white' glowWidth='7%,0.5pt' priority='-20' wrapWidth='5em'/>
    <condition exp='@=0'>
        <condition exp='_iconText'>
            <icon textAttrib='_iconText' font-size='24m,12pt,72pt' color='ncsred' colorAttrib='_color' canOverlap='true'/>
        <condition exp='!_iconText'>
            <icon ref='pushpin-icon' color='ncsred' colorAttrib='_color' canOverlap='yes' canCombine='yes'/>
            <condition exp='_combined gt 1'>
                <icon ref='large-pushpin-icon' color='ncsred'/>
                <label position='icon' labelFormat='_combined' color='ncsred' colorAttrib='_color' font-size='12m,6pt,12pt' glow='white' glowWidth='7%,1' priority='-21' wrapWidth='5em'/>
    <condition exp='@!=0'>
        <shape border='ncsred' borderWidth='2m,0.6pt' fill='ncsred' opacity='0.5'/>
        <line fill='ncsred' opacity='0.5' width='5m,0.6pt'/>

Here, the outer two conditions distinguish point pushpin objects ('@=0'; @ is the type, and 0 means a point; 1 means a line, 2 a polygon and 3 an array or texture) from others. Within point objects, those with an _iconText attribute are treated differently from those without, and pushpins without _iconText are drawn using a larger icon if they are the result of combining several pushpins.

When the map is drawn, objects are matched to the innermost test that succeeds.

Style Sheets Directory