add_layers_control: Add a layers control to the map

View source: R/controls.R

add_layers_controlR 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 = FALSE
)

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.

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(collapsible = TRUE)

## End(Not run)

mapgl documentation built on Nov. 1, 2024, 5:08 p.m.