From a5cc81b2340fe82be7813564cbbd2c1d83b87f0d Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 29 Feb 2024 10:51:41 +0900 Subject: [PATCH 1/4] Add the Alidade Satellite style --- R/get_stadiamap.R | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/R/get_stadiamap.R b/R/get_stadiamap.R index 3ae4eb9..228a3c6 100644 --- a/R/get_stadiamap.R +++ b/R/get_stadiamap.R @@ -1,9 +1,8 @@ # NOTE: Be sure to update the documentation for maptype both in this file and # in get_map.R whenever you change this! -# TODO: Extend with our own styles! STADIA_BASEMAP_TYPES <- c("stamen_terrain", "stamen_toner", "stamen_toner_lite", "stamen_watercolor", "alidade_smooth", "alidade_smooth_dark", - "outdoors") + "alidade_satellite", "outdoors", "osm_bright") STADIA_BACKGROUND_LAYERGROUP_TYPES <- c("stamen_terrain_background", "stamen_toner_background") STADIA_TRANSPARENT_LAYERGROUP_TYPES <- c("stamen_terrain_labels", "stamen_terrain_lines", "stamen_toner_labels", "stamen_toner_lines") @@ -19,7 +18,8 @@ STADIA_VALID_MAP_TYPES <- c(STADIA_BASEMAP_TYPES, #' @param bbox a bounding box in the format c(lowerleftlon, lowerleftlat, #' upperrightlon, upperrightlat). #' @param zoom a zoom level -#' @param maptype stamen_terrain, stamen_toner, stamen_toner_lite, stamen_watercolor, +#' @param maptype alidade_smooth, alidade_smooth_dark, alidade_satellite, outdoors, osm_bright, +#' stamen_terrain, stamen_toner, stamen_toner_lite, stamen_watercolor, #' stamen_terrain_background, stamen_toner_background, #' stamen_terrain_lines, stamen_terrain_labels, #' stamen_toner_lines, stamen_toner_labels. @@ -133,7 +133,7 @@ STADIA_VALID_MAP_TYPES <- c(STADIA_BASEMAP_TYPES, #' ## known issues #' ######################################## #' -#' # Stamen's original tilesets were raster renders built up over time, but have not been +#' # Stamen's watercolor tileset was built up over time, but have not been #' # actively rendered for several years. As a consequence, some tiles simply do not exist, #' # particularly at high zoom levels. #' # @@ -191,7 +191,13 @@ get_stadiamap <- function( filetype <- "png" } - cli::cli_alert_info("\u00a9 Stadia Maps \u00a9 Stamen Design \u00a9 OpenMapTiles \u00a9 OpenStreetMap contributors.") + if(grepl("stamen", maptype)){ + cli::cli_alert_info("\u00a9 Stadia Maps \u00a9 Stamen Design \u00a9 OpenMapTiles \u00a9 OpenStreetMap contributors.") + } else if(grepl("satellite", maptype)){ + cli::cli_alert_info("\u00a9 CNES, Distribution Airbus DS \u00a9 Airbus DS \u00a9 PlanetObserver (Contains Copernicus Data) \u00a9 Stadia Maps \u00a9 OpenMapTiles \u00a9 OpenStreetMap contributors.") + } else { + cli::cli_alert_info("\u00a9 Stadia Maps \u00a9 OpenMapTiles \u00a9 OpenStreetMap contributors.") + } # determine tiles to get fourCorners <- expand.grid( From 6b7b0b879a9c8ef4807c4e37de1fefeccb55fa7f Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 29 Feb 2024 11:27:19 +0900 Subject: [PATCH 2/4] Minor fixes and refactoring --- R/get_stadiamap.R | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/R/get_stadiamap.R b/R/get_stadiamap.R index 228a3c6..b5459ce 100644 --- a/R/get_stadiamap.R +++ b/R/get_stadiamap.R @@ -184,13 +184,6 @@ get_stadiamap <- function( color <- match.arg(color) if(is.null(names(bbox))) names(bbox) <- c("left","bottom","right","top") - # set image type (watercolor is JPEG-only) - if(maptype %in% c("stamen_watercolor")){ - filetype <- "jpg" - } else { - filetype <- "png" - } - if(grepl("stamen", maptype)){ cli::cli_alert_info("\u00a9 Stadia Maps \u00a9 Stamen Design \u00a9 OpenMapTiles \u00a9 OpenStreetMap contributors.") } else if(grepl("satellite", maptype)){ @@ -309,7 +302,7 @@ get_stamen_url <- function(maptype, zoom, x, y) { key <- stadiamaps_key() # format URL - if(maptype %in% c("stamen_watercolor")) filetype <- "jpg" else filetype <- "png" + if(maptype %in% c("stamen_watercolor", "alidade_satellite")) filetype <- "jpg" else filetype <- "png" url <- glue("https://tiles.stadiamaps.com/tiles/{maptype}/{zoom}/{x}/{y}.{filetype}?api_key={key}") return(url) From fd0b0db3ce1e0c553ae1bf413f9357f2c3b8f860 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 29 Feb 2024 11:34:05 +0900 Subject: [PATCH 3/4] Fix logging; improve readability --- R/get_stadiamap.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/R/get_stadiamap.R b/R/get_stadiamap.R index b5459ce..a6b27f3 100644 --- a/R/get_stadiamap.R +++ b/R/get_stadiamap.R @@ -302,7 +302,11 @@ get_stamen_url <- function(maptype, zoom, x, y) { key <- stadiamaps_key() # format URL - if(maptype %in% c("stamen_watercolor", "alidade_satellite")) filetype <- "jpg" else filetype <- "png" + if(maptype %in% c("stamen_watercolor", "alidade_satellite")) { + filetype <- "jpg" + } else { + filetype <- "png" + } url <- glue("https://tiles.stadiamaps.com/tiles/{maptype}/{zoom}/{x}/{y}.{filetype}?api_key={key}") return(url) @@ -327,6 +331,13 @@ get_stadiamap_tile <- function(maptype, zoom, x, y, color, force = FALSE, messag # deal with bad responses if (response$status_code != 200L) { + # set image type for logging (we don't log the full URL to avoid exposing API keys accidentally) + if(maptype %in% c("stamen_watercolor", "alidade_satellite")){ + filetype <- "jpg" + } else { + filetype <- "png" + } + httr::message_for_status(response, glue("acquire tile /{maptype}/{zoom}/{x}/{y}.{filetype}")) if (messaging) message("\n", appendLF = FALSE) From d8ac1e3229e0f42422fff9ca802a18835dd47f31 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 29 Feb 2024 11:44:35 +0900 Subject: [PATCH 4/4] roxygenize --- man/get_stadiamap.Rd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/man/get_stadiamap.Rd b/man/get_stadiamap.Rd index 3a044cc..fc72d3d 100644 --- a/man/get_stadiamap.Rd +++ b/man/get_stadiamap.Rd @@ -23,7 +23,8 @@ upperrightlon, upperrightlat).} \item{zoom}{a zoom level} -\item{maptype}{stamen_terrain, stamen_toner, stamen_toner_lite, stamen_watercolor, +\item{maptype}{alidade_smooth, alidade_smooth_dark, alidade_satellite, outdoors, osm_bright, +stamen_terrain, stamen_toner, stamen_toner_lite, stamen_watercolor, stamen_terrain_background, stamen_toner_background, stamen_terrain_lines, stamen_terrain_labels, stamen_toner_lines, stamen_toner_labels.} @@ -149,7 +150,7 @@ qmap("the white house", zoom = 16, source = "stadia", maptype = "stamen_terrain" ## known issues ######################################## -# Stamen's original tilesets were raster renders built up over time, but have not been +# Stamen's watercolor tileset was built up over time, but have not been # actively rendered for several years. As a consequence, some tiles simply do not exist, # particularly at high zoom levels. #