Skip to content

Instantly share code, notes, and snippets.

@MilesMcBain
Last active April 15, 2021 23:52
Show Gist options
  • Save MilesMcBain/c15b2af3bbeb25dc123016df1b65cc93 to your computer and use it in GitHub Desktop.
Save MilesMcBain/c15b2af3bbeb25dc123016df1b65cc93 to your computer and use it in GitHub Desktop.
concat_maps.R
concat_maps <- function(...) {
rdeck_maps <- list(...)
rdeck_map_names <- names(rdeck_maps)
rdeck_map_names[nzchar(rdeck_map_names) == 0] <- "Base layers"
# set up init for reduce
container <- rdeck_maps[[1]]
container$x$layers <-
map(container$x$layers, function(layer) {
layer$group_name <- rdeck_map_names[[1]]
layer$visibility_toggle <- TRUE
layer$visible <- TRUE
layer
})
reduce2(rdeck_maps[-1], rdeck_map_names[-1],
.init = container,
.f = function(merged_map, a_map, a_map_name) {
renamed_layers <-
map(a_map$x$layers, function(layer) {
layer$group_name <- a_map_name
layer$visibility_toggle <- TRUE
layer$visible <- FALSE
layer
})
merged_map$x$layers <-
c(merged_map$x$layers, renamed_layers)
merged_map
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment