Provider Tiles
In the previous exercise, addTiles()
added the default OpenStreetMap (OSM) tile to your leaflet
map. Map tiles weave multiple map images together. The map tiles presented adjust when a user zooms or pans the map enabling the interactive features you experimented with in exercise 2.
The leaflet
package comes with more than 100 map tiles that you can use. These tiles are stored in a list called providers
and can be added to your map using addProviderTiles()
instead of addTiles()
.
The leaflet
and tidyverse
libraries have been loaded for you.
This exercise is part of the course
Interactive Maps with leaflet in R
Exercise instructions
- Print the list of 100+ provider tiles that are included in the
leaflet
package. - To make this output more readable, print just the names of the provider tiles using the
names()
function. - Use the
str_detect()
function from the stringr package to determine which provider tiles include the string "CartoDB". - Print the name of every provider map tile that includes the string "CartoDB".
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Print the providers list included in the leaflet library
providers
# Print only the names of the map tiles in the providers list
names(___)
# Use str_detect() to determine if the name of each provider tile contains the string "CartoDB"
str_detect(___(providers), "___")
# Use str_detect() to print only the provider tile names that include the string "CartoDB"
___(providers)[str_detect(names(providers), "___")]