Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Interactive Maps with leaflet in R

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Remove markers, reset bounds, and store the updated map in the m object
map_clear <- map  %>%
        clear___()  %>% 
        clear___()
Code bewerken en uitvoeren