Learn R Programming

webmap (version 1.1.1)

add_search_button: Add search button to a web map

Description

Add a button to a Leaflet map to search markers/features location by property. Functionality provided by the leaflet-search plugin for Leaflet.

Usage

add_search_button(
  map,
  group,
  property_name = "label",
  zoom = NULL,
  text_placeholder = "Search...",
  open_popup = FALSE,
  position = "topleft"
)

Value

A new HTML web map with added element, an object of class 'leaflet'.

Arguments

map

'leaflet'. Map widget object

group

'character' string. Name of the group whose features will be searched.

property_name

'character' string. Property name used to describe markers, such as, "label" and "popup".

zoom

'integer' count. Zoom level for move to location after marker found in search.

text_placeholder

'character' string. Message to show in search element.

open_popup

'logical' flag. Whether to open the marker popup associated with the searched for marker.

position

'character' string. Position of the button on the web map. Possible values are "topleft", "topright", "bottomleft", and "bottomright".

Author

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

See Also

make_map function for creating a map widget.

Examples

Run this code
make_map(maps = "Topo") |>
  leaflet::addMarkers(
    lng = ~lng,
    lat = ~lat,
    label = ~name,
    popup = ~name,
    group = "marker",
    data = us_cities
  ) |>
  add_search_button(
    group = "marker",
    zoom = 15,
    text_placeholder = "Search city names..."
  )

Run the code above in your browser using DataLab