This function adds features from an existing source to a draw control on a map.
Examples
if (FALSE) { # \dontrun{
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
)
})
} # }