LoslegenKostenlos loslegen

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 map
  • clearBounds()- 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

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Remove markers, reset bounds, and store the updated map in the m object
map_clear <- map  %>%
        clear___()  %>% 
        clear___()
Code bearbeiten und ausführen