Creating your first leaflet map
You have seen how leaflet maps can be created as a collection of different layers.
There are also other settings that can allow users to select specific layers and map providers.
In this exercise, you will create your own leaflet map with various features.
There are four sf objects stored here as:
london_polylondon_looplondon_capitallistings_geo
You can look at the geometry attribute of each sf object with the $geometry notation.
The sf, tidyverse and leaflet libraries have been loaded.
Latihan ini adalah bagian dari kursus
Building Dashboards with shinydashboard
Petunjuk latihan
- Add another provider called
Esri.WorldStreetMap. - Add red polygons.
- Fill up
addLayersControl()so that different overlay groups and layers can be selected by the user, adding them in their order of appearance.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
leaflet(london_poly) %>%
addTiles(group="Default") %>%
addProviderTiles(providers$Stamen.Toner, group = "Toner") %>%
# Add another provider called Esri.WorldStreetMap
___(___, group = "World street map") %>%
# Add red polygons
___(group = "Ward", col=___, label=~as.character(Name)) %>%
addPolylines(loop_geo[,1], loop_geo[,2], group = "London loop") %>%
addPolylines(capital_geo[,1], capital_geo[,2],
group = "Capital ring", color = "orange") %>%
addMarkers(data = listings_geo,
group = "Listings", clusterOptions = markerClusterOptions()) %>%
# Set up to allow user selection of different overlay groups and layers
___