Closed yvanrichard closed 3 years ago
transparent_color
is the colour to use for transparent pixels. I.e. transparent pixels will become this colour.
As far as I'm aware, BitmapLayer doesn't support replacing visible pixels with a transparent colour; it is simple to do in R however:
# the pre-downloaded image
nz <- png::readPNG("image.png")
# any pixels with a greyscale colour of less than 0.8 * 255 will become transparent
grey <- (nz[, , 1] + nz[, , 2] + nz[, , 3]) / 3
nz[, , 4] <- nz[, , 4] * as.integer(grey >= 0.8)
## Deck
deck <- rdeck(map_style = "mapbox://styles/mapbox/dark-v9", initial_bounds = st_bbox(bounds, crs = 4326)) %>%
add_bitmap_layer(
name = "NZ",
bounds = bounds,
image = nz
)
deck
Oh right, I was misinterpreting the transparent_color
argument. My bad.
Thanks a lot for your elegant solution. And a big thank you for the package! Deck.gl is awesome and being able to use it from R is brilliant.
It looks like transparent_color is not respected when the image is passed as an array to add_bitmap_layer().
Here's a toy example, where I'd like the black background of the image to be transparent.