tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Logo not supported in view mode?

Open NickPyll opened this issue 5 years ago • 13 comments

Is there any plan to incorporate this capability or is there a good workaround? I work for a nonprofit and we are trying to embed a map I have created on our website but would like to have the logo. Thanks.

NickPyll avatar Jun 12 '20 12:06 NickPyll

@tim-salabim any idea it this is possible through leaflet or additional packages?

Not sure how good your html skills are, but you can always export the map with tmap_save to an html file, and edit this. You'll just have to add a floating div, and put the logo in there.

mtennekes avatar Jun 24 '20 10:06 mtennekes

Is this sing leafem::addLogo? If so, then currently this is not possible if the logo is a local file. It should work if the logo is a url.

I'd appreciate an issue in the leafem repo if that is where the root cause lies.

Backgroud: We'd need to turn the addLogo function into a proper js-binding (currently is just a onRender call). The problem is that we don't properly attach the logo to the map, but rather save the logo in the tempdir() where also the map is created. If we save the map elsewhere (as with tmap_save) we loose the image. This has been very low priority for me as it isn't core scope of mapview (more like sugar). That said, it should be possible to do this, as I've solved a similar issue with leafpop::addPopupImages.

tim-salabim avatar Jun 24 '20 11:06 tim-salabim

Is there any good news about the integration of leafem::addLogo into tmap? I've been trying to add one from a url using leafem::addLogo and lefpop::addPopupImages.

Both return errors.

inherits(map, c("leaflet", "leaflet_proxy")) is not TRUE from leafem Error in dispatch(map, method, leaflet = { : Invalid map parameter from leafpop

Here a reproducible example for both:

data("World")

rlogo <- "https://www.r-project.org/logo/Rlogo.svg"

m <- tm_shape(World, group = "World") +
    tm_borders()

m %>%  leafem::addLogo(rlogo,
                       src = "remote",
                       position = "topright",
                       offset.x = 20,
                       offset.y = 350,
                       width = 200,
                       height = 40.5)

m %>% leafpop::addPopupImages(rlogo,
                              group = "World",
                              width = 200,
                              height = 40.5)

Can anyone suggest a workable turnaround to add logos to interactive (t)maps?

P.S. editing the *.html manually is not an option for my case because the main goal of the project I'm working at is automating the creation of data reports.

IvanPalm avatar Apr 15 '21 17:04 IvanPalm

How about:

library(tmap)
library(leaflet)

data("World")

rlogo <- "https://www.r-project.org/logo/Rlogo.svg"

m <- tm_shape(World, group = "World") +
        tm_borders()

m <- tmap_leaflet(m)
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.2

m %>%  leafem::addLogo(rlogo,
                       src = "remote",
                       position = "topright",
                       offset.x = 20,
                       offset.y = 350,
                       width = 200,
                       height = 40.5)

Created on 2021-04-15 by the reprex package (v1.0.0)

Nowosad avatar Apr 15 '21 17:04 Nowosad

As easy as a breeze. Thank you very much @Nowosad!

Now the question is why the R logo I used in the example shows up while the logo I have to use in my project displays only an empty frame, without the logo image.
I guess it has something to do with the image format. The client passed me a *.png while the R logo is in vector ( *.svg). I will figure this out, it has nothing to do with tmap or r-leaflet. Thanks again!

IvanPalm avatar Apr 16 '21 14:04 IvanPalm

Currently, the file has to be located at a URL. Files are not supported so far. I am planning to address this soon.

tim-salabim avatar Apr 16 '21 14:04 tim-salabim

Hi @tim-salabim, thank you for pointing that out.
The *.png file I mentioned above is actually located in the GitHub project repo, just like the *.svg of the R logo is located in the r-project website. In spite of the file location, the *.svg shows up on the map, while the URL to the *.png image displays only the frame where the logo would be located on the map...but not the logo itself.
Thus, I am assuming that the image format (vector vs raster) is making the difference here.

IvanPalm avatar Apr 17 '21 09:04 IvanPalm

I'm planning to look into this tomorrow

tim-salabim avatar Apr 17 '21 09:04 tim-salabim

@IvanPalm I don't see a problem with .png files from a url:

library(leaflet)
library(leafem)

img <- "https://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"
leaflet() %>% addTiles() %>% addLogo(img)

Created on 2021-04-18 by the reprex package (v0.3.0)

tim-salabim avatar Apr 18 '21 11:04 tim-salabim

And with tmap

library(tmap)
library(leaflet)

data("World")

img <- "https://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"

m <- tm_shape(World, group = "World") +
  tm_borders()

m <- tmap_leaflet(m)
#> Linking to GEOS 3.8.0, GDAL 3.1.0, PROJ 7.0.0

m %>%  leafem::addLogo(img,
                       src = "remote",
                       position = "topright")

Created on 2021-04-18 by the reprex package (v0.3.0)

tim-salabim avatar Apr 18 '21 11:04 tim-salabim

@IvanPalm are you sure that you are using the raw link to your file? For example https://raw.githubusercontent.com/mtennekes/tmap/master/inst/img/airplane.png, and not https://github.com/mtennekes/tmap/blob/master/inst/img/airplane.png.

Nowosad avatar Apr 18 '21 11:04 Nowosad

Hi @tim-salabim I tried that out too, and I've got to same conclusion. Both *.svg and *.png files are supported.

Hi @Nowosad Cannot deny that I stumbled across that a few times, but not this time. I was using the raw download URL to the image file. The difference between the one I was using and the URL you reported in your example is that mine ended with a token. I.e. https://raw.githubusercontent.com/USER/REPO/*.png?token=ALPHANUMERICTOKEN.
I guess that's due to the fact that I'm working on a private repo.

Every time I checked the raw URL to the image, the token had changed, and every time it had changed, the logo had disappeared from the maps. I have now uploaded the image to a different location and the logo is displayed regularly. I would be curious to know how to deal with such cases, but the issue with the logo is now solved.

Thank you for your time!

IvanPalm avatar Apr 18 '21 13:04 IvanPalm

As far as I'm concerned it's only partly solved because addLogo will still not work if the image points to a local file and the map is saved (and shared as a html file). Yet, I don't have enough time at the moment to re-implement properly. Though I'm not too worried as this does not come up very often... Sorry, but maintaining open source projects in free-time is what it is...

tim-salabim avatar Apr 18 '21 13:04 tim-salabim