@@ -198,15 +198,18 @@ download_tiles <- function(tile_grid, param, apikey, verbose, cachedir,
198198 }
199199 }
200200 cpt <- 0
201+
202+ is_retina <- grepl(pattern = " {r}" , x = param $ q , fixed = TRUE )
203+ ret <- ifelse(isTRUE(retina ) && isTRUE(is_retina ), " _@2x" , " " )
204+
201205 for (i in seq_along(images )) {
202206 x <- tile_grid $ tiles [i , ]
203207 x <- trimws(x )
204- is_retina <- grepl(pattern = " {r}" , x = param $ q , fixed = TRUE )
205- ret <- ifelse(isTRUE(retina ) && isTRUE(is_retina ), " @2x" , " " )
208+
206209 outfile <- paste0(
207- cachedir , " /" , src , " _" , zoom , " _" , x [1 ], " _" ,
208- x [2 ], " _" , ret , " ." , ext
210+ cachedir , " /" , src , " _" , zoom , " _" , x [1 ], " _" , x [2 ], ret , " ." , ext
209211 )
212+
210213 if (! file.exists(outfile ) || isTRUE(forceDownload )) {
211214 q <- gsub(
212215 pattern = " {s}" , replacement = sample(param $ sub , 1 , TRUE ),
@@ -216,12 +219,10 @@ download_tiles <- function(tile_grid, param, apikey, verbose, cachedir,
216219 q <- gsub(pattern = " {y}" , replacement = x [2 ], x = q , fixed = TRUE )
217220 q <- gsub(pattern = " {z}" , replacement = zoom , x = q , fixed = TRUE )
218221 q <- gsub(pattern = " {apikey}" , replacement = apikey , x = q , fixed = TRUE )
219-
220- if (isTRUE(retina )) {
221- q <- gsub(pattern = " {r}" , replacement = " @2x" , x = q , fixed = TRUE )
222- } else {
223- q <- gsub(pattern = " {r}" , replacement = " " , x = q , fixed = TRUE )
224- }
222+ q <- gsub(
223+ pattern = " {r}" , replacement = substr(ret , 2 , 4 ), x = q ,
224+ fixed = TRUE
225+ )
225226
226227 e <- try(curl :: curl_download(url = q , destfile = outfile ), silent = TRUE )
227228
@@ -241,8 +242,7 @@ download_tiles <- function(tile_grid, param, apikey, verbose, cachedir,
241242 if (verbose ) {
242243 ntiles <- length(images )
243244 message(ntiles , " tile" , ifelse(ntiles > 1 , " s" , " " ))
244-
245- if (cpt != length(images )) {
245+ if (cpt != ntiles ) {
246246 message(" The resulting raster is built with previously cached tiles." )
247247 } else {
248248 if (isTRUE(retina )) {
@@ -287,6 +287,8 @@ compose_tiles <- function(tile_grid, images, flip) {
287287 # warning is: [rast] unknown extent
288288 r_img <- suppressWarnings(terra :: rast(img ))
289289
290+ # use terra::is.flipped in next version
291+
290292 # flip tiles
291293 if (missing(flip )) {
292294 flip <- FALSE
0 commit comments