Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. if (!isGeneric("+")) {
  2. setGeneric("+", function(x, y, ...)
  3. standardGeneric("+"))
  4. }
  5.  
  6. #' mapview + mapview; adds data from the second map to the first
  7. #'
  8. #' @author Adapted from
  9. #' \href{https://github.com/r-spatial/mapview/blob/develop/R/plus.R}{
  10. #' tim-salabim code}.
  11. #' @param e1 a mapview map to which e2 should be added.
  12. #' @param e2 a mapview map from which the objects should be added to e1.
  13. #' @examples
  14. #' \dontrun{
  15. #' eeobject <- ee$FeatureCollection("users/csaybar/DLdemos/train_set")
  16. #' center <- eeobject$geometry()$centroid()$getInfo()$coordinates
  17. #' vizparams <- list(color = "FF0000", strokeWidth = 5)
  18. #' m1 <- ee_map(eeobject, vizparams, center, objname = "Arequipa-landuse")
  19. #'
  20. #' collection <- ee$ImageCollection("LANDSAT/LC08/C01/T1_TOA")$
  21. #' filter(ee$Filter()$eq("WRS_PATH", 44))$
  22. #' filter(ee$Filter()$eq("WRS_ROW", 34))$
  23. #' filterDate("2014-01-01", "2015-01-01")$
  24. #' sort("CLOUD_COVER")
  25. #' eeobject <- collection$median()
  26. #' vizparams <- list(bands = c("B4", "B3", "B2"), max = 0.3)
  27. #' center <- c(-122.3578, 37.7726)
  28. #' m2 <- ee_map(eeobject, vizparams, center, objname = "SF")
  29. #' m1 + m2
  30. #' }
  31. #'
  32. setMethod(
  33. "+",
  34. signature(
  35. e1 = "mapview",
  36. e2 = "mapview"
  37. ),
  38. function(e1, e2) {
  39. e2_token <- e2@object$tokens
  40. e2_name <- e2@object$names
  41. e2_opacity <- e2@object$opacity
  42. e2_shown <- e2@object$shown
  43.  
  44. for (x in seq_len(length(e2_name))) {
  45. e1@map <- e1@map %>%
  46. addTiles(urlTemplate = e2_token[x],
  47. group = e2_name[x],
  48. options = tileOptions(opacity = e2_opacity[x])) %>%
  49. ee_mapViewLayersControl(names = e2_name[x]) %>%
  50. hideGroup(if (!e2_shown[x]) e2_name[x] else NULL)
  51. }
  52. return(e1)
  53. }
  54. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement