0

I'm working on adding a WMTS layer to my R Leaflet map using this url:

https://mrdata.usgs.gov/mapcache/wmts?layer=alteration&service=WMTS&request=GetCapabilities&version=1.0.0

I add the url into my code under the "addWMSTiles" option in R Leaflet like such:

library(shiny)
library(leaflet)

ui <- shinyUI(
fluidPage(
    leafletOutput("map", width = "100%", height = "900px")
)
)

server <- function(input, output) {

output$map <- renderLeaflet({
    leaflet() %>%
        addTiles() %>%
        setView(-93.65, 42.0285, zoom = 4) %>%
        addWMSTiles("https://mrdata.usgs.gov/mapcache/wmts?layer=alteration&service=WMTS&request=GetCapabilities&version=1.0.0",
            layers = "sim3340",
            options = WMSTileOptions(format = "image/png", transparent = TRUE),
            attribution = "")
})
}

app <- shinyApp(ui = ui, server = server)
runApp(app, launch.browser = TRUE)

When I run this code the map will display in the browser but all that displays is the base leaflet (OpenStreets) Map (image below).

enter image description here

When there should be some coloring around CA and AZ since that's that WMTS layer is highlighting.

At first I thought it may be due to there being 3 different projection matrices in the WMTS layer but even if I call crs = "EPSG:6.3:3857" in the addWMSTiles options it still shows up as the base map.

What do I need to change or add to make this WMTS layer show up on the map?

Thank you and as always any help is appreciated!

1 Answer 1

0

This should do it. The call to your baseUrl was not correct.

library(shiny)
library(leaflet)

ui <- shinyUI(
  fluidPage(
    leafletOutput("map", width = "100%", height = "900px")
  )
)

server <- function(input, output) {

  output$map <- renderLeaflet({
    leaflet() %>%
      addTiles() %>%
      setView(-93.65, 42.0285, zoom = 4) %>%
      addWMSTiles(baseUrl = "https://mrdata.usgs.gov/mapcache/wms/",
                  layers = "sim3340",
                  options = WMSTileOptions(format = "image/png", transparent = TRUE),
                  attribution = "")
  })
}

app <- shinyApp(ui = ui, server = server)
runApp(app, launch.browser = TRUE)
2
  • Thank you! I see you're using the WMS layer...does leaflet in R not work with WMTS layers?
    – statsguy
    Jul 12, 2018 at 13:33
  • I think it is using the wms as a WMTS. If you zoom in, you will see different Tiles. Check out this page for further examples.
    – SeGa
    Jul 12, 2018 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.