Skip to content

Commit

Permalink
Merge pull request #78 from trafficonese/stars_pane
Browse files Browse the repository at this point in the history
fix: fixes #58 - expose option to addStarsImage
  • Loading branch information
tim-salabim authored May 29, 2024
2 parents d5caa1b + 4f58d62 commit 0961b76
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ importFrom(leaflet,addRasterImage)
importFrom(leaflet,colorNumeric)
importFrom(leaflet,expandLimits)
importFrom(leaflet,getMapData)
importFrom(leaflet,gridOptions)
importFrom(leaflet,invokeMethod)
importFrom(methods,formalArgs)
importFrom(png,writePNG)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ leafem 0.2.3.9001 (2024-04-17)
features and improvements

bug fixes
* addStarsImage() now accepts an `option` argument. Requires leaflet >= 2.2.2 #58

documentation etc

Expand Down
38 changes: 11 additions & 27 deletions R/addStarsImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,10 @@
#' @param map a mapview or leaflet object.
#' @param x a stars layer.
#' @param band the band number to be plotted.
#' @param colors the color palette (see colorNumeric) or function to use to
#' color the raster values (hint: if providing a function, set na.color
#' to "#00000000" to make NA areas transparent)
#' @param opacity the base opacity of the raster, expressed from 0 to 1
#' @param attribution the HTML string to show as the attribution for this layer
#' @param layerId the layer id
#' @param group the name of the group this raster image should belong to
#' (see the same parameter under addTiles)
#' @param project if TRUE, automatically project x to the map projection
#' expected by Leaflet (EPSG:3857); if FALSE, it's the caller's responsibility
#' to ensure that x is already projected, and that extent(x) is
#' expressed in WGS84 latitude/longitude coordinates
#' @param method the method used for computing values of the new,
#' projected raster image. "bilinear" (the default) is appropriate for
#' continuous data, "ngb" - nearest neighbor - is appropriate for categorical data.
#' Ignored if project = FALSE. See projectRaster for details.
#' @param maxBytes the maximum number of bytes to allow for the projected image
#' (before base64 encoding); defaults to 4MB.
#' @param data the data object from which the argument values are derived; by
#' default, it is the \code{data} object provided to \code{leaflet()}
#' initially, but can be overridden.
#' @inheritParams leaflet::addRasterImage
#' @param ... currently not used.
#'
#' @details
Expand All @@ -43,7 +26,7 @@
#' }
#'
#' @importFrom grDevices col2rgb colors
#' @importFrom leaflet colorNumeric expandLimits getMapData invokeMethod
#' @importFrom leaflet colorNumeric expandLimits getMapData invokeMethod gridOptions
#' @importFrom sf st_as_sfc st_bbox st_transform
#' @importFrom base64enc base64encode
#' @importFrom png writePNG
Expand All @@ -60,6 +43,7 @@ addStarsImage <- function(
, project = FALSE
, method = c("auto", "bilinear", "ngb")
, maxBytes = 4 * 1024 * 1024
, options = gridOptions()
, data = getMapData(map)
, ...
) {
Expand Down Expand Up @@ -162,16 +146,16 @@ addStarsImage <- function(
list(bounds[4], bounds[1]),
list(bounds[2], bounds[3])
)
options$opacity <- opacity
options$attribution <- attribution

map = leaflet::invokeMethod(
map, data, "addRasterImage", uri, latlng,
opacity, attribution, layerId, group
)

leaflet::expandLimits(
map,
c(bounds[2], bounds[4]),
c(bounds[1], bounds[3])
)
layerId, group, options
) %>%
leaflet::expandLimits(
c(bounds[2], bounds[4]),
c(bounds[1], bounds[3])
)

}
33 changes: 20 additions & 13 deletions man/addStarsImage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0961b76

Please sign in to comment.