在 R Leaflet htmlwidget 上叠加静态图像

Overlay Static Images on R Leaflet htmlwidget

是否可以将图像叠加到 R 传单地图上 - 或者可能在传单中 html - 这将保持固定在地图本身之上?

也就是说,图像不会在地图本身上呈现,而是固定在浏览器的视口中,这样当您平移或缩放时,它会在相同位置保持相同大小。

例如,我想叠加 this image,固定在使用以下 R 代码呈现的地图的左上角:

library(htmlwidgets)
library(leaflet)

m <- leaflet() %>%
  addTiles() %>%
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")

saveWidget(m, file = "m.html", selfcontained = F)

在 html 中,您可以添加具有高 z-index 的 - 将内部放置在 html 小部件上方。

对于上面的例子,包括以下html上面的htmlwidget容器覆盖图像。

<div style="position:fixed;top:0px;left:0px;z-index:11000;">
<img src="https://www.r-project.org/logo/Rlogo.svg"/>
</div>

您可以使用包 mapview 中的 addLogo() 执行此操作。

library(htmlwidgets)
library(leaflet)
library(mapview)

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

m <- leaflet() %>%
  addTiles() %>%
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") %>%
  addLogo(img, url = "https://www.r-project.org/logo/")

m

我知道这是一个传单问题,但我想看看它是否适用于 googelway 和 add_overlay() - 它确实适用:

library(googleway)

map_key <- 'my_map_key'

google_map(key = map_key ) %>%
    add_overlay(north = -36.852, east = 174.768, west = 174.668, south = -36.952,
            overlay_url = "https://www.r-project.org/logo/Rlogo.svg")