R/zoom_map_to_neighbourhood.R

Defines functions zoom_map_to_neighbourhood

Documented in zoom_map_to_neighbourhood

#' Zoom map of Toronto to neighbourhood
#'
#' @param map Map created by \link{map_toronto}
#' @param neighbourhood Neighbourhood from \link{neighbourhoods}
#'
#' @export
#'
#' @examples
#' library(sf)
#' map_toronto() %>%
#'   add_blank_aggregate_layers() %>%
#'   zoom_map_to_neighbourhood("Casa Loma")
zoom_map_to_neighbourhood <- function(map, neighbourhood) {
  searched_neighbourhood <- lemr::neighbourhoods %>%
    dplyr::filter(.data$neighbourhood == !!neighbourhood)

  map %>%
    # Filter the "neighbourhood_click_line" layers to be for this neighbourhood
    mapboxer::set_filter(layer_id = "neighbourhood_click_line", list("==", "neighbourhood", neighbourhood)) %>%
    # Zoom to the neighbourhood
    mapboxer::fit_bounds(sf::st_bbox(searched_neighbourhood), maxZoom = 14, pitch = 0, bearing = bearing)
}
purposeanalytics/lemur documentation built on Dec. 22, 2021, 10:52 a.m.