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

add easybutton with both tm_facets and tmap_leaflet #684

Open
arnaudmilet opened this issue Dec 15, 2022 · 0 comments
Open

add easybutton with both tm_facets and tmap_leaflet #684

arnaudmilet opened this issue Dec 15, 2022 · 0 comments
Labels

Comments

@arnaudmilet
Copy link

arnaudmilet commented Dec 15, 2022

Hi, Thank you so much for this great package which is very usefull and easy to use.
I try to toggle the legend on an interactive facets map. It works with simple map but not with facets map. Can you help me please?
Thanks in advance:)

The error is "Error in dispatch(map, method, leaflet = { : Invalid map parameter"

Here is the code that we can use:

#1- Works
data(World, metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100

map1 <- tm_shape(metro) +
  tm_bubbles("pop2010", col = "growth", 
             border.col = "black", 
             border.alpha = .5, 
             style="fixed", breaks=c(-Inf, seq(0, 6, by=2), Inf),
             palette="-RdYlBu", contrast=1, 
             title.size="Metro population", 
             title.col="Growth rate (%)", id="name") + 
  tm_layout(legend.bg.color = "grey90", legend.bg.alpha=.5, legend.frame=TRUE)


lf1 <- tmap_leaflet(map1)

lf1 %>% 
  addEasyButton(easyButton(
    icon = htmltools::span("L"),
    onClick = JS("function(btn, map){$('.legend').toggle();}")))

#2- doesn't work

map2 <- tm_shape(World) +
  tm_polygons(c("well_being", "life_exp"),
              style=c("pretty", "fixed"), breaks=list(NULL, seq(45, 85, by = 5)),
              palette=list("Oranges", "Purples"),
              border.col = "black",
              title=c("Well-Being Index", "Life Expectancy")) +
  tm_format("World")

lf2 <- tmap_leaflet(map2)

lf2 %>% 
  addEasyButton(easyButton(
    icon = htmltools::span("L"),
    onClick = JS("function(btn, map){$('.legend').toggle();}")))
@Nowosad Nowosad added the bug label Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants