leaflet.extras2 icon indicating copy to clipboard operation
leaflet.extras2 copied to clipboard

Blank WMS Pop Up

Open simon-tarr opened this issue 3 years ago • 3 comments

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.

simon-tarr avatar Jul 30 '20 12:07 simon-tarr

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

trafficonese avatar Jul 31 '20 06:07 trafficonese

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?

simon-tarr avatar Jul 31 '20 08:07 simon-tarr

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 https://github.com/heigeo/leaflet.wms/issues/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 avatar Jul 31 '20 13:07 trafficonese