BaşlayınÜcretsiz Başlayın

Adding a Piece of Flair

Earlier in this chapter, we used addSearchOSM() to find the middle of the US. To search for markers, rather than locations, we can use the addSearchFeatures() function. addSearchFeatures() will add a search box that you can use to find markers in the group(s) passed to the targetGroups argument. For example, to search our map for public colleges we could use the following code.

m4  %>% 
  addSearchFeatures(
    targetGroups = 'Public',
    options = searchFeaturesOptions(zoom = 10)) 

The m4 map and the leaflet.extras package have been loaded for you.

Bu egzersiz

Interactive Maps with leaflet in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use the addSearchFeatures() function to make colleges in all sectors searchable.
  • Set the search zoom level to 18.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Make each sector of colleges searchable 
m4_search <- m4  %>% 
  addSearchFeatures(
    targetGroups = ___(___, ___, ___), 
    # Set the search zoom level to 18
    options = searchFeaturesOptions(___ = ___)) 

# Try searching the map for a college
m4_search
Kodu Düzenle ve Çalıştır