Cleaning up the Base Map
If you are storing leaflet maps in objects, there will come a time when you need to remove markers or reset the view. You can accomplish these tasks with the following functions.
clearMarkers()- Remove one or more features from a mapclearBounds()- Clear bounds and automatically determine bounds based on map elements
To remove the markers and to reset the bounds of our m map we would:
m <- m %>%
addMarkers(lng = dc_hq$lon, lat = dc_hq$lat) %>%
setView(lat = 50.9, lng = 4.7, zoom = 5)
m %>%
clearMarkers() %>%
clearBounds()
The leaflet map of DataCamp's headquarters has been printed for you.
Diese Übung ist Teil des Kurses
Interactive Maps with leaflet in R
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Remove markers, reset bounds, and store the updated map in the m object
map_clear <- map %>%
clear___() %>%
clear___()