clear_legend: Clear Legend

View source: R/map_legend.R View source: R/legend.R

clear_legendR Documentation

Clear Legend

Description

Clears the legend for a given layer_id

Removes a legend from the map

Usage

clear_legend(map, layer_id)

clear_legend(map, layer_id)

Arguments

map

the map from which you want to clear the legend.

layer_id

single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly

Examples



sf <- spatialwidget::widget_melbourne
sf$my_colour <- ifelse( substr(sf$SA2_NAME, 1, 1) == "A", "#00FF00FF", "#FF0000FF")

l1 <- legend_element(
	variables = c("Begins with A", "Doesn't begin with A")
	, colours = c("#00FF00FF", "#FF0000FF")
	, colour_type = "fill"
	, variable_type = "category"
)
js <- mapdeck_legend(l1)

set_token(secret::get_secret("MAPBOX"))

## Add a legend
mapdeck() %>%
  add_legend(legend = js, layer_id = "my_layer")

## Calling `clear_legend` should immediately remove it
mapdeck() %>%
  add_legend(legend = js, layer_id = "my_layer") %>%
  clear_legend(layer_id = "my_layer")




SymbolixAU/mapdeck documentation built on April 14, 2025, 2:07 a.m.