作者tytony (混沌的大气)
看板R_Language
标题[问题] R Leaflet读取JS plugin方法
时间Mon Mar 5 19:18:45 2018
[问题类型]:
经验谘询
[软体熟悉度]:
使用者(已经有用R 做过不少作品)
[问题叙述]:
各位好
最近在github找到在Leaflet画风标(windbarb)的JS套件
我照着在R Leaflet运用JS套件的方法去写程式码
执行之後地图可开启,但无法显示出风标,也没有任何错误讯息
不知从何处debug,感觉是JS部分没吃进去
恳请有用处理过类似语法的前辈指点,谢谢!
风标JS套件Github
https://github.com/JoranBeaufort/Leaflet.windbarb
R使用Leaflet JS套件方法
https://gist.github.com/jcheng5/c084a59717f18e947a17955007dc5f92
[程式范例]:
library(leaflet)
library(htmltools)
library(htmlwidgets)
windbarb <- htmlDependency("leaflet-windbarb", "0.0.1",
c(href =
"
https://github.com/JoranBeaufort/Leaflet.windbarb/blob/master/src/"),
script = "leaflet-windbarb.js")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
# 下面JS部分是直接拿风标github的范例语法
leaflet() %>% addTiles() %>% setView(7.222309, 47.11285, 12) %>%
registerPlugin(windbarb) %>%
onRender('function(el, x) {
var meteoPoints = [
[ 47.11285 , 7.222309, 5, 190],
[ 47.085272, 7.20377 , 30, 90],
[ 47.092285, 7.156734, 47, 170],
];
meteoPoints.forEach(function(p){
var icon = L.WindBarb.icon({deg: p[3], speed: p[2]});
var marker = L.marker([p[0],p[1]], {icon: icon}).addTo(this);
});')
[环境叙述]:
R 3.4.3 + Win 7
[关键字]:
Leaflet / Javascript
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.226.64.125
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1520248733.A.502.html
1F:→ Wush978: 你如果用浏览器开启後,再打开浏览器的javascript除错器 03/05 20:08
2F:→ Wush978: 有没有出现什麽错误讯息? 03/05 20:09
3F:→ tytony: Chrome显示its MIME type is not executable 03/05 20:23
4F:→ tytony: 另外还有找不到icon的属性 03/05 20:23
5F:→ tytony: 问题已经找到了 是scr网址写法有错导致失败 03/06 07:30