geokit/mercator
Web Mercator (EPSG:3857) tile and quadkey conversion.
Web Mercator is the projection used by every slippy map service:
Google Maps, OpenStreetMap, Bing Maps, Mapbox. The world at zoom
level z is divided into 2 ^ z × 2 ^ z square tiles indexed
by (x, y) with (0, 0) at the top-left (north-west) corner.
Tiles outside the supported latitude range (±85.05112878°,
where the projection clips to keep the map square) are not
representable; from_lat_lng clamps latitude
rather than reporting an error.
Quadkeys are Bing Maps’ single-string encoding of (zoom, x, y).
Types
Errors returned by tile and quadkey operations.
pub type MercatorError {
ZoomOutOfRange(zoom: Int)
TileCoordOutOfRange(zoom: Int, x: Int, y: Int)
InvalidQuadkeyChar(char: String, position: Int)
EmptyQuadkey
}
Constructors
-
ZoomOutOfRange(zoom: Int)Zoom level was outside
[0, 30]. -
TileCoordOutOfRange(zoom: Int, x: Int, y: Int)xorywas outside[0, 2^zoom). -
InvalidQuadkeyChar(char: String, position: Int)A character outside
{0, 1, 2, 3}appeared in a quadkey. -
EmptyQuadkeyquadkey_to_tilewas called with an empty string.
Values
pub fn bounds(tile tile: Tile) -> #(latlng.LatLng, latlng.LatLng)
The south-west and north-east corners of tile, returned as
#(sw, ne).
pub fn from_lat_lng(
point point: latlng.LatLng,
zoom zoom: Int,
) -> Result(Tile, MercatorError)
pub fn from_quadkey(
quadkey quadkey: String,
) -> Result(Tile, MercatorError)
pub fn new(
zoom zoom: Int,
x x: Int,
y y: Int,
) -> Result(Tile, MercatorError)
Build a Tile. zoom must be in [0, 30]; x and y
must each be in [0, 2^zoom).
Matches the constructor naming convention used by every other
opaque type in geokit (e.g. latlng.new).
pub fn tile(
zoom zoom: Int,
x x: Int,
y y: Int,
) -> Result(Tile, MercatorError)
Deprecated: Use mercator.new — the constructor was renamed for parity with latlng.new (will be removed in 1.0).
pub fn to_lat_lng(tile tile: Tile) -> latlng.LatLng
Top-left (north-west) corner of tile as a
LatLng.
pub fn to_quadkey(tile tile: Tile) -> String
Encode tile as a Bing-style quadkey. The length of the result
equals zoom(tile).