Calculate tile extent for a given x, y tile at a zoom level.

mercator_tile_extent(tile_x, tile_y, zoom, tile_size = 256)

Arguments

tile_x

x coordinate of tile

tile_y

y coordinate of tile

zoom

zoo level

tile_size

tile dimensions (assumed square, i.e. 256x256)

Value

A numeric vector of the spatial extent, in 'xmin', 'xmax', 'ymin', 'ymax' form.

Details

Currently only spherical Mercator is supported.

Examples

mercator_tile_extent(2, 4, zoom = 10)
#>      xmin      xmax      ymin      ymax 
#> -19959237 -19920101  19841830  19880965 

global <- mercator_tile_extent(0, 0, zoom = 0)
plot(NA, xlim = global[c("xmin", "xmax")], ylim = global[c("ymin", "ymax")])
rect_plot <- function(x) rect(x["xmin"], x["ymin"], x["xmax"], x["ymax"])
rect_plot(mercator_tile_extent(1, 1, zoom = 2))
rect_plot(mercator_tile_extent(2, 1, zoom = 2))
rect_plot(mercator_tile_extent(1, 2, zoom = 2))

rect_plot(mercator_tile_extent(1, 1, zoom = 4))
rect_plot(mercator_tile_extent(2, 1, zoom = 4))
rect_plot(mercator_tile_extent(1, 2, zoom = 4))