Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank WMS Pop Up #4

Open
simon-tarr opened this issue Jul 30, 2020 · 3 comments
Open

Blank WMS Pop Up #4

simon-tarr opened this issue Jul 30, 2020 · 3 comments
Labels
upstream Bug in upstream repo

Comments

@simon-tarr
Copy link

simon-tarr commented Jul 30, 2020

Hello,

I'm trying to load some data on wetland areas into a Leaflet map and enable a popup when clicking various parts of the layer. I have studied the WMS XML file and I believe it's queryable, so I thought I would be able to implement this functionality with leaflet.extras2::addWMS(). I've included below a short code snippet showing what I'm up to. I was wondering if I've done something wrong or whether there's an issue with addWMS()? When I use the below code the pop up box is always empty.

NB. Please be patient for the map to load...the WMS server is pretty slow!

leaflet() %>%
            leaflet.extras2::addWMS(baseUrl = "https://environment.data.gov.uk/spatialdata/ramsar-england/wms", layers = "Ramsar_England", options = WMSTileOptions(
                                        transparent = TRUE,
                                        format = "image/png",
                                        info_format = "text/html")) %>% 
            setView(lng = -1.8, lat = 52.0, zoom = 5) 

Here's a link to the WMS XML data.

@trafficonese
Copy link
Owner

trafficonese commented Jul 31, 2020

This seems to be a Cross-Origin-problem and might have to be tackled in the underlying library.

Those are the errors I see in the browser console:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

@simon-tarr
Copy link
Author

Thanks for the reply. It's a shame that it's possibly an issue with leaflet.js....I'm assuming a reasonably quick fix for this is probably out of the question? I'm happy to raise an issue with the library team but not sure how best to word it. Are you able to assist?

@trafficonese
Copy link
Owner

If you need it only for local development, there is this Chrome plugin, which overwrites Access-Control-Allow-Origin.

The following shiny-app should work with activated CORS changer.

But including popupOptions seems to confuse the WMS. I'll push a fix in a bit.

The original problem has already an issue heigeo/leaflet.wms#65

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

ui <- fluidPage(
  leafletOutput("map")
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>%
      addWMS(baseUrl = "https://environment.data.gov.uk/spatialdata/ramsar-england/wms",
             layers = "Ramsar_England",
             #popupOptions = popupOptions(maxWidth = 820),
             options = WMSTileOptions(
               transparent = TRUE,
               info_format = "text/html",
               format = "image/png",
               tiled = FALSE
             )) %>% 
      setView(lng = -1.8, lat = 52.0, zoom = 5)
  })
}
shinyApp(ui, server)

@trafficonese trafficonese added the upstream Bug in upstream repo label Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Bug in upstream repo
Projects
None yet
Development

No branches or pull requests

2 participants