<scale> and <zoom> sections in style sheets

You will nearly always want your maps to look different at different scales. Some objects will not appear at some scales, and other will be drawn very differently. For example, minor roads may not appear at small scales, and city names may be suppressed or drawn as a faint overlay at large scales.

The easiest way to make this happen is to use <scale> sections:

<scale min='m' max='n'>
   ...
</scale>

with any balanced XML you like inside them.

You can omit either the min or max attribute. Omitted attributes are inherited from the enclosing section; the outermost section implicitly has no upper or lower limit. The min and max values are the denominators of the scale fractions, and the interval is half-open: for example, <scale min='10000' max='50000'> covers the range from 1:10,000, up to but not including 1:50,000.

Here is an example of nested <scale> sections:

<scale min='25000'>
   <layer name='place'>
   <label font-size='200m,12pt,24pt' font-weight='bold' color='darkslategrey' glow='white' glowWidth='7%,1' case='title' priority='1' wrapWidth='6em'/>
      <condition test='Type#FFFF0000=cit'>
      <label color='black' priority='0'/>
      </condition>
      <scale max='50000'>
         <condition test='Type#FFFF0000=tow'/>
      </scale>
      <scale max='200000'>
         <condition test='Type#FFFF0000=vil'/>
      </scale>
      <scale max='100000'>
         <condition test='Type#FFFF0000=sub'/>
      </scale>
      <scale max='50000'>
         <condition test='Type#FFFF0000=ham'/>
      </scale>
   </layer>
</scale>

The <zoom> element can be used in the same way as a <scale> section, but instead of a scale denominator it refers to a zoom level as used in OpenStreetMap, Google Maps, and other tile-based slippy-map systems. These systems use a spherical Mercator projection, rendering the whole world between roughly 85 degrees north and 85 degrees south as a square. This whole-world square, drawn to the display in a space 256 x 256 pixels, is known as zoom level 0. Zoom level 1 divides the level-0 map into 4 squares; zoom level 2 divides each level-1 map into 4 squares, and so on.

You can use <zoom> as a simple way to control map styles at different zoom levels when using CartoType to generate slippy-map tiles.

< Back to Style Sheets Main Page