Web Mercator conversion between geographic coordinates and world pixels.
At zoom z the world is a square 256 * 2^z world pixels on a side, with x growing
east from longitude -180 and y growing south from the northern edge of the projection.
The 256 is the slippy-map convention that defines what a zoom level means; it is
independent of the pixel size of any tile images.
Latitudes are clamped to ±85.0511°, where Mercator y reaches the edge of
the square. Longitudes are not wrapped: lng + 360 projects one world width further
east, which is what a view across the antimeridian needs.
Summary
Functions
Clamps a latitude to the range Web Mercator can represent.
Converts world pixels at zoom back to {lat, lng}.
The largest latitude Web Mercator can represent, in degrees.
Projects {lat, lng} to world pixels at zoom.
The width and height of the world, in world pixels, at zoom.
Types
Functions
Clamps a latitude to the range Web Mercator can represent.
iex> StaticMaps.Projection.clamp_latitude(90)
85.0511287798066
iex> StaticMaps.Projection.clamp_latitude(45)
45
@spec from_world(point(), non_neg_integer()) :: {float(), float()}
Converts world pixels at zoom back to {lat, lng}.
The inverse of to_world/2 for latitudes within the projection's range.
@spec max_latitude() :: float()
The largest latitude Web Mercator can represent, in degrees.
@spec to_world(lat_lng(), non_neg_integer()) :: point()
Projects {lat, lng} to world pixels at zoom.
iex> StaticMaps.Projection.to_world({0, 0}, 0)
{128.0, 128.0}
iex> StaticMaps.Projection.to_world({0, -180}, 1)
{0.0, 256.0}
@spec world_size(non_neg_integer()) :: pos_integer()
The width and height of the world, in world pixels, at zoom.
iex> StaticMaps.Projection.world_size(0)
256
iex> StaticMaps.Projection.world_size(3)
2048