为了账号安全,请及时绑定邮箱和手机立即绑定

在 R Leaflet 中实现一个(javascript)插件

在 R Leaflet 中实现一个(javascript)插件

慕码人2483693 2023-02-23 10:05:52
我正在用 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);       }")
查看完整描述

1 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

也许你还没有解决你的问题。第一步是确保您的 htmlDependency 源确实存在。根据您的路径,我得到以下响应:{"error":"Not Found"}

jsdelivr以 application/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')



查看完整回答
反对 回复 2023-02-23
  • 1 回答
  • 0 关注
  • 86 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号