Home Documentation CartoType style sheets Macros

Style sheet macros

Style sheets can get very big. One way to save space is to use macros: predefined sections that can be referenced by name. You define macros in the <defs> section like this:

<defs>

<macro id='minor-road-label'>
<label font-size='75%,8pt' glow='white' color='black' case='assume-title' maxScale='20000'/>
</macro>

<macro id='standard-tunnel'>
<tunnel dashArray='1,1' fade='0.3' mouth='dimgrey' mouthWidth='20%,1' mouthPath='m 0 512 a 512 512 0 1 1 0 -1024'/>
</macro>

</defs>

and refer to them like this:

<!-- SERVICE -->
<condition test='RoadType=#600,#7FF'>
<scale max='50000'/>
<line width='12m,2pt' fill='white' border='dimgrey' borderWidth='8%,0.7,2'/>
<macro ref='minor-road-label'/>
<oneWayArrow path='#arrow' gap='2500' fill='teal' opacity='0.5' isLabel='yes'/>
<bridge width='18m,2pt' border='dimgrey' borderWidth='14%,1' endPath='l 512 512'/>
<macro ref='standard-tunnel'/>
</condition>

<!-- TRACK -->
<condition test='RoadType#F80=#500'>
<scale max='50000'/>
<line width='12m,2pt' fill='white' border='dimgrey' borderWidth='8%,0.7,2'/>
<macro ref='minor-road-label'/>
<oneWayArrow path='#arrow' gap='2500' fill='teal' opacity='0.5' isLabel='yes'/>
<bridge width='18m,2pt' border='dimgrey' borderWidth='14%,1' endPath='l 512 512'/>
<macro ref='standard-tunnel'/>
</condition>

Macros can contain any valid XML, as long as it is balanced, which means each opening tag must have a matching closing tag, or end in />.