addFgb color depend on a variable?
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)
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)
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
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.
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?