Skip to content

Commit

Permalink
addGeotiff for files, addGeoRaster for stars, stars_proxy & raster, #25
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-salabim committed Jul 13, 2020
1 parent 96255c1 commit c7d5f47
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
51 changes: 47 additions & 4 deletions R/addGeoRaster.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
addGeoRaster = function(map,
file = NULL,
url = NULL,
x,
group = NULL,
layerId = NULL,
resolution = 96,
opacity = 0.8,
colorOptions = colorOptions(),
pixelValuesToColorFn = NULL) {

if (inherits(x, "Raster")) {
x = stars::st_as_stars(x)
}

if (!sf::st_is_longlat(x)) {
x = stars::st_warp(x, crs = 4326)
}

fl = tempfile(fileext = ".tif")

if (inherits(x, "stars_proxy")) {
file.copy(x[[1]], fl)
}

if (!inherits(x, "stars_proxy")) {
stars::write_stars(x, dsn = fl)
}

addGeotiff(
map
, file = fl
, url = NULL
, group = group
, layerId = layerId
, resolution = resolution
, opacity = opacity
, colorOptions = colorOptions
, pixelValuesToColorFn = pixelValuesToColorFn
)

}



addGeotiff = function(map,
file = NULL,
url = NULL,
group = NULL,
layerId = NULL,
resolution = 96,
opacity = 0.8,
colorOptions = colorOptions(),
pixelValuesToColorFn = NULL) {

if (inherits(map, "mapview")) map = mapview2leaflet(map)

if (is.null(file) & is.null(url))
Expand Down Expand Up @@ -36,7 +79,7 @@ addGeoRaster = function(map,
leaflet::invokeMethod(
map
, data = leaflet::getMapData(map)
, method = "addGeoRaster"
, method = "addGeotiff"
, url
, group
, layerId
Expand All @@ -55,7 +98,7 @@ addGeoRaster = function(map,
leaflet::invokeMethod(
map
, data = leaflet::getMapData(map)
, method = "addGeoRaster"
, method = "addGeotiff"
, url
, group
, layerId
Expand Down
14 changes: 7 additions & 7 deletions inst/htmlwidgets/lib/georaster-for-leaflet/georaster-binding.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
LeafletWidget.methods.addGeoRaster = function (url,
group,
layerId,
resolution,
opacity,
colorOptions,
pixelValuesToColorFn) {
LeafletWidget.methods.addGeotiff = function (url,
group,
layerId,
resolution,
opacity,
colorOptions,
pixelValuesToColorFn) {

var map = this;

Expand Down

0 comments on commit c7d5f47

Please sign in to comment.