R的Leaflet中的openweathermap天气瓷砖 [英] openweathermap weather tile in Leaflet in R
问题描述
我正在尝试使用 leaflet-openweathermap
javascript在Shiny应用程序中的宣传单
地图上添加自定义天气图块图书馆提供
I am trying to add custom weather tiles on a leaflet
map in a Shiny application using leaflet-openweathermap
javascript library available here. I am not conversant with javascript and the map doesn't render the weather layers.
I first downloaded leaflet-openweathermap.js
and placed it in www/js
folder in my app's path. I then registered the plugin:
openWeatherPlugin <- htmlDependency(
"Leaflet.OpenWeather",
"1.6.0",
src = normalizePath(path = getwd()),
script = "www/js/leaflet.openweathermap.js"
)
To render a weather layer on leaflet, this is what I tried:
leaflet() %>%
addTiles() %>%
registerPlugin(openWeatherPlugin) %>%
onRender("
function(el, x){
L.OWM.clouds({showLegend: true, opacity: 0.5, appId: 'MY_APP_ID'})
}
")
MY_APP_ID
is a valid ID obtained from openweathermap.org
However the above code doesn't generate the desired weather layer of clouds. I am not conversant with javascript and don't know what's wrong with this code. Appreciate some help please.
What if you add .addTo(this);
in the onRender
call, like:
onRender("function(el, x){
L.OWM.clouds({showLegend: true, opacity: 0.5, appId: 'MY_APP_ID'}).addTo(this);
}
")
and the javascript file is called leaflet-openweathermap.js
and you've got leaflet.openweathermap.js
or did you change to hyphen to a point?
I am not getting any clouds with your API key. So I dont think the ID is valid, since I'm getting this msg in the console.
[HTTP/1.1 401 Unauthorized 99ms]
The appId
is your private key, not the name.
It works with a working key.
这篇关于R的Leaflet中的openweathermap天气瓷砖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!