Open manomuthus opened 9 months ago
Can you show the code? Might have to do with layer names?
#function to generate a mapview map
generate_map <- function(haz_list) {
#for dummy map layer for legend
dummy_map <- haz_list %>% last() %>% dplyr::select(haz, cell) %>% st_rasterize() %>% rast() %>% raster()
dummy_map$haz <- -0.01
#range for legend
haz_range <- haz_list %>%
sapply(function (x) range(x %>% pull(haz), na.rm = T)) %>%
c() %>%
range
mapview_pal <- RColorBrewer::brewer.pal(9,"Blues")
hazard_map <- mapview(haz_list, zcol = "haz",col.regions = mapview_pal, na.color = "transparent", layer.name = paste(c(10, 20, 50, 100, 200, 500), "yr"), legend = F, homebutton = FALSE, alpha = 0, alpha.regions = 1, label = rep("haz", 6))+
mapview(dummy_map, col.regions = mapview_pal, at = seq(haz_range[1], haz_range[2], length.out = 11), na.color = "transparent", layer.name = "haz", legend = T, homebutton = FALSE)
return(hazard_map)
}
#generate maps for two different data sets
map1 <- generate_map(haz_list_1)
map2 <- generate_map(haz_list_2)
map1 #produces map1 shown above
map2 #produces map2 shown above
leafsync::sync(map1, map2) #produces duplicate maps
haz_list_1
and haz_list_2
can be downloaded from here
Okay. As you mentioned it was due to layer names. I was using the same layer names inside map1 and map2 and it caused all the issues. Changing the layer names has fixed the issue. It would be better to mention this in the documentation.
I have a bizarre thing going on with
leafsync::sync
. I have two maps generated usingmapview
. The underlying data is insf
formatmap1![image](https://github.com/r-spatial/leafsync/assets/20112558/1e189c93-fd02-4ad5-a3b1-374036a6810b)
map2![image](https://github.com/r-spatial/leafsync/assets/20112558/d364381b-27a2-429c-902e-f87ebef15e4a)
As you can see they are two different maps with different legends. But when I try to put them together using leafsync::sync the first map is duplicated instead of the second map (the legends are different though).
leafsync::sync(map1,map2)
produces the following mapand![image](https://github.com/r-spatial/leafsync/assets/20112558/74980700-ff2b-46fb-a30a-9e60a8ffdbf2)
leafsync::sync(map2,map1)
produces the following mapThis has never happened before and I am creating some other simple maps using leafsync::sync and they are absolutely fine. I have tried reinstalling
leaflet
andleafsync
and it didn't help. This issue is driving me crazy. Any idea why this is happening?