Tcl Library Source Code

Bounty program for improvements to Tcl and certain Tcl packages.

[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]


map::slippy - Common code for slippy based map packages

Table Of Contents


package require Tcl 8.6
package require map::slippy ?0.7.1?

::map slippy length level
::map slippy tiles level
::map slippy tile size
::map slippy tile valid tile levels ?msgvar?
::map slippy geo distance geo1 geo2
::map slippy geo 2tile geo
::map slippy geo 2tile.float geo
::map slippy geo 2point geo
::map slippy tile 2geo tile
::map slippy tile 2point tile
::map slippy point 2geo point
::map slippy point 2tile point
::map slippy fit geobox canvdim geobox zmin zmax


This package provides a number of methods doing things needed by all types of slippy-based map packages.


Coordinate systems

The commands of this package operate on three distinct coordinate systems, which are explained below.


Geographical coordinates are represented by Latitude and Longitude, each of which is measured in degrees, as they are essentially angles.

Zero longitude is the Greenwich meridian, with positive values going east, and negative values going west, for a total range of +/- 180 degrees. Note that +180 and -180 longitude are the same meridian, opposite to greenwich.

zero latitude the Equator, with positive values going north and negative values going south. While the true range is +/- 90 degrees the projection used by the package requires us to cap the range at +/- 85.05112877983284 degrees. This means that north and south pole are not representable and not part of any map.


While Geographical coordinates of the previous section are independent of zoom level the tile coordinates are not.

Generally the integer part of tile coordinates represent the row and column number of the tile in question, wheras the fractional parts signal how far inside the tile the location in question is, with pure integer coordinates (no fractional part) representing the upper left corner of the tile.

The zero point of the map is at the upper left corner, regardless of zoom level, with larger coordinates going right (east) and down (south), and smaller coordinates going left (west) and up (north). Again regardless of zxoom level.

Negative tile coordinates are not allowed.

At zoom level 0 the whole map is represented by a single, putting the geographic zero at 1/2, 1/2 of tile coordinates, and the range of tile coordinates as [0...1].

To go from a zoom level N to the next deeper level N+1 each tile of level N is split into its four quadrants, which then are the tiles of level N+1.

This means that at zoom level N the map is sliced (horizontally and vertically) into 2^N stripes, for a total of 4^N tiles, with tile coordinates ranging from 0 to 2^N+1.


pixel coordinates, also called point coordinates are in essence tile coordinates scaled by the size of the image representing a tile. This tile size currently has a fixed value, 256.




geodesy, geography, latitute, location, longitude, map, slippy, zoom