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

deck gl layers toggle #198

Open
paragemini opened this issue May 11, 2022 · 2 comments
Open

deck gl layers toggle #198

paragemini opened this issue May 11, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@paragemini
Copy link

paragemini commented May 11, 2022

Hello -

I have a dataframe with racial makeup for Chicago. I am trying to add 5 different layers for 5 different races. Is there a way to toggle them on and off like one do in leaflet like the jpeg below ?

image

properties <- list(
  getPosition = ~lng + lat, #[165, 42,42]
  getRadius = 25, #JS("data => Math.sqrt(data.exits)"),
  #orange 246, 107, 14 
  # white race : blue dark : [64, 223, 239]
  #black race dark [255,198,0]  , light : 246, 107, 14
  getColor = JS("data => data.Type === 'White_alone' ? [10, 161, 221]: 
                data.Type === 'Black_or_African_American_alone' ? [246, 107, 14] : 
                data.Type === 'Some_other_race_alone' ? [6,255,0]: 
                data.Type === 'Asian_alone' ? [249, 7, 22] :
                data.Type === 'Two_or_more_races' ? [246, 107, 14] :
                data.Type === 'American_Indian_and_Alaska_Native_alone' ? [255, 23, 0] :
                data.Type === 'Native_Hawaiian_and_Other_Pacific_Islander_alone' ? [147, 255, 216] : [24, 10, 10]"),
  tooltip = "{{Type}}"
)

deck <- deckgl(zoom = 10.5, latitude = 41.889673, longitude = -87.634711) %>%
  add_scatterplot_layer(data = split_race_dot[[7]], properties = properties) %>%
  add_scatterplot_layer(data = split_race_dot[[3]], properties = properties, 
                        visible = FALSE) %>%
  add_scatterplot_layer(data = split_race_dot[[1]], properties = properties, 
                        visible = FALSE) %>%
  add_scatterplot_layer(data = split_race_dot[[2]], properties = properties, 
                        visible = FALSE) %>%
  add_scatterplot_layer(data = split_race_dot[[4]], properties = properties, 
                        visible = FALSE) %>%

  add_basemap(style = use_carto_style("positron"))  

if (interactive()) deck

Final layer box that could probably come at the top-right corner of the final map
Thank you for the lovely package!!

image

@crazycapivara crazycapivara added the duplicate This issue or pull request already exists label May 19, 2022
@crazycapivara
Copy link
Owner

crazycapivara commented May 19, 2022

Duplicate #153

@crazycapivara
Copy link
Owner

@paragemini

It is not implemented yet but you can use the json editor:

remotes::install_github("crazycapivara/deckgl")

library(deckgl)

deckgl(zoom = 10, pitch = 35) %>%
  add_scatterplot_layer(
    data = bart_stations,
    getPosition = ~lng + lat,
    radiusScale = 6,
    getRadius = 50,
    getColor = c(240, 140, 20),
    visible = TRUE
  ) %>%
  add_text_layer(
    data = bart_stations,
    getPosition = ~lng + lat,
    getText = ~name,
    getAlignmentBaseline = "bottom",
    visible = TRUE
  ) %>%
  add_basemap() %>%
  add_json_editor(maxLines = 25)

Then change visible = false/true in the editor for layers you want to hide/show

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants