代码之家  ›  专栏  ›  技术社区  ›  Dhiraj

openweathermap在R中的单张中的天气瓷砖

  •  1
  • Dhiraj  · 技术社区  · 7 年前

    leaflet 在闪亮的应用程序中使用 leaflet-openweathermap 可用的javascript库 here

    我第一次下载 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 然而,上面的代码并没有生成所需的天气云层。我不熟悉javascript,也不知道这段代码有什么问题。谢谢你的帮助。

    2 回复  |  直到 7 年前
        1
  •  1
  •   SeGa    7 年前

    如果你加上 .addTo(this); 在 onRender

      onRender("function(el, x){
              L.OWM.clouds({showLegend: true, opacity: 0.5, appId: 'MY_APP_ID'}).addTo(this);
            }
           ")
    

    javascript文件被称为 leaflet-openweathermap.js leaflet.openweathermap.js 或者你改成连字符了?

    这个 appId 是你的私钥,不是名字。

    enter image description here

        2
  •  4
  •   beroe    7 年前

    addProviderTiles 函数而不是原始javascript或openweather库。为此我不得不加上 apiKey 在内部 providerTileOptions

    mw = leaflet() %>%
        addProviderTiles(providers$CartoDB.Positron) %>%
        setView(-122.36075812146, 35.6759920119894, zoom = 11) %>% 
        addProviderTiles(providers$OpenWeatherMap.Wind,  
            options=providerTileOptions(apiKey="<myAPIkey>"))              
    
    mw