|
49 | 49 | #' @param layerId the ID of the legend; subsequent calls to \code{addLegend}
|
50 | 50 | #' or \code{addControl} with the same \code{layerId} will replace this
|
51 | 51 | #' legend. The ID can also be used with \code{removeControl}.
|
| 52 | +#' @param group \code{group} name of a leaflet layer group. |
| 53 | +#' Supplying this value will tie the legend to the leaflet layer group |
| 54 | +#' with this name and will auto add/remove the legend as the |
| 55 | +#' group is added/removed, for example via layerControl. |
| 56 | +#' You will need to set the \code{group} when you add a layer |
| 57 | +#' (e.g. \code{\link{addPolygons}}) and supply the same name here. |
52 | 58 | #' @example inst/examples/legend.R
|
53 | 59 | #' @export
|
54 | 60 | addLegend <- function(
|
55 | 61 | map, position = c('topright', 'bottomright', 'bottomleft', 'topleft'),
|
56 |
| - pal, values, na.label = 'NA', bins = 7, colors, opacity = 0.5, labels, |
| 62 | + pal, values, na.label = 'NA', bins = 7, colors, opacity = 0.5, labels = NULL, |
57 | 63 | labFormat = labelFormat(), title = NULL, className = "info legend",
|
58 |
| - layerId = NULL |
| 64 | + layerId = NULL, group = NULL |
59 | 65 | ) {
|
60 | 66 | position = match.arg(position)
|
61 | 67 | type = 'unknown'; na.color = NULL
|
@@ -147,7 +153,7 @@ addLegend <- function(
|
147 | 153 | colors = I(unname(colors)), labels = I(unname(labels)),
|
148 | 154 | na_color = na.color, na_label = na.label, opacity = opacity,
|
149 | 155 | position = position, type = type, title = title, extra = extra,
|
150 |
| - layerId = layerId, className = className |
| 156 | + layerId = layerId, className = className, group = group |
151 | 157 | )
|
152 | 158 | invokeMethod(map, getMapData(map), "addLegend", legend)
|
153 | 159 | }
|
|
0 commit comments