Skip to content

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

@pcollender

Description

@pcollender

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions