首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在R Leaflet中实现(javascript)插件

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

Stack Overflow用户
提问于 2019-06-26 20:47:02
回答 1查看 242关注 0票数 1

我正在用R构建一个Leaflet应用程序。

我想使用这个插件https://github.com/Turbo87/leaflet-sidebar,但是我不知道从哪里开始。

在R中实现Javascript Leaflet插件的指南并没有起到帮助作用。有谁有什么步骤/指南/代码可以让我在我的R宣传单中实现这个插件?任何帮助都将不胜感激。

这是我目前所在的位置:

代码语言:javascript
复制
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);
       }")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-11 18:20:52

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

jsdelivr以应用程序/javascript格式通过npm和github提供了大多数可用的js库。使用它而不是原始的github路径,您可以尝试:

代码语言:javascript
复制
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')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56773210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档