I am recently working on a project. Its one dimension is to make a leaflet map with different basemap layers. Here is the code so far;
library(leaflet)
library(leaflet.providers)
leaflet() %>%
addProviderTiles("OpenStreetMap", group = "OpenStreetMap") %>%
addProviderTiles("Esri.NatGeoWorldMap", group = "Esri.NatGeoWorldMap") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri.WorldStreetMap") %>%
addProviderTiles("Esri.WorldTopoMap", group = "Esri.WorldTopoMap") %>%
addProviderTiles("Esri.WorldImagery", group = "Esri.WorldImagery") %>%
addLayersControl(baseGroups = c("OpenStreetMap",
"Esri.NatGeoWorldMap", "Esri.WorldStreetMap",
"Esri.WorldTopoMap", "Esri.WorldImagery"),
position = "topleft")
this line of code provides me a working leaflet map. However when I add a different layer, namely TopPlusOpen.Color
as suggested in this website: https://leaflet-extras.github.io/leaflet-providers/preview/, the map does not show different layers it was showing previously and especially layers control on the top left side disappears. Here is the code for this error;
library(leaflet)
library(leaflet.providers)
leaflet() %>%
addProviderTiles("OpenStreetMap", group = "OpenStreetMap") %>%
addProviderTiles("TopPlusOpen.Color", group = "TopPlusOpen.Color") %>%
addProviderTiles("Esri.NatGeoWorldMap", group = "Esri.NatGeoWorldMap") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri.WorldStreetMap") %>%
addProviderTiles("Esri.WorldTopoMap", group = "Esri.WorldTopoMap") %>%
addProviderTiles("Esri.WorldImagery", group = "Esri.WorldImagery") %>%
addLayersControl(baseGroups = c("OpenStreetMap","TopPlusOpen.Color",
"Esri.NatGeoWorldMap", "Esri.WorldStreetMap",
"Esri.WorldTopoMap", "Esri.WorldImagery"),
position = "topleft")
I could not understand what causes this problem, as "TopPlusOpen.Color" is one of layers option and I look forward whether there are any similar layers to it that I can use. I appreciate any comments and suggestions and thank you beforehand.
It doesn't look like TopPlusOpen.Color
is one of the default providers included in the providers
list of the leaflet
package. That said, you can still use those tiles using the URL template provided at the website in your original question. Instead of using addProviderTiles()
, which fetches tiles from a pre-determined list of providers, you can add your own with addTiles()
and supplying the urlTemplate
argument (don't forget to attribute them properly!).
library(leaflet)
library(leaflet.providers)
leaflet() %>%
addProviderTiles("OpenStreetMap", group = "OpenStreetMap") %>%
addTiles(urlTemplate = 'http://sgx.geodatenzentrum.de/wmts_topplus_open/tile/1.0.0/web/default/WEBMERCATOR/{z}/{y}/{x}.png',
attribution = 'Map data: © <a href="http://www.govdata.de/dl-de/by-2-0">dl-de/by-2-0</a>',
group = "TopPlusOpen.Color") %>%
addProviderTiles("Esri.NatGeoWorldMap", group = "Esri.NatGeoWorldMap") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri.WorldStreetMap") %>%
addProviderTiles("Esri.WorldTopoMap", group = "Esri.WorldTopoMap") %>%
addProviderTiles("Esri.WorldImagery", group = "Esri.WorldImagery") %>%
addLayersControl(
baseGroups = c(
"OpenStreetMap",
"TopPlusOpen.Color",
"Esri.NatGeoWorldMap",
"Esri.WorldStreetMap",
"Esri.WorldTopoMap",
"Esri.WorldImagery"
),
position = "topleft"
)
The end result, with the TopPlusOpen.Color
basemap tiles active, looks like the following: