作者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/m.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