add_features_to_draw | R Documentation |
This function adds features from an existing source to a draw control on a map.
add_features_to_draw(map, source, clear_existing = FALSE)
map |
A map object with a draw control already added |
source |
Character string specifying a source ID to get features from |
clear_existing |
Logical, whether to clear existing drawn features before adding new ones. Default is FALSE. |
The modified map object
## Not run:
library(mapgl)
library(tigris)
# Add features from an existing source
tx <- counties(state = "TX", cb = TRUE)
mapboxgl(bounds = tx) |>
add_source(id = "tx", data = tx) |>
add_draw_control() |>
add_features_to_draw(source = "tx")
# In a Shiny app
observeEvent(input$load_data, {
mapboxgl_proxy("map") |>
add_features_to_draw(
source = "dynamic_data",
clear_existing = TRUE
)
})
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.