The Leaflet JS mapping library has lots of plugins available. The Leaflet package for R provides direct support for some, but far from all, of these plugins, by providing R functions for invoking the plugins.
If you as an R user find yourself wanting to use a Leaflet plugin that isn't directly supported in the R package, you can use the technique shown here to load the plugin yourself and invoke it using JS code.
Hi, many thanks for the above insight... Its aloud me to load the Bing "Roads" basemap quite nicely... But I'm having real trouble applying the grayscale plugin to that layer... (I've tried many different methods). Can anyone help? Many thanks, Richard.
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
bingPlugin <- htmlDependency("leaflet.plugins", "2.0.0",
src=c(href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-plugins/2.0.0/layer/tile/"),
script="Bing.min.js")
grayscalePlugin <- htmlDependency("leaflet-grayscale", "0.0.0" ,
src=c(href="https://github.com/Zverik/leaflet-grayscale"),
script="TileLayer.Grayscale.js")
leaflet() %>%
registerPlugin(grayscalePlugin) %>%
registerPlugin(bingPlugin) %>%
onRender("function(el, x) {
var imagerySet='Road';
var bing=new L.BingLayer.grayscale(
'IGQNg4zQGQnWnhrgeRtx~-_iDYzKzo9RJjvpr-6mMgg~AkD6k2dx3I-4tQgUUh1lITbm-ts2iumSNTmAd5qtIWCJPIoptszrzXs6-mk9_IcA',
{type: imagerySet});
this.addLayer(bing);
}") %>%
addPolygons(data=Building, color="black", fill=TRUE, fillColor="pink",
group="Building", opacity=0.3, weight=0.5)