I have to RasterLayer
-objects (raster1
and raster2
) in R. And I want to add them both to a leaflet-map. I also wanted to have the option to show or hide them. So I thought I'd add them with their names to the addLayersControl
-option. But it doesn't work. It shows both layers at the same time and I can't hide them. So far my code looks like this. I think the problem is in how to add them to the addLayersControl
-function.
leaflet() %>%
addTiles() %>%
addRasterImage(raster1, opacity = 0.3) %>%
addRasterImage(raster2, opacity = 0.3) %>%
addLayersControl(
baseGroups = c("OSM (default)"),
overlayGroups = c("raster1", "raster2"),
options = layersControlOptions(collapsed = FALSE)
)
I guess that's kind of easy,but I can't think of any sollution.