Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

addLogo

add a local or remote image (png, jpg, gif, bmp, ...) to a leaflet map


Description

This function adds an image to a map. Both local and remote (web) image sources are supported. Position on the map is completely controllable.

Usage

addLogo(
  map,
  img,
  alpha = 1,
  src = c("remote", "local"),
  url,
  position = c("topleft", "topright", "bottomleft", "bottomright"),
  offset.x = 50,
  offset.y = 13,
  width = 60,
  height = 60
)

Arguments

map

a mapview or leaflet object.

img

the image to be added to the map.

alpha

opacity of the added image.

src

character specifying the source location ("local" for images from the disk, "remote" for web image sources).

url

an optional URL to be opened when clicking on the image (e.g. company's homepage).

position

one of "topleft", "topright", "bottomleft", "bottomright".

offset.x

the offset in x direction from the chosen position (in pixels).

offset.y

the offset in y direction from the chosen position (in pixels).

width

width of the rendered image in pixels.

height

height of the rendered image in pixels.

Examples

library(leaflet)
## default position is topleft next to zoom control

img <- "https://www.r-project.org/logo/Rlogo.svg"
leaflet() %>% addTiles() %>% addLogo(img, url = "https://www.r-project.org/logo/")

## with local image
if (requireNamespace("png")) {
  library(png)

  img <- system.file("img", "Rlogo.png", package="png")
  leaflet() %>% addTiles() %>% addLogo(img, src = "local", alpha = 0.3)

  ## dancing banana gif :-)
  m <- leaflet() %>%
    addTiles() %>%
    addCircleMarkers(data = breweries91)

  addLogo(m, "https://jeroenooms.github.io/images/banana.gif",
          position = "bottomleft",
          offset.x = 5,
          offset.y = 40,
          width = 100,
          height = 100)
}

leafem

'leaflet' Extensions for 'mapview'

v0.1.3
MIT + file LICENSE
Authors
Tim Appelhans [cre, aut], Christoph Reudenbach [ctb], Kenton Russell [ctb], Jochen Darley [ctb], Daniel Montague [ctb] (Leaflet.EasyButton plugin), Lorenzo Busetto [ctb], Luigi Ranghetti [ctb], Miles McBain [ctb], Sebastian Gatscha [ctb], Björn Harrtell [ctb] (FlatGeobuf plugin), Daniel Dufour [ctb] (georaster-layer-for-leaflet)
Initial release
2020-07-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.