clear_legend | R Documentation |
Remove one or more legends from a Mapbox GL or MapLibre GL map in a Shiny application.
clear_legend(map, legend_ids = NULL)
map |
A map proxy object created by |
legend_ids |
Optional. A character vector of legend IDs to clear. If not provided, all legends will be cleared. |
The updated map proxy object with the specified legend(s) cleared.
This function can only be used with map proxy objects in Shiny applications. It cannot be used with static map objects.
## Not run:
# In a Shiny server function:
# Clear all legends
observeEvent(input$clear_all, {
mapboxgl_proxy("map") %>%
clear_legend()
})
# Clear specific legends by ID
observeEvent(input$clear_specific, {
mapboxgl_proxy("map") %>%
clear_legend(legend_ids = c("legend-1", "legend-2"))
})
# Clear legend after removing a layer
observeEvent(input$remove_layer, {
mapboxgl_proxy("map") %>%
remove_layer("my_layer") %>%
clear_legend(legend_ids = "my_layer_legend")
})
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.