1

This has to be an easy fix but this is my first time using mapview and mapshot and I'm stuck. I've investigated other postings and the documentation but I can't see a source.

I've created an object with mapview. I can view the map ok and I can export and save successfully from the viewer. However, I'm trying to save from code using mapshot.

This works great with an html output but not for the png. No error messages show and the file saves in the right place absolutely fine. It's just that the saved PNG file shows a map and no data.

library(openair)
library(dplyr)
library(mapview)

sites <- importMeta(source = "saqn", all = FALSE)

edinburgh_sites <- sites %>% filter(substr(site, 1, 9) == "Edinburgh")
glimpse(edinburgh_sites)

Rows: 14 Columns: 5 $ site "Edinburgh Centre", "Edinburgh Currie", "Edinbur… $ code "ED", "ED11", "ED10", "ED5", "ED6", "ED2", "EDNS… $ latitude 55.95197, 55.89691, 55.93903, 55.93771, 55.94583… $ longitude -3.195775, -3.319660, -3.392727, -3.232267, -3.2… $ site_type "Urban Background", "Suburban Background", "Urba…

edinburgh_sites_map = mapview(edinburgh_sites, xcol = "longitude", ycol = "latitude", crs = 4326, grid = FALSE)
edinburgh_sites_map
mapshot(edinburgh_sites_map, 
        file = paste0(getwd(), "/Figures/edin_sites_map.png"))

In the viewer (and when exported from viewer): enter image description here

When saved using mapshot() as a png: enter image description here

  • If I remember correctly, mapshot uses webshot which uses phantomjs, right? If so I am not sure it necessarily is an easy fix, there are a lot of layers where something could be going wrong... – SamR Jun 29 '22 at 17:16
  • Ok, thanks. I still haven't managed to find a fix for this but will use the export/saving function from viewer in the interim. – Alwayslearning Jun 30 '22 at 20:28
  • 1
    @Alwayslearning I am in the middle of fixing this issue. I would appreciate if you could `remotes::install_github("r-spatial/mapview@429-update-to-webshot2")` and let me know if it fixes your issue? Please also see https://github.com/r-spatial/mapview/issues/419 for a bit more discussion around this issue. – TimSalabim Jul 01 '22 at 06:07
  • @TimSalabim awesome, I installed the fix and it now works. Thanks for that. I'm a coding newbie so naively thought it might have been something simple in my code. – Alwayslearning Jul 01 '22 at 11:08
  • Another thing that comes to mind here is to try `mapviewOptions(fgb = FALSE)` before generating the map. – TimSalabim Jul 03 '22 at 08:16
  • @TimSalabim I'm having the same issue and tried running that install, but it failed to download because it could not open the URL. – Todd Burus Sep 16 '22 at 19:35
  • It has been merged into master and is now called `mapshot2()` – TimSalabim Sep 17 '22 at 07:04

0 Answers0