R to redirect leaflets when clicking on a bitmap

I use a booklet for R, and I just want to be redirected to some URL when I click on the bitmap. My current code is as follows:

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 

The result is the following:

raster map

+2
source share
1 answer

You can use viewExtent from the mapview package for this:

 library(mapview) mapview(poppendorf[[10]]) + viewExtent(poppendorf[[10]], opacity = 0, fillOpacity = 0, popup = '<a href="http://www.google.com">Search Google</a>') 

viewExtent does, as the name suggests, draw a rectangle around the bitmap (or any feature that forms the sp package). By setting the line and filling the opacity to zero and providing a custom popup, you can achieve something that is very close to what you want. I do not know how to directly link hyperlinks to bitmap objects in a leaflet for R.

NTN, Tim

+5
source

All Articles