Skip to content

Commit 55773a7

Browse files
committed
Add options to addRasterImage
1 parent 8db80b6 commit 55773a7

38 files changed

+737
-247
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ Suggests:
6161
RJSONIO,
6262
purrr,
6363
testthat
64-
RoxygenNote: 6.1.1
64+
RoxygenNote: 7.1.0
6565
Encoding: UTF-8
6666
LazyData: true

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export(fitBounds)
111111
export(flyTo)
112112
export(flyToBounds)
113113
export(getMapData)
114+
export(gridOptions)
114115
export(groupOptions)
115116
export(hideGroup)
116117
export(highlightOptions)

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FEATURES
88
*
99

1010
BUG FIXES and IMPROVEMENTS
11-
*
11+
* `addRasterImage` now takes `options = gridOptions()`, so that arbitrary Leaflet layer options can be controlled.
1212

1313

1414

R/layers.R

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ epsg3857 <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y
218218
#' Ignored if \code{project = FALSE}. See \code{\link{projectRaster}} for details.
219219
#' @param maxBytes the maximum number of bytes to allow for the projected image
220220
#' (before base64 encoding); defaults to 4MB.
221+
#' @param options a list of additional options, intended to be provided by
222+
#' a call to \code{\link{gridOptions}}
221223
#' @template data-getMapData
222224
#'
223225
#' @examples
@@ -243,10 +245,14 @@ addRasterImage <- function(
243245
project = TRUE,
244246
method = c("auto", "bilinear", "ngb"),
245247
maxBytes = 4 * 1024 * 1024,
248+
options = tileOptions(),
246249
data = getMapData(map)
247250
) {
248251
stopifnot(inherits(x, "RasterLayer"))
249252

253+
options$opacity <- opacity
254+
options$attribution <- attribution
255+
250256
raster_is_factor <- raster::is.factor(x)
251257
method <- match.arg(method)
252258
if (method == "auto") {
@@ -304,7 +310,7 @@ addRasterImage <- function(
304310
list(raster::ymin(bounds), raster::xmax(bounds))
305311
)
306312

307-
invokeMethod(map, data, "addRasterImage", uri, latlng, opacity, attribution, layerId, group) %>%
313+
invokeMethod(map, data, "addRasterImage", uri, latlng, opacity, attribution, layerId, group, options) %>%
308314
expandLimits(
309315
c(raster::ymin(bounds), raster::ymax(bounds)),
310316
c(raster::xmin(bounds), raster::xmax(bounds))
@@ -373,6 +379,23 @@ tileOptions <- function(
373379
))
374380
}
375381

382+
#' @describeIn map-options Options for grid layers
383+
#' @export
384+
gridOptions <- function(
385+
tileSize = 256,
386+
updateWhenIdle = NULL,
387+
zIndex = 1,
388+
minZoom = 0,
389+
maxZoom = NULL,
390+
...
391+
) {
392+
filterNULL(list(
393+
tileSize = tileSize, updateWhenIdle = updateWhenIdle, zIndex = zIndex,
394+
minZoom = minZoom, maxZoom = maxZoom,
395+
...
396+
))
397+
}
398+
376399
#' Remove elements from a map
377400
#'
378401
#' Remove one or more features from a map, identified by \code{layerId}; or,

inst/htmlwidgets/leaflet.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@ methods.setGroupOptions = function (group, options) {
21272127
this.showHideGroupsOnZoom();
21282128
};
21292129

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

@@ -2246,12 +2246,10 @@ methods.addRasterImage = function (uri, bounds, opacity, attribution, layerId, g
22462246
};
22472247
img.src = uri;
22482248

2249-
var canvasTiles = _leaflet2.default.gridLayer({
2250-
opacity: opacity,
2251-
attribution: attribution,
2249+
var canvasTiles = _leaflet2.default.gridLayer(Object.assign({}, options, {
22522250
detectRetina: true,
22532251
async: true
2254-
});
2252+
}));
22552253

22562254
// NOTE: The done() function MUST NOT be invoked until after the current
22572255
// tick; done() looks in Leaflet's tile cache for the current tile, and

javascript/src/methods.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ methods.setGroupOptions = function(group, options) {
983983
this.showHideGroupsOnZoom();
984984
};
985985

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

@@ -1104,12 +1104,10 @@ methods.addRasterImage = function(uri, bounds, opacity, attribution, layerId, gr
11041104
};
11051105
img.src = uri;
11061106

1107-
let canvasTiles = L.gridLayer({
1108-
opacity: opacity,
1109-
attribution: attribution,
1107+
let canvasTiles = L.gridLayer(Object.assign({}, options, {
11101108
detectRetina: true,
11111109
async: true
1112-
});
1110+
}));
11131111

11141112
// NOTE: The done() function MUST NOT be invoked until after the current
11151113
// tick; done() looks in Leaflet's tile cache for the current tile, and

man/addAwesomeMarkers.Rd

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addGraticule.Rd

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addLayersControl.Rd

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/addLegend.Rd

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)