diff --git a/R/basemap.R b/R/basemap.R index 30e4769..98b4f2e 100644 --- a/R/basemap.R +++ b/R/basemap.R @@ -5,7 +5,7 @@ #' @param ext extent to be covered by the basemap as any spatial class supported by \code{st_bbox}. #' @param map_service character, a map service, either \code{"osm"}, \code{"carto"} or \code{"mapbox"}. Default is \code{"osm"}. #' @param map_type character, a map type, e.g. \code{"streets"}. For a full list of available map types, see \code{\link{get_maptypes}}. -#' @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. +#' @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. #' @param map_res numeric, resolution of base map in range from 0 to 1. #' @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. #' @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 @@ #' #' # set defaults for the basemap #' set_defaults(map_service = "osm", map_type = "terrain_bg") -#' # for osm_stamen, osm thunderforest and mapbox maps, you need a API token. +#' # for "osm_stamen", "osm_stadia", osm "thunderforest" and "mapbox" maps, you need a API token. #' # Register for free at stadiamaps.com, thunderforest.com and mapbox.com to get tokens. #' #' \dontrun{ @@ -106,6 +106,7 @@ basemap <- function(ext = NULL, map_service = NULL, map_type = NULL, map_res = N 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) 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) 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) + 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) extras <- list(...) if(!is.null(extras$browse)) browse <- extras$browse else browse <- TRUE diff --git a/R/get_maptypes.R b/R/get_maptypes.R index 51a16e9..6401877 100644 --- a/R/get_maptypes.R +++ b/R/get_maptypes.R @@ -2,7 +2,7 @@ #' #' 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. #' -#' @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. +#' @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. #' @return A character vector of supported map types #' #' @@ -12,6 +12,8 @@ #' #' \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}) #' +#' \code{"osm_stadia"}: Stadia Maps (\url{https://stadiamaps.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright}) +#' #' \code{"osm_thunderforest"}: Thunderforest (\url{https://www.thunderforest.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright}) #' #' \code{"carto"}: Carto (\url{https://carto.com/}) diff --git a/R/internal.R b/R/internal.R index 38e50ef..c9fa345 100644 --- a/R/internal.R +++ b/R/internal.R @@ -175,13 +175,14 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge if(any(map_service != "mapbox", all(map_service == "mapbox", map_type == "terrain"))) ".png", # file suffix or not if(map_service == "mapbox") paste0("?access_token=", map_token), # token or not if(map_service == "osm_thunderforest") paste0("?apikey=", map_token), # token or not - if(map_service == "osm_stamen") paste0("?api_key=", map_token) # token or not + if(map_service == "osm_stamen") paste0("?api_key=", map_token), # token or not + if(map_service == "osm_stadia") paste0("?api_key=", map_token) # token or not ) if(isTRUE(http_error(url))){ resp <- GET(url) status <- resp$status_code - if(any(status == 401 & map_service == "mapbox", status == 401 & map_service == "osm_stamen")) out("Authentification failed. Is your map_token correct?", type = 3) + 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) if(status == 403 & map_service == "osm_thunderforest") out("Authentification failed. Is your map_token correct?", type = 3) } if(!file.exists(file)){ @@ -399,7 +400,14 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge .md_maptypes_table <- function(maptypes){ x <- paste0(lapply(names(maptypes), function(service){ paste0(unlist(lapply(maptypes[[service]], function(x, s = service){ - paste0("| `", s, "` | `", x, "` | ", if(any(grepl("mapbox", s), grepl("osm_thunderforest", s), grepl("osm_stamen", s))) "yes" else "no", " |") + token <- if(grepl("mapbox", s)){ + "yes, register: https://mapbox.com" + } else if(grepl("osm_thunderforest", s)){ + "yes, register: https://www.thunderforest.com/" + } else if(any(grepl("osm_stamen", s), grepl("osm_stadia", s))){ + "yes, register: https://stadiamaps.com/" + } else "no" + paste0("| `", s, "` | `", x, "` | ", token, " |") })), collapse = "\n") }), collapse = "\n") 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 terrain_bg = "https://tiles.stadiamaps.com/tiles/stamen_terrain_background/", watercolor = "https://tiles.stadiamaps.com/tiles/stamen_watercolor/" ), + osm_stadia = c( + alidade_smooth = "https://tiles.stadiamaps.com/tiles/alidade_smooth/", + alidade_smooth_dark = "https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/", + outdoors = "https://tiles.stadiamaps.com/tiles/outdoors/", + osm_bright = "https://tiles.stadiamaps.com/tiles/osm_bright/" + ), osm_thunderforest = list( cycle = "https://tile.thunderforest.com/cycle/", transport = "https://tile.thunderforest.com/transport/", @@ -517,7 +531,8 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge world_reference_overlay = "https://services.arcgisonline.com/arcgis/rest/services/Reference/World_Reference_Overlay/MapServer/tile/", world_transportation = "https://services.arcgisonline.com/arcgis/rest/services/Reference/World_Transportation/MapServer/tile/", delorme_world_base_map = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/DeLorme_World_Base_Map/MapServer/tile/", - world_navigation_charts = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/World_Navigation_Charts/MapServer/tile/") + world_navigation_charts = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/World_Navigation_Charts/MapServer/tile/" + ) )) if(!dir.exists(getOption("basemaps.defaults")$map_dir)) dir.create(getOption("basemaps.defaults")$map_dir) diff --git a/README.md b/README.md index ec3505d..e89402a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Coverage](https://codecov.io/gh/16eagle/basemaps/branch/master/graph/badge.svg)](https://app.codecov.io/gh/16EAGLE/basemaps) [![Package dependencies](https://tinyverse.netlify.com/badge/basemaps)](https://CRAN.R-project.org/package=basemaps) -`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. +`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. ## Installation @@ -203,21 +203,25 @@ This table lists all currently implemented map services and map types and indica | `osm` | `streets` | no | | `osm` | `streets_de` | no | | `osm` | `topographic` | no | -| `osm_stamen` | `toner` | yes | -| `osm_stamen` | `toner_bg` | yes | -| `osm_stamen` | `terrain` | yes | -| `osm_stamen` | `terrain_bg` | yes | -| `osm_stamen` | `watercolor` | yes | -| `osm_thunderforest` | `cycle` | yes | -| `osm_thunderforest` | `transport` | yes | -| `osm_thunderforest` | `landscape` | yes | -| `osm_thunderforest` | `outdoors` | yes | -| `osm_thunderforest` | `transport_dark` | yes | -| `osm_thunderforest` | `spinal` | yes | -| `osm_thunderforest` | `pioneer` | yes | -| `osm_thunderforest` | `mobile_atlas` | yes | -| `osm_thunderforest` | `neighbourhood` | yes | -| `osm_thunderforest` | `atlas` | yes | +| `osm_stamen` | `toner` | yes, register: https://stadiamaps.com/ | +| `osm_stamen` | `toner_bg` | yes, register: https://stadiamaps.com/ | +| `osm_stamen` | `terrain` | yes, register: https://stadiamaps.com/ | +| `osm_stamen` | `terrain_bg` | yes, register: https://stadiamaps.com/ | +| `osm_stamen` | `watercolor` | yes, register: https://stadiamaps.com/ | +| `osm_stadia` | `alidade_smooth` | yes, register: https://stadiamaps.com/ | +| `osm_stadia` | `alidade_smooth_dark` | yes, register: https://stadiamaps.com/ | +| `osm_stadia` | `outdoors` | yes, register: https://stadiamaps.com/ | +| `osm_stadia` | `osm_bright` | yes, register: https://stadiamaps.com/ | +| `osm_thunderforest` | `cycle` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `transport` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `landscape` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `outdoors` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `transport_dark` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `spinal` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `pioneer` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `mobile_atlas` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `neighbourhood` | yes, register: https://www.thunderforest.com/ | +| `osm_thunderforest` | `atlas` | yes, register: https://www.thunderforest.com/ | | `carto` | `light` | no | | `carto` | `light_no_labels` | no | | `carto` | `light_only_labels` | no | @@ -228,13 +232,13 @@ This table lists all currently implemented map services and map types and indica | `carto` | `voyager_no_labels` | no | | `carto` | `voyager_only_labels` | no | | `carto` | `voyager_labels_under` | no | -| `mapbox` | `streets` | yes | -| `mapbox` | `outdoors` | yes | -| `mapbox` | `light` | yes | -| `mapbox` | `dark` | yes | -| `mapbox` | `satellite` | yes | -| `mapbox` | `hybrid` | yes | -| `mapbox` | `terrain` | yes | +| `mapbox` | `streets` | yes, register: https://mapbox.com | +| `mapbox` | `outdoors` | yes, register: https://mapbox.com | +| `mapbox` | `light` | yes, register: https://mapbox.com | +| `mapbox` | `dark` | yes, register: https://mapbox.com | +| `mapbox` | `satellite` | yes, register: https://mapbox.com | +| `mapbox` | `hybrid` | yes, register: https://mapbox.com | +| `mapbox` | `terrain` | yes, register: https://mapbox.com | | `esri` | `natgeo_world_map` | no | | `esri` | `usa_topo_maps` | no | | `esri` | `world_imagery` | no | diff --git a/man/basemap.Rd b/man/basemap.Rd index ef505f0..3e9d7cf 100644 --- a/man/basemap.Rd +++ b/man/basemap.Rd @@ -156,7 +156,7 @@ basemap_mapview( \item{map_res}{numeric, resolution of base map in range from 0 to 1.} -\item{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.} +\item{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.} \item{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.} @@ -195,7 +195,7 @@ get_maptypes() # set defaults for the basemap set_defaults(map_service = "osm", map_type = "terrain_bg") -# for osm_stamen, osm thunderforest and mapbox maps, you need a API token. +# for "osm_stamen", "osm_stadia", osm "thunderforest" and "mapbox" maps, you need a API token. # Register for free at stadiamaps.com, thunderforest.com and mapbox.com to get tokens. \dontrun{ diff --git a/man/defaults.Rd b/man/defaults.Rd index 3fe6069..b85e8d6 100644 --- a/man/defaults.Rd +++ b/man/defaults.Rd @@ -29,7 +29,7 @@ reset_defaults() \item{map_res}{numeric, resolution of base map in range from 0 to 1.} -\item{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.} +\item{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.} \item{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.} } diff --git a/man/get_maptypes.Rd b/man/get_maptypes.Rd index 16fc54c..fb19633 100644 --- a/man/get_maptypes.Rd +++ b/man/get_maptypes.Rd @@ -6,7 +6,9 @@ \source{ \code{"osm"}: Open Street Map contributors (\url{https://www.openstreetmap.org/copyright}), Open Topo Map (\url{https://opentopomap.org/}), Martin Tesar (\url{http://mtbmap.cz/}) -\code{"osm_stamen"}: Stamen (\url{http://maps.stamen.com/}) via Stadia Maps (\url{https://stadiamaps.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright}) +\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}) + +\code{"osm_stadia"}: Stadia Maps (\url{https://stadiamaps.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright}) \code{"osm_thunderforest"}: Thunderforest (\url{https://www.thunderforest.com/}), Open Street Map contributors (\url{https://www.openstreetmap.org/copyright}) @@ -20,7 +22,7 @@ get_maptypes(map_service = NULL) } \arguments{ -\item{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.} +\item{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.} } \value{ A character vector of supported map types