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

Lighting effects for R deckgl #200

Open
paragemini opened this issue May 29, 2022 · 1 comment
Open

Lighting effects for R deckgl #200

paragemini opened this issue May 29, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@paragemini
Copy link

Hello, I am trying to mimic the example of extruded Polygons for Vancouver, B.C especially the lighting effects.

I do see the lighting effect defined here in the below example :
https://github.com/crazycapivara/deckgl/blob/master/_examples/deckgl-examples/hexagon-layer_road-safety-in-the-uk.R

But when I use to add this to the example, nothing happens. Would be grateful for any assistance

library(deckgl)
library(data.table)

data_url <- paste0(
  "https://raw.githubusercontent.com/",
  "uber-common/deck.gl-data/",
  "master/examples/3d-heatmap/heatmap-data.csv"
)
sample_data <- fread(data_url) %>%
  na.omit()

color_to_rgb <- function(color) col2rgb(color) %>% as.vector()
color_range <- c("#0198BD", "#49E3CE", "#D8FEB5", "#FEEDB1", "#FEAD54", "#D1374E") %>%
  lapply(color_to_rgb)

light_settings <- list(
  lightsPosition = c(-0.144528, 49.739968, 8000, -3.807751, 54.104682, 8000),
  ambientRatio = 0.4,
  diffuseRatio = 0.6,
  specularRatio = 0.2,
  lightsStrength = c(0.8, 0.0, 0.8, 0.0),
  numberOfLights = 2
)

initial_view_state <- list(
  longitude = -1.4157267858730052,
  latitude = 52.232395363869415,
  zoom = 6.6,
  pitch = 40.5,
  bearing = -27.396674584323023
)

 deckgl(
  initialViewState = initial_view_state,
  effect = light_settings
) %>%
  add_grid_layer(
    data = sample_data,
    getPosition = ~lng + lat,
    cellSize = 2000,
    elevationScale = 50,
    extruded = TRUE,
    opacity = 0.5,
    colorRange = color_range,
    lightSettings = light_settings,
    getTooltip = JS("object => `${object.count} accidents`")
  ) %>% 
  add_basemap()
@crazycapivara
Copy link
Owner

crazycapivara commented Jun 10, 2022

Unfortunately they changed the API for the lightning effects, so that I need to wrap the new classes.
For now you can try to pass pure JavaScript via the JS function in R. See using-lighting.

@crazycapivara crazycapivara added the enhancement New feature or request label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants