This post shows how to change the background tile used by the
leaflet
R package. It provides an overview of the most
common options with their associated code.
This post follows the previous posts on leaflet
: most
basic map, and
zooming on a
specific area.
Leaflet
offers several tiles to customize the
background used on a map.
A tile can be loaded thanks to the
addProviderTiles()
function.
# Load the library
library(leaflet)
# Note: if you do not already installed it, install it with:
# install.packages("leaflet")
# Background 1: NASA
m <- leaflet() %>%
addTiles() %>%
setView( lng = 2.34, lat = 48.85, zoom = 5 ) %>%
addProviderTiles("NASAGIBS.ViirsEarthAtNight2012")
m
# Background 2: World Imagery
m <- leaflet() %>%
addTiles() %>%
setView( lng = 2.34, lat = 48.85, zoom = 3 ) %>%
addProviderTiles("Esri.WorldImagery")
m
# save the widget in a html file if needed.
# library(htmlwidgets)
# saveWidget(m, file=paste0( getwd(), "/HtmlWidget/backgroundMapTile.html", width="1000px"))
Many tiles are made available. A complete list can be found here. Most famous are probably:
NASAGIBS.ViirsEarthAtNight2012
Esri.WorldImagery
Esri.WorldGrayCanvas
Esri.WorldTerrain
Esri.WorldTopoMap