Skip to content

Commit

Permalink
Extract map option types
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Oct 4, 2024
1 parent 8343dad commit be2251a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
36 changes: 6 additions & 30 deletions R/maplibre.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,7 @@ mapOptions <- function(style = basemaps$carto$dark_matter,
scroll_zoom = NULL,
zoom = NULL,
...) {

types <- list(
style = function(x) {is.list(x) | is.character(x)},
antialias = is.logical,
attributionControl = is.logical,
bearing = function(x) {is.integer(x) | is.numeric(x)},
bearingSnap = is.integer,
bounds = is.list,
boxZoom = is.logical,
center = is.list,
clickTolerance = function(x) {is.integer(x) | x==round(x,0)},
customAttribution = is.logical,
doubleClickZoom = is.logical,
fadeDuration = function(x) {is.integer(x) | x==round(x,0)},
fitBoundsOptions = is.list,
hash = is.logical,
interactive = is.logical,
keyword = is.logical,
maxBounds = is.list,
maxPitch = function(x) {is.integer(x) | x==round(x,0)},
maxZoom = function(x) {is.integer(x) | x==round(x,0)},
minPitch = function(x) {is.integer(x) | x==round(x,0)},
minZoom = function(x) {is.integer(x) | x==round(x,0)},
pitch = function(x) {is.integer(x) | x==round(x,0)},
scrollZoom = is.logical,
zoom = function(x) {is.integer(x) | is.numeric(x)}

)
# BODY
purrr::compact(
rdantic(
list(
Expand All @@ -144,8 +117,11 @@ mapOptions <- function(style = basemaps$carto$dark_matter,
pitch = pitch,
scrollZoom = scroll_zoom,
style = style,
zoom = zoom), types),
...)
zoom = zoom
), TYPES_MAP_OPTIONS
),
...
)
}


Expand Down
2 changes: 1 addition & 1 deletion R/marker.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Marker <- function(lngLat, popup = NULL, ...) {
#'
#' @example examples/markers.R
MarkerOptions <- function(anchor = NULL, color = NULL, pitchAlignment = NULL, rotationAlignment = NULL,
draggable = NULL, rotation = NULL, scale = NULL,...){
draggable = NULL, rotation = NULL, scale = NULL, ...) {
marker_options <- list(...)
stopifnot(sapply(marker_options[c("anchor", "color", "pitchAlignment", "rotationAlignment")], function(x) {
is.null(x) | is.character(x)
Expand Down
47 changes: 47 additions & 0 deletions R/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,50 @@ TYPES_LAYER <- list(
paint = is.list,
layout = is.list
)

TYPES_MAP_OPTIONS <- list(
style = function(x) {
is.list(x) | is.character(x)
},
antialias = is.logical,
attributionControl = is.logical,
bearing = function(x) {
is.integer(x) | is.numeric(x)
},
bearingSnap = is.integer,
bounds = is.list,
boxZoom = is.logical,
center = is.list,
clickTolerance = function(x) {
is.integer(x) | x == round(x, 0)
},
customAttribution = is.logical,
doubleClickZoom = is.logical,
fadeDuration = function(x) {
is.integer(x) | x == round(x, 0)
},
fitBoundsOptions = is.list,
hash = is.logical,
interactive = is.logical,
keyword = is.logical,
maxBounds = is.list,
maxPitch = function(x) {
is.integer(x) | x == round(x, 0)
},
maxZoom = function(x) {
is.integer(x) | x == round(x, 0)
},
minPitch = function(x) {
is.integer(x) | x == round(x, 0)
},
minZoom = function(x) {
is.integer(x) | x == round(x, 0)
},
pitch = function(x) {
is.integer(x) | x == round(x, 0)
},
scrollZoom = is.logical,
zoom = function(x) {
is.integer(x) | is.numeric(x)
}
)
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ rdantic <- function(.obj, types, test = 1L) {
for (k in names(.obj)) {
type_check <- types[[k]]
value <- .obj[[k]]
if(!is.null(value)){
if (!is.null(value)) {
if (!type_check(value)) {
stop(value, " is not ", deparse(substitute(type_check)) , call.=FALSE)
stop(value, " is not ", deparse(substitute(type_check)), call. = FALSE)
}
}
}
Expand Down

0 comments on commit be2251a

Please sign in to comment.