我正在R中构建一个Leaflet应用程序。
我想使用此插件https://github.com/Turbo87/leaflet-sidebar但是,我不知道从哪里开始。
关于在R中实现Javascript Leaflet插件的指南无法提供帮助。是否有人可以执行任何步骤/指导/代码来在我的R Leaflet中实现该插件?任何帮助将不胜感激。
这是我目前在的位置:
sidebarPlugin <- htmlDependency("leaflet-sidebar", "0.2.0",
src = c(href = "https://github.com/Turbo87/leaflet-sidebar.git"),
script = "src/L.Control.Sidebar.js")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map}
testLeaflet <- leaflet() %>%
addTiles %>%
addPolylines(data = dijkjson)%>%
#register plugin on this map instance
registerPlugin(sidebarPlugin)%>%
addControl("Test2", position = "topright")%>%
# Add your custom JS logic here. The `this` keyword
# refers to the Leaflet (JS) map object.
onRender("function(el, x) {
var sidebar = L.control.sidebar('sidebar', {
position: 'left'}).addTo(this);
map.addControl(sidebar).addTo(this);
sidebar.show().addTo(this);
}")
也许您还没有解决问题。第一步是确保您的htmlDependency源确实存在。使用您的路径,我得到以下响应:{“错误”:“找不到”}
jsdelivr提供了可通过npm和github以应用程序/ JavaScript格式使用的大多数js库。使用它而不是原始的github路径,您可以尝试:
sidebarPlugin <- htmltools::htmlDependency("L.Control.Sidebar", "0.2.1",
src = c(href = 'https://cdn.jsdelivr.net/gh/Turbo87/[email protected]/src'),
script = 'L.Control.Sidebar.js', stylesheet = 'L.Control.Sidebar.css')