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>

Drawing order

CartoType draws objects by grouping them according to various rules. These rules are given in the order in which they are applied.

Geometry before labels. The geometry of all map objects (their lines and polygons) is drawn before all labels, with the exception of 3D buildings, which at present are drawn after labels to avoid visual clutter. Icons are normally treated as geometry. They are treated as labels if they are repeated icons like one-way arrows and have the attribute isLabel='yes' in their style sheet element. Labels may be grouped by inserting the element <labelLayer/> between layers. Labels within each group don't overlap each other, but labels in different groups can overlap other layers. The <labelLayer/> feature is used by the standard style sheet to overlay transparent town names over street names, etc., at large scales. Labels within a label group are drawn according to label priority (the priority attribute in the <label> element); that is, labels with smaller priority numbers are drawn first, and subsequent labels that would overlap them are discarded.

Layers before the first road layer, then other layers. The first road layer is the first layer with an attribute of road='yes' or road='true', or with the name 'road'. This allows roads, railways, etc., to be drawn over parks, rivers, etc.,even if they are sub-surface.

Sub-surface objects like tunnels, then surface objects, then objects at higher levels like bridges. Other objects drawn at high levels include routes and vehicle icons, which must overlay everything else. Object levels are used if a layer's road flags (given by the roadFlags attribute in the <layer> element) include the level mask 0xF000; the level is held as a signed nybble in the range -7 ... 8; 0 means the surface.

Layers in their style sheet order. After the rules above have been applied, layers are drawn in the order in which they appear in the style sheet. Layer groups (the <layerGroup> element) can enclose groups of layers. They allow road cores and borders to be drawn correctly by causing all the borders of objects in a layer group to be drawn first, then the cores. The road layers are always enclosed in a layer group.

Within a layer, conditions in their style sheet order. A layer may contain <condition> sections. They are drawn in their style sheet order.

Style Sheets Directory