leafem icon indicating copy to clipboard operation
leafem copied to clipboard

Local images not saved when using addLogo and mapshot

Open tim-salabim opened this issue 5 years ago • 4 comments

From @nekronaut https://github.com/r-spatial/mapview/issues/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?

tim-salabim avatar May 06 '20 09:05 tim-salabim

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...

tim-salabim avatar May 06 '20 09:05 tim-salabim

I am experiencing this now. I feel like I had this solved in the past by doing something like this. src is set to 'remote' since that used to do the trick in Rmd and qmd files even though the image would be embedded in the html. But it doesn't seem to be working.

addLogo(img=here::here('images', 'logo.png'), src='remote', url='https://www.example.com')

jaredlander avatar May 23 '23 20:05 jaredlander

The only thing working at the moment is a truely remote image (i.e. accessible via url).

tim-salabim avatar May 24 '23 06:05 tim-salabim

Hi, I'm experiencing this same issue with local images not rendering correctly during export of leaflet maps. I was wondering if any of you ever found a workaround?

shallot86 avatar Dec 14 '23 15:12 shallot86