我正在用R构建一个Leaflet应用程序。
我想使用这个插件https://github.com/Turbo87/leaflet-sidebar,但是我不知道从哪里开始。
在R中实现Javascript Leaflet插件的指南并没有起到帮助作用。有谁有什么步骤/指南/代码可以让我在我的R宣传单中实现这个插件?任何帮助都将不胜感激。
这是我目前所在的位置:
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);
}")发布于 2020-02-11 18:20:52
也许你还没有解决你的问题。第一步是确保您的htmlDependency源代码确实存在。使用您的路径,我得到以下响应:{"error":"Not Found"}
jsdelivr以应用程序/javascript格式通过npm和github提供了大多数可用的js库。使用它而不是原始的github路径,您可以尝试:
sidebarPlugin <- htmltools::htmlDependency("L.Control.Sidebar", "0.2.1",
src = c(href = 'https://cdn.jsdelivr.net/gh/Turbo87/leaflet-sidebar@0.2.1/src'),
script = 'L.Control.Sidebar.js', stylesheet = 'L.Control.Sidebar.css')https://stackoverflow.com/questions/56773210
复制相似问题