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

mapshot

Save mapview or leaflet map as HTML and/or image


Description

Save a mapview or leaflet map as .html index file or .png, .pdf, or .jpeg image.

Usage

mapshot(
  x,
  url = NULL,
  file = NULL,
  remove_controls = c("zoomControl", "layersControl", "homeButton", "scaleBar",
    "drawToolbar", "easyButton"),
  ...
)

Arguments

x

mapview or leaflet object (or any other hmtlwidget).

url

Output .html file. If not supplied and 'file' is specified, a temporary index file will be created.

file

Output .png, .pdf, or .jpeg file.

remove_controls

character vector of control buttons to be removed from the map when saving to file. Any combination of "zoomControl", "layersControl", "homeButton", "scaleBar", "drawToolbar", "easyButton". If set to NULL nothing will be removed. Ignord if x is not a mapview or leaflet map.

...

Further arguments passed on to saveWidget and/or webshot.

Details

mapshot can be used to save both leaflet and mapview maps as html or png files or both. In theory, it should also work for any and all other htmlwidgets but has not been tested extensively for other htmlwidgets.

In case you want to save larger maps mapshot is likely to fail. You can try setting selfcontained = FALSE to avoid errors and create a valid local html file.

See Also

Examples

## Not run: 
  m = mapview(breweries)

  ## create standalone .html
  mapshot(m, url = paste0(getwd(), "/map.html"))

  ## create standalone .png; temporary .html is removed automatically unless
  ## 'remove_url = FALSE' is specified
  mapshot(m, file = paste0(getwd(), "/map.png"))
  mapshot(m, file = paste0(getwd(), "/map.png"),
          remove_controls = c("homeButton", "layersControl"))

  ## create .html and .png
  mapshot(m, url = paste0(getwd(), "/map.html"),
          file = paste0(getwd(), "/map.png"))

## End(Not run)

mapview

Interactive Viewing of Spatial Data in R

v2.10.0
GPL (>= 3) | file LICENSE
Authors
Tim Appelhans [cre, aut], Florian Detsch [aut], Christoph Reudenbach [aut], Stefan Woellauer [aut], Spaska Forteva [ctb], Thomas Nauss [ctb], Edzer Pebesma [ctb], Kenton Russell [ctb], Michael Sumner [ctb], Jochen Darley [ctb], Pierre Roudier [ctb], Patrick Schratz [ctb], Environmental Informatics Marburg [ctb], Lorenzo Busetto [ctb]
Initial release

We don't support your browser anymore

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