Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

addHomeButton

Add a home button / zoom-to-layer button to a map.


Description

This function adds a button to the map that enables zooming to a provided extent / bbox.

Usage

addHomeButton(map, ext, group = "layer", position = "bottomright", add = TRUE)

removeHomeButton(map)

Arguments

map

a mapview or leaflet object.

ext

the extent / bbox to zoom to.

group

the name of the group/layer to be zoomed to (or any character string)

position

the position of the button (one of 'topleft', 'topright', 'bottomleft', 'bottomright'). Defaults to 'bottomright'.

add

logical. Whether to add the button to the map (mainly for internal use).

Functions

  • removeHomeButton: remove a homeButton from a map

Examples

library(leaflet)
library(raster)

## pass a group name only
m <- leaflet() %>%
  addProviderTiles("OpenStreetMap") %>%
  addCircleMarkers(data = breweries91, group = "breweries91") %>%
  addHomeButton(group = "breweries91")
m

## pass a raster extent - group can now be an arbitrary label
m <- leaflet() %>%
  addProviderTiles("OpenStreetMap") %>%
  addCircleMarkers(data = breweries91, group = "breweries91") %>%
  addHomeButton(ext = extent(breweries91), group = "Brew")
m

## remove the button
removeHomeButton(m)

leafem

'leaflet' Extensions for 'mapview'

v0.1.3
MIT + file LICENSE
Authors
Tim Appelhans [cre, aut], Christoph Reudenbach [ctb], Kenton Russell [ctb], Jochen Darley [ctb], Daniel Montague [ctb] (Leaflet.EasyButton plugin), Lorenzo Busetto [ctb], Luigi Ranghetti [ctb], Miles McBain [ctb], Sebastian Gatscha [ctb], Björn Harrtell [ctb] (FlatGeobuf plugin), Daniel Dufour [ctb] (georaster-layer-for-leaflet)
Initial release
2020-07-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.