add_layers_control {mapgl} | R Documentation |
Add a layers control to the map
Description
Add a layers control to the map
Usage
add_layers_control(
map,
position = "top-left",
layers = NULL,
collapsible = TRUE,
use_icon = TRUE,
background_color = NULL,
active_color = NULL,
hover_color = NULL,
active_text_color = NULL,
inactive_text_color = NULL,
margin_top = NULL,
margin_right = NULL,
margin_bottom = NULL,
margin_left = NULL
)
Arguments
map |
A map object. |
position |
The position of the control on the map (one of "top-left", "top-right", "bottom-left", "bottom-right"). |
layers |
A vector of layer IDs to be included in the control. If NULL, all layers will be included. |
collapsible |
Whether the control should be collapsible. |
use_icon |
Whether to use a stacked layers icon instead of the "Layers" text when collapsed. Only applies when collapsible = TRUE. |
background_color |
The background color for the layers control; this will be the color used for inactive layer items. |
active_color |
The background color for active layer items. |
hover_color |
The background color for layer items when hovered. |
active_text_color |
The text color for active layer items. |
inactive_text_color |
The text color for inactive layer items. |
margin_top |
Custom top margin in pixels, allowing for fine control over control positioning to avoid overlaps. Default is NULL (uses standard positioning). |
margin_right |
Custom right margin in pixels. Default is NULL. |
margin_bottom |
Custom bottom margin in pixels. Default is NULL. |
margin_left |
Custom left margin in pixels. Default is NULL. |
Value
The modified map object with the layers control added.
Examples
## Not run:
library(tigris)
options(tigris_use_cache = TRUE)
rds <- roads("TX", "Tarrant")
tr <- tracts("TX", "Tarrant", cb = TRUE)
maplibre() |>
fit_bounds(rds) |>
add_fill_layer(
id = "Census tracts",
source = tr,
fill_color = "purple",
fill_opacity = 0.6
) |>
add_line_layer(
"Local roads",
source = rds,
line_color = "pink"
) |>
add_layers_control(
position = "top-left",
background_color = "#ffffff",
active_color = "#4a90e2"
)
# Avoid collision with other controls using margin parameters
maplibre() |>
add_navigation_control(position = "top-right") |>
add_layers_control(
position = "top-right",
margin_top = 110
)
## End(Not run)