# `StaticMaps.Projection`
[🔗](https://gitlab.com/tristanperalta/staticmaps/blob/v0.1.0/lib/static_maps/projection.ex#L1)

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.

# `lat_lng`

```elixir
@type lat_lng() :: {number(), number()}
```

`{latitude, longitude}` in degrees.

# `point`

```elixir
@type point() :: {float(), float()}
```

`{x, y}` in world pixels at some zoom.

# `clamp_latitude`

```elixir
@spec clamp_latitude(number()) :: number()
```

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

# `from_world`

```elixir
@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.

# `max_latitude`

```elixir
@spec max_latitude() :: float()
```

The largest latitude Web Mercator can represent, in degrees.

# `to_world`

```elixir
@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}

# `world_size`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
