Skip to content

Commit

Permalink
Pass addRasterImage options correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Feb 18, 2024
1 parent bac0105 commit 4dfb58f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ addRasterImage <- function(
project = project,
method = method,
maxBytes = maxBytes,
options = options,
data = data
)
} else if (inherits(x, "RasterLayer")) {
Expand All @@ -285,6 +286,7 @@ addRasterImage <- function(
project = project,
method = method,
maxBytes = maxBytes,
options = options,
data = data
)
} else {
Expand Down Expand Up @@ -392,6 +394,7 @@ addRasterImage_RasterLayer <- function(
project = TRUE,
method = c("auto", "bilinear", "ngb"),
maxBytes = 4 * 1024 * 1024,
options = gridOptions(),
data = getMapData(map)
) {

Expand Down Expand Up @@ -450,7 +453,7 @@ addRasterImage_RasterLayer <- function(
list(raster::ymin(bounds), raster::xmax(bounds))
)

invokeMethod(map, data, "addRasterImage", uri, latlng, opacity, attribution, layerId, group, options) %>%
invokeMethod(map, data, "addRasterImage", uri, latlng, layerId, group, options) %>%
expandLimits(
c(raster::ymin(bounds), raster::ymax(bounds)),
c(raster::xmin(bounds), raster::xmax(bounds))
Expand All @@ -468,6 +471,7 @@ addRasterImage_SpatRaster <- function(
project = TRUE,
method = c("auto", "bilinear", "ngb"),
maxBytes = 4 * 1024 * 1024,
options = gridOptions(),
data = getMapData(map)
) {
if (!is_installed("terra", "1.6-3")) { # for terra::has.RGB()
Expand All @@ -477,6 +481,9 @@ addRasterImage_SpatRaster <- function(
)
}

options$opacity <- opacity
options$attribution <- attribution

if (terra::has.RGB(x)) {
# RGB(A) channels to color table
x <- terra::colorize(x, "col")
Expand Down Expand Up @@ -554,7 +561,7 @@ addRasterImage_SpatRaster <- function(
list(terra::ymin(bounds), terra::xmax(bounds))
)

invokeMethod(map, data, "addRasterImage", uri, latlng, opacity, attribution, layerId, group) %>%
invokeMethod(map, data, "addRasterImage", uri, latlng, layerId, group, options) %>%
expandLimits(
c(terra::ymin(bounds), terra::ymax(bounds)),
c(terra::xmin(bounds), terra::xmax(bounds))
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/assets/leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ methods.setGroupOptions = function (group, options) {
this.showHideGroupsOnZoom();
};

methods.addRasterImage = function (uri, bounds, opacity, attribution, layerId, group, options) {
methods.addRasterImage = function (uri, bounds, layerId, group, options) {
// uri is a data URI containing an image. We want to paint this image as a
// layer at (top-left) bounds[0] to (bottom-right) bounds[1].
// We can't simply use ImageOverlay, as it uses bilinear scaling which looks
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ methods.setGroupOptions = function(group, options) {
this.showHideGroupsOnZoom();
};

methods.addRasterImage = function(uri, bounds, opacity, attribution, layerId, group, options) {
methods.addRasterImage = function(uri, bounds, layerId, group, options) {
// uri is a data URI containing an image. We want to paint this image as a
// layer at (top-left) bounds[0] to (bottom-right) bounds[1].

Expand Down

0 comments on commit 4dfb58f

Please sign in to comment.