单击栅格图像时,R用于传单重定向 [英] R for leaflet redirect when clicking on raster image
问题描述
我正在使用R的传单,当我单击光栅图像时,我只是想重定向到某些URL.我当前的代码如下:
I'm using leaflet for R and I simply would like to be redirected on some URL when I click on the raster image. My current code is the following :
library(htmlwidgets)
library(raster)
library(leaflet)
library(sp)
imgPath = paste(projectPath,"/test.tif", sep = "")
outPath = paste(projectPath, "/leaflethtmlgen.html", sep="")
r <- raster(imgPath)
pal <- colorNumeric(c("#FF0000", "#666666", "#FFFFFF"), values(r),
na.color = "transparent")
m <- leaflet()
m <- addTiles(m)
m <- addRasterImage(m,r, colors=pal, opacity = 0.9, maxBytes = 123123123, group = "Raster1")
m <- addLegend(m,pal = pal, values = values(r), title = "Test")
m <- addLayersControl(
m,
overlayGroups = c("Raster1"),
options = layersControlOptions(collapsed = FALSE)
)
m
结果如下:
推荐答案
您可以为此使用mapview包中的viewExtent
:
You could use viewExtent
from the mapview package for that:
library(mapview)
mapview(poppendorf[[10]]) +
viewExtent(poppendorf[[10]],
opacity = 0, fillOpacity = 0,
popup = '<a href="http://www.google.com">Search Google</a>')
viewExtent
顾名思义,是在光栅图像(或sp包中的任何空间对象)范围内绘制一个矩形.通过将线条和填充不透明度设置为零并提供自定义弹出窗口,您可以实现非常接近您想要的效果.我不知道有什么方法可以直接将超链接链接到R的传单中的栅格对象.
viewExtent
does as the name suggests draw a rectangle around the the extent of a raster image (or any spatial object form the sp package). By setting the line and fill opacity to zero and providing a custom popup you can achieve something that is pretty close to what you want. I am not aware of any way to directly link hyperlinks to raster objects in leaflet for R.
HTH, 蒂姆
这篇关于单击栅格图像时,R用于传单重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!