Local images not saved when using addLogo and mapshot
tim-salabim opened this issue · 4 comments
From @nekronaut r-spatial/mapview#290:
I am trying to save mapview
generated maps including local images to html, using addLogo
and mapshot
. Although locally saved images are displayed in the viewer/browser, they are not saved to file. Let me demonstrate...
Saving these examples from the documentation work, but they use remote images. For simplicity's sake, I prefer using mapview
syntax, but I have also tried leaflet
notation:
library(mapview)
library(leaflet)
library(leafem)
#mapview syntax
m1 <- mapview(breweries)
m1 <- addLogo(m1, "https://jeroenooms.github.io/images/banana.gif",
position = "bottomleft",
offset.x = 5,
offset.y = 40,
width = 100,
height = 100)
mapshot(m1, url = paste0(getwd(), "\\test1.html"))
#leaflet syntax
img <- "https://www.r-project.org/logo/Rlogo.svg"
m2 <- leaflet() %>%
addTiles() %>%
addLogo(img, url = "https://www.r-project.org/logo/")
mapshot(m2, url = paste0(getwd(), "\\test2.html"))
Unfortunately, no such luck when using locally saved images:
download.file(url="https://www.r-project.org/logo/Rlogo.svg", destfile=paste0(getwd(), "\\Rlogo.svg")
#mapview syntax
m3 <- mapview(breweries)
m3 <- addLogo(m3, paste0(getwd(), "\\Rlogo.svg"),
src = "local",
position = "bottomleft",
offset.x = 5,
offset.y = 40,
width = 100,
height = 100)
mapshot(m3, url = paste0(getwd(), "\\test3.html"))
#leaflet syntax
m4 = leaflet() %>%
addTiles() %>%
addLogo(paste0(getwd(), "\\Rlogo.svg"), src = "local")
mapshot(m4, url = paste0(getwd(), "\\test4.html"))
I have looked at the available documentation as well as here and here. Is this a bug, or am I missing something?
Yes, images are not attached to the map in any sensible way (we use htmlwidgets::onRender
) so that this currently only works for remote images.
Need to implement a proper method to handle this correctly. May take a while...