javascript - R 中 Leaflet 中的 openweathermap 天气图 block

标签 javascript r openweathermap htmlwidgets r-leaflet

我正在尝试使用可用的 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/

相关文章:

javascript - jQuery .wrap() 无需重新聚焦

javascript - D3 多力定向图

image - OSX 中的 tiff() 分辨率和压缩设置不可靠

ios - 如何在 Swift 2.0 中从数组内部的数组中提取 JSON 数据

javascript - 如何在不使用 SVG 图像的情况下使用带有文本的 React 创建圆形/方形?

javascript - 在动态标记上使用事件

r - 基于成对距离的聚类组

r - ggplot删除特定的x轴标签

javascript - React - 使用用户输入进行 API 调用的正确方法是什么?

javascript - 使用 Openweathermap API 出现找不到 http 错误