[問題類型]:
經驗諮詢
[軟體熟悉度]:
使用者(已經有用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