mapview icon indicating copy to clipboard operation
mapview copied to clipboard

Side by side rendering with "|" does not work for rasters

Open pcollender opened this issue 3 months ago • 0 comments

When attempting to render two raster images side by side with a slider via the map1 | map2 syntax, mapview fails to produce any output. I believe this is because the default method for plotting raster in mapview is addRasterImage, while the slider operator (mapview:::.__T__|:base$mapview#mapview) only looks for addGeotiff.

Relevant line of code in mapview:::.__T__|:base$mapview#mapview:

e1_feat_idx = getCallEntryFromMap(e1@map, c("addPolygons", 
            "addPolylines", "addCircleMarkers", "addFlatGeoBuf", 
            "addGeotiff"))

Reproducible example:

library(terra)
library(mapview)
library(jpeg)

# 2000
web_img2000 <- "http://cdn.newsapi.com.au/image/v1/68565a36c0fccb1bc43c09d96e8fb029"
jpg2000 <- readJPEG(readBin(web_img2000, "raw", 1e6))

# Convert imagedata to raster
rst_blue2000 <- rast(jpg2000[, , 1])
rst_green2000 <- rast(jpg2000[, , 2])
rst_red2000 <- rast(jpg2000[, , 3])

img2000 <- rast(jpg2000)
names(img2000) = c('blue','green','red')
#arbitrary coordinates
ext(img2000) = c(-1,1, -1,1)
crs(img2000) = 'epsg:4326'

# 2013
web_img2013 <- "http://cdn.newsapi.com.au/image/v1/5707499d769db4b8ec76e8df61933f2a"
jpg2013 <- readJPEG(readBin(web_img2013, "raw", 1e6))

# Convert imagedata to raster
img2013 <- rast(jpg2013)
names(img2013) = c('blue','green','red')
#arbitrary coordinates
ext(img2013) = c(-1,1, -1,1)
crs(img2013) = 'epsg:4326'

# map each layer individually
mapview(img2000)
mapview(img2013)

mapview(img2000) | mapview(img2013)

pcollender avatar Sep 08 '25 17:09 pcollender