Learn R Programming

mapgl (version 0.1.3)

add_geocoder_control: Add a geocoder control to a map

Description

This function adds a Geocoder search bar to a Mapbox GL or MapLibre GL map. By default, a marker will be added at the selected location and the map will fly to that location. The results of the geocode are accessible in a Shiny session at input$MAPID_geocoder$result, where MAPID is the name of your map.

Usage

add_geocoder_control(
  map,
  position = "top-right",
  placeholder = "Search",
  collapsed = FALSE,
  ...
)

Value

The modified map object with the geocoder control added.

Arguments

map

A map object created by the mapboxgl or maplibre function.

position

The position of the control. Can be one of "top-left", "top-right", "bottom-left", or "bottom-right". Default is "top-right".

placeholder

A string to use as placeholder text for the search bar. Default is "Search".

collapsed

Whether the control should be collapsed until hovered or clicked. Default is FALSE.

...

Additional parameters to pass to the Geocoder.

Examples

Run this code
if (FALSE) {
library(mapgl)

mapboxgl() |>
    add_geocoder_control(position = "top-left", placeholder = "Enter an address")

maplibre() |>
    add_geocoder_control(position = "top-right", placeholder = "Search location")
}

Run the code above in your browser using DataLab