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

addFgb color depend on a variable? #87

Open
trafficonese opened this issue Jul 29, 2024 · 4 comments
Open

addFgb color depend on a variable? #87

trafficonese opened this issue Jul 29, 2024 · 4 comments

Comments

@trafficonese
Copy link
Contributor

I am wondering if this is possible (using color = "MaxWind" or a palette)? I guess not, since color is not used in scaleOptions.

library(leaflet)
library(leafem)
library(sf)

lines <- st_as_sf(leaflet::atlStorms2005)

fgb_file <- tempfile(fileext = ".fgb")
st_write(lines, fgb_file)

leaflet() %>% 
  addTiles() %>% 
  leafem::addFgb(fgb_file, color = "MaxWind", opacity=1, weight = 1) %>% 
  leafem::addMouseCoordinates() %>%
  setView(-50, 45, 3)

I would like to use something similar to leafgl:

library(leafgl)
leaflet() %>% 
  addTiles() %>% leafem::addMouseCoordinates() %>% 
  addGlPolylines(data = lines, color = "MaxWind", opacity=1, weight = 1) 
@trafficonese
Copy link
Contributor Author

It works, when adding the color as a column name and passing color = NULL.
This was hard to to find, maybe we can add some documentation to the function.

library(leaflet)
library(leafem)
library(sf)

lines <- st_as_sf(leaflet::atlStorms2005)

lines$color <- colorNumeric("viridis", lines$MaxWind)(lines$MaxWind)

fgb_file <- tempfile(fileext = ".fgb")
st_write(lines, fgb_file)

leaflet() %>% 
  addTiles() %>% 
  leafem::addFgb(fgb_file, color = NULL, opacity=1, weight = 1) %>% 
  leafem::addMouseCoordinates() %>%
  setView(-50, 45, 3)

@tim-salabim
Copy link
Member

Yeah, given that we load the file directly in JavaScript, we need to have the coloring be part of the data... Unless we come up with a solution in JavaScript, which we can using chroma.js

@trafficonese
Copy link
Contributor Author

Thanks for your help!
Yes we could do that, but I am not too familiar with chroma.js and for now I am fine with the current setup, but I thought we can document it better, as it is maybe not so intuitive to assign it as column with the correct name.

@tim-salabim
Copy link
Member

Maybe, as a compromise, we can point out to assign a variable of any name and then let the user supply that name as the color/fillColor variable?

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