Skip to content

Commit

Permalink
Merge branch 'layergroupconditional' of https://github.com/trafficone…
Browse files Browse the repository at this point in the history
…se/leaflet.extras2 into layergroupconditional

# Conflicts:
#	R/layergroupconditional.R
  • Loading branch information
trafficonese committed Jan 12, 2025
2 parents 9891dc7 + 525672a commit e8927cc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions R/layergroupconditional.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,27 @@ layerGroupConditionalDependency <- function() {
#' breweries91 <- st_as_sf(breweries91)
#' lines <- st_as_sf(atlStorms2005)
#' polys <- st_as_sf(leaflet::gadmCHE)
#' groups <- c("atlStorms","breweries","gadmCHE")
#' groups <- c("atlStorms", "breweries", "gadmCHE")
#'
#' leaflet() %>%
#' addTiles() %>%
#' #leafem::addMouseCoordinates() %>%
#' addPolylines(data = lines, label = ~Name, group = groups[1]) %>%
#' addCircleMarkers(data = breweries91, label = ~brewery, group = groups[2]) %>%
#' addPolygons(data = polys, label = ~NAME_1, group = groups[3]) %>%
#' addLayerGroupConditional(groups = groups,
#' conditions = list(
#' "(zoomLevel) => zoomLevel < 4" = groups[1],
#' "(zoomLevel) => zoomLevel >= 4 & zoomLevel < 6 " = groups[2],
#' "(zoomLevel) => zoomLevel >= 6" = groups[3]
#' )) %>%
#' addLayerGroupConditional(
#' groups = groups,
#' conditions = list(
#' "(zoomLevel) => zoomLevel < 4" = groups[1],
#' "(zoomLevel) => zoomLevel >= 4 & zoomLevel < 6 " = groups[2],
#' "(zoomLevel) => zoomLevel >= 6" = groups[3]
#' )
#' ) %>%
#' hideGroup(groups) %>%
#' addLayersControl(overlayGroups = groups,
#' options = layersControlOptions(collapsed=FALSE))
#' addLayersControl(
#' overlayGroups = groups,
#' options = layersControlOptions(collapsed = FALSE)
#' )
#'
addLayerGroupConditional <- function(map, groups = NULL, conditions = NULL) {
map$dependencies <- c(map$dependencies, layerGroupConditionalDependency())
Expand Down

0 comments on commit e8927cc

Please sign in to comment.