LiveMap.Tile (live_map v0.0.1) View Source

This module contains functions to manipulate map tiles.

Link to this section Summary

Functions

Retrieves a tile at certain coordinates and zoom level.

Maps tiles around a center tile that covers a rectangle box.

Maps tiles around a center coordinates and zoom that covers a rectangle box.

Converts a longitude at certain zoom to tile x number

Convers a latitude at certain zoom to tile y number

Link to this section Types

Specs

latitude() :: number()

Specs

longitude() :: number()

Specs

t() :: %LiveMap.Tile{
  latitude: latitude(),
  longitude: longitude(),
  raw_x: number(),
  raw_y: number(),
  x: x(),
  y: y(),
  z: zoom()
}

Specs

x() :: pos_integer()

Specs

y() :: pos_integer()

Specs

zoom() :: pos_integer()

Link to this section Functions

Link to this function

at(latitude, longitude, zoom)

View Source

Specs

at(latitude(), longitude(), zoom()) :: t()

Retrieves a tile at certain coordinates and zoom level.

Based on https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames.

Examples:

iex> tile = LiveMap.Tile.at(0, 0, 0)
iex> tile.x
0
iex> tile.y
0

iex> tile = LiveMap.Tile.at(360, 170.1022, 0)
iex> tile.x
0
iex> tile.y
0

iex> tile = LiveMap.Tile.at(47.47607, 7.56198, 16)
iex> tile.x
34144
iex> tile.y
22923
Link to this function

map(center, width, height, mapper \\ &Function.identity/1)

View Source

Specs

map(t(), number(), number(), function()) :: list()

Maps tiles around a center tile that covers a rectangle box.

Note that by default, the resulting tiles do not have latitude and longitude coordinates. If such values are desired, use the last parameter to provide a custom mapper function to also load the coordinates.

Examples:

# At zoom 0, the whole world is rendered in 1 tile.
iex> center = LiveMap.Tile.at(0, 0, 0)
iex> [center] == LiveMap.Tile.map(center, 256, 256)
true

# At zoom 1, 4 tiles are used on a 512x512 map.
iex> center = LiveMap.Tile.at(0, 0, 1)
iex> tiles = LiveMap.Tile.map(center, 512, 512)
iex> Enum.map(tiles, fn %{x: x, y: y} -> {x, y} end)
[{0, 0}, {0, 1}, {1, 0}, {1, 1}]

# Can also pass a mapper function to transform the tiles.
iex> center = LiveMap.Tile.at(0, 0, 1)
iex> LiveMap.Tile.map(center, 512, 512, fn %{x: x, y: y} -> {x, y} end)
[{0, 0}, {0, 1}, {1, 0}, {1, 1}]
Link to this function

map(latitude, longitude, zoom, width, height, mapper \\ &Function.identity/1)

View Source

Specs

map(latitude(), longitude(), zoom(), number(), number(), function()) :: list()

Maps tiles around a center coordinates and zoom that covers a rectangle box.

The coordinates and zoom are used to generate a Tile and pass to map/4.

Examples:

iex> [center] = LiveMap.Tile.map(0, 0, 0, 256, 256)
iex> center.x
0
iex> center.y
0

Specs

x(longitude(), zoom()) :: number()

Converts a longitude at certain zoom to tile x number

Notes that the return value is not rounded. If used with slippy map, round it down to the nearest integer.

Examples:

iex> floor(Tile.x(0, 0))
0

iex> floor(Tile.x(170.1022, 0))
0

iex> floor(Tile.x(7.56198, 16))
34144

Specs

y(latitude(), zoom()) :: number()

Convers a latitude at certain zoom to tile y number

Notes that the return value is not rounded. If used with slippy map, round it down to the nearest integer.

Examples:

iex> floor(Tile.y(0, 0))
0

iex> floor(Tile.y(360, 0))
0

iex> floor(Tile.y(47.47607, 16))
22923