[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leafsync strange behaviour - duplicate maps when syncing two different maps #7

Open
manomuthus opened this issue Oct 1, 2023 · 3 comments

Comments

@manomuthus
Copy link
manomuthus commented Oct 1, 2023

I have a bizarre thing going on with leafsync::sync. I have two maps generated using mapview. The underlying data is in sf format

map1
image

map2
image

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 map
image

and leafsync::sync(map2,map1) produces the following map
image

This 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 and leafsync and it didn't help. This issue is driving me crazy. Any idea why this is happening?

@tim-salabim
Copy link
Member

Can you show the code? Might have to do with layer names?

@manomuthus
Copy link
Author
manomuthus commented Oct 2, 2023
#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

@manomuthus manomuthus changed the title leafsync strange behaviour - duplicate maps when syncing two different m leafsync strange behaviour - duplicate maps when syncing two different maps Oct 2, 2023
@manomuthus
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants