Skip to content

Commit e1a8835

Browse files
committed
vectorized ext argument for dateline-crossing extents to be merged
1 parent bc6ea80 commit e1a8835

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

R/basemap.R

+8-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ basemap <- function(ext = NULL, map_service = NULL, map_type = NULL, map_res = N
9595
if(inherits(verbose, "logical")) options(basemaps.verbose = verbose)
9696
if(is.null(ext)) ext <- getOption("basemaps.defaults")$ext
9797
if(is.null(ext)) out("Argument 'ext' is not defined and there is no default defined using set_defaults().", type = 3)
98-
if(inherits(ext, "sf")) ext <- st_bbox(ext)
98+
if(!inherits(ext, "list")) ext <- list(ext)
99+
ext <- lapply(ext, function(x){
100+
if(inherits(x, "sf")) st_bbox(x) else x
101+
})
99102
if(is.null(map_service)) map_service <- getOption("basemaps.defaults")$map_service
100103
if(is.null(map_type)) map_type <- getOption("basemaps.defaults")$map_type
101104
if(is.null(map_res)) map_res <- getOption("basemaps.defaults")$map_res
@@ -119,10 +122,12 @@ basemap <- function(ext = NULL, map_service = NULL, map_type = NULL, map_res = N
119122

120123
## transform ext if needed
121124
crs_webmerc <- st_crs(3857)
122-
if(st_crs(ext) != crs_webmerc){
125+
if(any(sapply(ext, function(x) st_crs(x) != crs_webmerc, USE.NAMES = F))){
123126
out(paste0("Transforming 'ext' to Web Mercator (EPSG: 3857), since 'ext' has a different CRS. The CRS of the returned basemap will be Web Mercator, which is the default CRS used by the supported tile services."), type = 2)
124127
}
125-
ext <- st_bbox(st_transform(st_as_sfc(st_bbox(ext)), crs = crs_webmerc)) #bbox as web mercator, always
128+
ext <- lapply(ext, function(x){
129+
st_bbox(st_transform(st_as_sfc(st_bbox(x)), crs = crs_webmerc)) #bbox as web mercator, always
130+
})
126131

127132
## get map
128133
out(paste0("Loading basemap '", map_type, "' from map service '", map_service, "'..."))

0 commit comments

Comments
 (0)