Skip to content

Commit c7d5f47

Browse files
committed
addGeotiff for files, addGeoRaster for stars, stars_proxy & raster, #25
1 parent 96255c1 commit c7d5f47

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

R/addGeoRaster.R

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
addGeoRaster = function(map,
2-
file = NULL,
3-
url = NULL,
2+
x,
43
group = NULL,
54
layerId = NULL,
65
resolution = 96,
76
opacity = 0.8,
87
colorOptions = colorOptions(),
98
pixelValuesToColorFn = NULL) {
109

10+
if (inherits(x, "Raster")) {
11+
x = stars::st_as_stars(x)
12+
}
13+
14+
if (!sf::st_is_longlat(x)) {
15+
x = stars::st_warp(x, crs = 4326)
16+
}
17+
18+
fl = tempfile(fileext = ".tif")
19+
20+
if (inherits(x, "stars_proxy")) {
21+
file.copy(x[[1]], fl)
22+
}
23+
24+
if (!inherits(x, "stars_proxy")) {
25+
stars::write_stars(x, dsn = fl)
26+
}
27+
28+
addGeotiff(
29+
map
30+
, file = fl
31+
, url = NULL
32+
, group = group
33+
, layerId = layerId
34+
, resolution = resolution
35+
, opacity = opacity
36+
, colorOptions = colorOptions
37+
, pixelValuesToColorFn = pixelValuesToColorFn
38+
)
39+
40+
}
41+
42+
43+
44+
addGeotiff = function(map,
45+
file = NULL,
46+
url = NULL,
47+
group = NULL,
48+
layerId = NULL,
49+
resolution = 96,
50+
opacity = 0.8,
51+
colorOptions = colorOptions(),
52+
pixelValuesToColorFn = NULL) {
53+
1154
if (inherits(map, "mapview")) map = mapview2leaflet(map)
1255

1356
if (is.null(file) & is.null(url))
@@ -36,7 +79,7 @@ addGeoRaster = function(map,
3679
leaflet::invokeMethod(
3780
map
3881
, data = leaflet::getMapData(map)
39-
, method = "addGeoRaster"
82+
, method = "addGeotiff"
4083
, url
4184
, group
4285
, layerId
@@ -55,7 +98,7 @@ addGeoRaster = function(map,
5598
leaflet::invokeMethod(
5699
map
57100
, data = leaflet::getMapData(map)
58-
, method = "addGeoRaster"
101+
, method = "addGeotiff"
59102
, url
60103
, group
61104
, layerId

inst/htmlwidgets/lib/georaster-for-leaflet/georaster-binding.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
LeafletWidget.methods.addGeoRaster = function (url,
2-
group,
3-
layerId,
4-
resolution,
5-
opacity,
6-
colorOptions,
7-
pixelValuesToColorFn) {
1+
LeafletWidget.methods.addGeotiff = function (url,
2+
group,
3+
layerId,
4+
resolution,
5+
opacity,
6+
colorOptions,
7+
pixelValuesToColorFn) {
88

99
var map = this;
1010

0 commit comments

Comments
 (0)