trafficonese / leaflet.extras2

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras2/
GNU General Public License v3.0
85 stars 19 forks source link

Problems with getFeatureInfo #14

Open Rudolf-May opened 3 years ago

Rudolf-May commented 3 years ago

Hallo trafficonese,

I had been very happy when i found your plugin for leaflet which enables to retrieve the feature info from a wms when clicking on some feature of a wms layer. It worked perfectly when I tested this in my local RStudio environment. But - when I upload the app to my productive server (where shiny server is configured to run behind an apache proxy) I get blank popups instead of the feature information. This is my simplified code for testing (you can try it here: https://floraweb.de/shiny/wmstest):

library(leaflet)
library(leaflet.extras)
library(leaflet.extras2)
library(shiny)

ui <- fluidPage(
  leafletOutput("myMap", height = "600"))

server <- function(input, output, session) {
  output$myMap <- renderLeaflet(leaflet() %>% 
                    setView(lng=10,lat=51.2, zoom = 6) %>% addTiles(group = "OSM") %>%
                    addProviderTiles(providers$OpenTopoMap, group = "Topo") %>%
                    addProviderTiles(providers$Esri.WorldImagery, group = "ESRI Sat") %>%
                    addWMS(baseUrl = "http://geodienste.bfn.de/ogc/wms/schutzgebiet?",
                           group="NP",
                           layers = "Nationalparke",
                           options = WMSTileOptions(format="image/png",transparent=TRUE,opacity=0.7,info_format = "text/html",tiled = FALSE),
                           attribution = "Overlaykarten: (c) Bundesamt für Naturschutz (BfN) 2015") %>%
                    addWMS(baseUrl = "http://geodienste.bfn.de/ogc/wms/schutzgebiet?",
                           group="BSR",
                           layers = "Biosphaerenreservate",
                           options = WMSTileOptions(transparent = TRUE,opacity=0.7,format = "image/png",info_format = "text/html",tiled = FALSE),
                           attribution = "Overlaykarten: (c) Bundesamt für Naturschutz (BfN) 2015" ) %>%
                    addWMS(baseUrl = "http://geodienste.bfn.de/ogc/wms/gliederungen?",
                           group="RGL",
                           layers = "Naturraeume",
                           options = WMSTileOptions(format="image/png",transparent=TRUE,opacity=0.7,info_format = "text/html",tiled = FALSE),
                           attribution = "Overlaykarten: (c) Bundesamt für Naturschutz (BfN) 2015" ) %>%
                    addWMS(baseUrl = "http://sg.geodatenzentrum.de/wms_vg250-ew?",
                           group="VG250",
                           layers = "vg250_krs",
                           options = WMSTileOptions(format="image/png",transparent=TRUE,opacity=0.7,info_format = "text/html",tiled = FALSE),
                           attribution = "Overlaykarte: (c) Bundesamt für Kartographie und Geodäsie (BKG) 2014" ) %>%
                    addLayersControl(
                          baseGroups = c("OSM", "Topo", "ESRI Sat"),
                          overlayGroups = c("NP","BSR","RGL","VG250"),
                          options = layersControlOptions(collapsed = TRUE)) %>%
                    hideGroup("NP") %>% hideGroup("BSR") %>% hideGroup("RGL") %>% hideGroup("VG250") %>%
                    addResetMapButton()
        )
}
shinyApp(ui, server)

I would be very happy if you could help to find out what might be the reason for this (I have read the issue #4, but this did'nt put me on the right track...

Rudolf-May commented 3 years ago

I think I have located the cause of the problem. Having a shiny-server working behind an apache proxy a response status code "301 moved permanently" is returned by the shiny-server. In the source code of the wms.leaflet plugin there is a helper function to return the "request.responseText" when the request.status === 200 (line 484 of the source on github). So in the scenario with the apache proxy the responseText will not be returned. The getfeatureinfo works as expected when the example app in my first post is served directly from the shiny server which then gives us a response status code 200. I have posted an issue on the github page https://github.com/heigeo/leaflet.wms/issues asking to add request.status===301. If this will be accepted I would kindly ask to provide an updated version of the leaflet.extras2 package. Beste regards Rudolf

trafficonese commented 3 years ago

Hey, thank you very much for digging into this. I'll just link the issue here (https://github.com/heigeo/leaflet.wms/issues/72)

Did you try it out with accepting the response code 301?

Rudolf-May commented 3 years ago

Hey, thank you very much for digging into this. I'll just link the issue here (heigeo/leaflet.wms#72)

Did you try it out with accepting the response code 301?

No, that is beyond my abilities since I am not fit in writing javascript code, though I can read and grasp most of what the code is meant to produce...

trafficonese commented 3 years ago

I uploaded a new branch, which accepts the request code 200 and 301.

You can install it with: remotes::install_github("trafficonese/leaflet.extras2@wms_301")

Could you please check if that works?