javascript - 在 R Leaflet 中实现 (javascript) 插件

标签 javascript java r plugins leaflet

我正在 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 以 application/javascript 格式提供大多数可用的 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')

关于javascript - 在 R Leaflet 中实现 (javascript) 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56773210/

相关文章:

Javascript 模式匹配矩阵

r - get_map 未传递 API key (HTTP 状态为 '403 Forbidden' )

regex - 从 R 中的字符串中删除反斜杠

java - 调用 spring-boot API 时出现状态码 404,但不适用于 postman 或浏览器

Java程序双击无法运行

java - 在多线程环境中设置对象字段

r - 是否可以强制 R 计算大数?

javascript - 为什么我的 HTML 页面在新打开的浏览器窗口中是空的?

javascript - localStorage 删除一个值并保留现有值

javascript - RegExp 匹配不带引号的单引号文本 - JavaScript