提供者圖磚
在前一個練習中,addTiles() 把預設的 OpenStreetMap(OSM)圖磚加入了你的 leaflet 地圖。地圖圖磚會把多張地圖影像拼接在一起。當使用者縮放或平移地圖時,圖磚會跟著調整,讓你能使用在練習 2 中操作過的互動功能。
leaflet 套件內建超過 100 種可用的地圖圖磚。這些圖磚儲存在名為 providers 的清單中,你可以改用 addProviderTiles()(而不是 addTiles())把它們加入地圖。
已為你載入 leaflet 與 tidyverse 函式庫。
本練習屬於課程
在 R 中使用 leaflet 製作互動式地圖
練習說明
- 列印
leaflet套件中包含的 100 多種提供者圖磚清單。 - 為了讓輸出更易讀,使用
names()只列印提供者圖磚的名稱。 - 使用 stringr 套件的
str_detect()判斷哪些提供者圖磚包含字串「CartoDB」。 - 列印每個名稱中包含「CartoDB」的提供者地圖圖磚。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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), "___")]