Description Usage Arguments Value Examples
View source: R/addPopupImages.R
Add image popups to leaflet layers.
1 2 3 4 5 6 7 8 9 |
map |
the |
image |
A character |
group |
the map group to which the popups should be added. |
width |
the width of the image(s) in pixels. |
height |
the height of the image(s) in pixels. |
tooltip |
logical, whether to show image(s) as popup(s) (on click) or tooltip(s) (on hover). |
... |
additional options passed on to the JavaScript creator function. See https://leafletjs.com/reference-1.7.1.html#popup & https://leafletjs.com/reference-1.7.1.html#tooltip for details. |
A leaflet
map.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | if (interactive()) {
## remote images -----
### one image
library(leaflet)
library(sf)
library(lattice)
pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
coords = c("x", "y"),
crs = 4326)
img = "http://bit.ly/1TVwRiR"
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pnt, group = "pnt") %>%
addPopupImages(img, group = "pnt")
### multiple file (types)
library(sf)
images = c(img,
"https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg",
"https://www.r-project.org/logo/Rlogo.png",
"https://upload.wikimedia.org/wikipedia/commons/d/d6/MeanMonthlyP.gif")
pt4 = data.frame(x = jitter(rep(174.764474, 4), factor = 0.01),
y = jitter(rep(-36.877245, 4), factor = 0.01))
pt4 = st_as_sf(pt4, coords = c("x", "y"), crs = 4326)
leaflet() %>%
addTiles() %>%
addMarkers(data = pt4, group = "points") %>%
addPopupImages(images, group = "points", width = 400) # NOTE the gif animation
## local images -----
pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
coords = c("x", "y"), crs = 4326)
img = system.file("img","Rlogo.png",package="png")
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pnt, group = "pnt") %>%
addPopupImages(img, group = "pnt")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.