Skip to contents

Also supports making groups exclusive (using radio inputs instead of checkbox). See the JavaScript plugin for more information https://github.com/trafficonese/leaflet-groupedlayercontrol/

Usage

addGroupedLayersControl(
  map,
  baseGroups = character(0),
  overlayGroups = character(0),
  position = c("topright", "bottomright", "bottomleft", "topleft"),
  options = groupedLayersControlOptions()
)

Arguments

map

the map to add the layers control to

baseGroups

character vector where each element is the name of a group. The user will be able to choose one base group (only) at a time. This is most commonly used for mostly-opaque tile layers.

overlayGroups

A list of named vectors where each element is the name of a group.

position

position of control: "topleft", "topright", "bottomleft", or "bottomright"

options

a list of additional options, intended to be provided by a call to groupedLayersControlOptions

See also

Other GroupedLayersControl: addGroupedOverlay(), groupedLayersControlOptions()

Examples

library(leaflet)
library(leaflet.extras)

leaflet() %>%
  addTiles(group = "OpenStreetMap") %>%
  addProviderTiles("CartoDB", group = "CartoDB") %>%
  addCircleMarkers(runif(20, -75, -74), runif(20, 41, 42),
    color = "red", group = "Markers2"
  ) %>%
  addCircleMarkers(runif(20, -75, -74), runif(20, 41, 42),
    color = "green", group = "Markers1"
  ) %>%
  addCircleMarkers(runif(20, -75, -74), runif(20, 41, 42),
    color = "yellow", group = "Markers3"
  ) %>%
  addCircleMarkers(runif(20, -75, -74), runif(20, 41, 42),
    color = "lightblue", group = "Markers4"
  ) %>%
  addCircleMarkers(runif(20, -75, -74), runif(20, 41, 42),
    color = "purple", group = "Markers5"
  ) %>%
  addGroupedLayersControl(
    baseGroups = c("OpenStreetMap", "CartoDB"),
    overlayGroups = list(
      "Layergroup_2" = c("Markers5", "Markers4"),
      "Layergroup_1" = c("Markers2", "Markers1", "Markers3")
    ),
    position = "topright",
    options = groupedLayersControlOptions(
      groupCheckboxes = TRUE,
      collapsed = FALSE,
      groupsCollapsable = TRUE,
      sortLayers = FALSE,
      sortGroups = FALSE,
      sortBaseLayers = FALSE,
      exclusiveGroups = "Layergroup_1"
    )
  )