Extends Leaflet for R by adding widget to control opacity of multiple layers, based on Leaflet.Control.Opacity (dayjournal/Leaflet.Control.Opacity) JavaScript plugin with some modifications to support layers other than tile layers (currently tested: tile, image and marker).
Before you begin, ensure you have met the following requirement(s):
R >= 3.5.0
installed.Install the latest version released on CRAN:
Or install the development version from GitHub:
if (!require("remotes")) install.packages("remotes")
remotes::install_github("meantrix/leaflet.multiopacity@main")
leaflet.multiopacity
provides the function addOpacityControls
to include opacity sliders in leaflet map.
# Load libraries
library(leaflet)
library(leaflet.multiopacity)
library(raster)
# Create raster example
r <- raster(xmn = -2.8, xmx = -2.79,
ymn = 54.04, ymx = 54.05,
nrows = 30, ncols = 30)
values(r) <- matrix(1:900, nrow(r), ncol(r), byrow = TRUE)
crs(r) <- crs("+init=epsg:4326")
# Provide layerId, group or category to show opacity controls
# If not specified, will render controls for all layers
leaflet() %>%
addProviderTiles("Wikimedia", layerId = "Wikimedia") %>%
addRasterImage(r, layerId = "raster") %>%
addAwesomeMarkers(lng = -2.79545, lat = 54.04321,
layerId = "hospital", label = "Hospital") %>%
addOpacityControls(layerId = c("raster", "hospital"),
collapsed = FALSE, position = "topright",
title = "Opacity Control")
For more information and examples, please take a look at the vignettes:
To contribute to leaflet.multiopacity
, follow these steps:
git checkout -b <branch_name>
.git commit -m '<commit_message>'
git push origin leaflet.multiopacity/<location>
Alternatively see the GitHub documentation on creating a pull request.
If you have detected a bug (or want to ask for a new feature), please file an issue with a minimal reproducible example on GitHub.
This project uses the following license: MIT License.