Question Details

No question body available.

Tags

r leaflet r-leaflet

Answers (1)

January 15, 2026 Score: 0 Rep: 11,665 Quality: Medium Completeness: 80%

Groups need to be one-dimensional from the addLegend vignette

group name of a leaflet layer group. Supplying this value will tie the legend to the leaflet layer group with this name and will auto add/remove the legend as the group is added/removed, for example via layerControl. You will need to set the group when you add a layer (e.g. addPolygons) and supply the same name here.

and consistent between addCircleMarkers and addLegend, so you'd need to add each group iteratively. For customizeLayersControl - param:includelegends=TRUE Legends are matched to layers by their group name. The legends need to be added with corresponding layer IDs.

--> So you also need to to map each legend to the LayerControl via a unique layerId.

library(leaflet)
library(sf)
library(data.table)
library(leafem)

#Create dataframe mapdata2025_sample