我正在尝试使用可用的 leaflet-openweathermap
javascript 库在 Shiny 应用程序的 leaflet
map 上添加自定义天气图 block here .我不熟悉 javascript,而且 map 不会渲染天气图层。
我首先下载了 leaflet-openweathermap.js
并将其放在我应用程序路径中的 www/js
文件夹中。然后我注册了插件:
openWeatherPlugin <- htmlDependency(
"Leaflet.OpenWeather",
"1.6.0",
src = normalizePath(path = getwd()),
script = "www/js/leaflet.openweathermap.js"
)
要在传单上渲染天气层,这是我尝试过的:
leaflet() %>%
addTiles() %>%
registerPlugin(openWeatherPlugin) %>%
onRender("
function(el, x){
L.OWM.clouds({showLegend: true, opacity: 0.5, appId: 'MY_APP_ID'})
}
")
MY_APP_ID
是从 openweathermap.org 获得的有效 ID
但是,上面的代码不会生成所需的云天气层。我不熟悉 javascript,也不知道这段代码有什么问题。感谢您的帮助。
最佳答案
我正在使用 addProviderTiles
函数而不是原始 javascript 或 openweather 库。为此,我必须在我的 OpenWeatherMap 帐户的 providerTileOptions
中添加 apiKey
:
mw = leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
setView(-122.36075812146, 35.6759920119894, zoom = 11) %>%
addProviderTiles(providers$OpenWeatherMap.Wind,
options=providerTileOptions(apiKey="<myAPIkey>"))
mw
关于javascript - R 中 Leaflet 中的 openweathermap 天气图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53137105/