Skip to contents

This function returns a bounding box at a defined zoom level centered on the mean value of a set of coordinates.

Usage

bbox_at_zoom(locs, zoom_level = NULL)

Arguments

locs

An sf or sp object. The bounding box will be centered on the mid point value of bound box of this object.

zoom_level

Numeric. Specifies how zoomed in the bounding box should be, eg. 1 = whole world and 4 = 1/4 of world. Defaults to NULL, which will calculate the zoom level required to contain locs

Value

an object with class "bbox" containing four values: xmin, ymin, xmax, and ymax. Values will be in units of locs (either decimal degrees or meters).

References

Code adapted from: https://www.r-bloggers.com/2019/04/zooming-in-on-maps-with-sf-and-ggplot2/