Structure of a CartoType style sheet

Summary:

<?xml version="1.0" encoding="UTF-8"?>
<CartoTypeStyleSheet name="mystylesheet" background="ivory" labelAttrib="name:en">
   <defs> ... </defs>
   <layer name="park"> ... </layer>
   <layer name="river"> ... </layer>
   <layer name="road"> ... </layer>
   <layer name="other-layer"> ... </layer>
   ...
   <labelLayer/>
</CartoTypeStyleSheet>

XML Declaration and <CartoTypeStyleSheet> section

The style sheet starts with the xml declaration and the opening tag of the <CartoTypeStyleSheet> section:

<?xml version="1.0" encoding="UTF-8"?>
<CartoTypeStyleSheet name="mystylesheet" background="ivory" labelAttrib="name:en">

The name attribute is not used at present. The background attribute tells CartoType what color to draw over the whole map before anything else is drawn. If it is omitted, the background of the map is drawn in white. The labelAttrib attribute gives the search path for labels. If it is omitted the standard name is used for all labels.

The roadflags attribute is a mask that specifies how non-road layers use road attributes for levels, tunnels, bridges and ramps. Its default value is '#FFFFFFFF' (the # indicates a hexadecimal number), which tells CartoType to use the tunnel, bridge, ramp and level attributes for all non-road layers. If it is 0, only roads are allowed to be tunnels and bridges and have levels, but you may override this setting in the <layer> section

You can control the the level, tunnel, bridge and ramp settings separately. The road level is kept in bits 12-15 (mask = #F000), the tunnel flag is bit 0 (mask = #1), the bridge flag is bit 16 (mask = #10000) and the ramp flag is bit 6 (mask = #40). For more details, see TRoadType in the API documentation.

Global definitions

There may be an optional <defs> section like this, defining objects used throughout the style sheet:

<defs>
   <hachure id="other-area-shading" width="1pt" interval="4pt" color="brown" opacity="0.4"/> 
   <icon id='station-icon' width='45m,5pt,200pt'>
      <svg width='220' height='220'>
      <circle fill='red' stroke='black' stroke-width='20' cx='110' cy='110' r='95'/> 
      </svg>
   </icon>
   <!-- A general-purpose arrow that will not stick outside its stroke if drawn using units of 1/1024 of the stroke width. -->
   <def id='arrow' string='M -450 -50 V 50 H 250 L -100 400 H 50 L 450 0 L 50 -400 H -100 L 250 -50 H -450 Z'/>
   <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>

This example defines a hachure, an SVG icon, the path of an arrow for one-way roads, and a macro for tunnel styles.

Layers

then one or more <layer> sections like this, defining map layers to be drawn:

<layer name="park">
   <shape fill="lightgreen"/>
   <label font-size="300m,8pt,24pt" color="green" case="title" position="centralpath"/>
</layer>

A layer can have a roadflags attribute, which overrides the default value or any value set in <CartoTypeStyleSheet>. See the section on <CartoTypeStyleSheet> above for details of this attribute.>

Label layer

The <labelLayer> section tells CartoType to draw any icons and labels:

<labelLayer/>

You can have more than one <labelLayer/> tag, and they can actually occur anywhere in the style sheet, not just at the end. Every time a <labelLayer/>is encountered, any labels for objects in the layers between it and any preceding <labelLayer/> tag are drawn. Labels are sorted according to their priorities if any, then by layer order, and within that in reverse order of <condition> sections (so that labels for objects drawn later and so taken to be more important, are drawn earlier and are thus more likely to appear).

Structure of a CartoType style sheet

The style sheet ends with the closing tag:

</CartoTypeStyleSheet>

Basic drawing order

When CartoType draws a map it draws objects in order of their z-level (optional vertical level), and within that, in order of the layers, as they appear in the style sheet.

This can make a big difference to the appearance of the map. For example, parks often contain lakes. If the parks in your data have holes in to exclude the lakes in them (which is unlikely), there is no problem, but usually park polygons have no such holes; the lakes are part of the park. Therefore you would usually draw parks before lakes and other bodies of water.

Style Sheets Directory