mapview icon indicating copy to clipboard operation
mapview copied to clipboard

Cannot plot rasters from list

Open ailich opened this issue 4 years ago • 2 comments

Rasters don't seem to be rendering when running mapview on a list of rasters which is a supported format according to the mapview help. Multiple rasters can still be plotted with the "+" operator but do not work if just a list is supplied. I've included a short reproducible example below. This was done using R 4.04 and mapview 2.9.9 (development version) on Windows. I tried the CRAN version of mapview as well (2.9.0) and got similar results except that the default extent of the resulting maps if there were multiple rasters was the whole world instead of just the areas plotted and then I needed to zoom in.

library(stars)
library(raster)
library(mapview)
raster_layer<- raster(system.file("tif/L7_ETMs.tif", package = "stars"))
raster_layer2<- raster_layer*2

raster_list<- list(raster_layer, raster_layer2)

mapview(raster_layer) m1

mapview(raster_layer2) m2

mapview(raster_list[[1]])+
mapview(raster_list[[2]])

m3

mapview(raster_list) m4

ailich avatar May 24 '21 20:05 ailich

Hi @ailich , nice catch.

This needs to be implemented in leafem::garnishMap which uses partial matching so any color argument supplied to the raster method of mapview becomes colors in the call to leaflet::addRasterImage. Given that we explicitly set the colors argument when calling garnishMap internally we end up with two spcifications of colors being passed to leaflet::addRasterImage and hence it fails.

Your example works with

remotes::install_github("r-spatial/leafem@issue_mv385")

Not sure, when I will merge this and update on CRAN. Highest priority at the moment is to get mapview on updated CRAN.

tim-salabim avatar Jun 04 '21 10:06 tim-salabim

@tim-salabim thanks, works great now!

ailich avatar Jun 04 '21 15:06 ailich