User:Bk/MapCSS

From OpenStreetMap Wiki
Jump to navigation Jump to search

Zoom

Example:

way|z-11[highway] { width: 1 }
way|z12-14[highway] { width: 2; }
way|z15[highway] { width: 4; }
way|z16-[highway] { width: 6; }

There are at least 2 interpretations:

Tile interpretation

You have slippy map (TMS) zoom levels like for the map on openstreetmap.org. Each number in the zoom selector simply corresponds to the tiles at that zoom level.

Scale interpretation

You consider the map scale (in pixel per meter) and define one particular scale C as zoom level 0. You get the other zoom levels by multiplying by 2. For this method, the projection does not matter and you can have continuous zoom.

Each zoom selector corresponds to a scale-range, so the rule is only applied, when the current scale is within this range.

s - current scale in pixel per meter
zoom2scale(z) = C * pow(2, z) - function that converts zoom to scale value (with some constant C)

  • |z-X applies, when s < zoom2scale(X + 0.5)
  • |zX-Y applies, when zoom2scale(X - 0.5) < s < zoom2scale(Y + 0.5)
  • |zX applies, when zoom2scale(X - 0.5) < s < zoom2scale(X + 0.5)
  • |zX- applies, when zoom2scale(X - 0.5) < s

So what is the value of the base scale C?

One way to choose it, is to make sure that in Mercator-projection, the slippy map scale is for the most part of the earth surface within the range [zoom2scale(Z - 0.5), zoom2scale(Z + 0.5)]. This way, both definitions (tile and scale) coincide.

The slippy map scale is given as 256 / (2 * Pi * 6378137) * pow(2, z) / cos(lat)

So setting

C = sqrt(2) * 256 / (2 * Pi * 6378137)

both interpretations are the same for latitudes from -60° to 60°. This is the best you can do.

Summary: |zX-Y applies, when the scale is greater than 256 / (2 * Pi * 6378137) * pow(2, X) and lower than 256 / (2 * Pi * 6378137) * pow(2, Y + 1).

Comments

As a consequence of the projection (Mercator, EPSG:3857), tiles in Oslo (ca. 60 deg N) have twice the scale as tiles of the same level at the equator. The choice, when to render a particular feature, should depend on the map scale only and not on some artificial distortion factor introduced by the projection.

This principle is also respected by Mapnik: Allthough it creates tiles (in the end), the zoom values in the style file do not correspond to tile levels, but will get converted to scale-bounds. --Bk 13:10, 1 May 2012 (BST)