Skip to content

Commit 9880888

Browse files
committed
adding Stadia Maps support
1 parent 9804754 commit 9880888

File tree

7 files changed

+59
-35
lines changed

7 files changed

+59
-35
lines changed

R/basemap.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @param ext extent to be covered by the basemap as any spatial class supported by \code{st_bbox}.
66
#' @param map_service character, a map service, either \code{"osm"}, \code{"carto"} or \code{"mapbox"}. Default is \code{"osm"}.
77
#' @param map_type character, a map type, e.g. \code{"streets"}. For a full list of available map types, see \code{\link{get_maptypes}}.
8-
#' @param map_token character, authentication token for services that require registration, which are \code{"osm_stamen"}, \code{"osm_thunderforest"} and \code{"mapbox"}. Register at \url{https://stadiamaps.com/} for stamen, \url{https://www.thunderforest.com/} and/or \url{https://www.mapbox.com/} to get tokens. Ignored for all other map services.
8+
#' @param map_token character, authentication token for services that require registration, which are \code{"osm_stamen"}, \code{"osm_stadia"}, \code{"osm_thunderforest"} and \code{"mapbox"}. Register at \url{https://stadiamaps.com/} (for stamen and stadia), \url{https://www.thunderforest.com/} and/or \url{https://www.mapbox.com/} to get tokens. Ignored for all other map services.
99
#' @param map_res numeric, resolution of base map in range from 0 to 1.
1010
#' @param map_dir character, cache directory where downloaded basemap tiles will be stored. By default, a temporary directory is used, which is destroyed when the session is terminated.
1111
#' @param class character, output class, either either \code{plot} (default), \code{magick}, \code{png}, \code{geotif} or if suggested packages are installed, \code{terra}, \code{raster}, \code{stars}, \code{ggplot}, \code{gglayer} or \code{mapview}.
@@ -38,7 +38,7 @@
3838
#'
3939
#' # set defaults for the basemap
4040
#' set_defaults(map_service = "osm", map_type = "terrain_bg")
41-
#' # for osm_stamen, osm thunderforest and mapbox maps, you need a API token.
41+
#' # for "osm_stamen", "osm_stadia", osm "thunderforest" and "mapbox" maps, you need a API token.
4242
#' # Register for free at stadiamaps.com, thunderforest.com and mapbox.com to get tokens.
4343
#'
4444
#' \dontrun{
@@ -106,6 +106,7 @@ basemap <- function(ext = NULL, map_service = NULL, map_type = NULL, map_res = N
106106
if(map_service == "mapbox" & is.na(map_token)) out("You need to define 'map_token' to use map_service 'mapbox'. Register at https://www.mapbox.com/ to obtain a token.", type = 3)
107107
if(map_service == "osm_thunderforest" & is.na(map_token)) out("You need to define 'map_token' to use map_service 'osm_thunderforest'. Register at https://thunderforest.com to obtain a token.", type = 3)
108108
if(map_service == "osm_stamen" & is.na(map_token)) out("You need to define 'map_token' to use map_service 'osm_stamen'. Register at https://stadiamaps.com to obtain a token.", type = 3)
109+
if(map_service == "osm_stadia" & is.na(map_token)) out("You need to define 'map_token' to use map_service 'osm_stadia'. Register at https://stadiamaps.com to obtain a token.", type = 3)
109110

110111
extras <- list(...)
111112
if(!is.null(extras$browse)) browse <- extras$browse else browse <- TRUE

R/get_maptypes.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' This function returns every supported map type that can be used as input to the \code{map_type} argument of \code{\link{set_defaults}}, \code{\link{basemap}} or associated functions.
44
#'
5-
#' @param map_service character, optional, either \code{"osm"}, \code{"osm_stamen"}, \code{"osm_thunderforest"}, \code{"carto"}, \code{"mapbox"} or \code{"esri"}. Otherwise, a list of map types for both services is returned.
5+
#' @param map_service character, optional, either \code{"osm"}, \code{"osm_stamen"}, \code{"osm_stadia"}, \code{"osm_thunderforest"}, \code{"carto"}, \code{"mapbox"} or \code{"esri"}. Otherwise, a list of map types for both services is returned.
66
#' @return A character vector of supported map types
77
#'
88
#'
@@ -12,6 +12,8 @@
1212
#'
1313
#' \code{"osm_stamen"}: Stamen (\url{https://maps.stamen.com/}) via Stadia Maps (\url{https://stadiamaps.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright})
1414
#'
15+
#' \code{"osm_stadia"}: Stadia Maps (\url{https://stadiamaps.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright})
16+
#'
1517
#' \code{"osm_thunderforest"}: Thunderforest (\url{https://www.thunderforest.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright})
1618
#'
1719
#' \code{"carto"}: Carto (\url{https://carto.com/})

R/internal.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,14 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge
175175
if(any(map_service != "mapbox", all(map_service == "mapbox", map_type == "terrain"))) ".png", # file suffix or not
176176
if(map_service == "mapbox") paste0("?access_token=", map_token), # token or not
177177
if(map_service == "osm_thunderforest") paste0("?apikey=", map_token), # token or not
178-
if(map_service == "osm_stamen") paste0("?api_key=", map_token) # token or not
178+
if(map_service == "osm_stamen") paste0("?api_key=", map_token), # token or not
179+
if(map_service == "osm_stadia") paste0("?api_key=", map_token) # token or not
179180
)
180181

181182
if(isTRUE(http_error(url))){
182183
resp <- GET(url)
183184
status <- resp$status_code
184-
if(any(status == 401 & map_service == "mapbox", status == 401 & map_service == "osm_stamen")) out("Authentification failed. Is your map_token correct?", type = 3)
185+
if(any(status == 401 & map_service == "mapbox", status == 401 & map_service == "osm_stamen", status == 401 & map_service == "osm_stadia")) out("Authentification failed. Is your map_token correct?", type = 3)
185186
if(status == 403 & map_service == "osm_thunderforest") out("Authentification failed. Is your map_token correct?", type = 3)
186187
}
187188
if(!file.exists(file)){
@@ -399,7 +400,14 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge
399400
.md_maptypes_table <- function(maptypes){
400401
x <- paste0(lapply(names(maptypes), function(service){
401402
paste0(unlist(lapply(maptypes[[service]], function(x, s = service){
402-
paste0("| `", s, "` | `", x, "` | ", if(any(grepl("mapbox", s), grepl("osm_thunderforest", s), grepl("osm_stamen", s))) "yes" else "no", " |")
403+
token <- if(grepl("mapbox", s)){
404+
"yes, register: https://mapbox.com"
405+
} else if(grepl("osm_thunderforest", s)){
406+
"yes, register: https://www.thunderforest.com/"
407+
} else if(any(grepl("osm_stamen", s), grepl("osm_stadia", s))){
408+
"yes, register: https://stadiamaps.com/"
409+
} else "no"
410+
paste0("| `", s, "` | `", x, "` | ", token, " |")
403411
})), collapse = "\n")
404412
}), collapse = "\n")
405413
cat(paste0("| `map_service` | `map_type` | `map_token` required? |\n | ------ | ------ | ------ |\n", x))
@@ -457,6 +465,12 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge
457465
terrain_bg = "https://tiles.stadiamaps.com/tiles/stamen_terrain_background/",
458466
watercolor = "https://tiles.stadiamaps.com/tiles/stamen_watercolor/"
459467
),
468+
osm_stadia = c(
469+
alidade_smooth = "https://tiles.stadiamaps.com/tiles/alidade_smooth/",
470+
alidade_smooth_dark = "https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/",
471+
outdoors = "https://tiles.stadiamaps.com/tiles/outdoors/",
472+
osm_bright = "https://tiles.stadiamaps.com/tiles/osm_bright/"
473+
),
460474
osm_thunderforest = list(
461475
cycle = "https://tile.thunderforest.com/cycle/",
462476
transport = "https://tile.thunderforest.com/transport/",
@@ -517,7 +531,8 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge
517531
world_reference_overlay = "https://services.arcgisonline.com/arcgis/rest/services/Reference/World_Reference_Overlay/MapServer/tile/",
518532
world_transportation = "https://services.arcgisonline.com/arcgis/rest/services/Reference/World_Transportation/MapServer/tile/",
519533
delorme_world_base_map = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/DeLorme_World_Base_Map/MapServer/tile/",
520-
world_navigation_charts = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/World_Navigation_Charts/MapServer/tile/")
534+
world_navigation_charts = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/World_Navigation_Charts/MapServer/tile/"
535+
)
521536
))
522537
if(!dir.exists(getOption("basemaps.defaults")$map_dir)) dir.create(getOption("basemaps.defaults")$map_dir)
523538

README.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![Coverage](https://codecov.io/gh/16eagle/basemaps/branch/master/graph/badge.svg)](https://app.codecov.io/gh/16EAGLE/basemaps)
99
[![Package dependencies](https://tinyverse.netlify.com/badge/basemaps)](https://CRAN.R-project.org/package=basemaps)
1010

11-
`basemaps` is a lightweight `R` package to download and cache spatial basemaps from open sources such as *OpenStreetMap*, *Stamen/Stadia Maps*, *Thunderforest*, *Carto*, *Mapbox* and others. Retrieved basemaps are translated into and returned as classes of choice, such as `raster`, `stars`, `terra`, `ggplot`, `mapview`, `magick`, or as files, such as `png` or `geotif`. The package aims to ease the use of basemaps in different contexts by providing a function interface as minimalist as possible.
11+
`basemaps` is a lightweight `R` package to download and cache spatial basemaps from open sources such as *OpenStreetMap*, *Stamen*, *Stadia*, *Thunderforest*, *Carto*, *Mapbox*, *Esri* and others. Retrieved basemaps are translated into and returned as classes of choice, such as `terra`, `stars`, `raster`, `ggplot`, `mapview`, `magick`, or as files, such as `png` or `geotif`. The package aims to ease the use of basemaps in different contexts by providing a function interface as minimalist as possible.
1212

1313

1414
## Installation
@@ -203,21 +203,25 @@ This table lists all currently implemented map services and map types and indica
203203
| `osm` | `streets` | no |
204204
| `osm` | `streets_de` | no |
205205
| `osm` | `topographic` | no |
206-
| `osm_stamen` | `toner` | yes |
207-
| `osm_stamen` | `toner_bg` | yes |
208-
| `osm_stamen` | `terrain` | yes |
209-
| `osm_stamen` | `terrain_bg` | yes |
210-
| `osm_stamen` | `watercolor` | yes |
211-
| `osm_thunderforest` | `cycle` | yes |
212-
| `osm_thunderforest` | `transport` | yes |
213-
| `osm_thunderforest` | `landscape` | yes |
214-
| `osm_thunderforest` | `outdoors` | yes |
215-
| `osm_thunderforest` | `transport_dark` | yes |
216-
| `osm_thunderforest` | `spinal` | yes |
217-
| `osm_thunderforest` | `pioneer` | yes |
218-
| `osm_thunderforest` | `mobile_atlas` | yes |
219-
| `osm_thunderforest` | `neighbourhood` | yes |
220-
| `osm_thunderforest` | `atlas` | yes |
206+
| `osm_stamen` | `toner` | yes, register: https://stadiamaps.com/ |
207+
| `osm_stamen` | `toner_bg` | yes, register: https://stadiamaps.com/ |
208+
| `osm_stamen` | `terrain` | yes, register: https://stadiamaps.com/ |
209+
| `osm_stamen` | `terrain_bg` | yes, register: https://stadiamaps.com/ |
210+
| `osm_stamen` | `watercolor` | yes, register: https://stadiamaps.com/ |
211+
| `osm_stadia` | `alidade_smooth` | yes, register: https://stadiamaps.com/ |
212+
| `osm_stadia` | `alidade_smooth_dark` | yes, register: https://stadiamaps.com/ |
213+
| `osm_stadia` | `outdoors` | yes, register: https://stadiamaps.com/ |
214+
| `osm_stadia` | `osm_bright` | yes, register: https://stadiamaps.com/ |
215+
| `osm_thunderforest` | `cycle` | yes, register: https://www.thunderforest.com/ |
216+
| `osm_thunderforest` | `transport` | yes, register: https://www.thunderforest.com/ |
217+
| `osm_thunderforest` | `landscape` | yes, register: https://www.thunderforest.com/ |
218+
| `osm_thunderforest` | `outdoors` | yes, register: https://www.thunderforest.com/ |
219+
| `osm_thunderforest` | `transport_dark` | yes, register: https://www.thunderforest.com/ |
220+
| `osm_thunderforest` | `spinal` | yes, register: https://www.thunderforest.com/ |
221+
| `osm_thunderforest` | `pioneer` | yes, register: https://www.thunderforest.com/ |
222+
| `osm_thunderforest` | `mobile_atlas` | yes, register: https://www.thunderforest.com/ |
223+
| `osm_thunderforest` | `neighbourhood` | yes, register: https://www.thunderforest.com/ |
224+
| `osm_thunderforest` | `atlas` | yes, register: https://www.thunderforest.com/ |
221225
| `carto` | `light` | no |
222226
| `carto` | `light_no_labels` | no |
223227
| `carto` | `light_only_labels` | no |
@@ -228,13 +232,13 @@ This table lists all currently implemented map services and map types and indica
228232
| `carto` | `voyager_no_labels` | no |
229233
| `carto` | `voyager_only_labels` | no |
230234
| `carto` | `voyager_labels_under` | no |
231-
| `mapbox` | `streets` | yes |
232-
| `mapbox` | `outdoors` | yes |
233-
| `mapbox` | `light` | yes |
234-
| `mapbox` | `dark` | yes |
235-
| `mapbox` | `satellite` | yes |
236-
| `mapbox` | `hybrid` | yes |
237-
| `mapbox` | `terrain` | yes |
235+
| `mapbox` | `streets` | yes, register: https://mapbox.com |
236+
| `mapbox` | `outdoors` | yes, register: https://mapbox.com |
237+
| `mapbox` | `light` | yes, register: https://mapbox.com |
238+
| `mapbox` | `dark` | yes, register: https://mapbox.com |
239+
| `mapbox` | `satellite` | yes, register: https://mapbox.com |
240+
| `mapbox` | `hybrid` | yes, register: https://mapbox.com |
241+
| `mapbox` | `terrain` | yes, register: https://mapbox.com |
238242
| `esri` | `natgeo_world_map` | no |
239243
| `esri` | `usa_topo_maps` | no |
240244
| `esri` | `world_imagery` | no |

man/basemap.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/defaults.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_maptypes.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)