Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!isGeneric("+")) {
- setGeneric("+", function(x, y, ...)
- standardGeneric("+"))
- }
- #' mapview + mapview; adds data from the second map to the first
- #'
- #' @author Adapted from
- #' \href{https://github.com/r-spatial/mapview/blob/develop/R/plus.R}{
- #' tim-salabim code}.
- #' @param e1 a mapview map to which e2 should be added.
- #' @param e2 a mapview map from which the objects should be added to e1.
- #' @examples
- #' \dontrun{
- #' eeobject <- ee$FeatureCollection("users/csaybar/DLdemos/train_set")
- #' center <- eeobject$geometry()$centroid()$getInfo()$coordinates
- #' vizparams <- list(color = "FF0000", strokeWidth = 5)
- #' m1 <- ee_map(eeobject, vizparams, center, objname = "Arequipa-landuse")
- #'
- #' collection <- ee$ImageCollection("LANDSAT/LC08/C01/T1_TOA")$
- #' filter(ee$Filter()$eq("WRS_PATH", 44))$
- #' filter(ee$Filter()$eq("WRS_ROW", 34))$
- #' filterDate("2014-01-01", "2015-01-01")$
- #' sort("CLOUD_COVER")
- #' eeobject <- collection$median()
- #' vizparams <- list(bands = c("B4", "B3", "B2"), max = 0.3)
- #' center <- c(-122.3578, 37.7726)
- #' m2 <- ee_map(eeobject, vizparams, center, objname = "SF")
- #' m1 + m2
- #' }
- #'
- setMethod(
- "+",
- signature(
- e1 = "mapview",
- e2 = "mapview"
- ),
- function(e1, e2) {
- e2_token <- e2@object$tokens
- e2_name <- e2@object$names
- e2_opacity <- e2@object$opacity
- e2_shown <- e2@object$shown
- for (x in seq_len(length(e2_name))) {
- e1@map <- e1@map %>%
- addTiles(urlTemplate = e2_token[x],
- group = e2_name[x],
- options = tileOptions(opacity = e2_opacity[x])) %>%
- ee_mapViewLayersControl(names = e2_name[x]) %>%
- hideGroup(if (!e2_shown[x]) e2_name[x] else NULL)
- }
- return(e1)
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement