-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.R
56 lines (50 loc) · 1.7 KB
/
controls.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Polygon editor options
#'
#' Options for the polygon editor
#' @name editor_options
#' @param mode <`editor-mode`> The polygon editor mode. One of:
#' - `view`: editor is in readonly mode
#' - `select`: select/unselect features
#' - `modify`: add/move/delete vertices
#' - `transform`: move/scale/rotate selected features
#' - `point`: draw points
#' - `linestring`: draw linestrings by clicking each vertex
#' - `polygon`: draw polygons by clicking each vertex
#' - `lasso`: freehand polygon draw by click-dragging
#' @param features <`sf` | `sfc`> Features with which to initialise the editor
#' @export
editor_options <- function(mode = cur_value(), features = cur_value()) {
tidyassert::assert(
is_cur_value(mode) || rlang::is_string(mode) && mode %in% editor_modes(),
error_message = c(
"x" = paste("{.arg mode} must be one of ", paste0(editor_modes(), collapse = ", "))
)
)
tidyassert::assert(
is.null(features) ||
is_cur_value(features) ||
(is_sf(features) || is_sfc(features)) && is_wgs84(features),
error_message = c(
"x" = "{.arg features} must be a {.emph WGS84} {.cls sf/sfc}"
)
)
structure(
list(
mode = mode,
features = features
),
class = "editor_options"
)
}
editor_modes <- function() {
c(
"view", "select",
"transform", "modify",
"point", "linestring", "polygon", "lasso"
)
}
is_editor_options <- function(object) inherits(object, "editor_options")
as_editor_options <- function(object) UseMethod("as_editor_options")
as_editor_options.default <- function(object) object
as_editor_options.NULL <- function(object) NULL
as_editor_options.logical <- function(object) if (isTRUE(object)) editor_options() else NULL