@@ -11,10 +11,9 @@ leafletEasyButtonDependencies <- function() {
11
11
}
12
12
13
13
# ' Create an easyButton statestate
14
- # ' @param stateName the name of the state
15
- # ' @param icon the button icon
16
- # ' @param title text to show on hover
17
- # ' @param onClick the action to take
14
+ # ' @param stateName a unique name for the state
15
+ # ' @seealso \code{\link{easyButton}}
16
+ # ' @describeIn easyButton state of an easyButton.
18
17
# ' @export
19
18
easyButtonState <- function (
20
19
stateName ,
@@ -34,22 +33,8 @@ easyButtonState <- function(
34
33
class = ' leaflet_easybutton_state' )
35
34
}
36
35
37
- # ' Create a list of easyButton states.
38
- # ' @param ... states created from \code{\link{easyButtonState}()}
39
- # ' @export
40
- easyButtonStateList <- function (... ) {
41
- res = structure(
42
- list (... ),
43
- class = " leaflet_easybutton_state_list"
44
- )
45
- cls = unlist(lapply(res , inherits , ' leaflet_easybutton_state' ))
46
- if (any(! cls ))
47
- stop(' Arguments passed to easyButtonStateList() must be icon objects returned from easyButtonState()' )
48
- res
49
- }
50
-
51
36
# ' Creates an easy button.
52
- # ' see \url{https://github.com/CliffCloud/Leaflet.EasyButton}
37
+ # ' @seealso \url{https://github.com/CliffCloud/Leaflet.EasyButton}
53
38
# ' @param icon the button icon
54
39
# ' @param title text to show on hover
55
40
# ' @param onClick the action to take
@@ -68,8 +53,10 @@ easyButton <- function(
68
53
if (! inherits(onClick ,' JS_EVAL' )) {
69
54
stop(" onClick needs to be a returned value from a JS() call" )
70
55
}
71
- if (! is.null(states ) && ! inherits(states ,' leaflet_easybutton_state_list' )) {
72
- stop(" states needs to be a returned value from a easyButtonStateList() call" )
56
+ if (! is.null(states ) && ! (
57
+ inherits(states ,' list' ) &&
58
+ all(sapply(states ,function (x ) inherits(x ,' leaflet_easybutton_state' ))))) {
59
+ stop(" states needs to be a list() of easyButton instances" )
73
60
}
74
61
structure(list (
75
62
icon = as.character(icon ),
@@ -82,20 +69,6 @@ easyButton <- function(
82
69
class = ' leaflet_easybutton' )
83
70
}
84
71
85
- # ' Creates a list of easy buttons.
86
- # ' @param ... icons created from \code{\link{easyButton}()}
87
- # ' @export
88
- easyButtonList = function (... ) {
89
- res = structure(
90
- list (... ),
91
- class = " leaflet_easybutton_list"
92
- )
93
- cls = unlist(lapply(res , inherits , ' leaflet_easybutton' ))
94
- if (any(! cls ))
95
- stop(' Arguments passed to easyButtonList() must be icon objects returned from easyButton()' )
96
- res
97
- }
98
-
99
72
# ' Add a EasyButton on the map
100
73
# ' see \url{https://github.com/CliffCloud/Leaflet.EasyButton}
101
74
# '
@@ -110,6 +83,7 @@ easyButtonList = function(...) {
110
83
# ' icon = htmltools::span(class='star','★'),
111
84
# ' onClick = JS("function(btn, map){ map.setZoom(1);}")))
112
85
# '
86
+ # ' @describeIn easyButton add an EasyButton to the map
113
87
# ' @export
114
88
addEasyButton <- function (
115
89
map ,
@@ -150,33 +124,34 @@ addEasyButton <- function(
150
124
# ' Add a easyButton bar on the map
151
125
# ' see \url{https://github.com/CliffCloud/Leaflet.EasyButton}
152
126
# '
153
- # ' @param map a map widget object
154
- # ' @param buttons the buttons object created with \code{\link{easyButtonList}}
155
- # ' @param position topleft|topright|bottomleft|bottomright
156
- # ' @param id id for the button bar
127
+ # ' @param ... a list of buttons created with \code{\link{easyButton}}
128
+ # ' @seealso \code{\link{addEasyButton}}
157
129
# ' @examples
158
130
# ' library(leaflet)
159
131
# '
160
132
# ' leaf <- leaflet() %>%
161
133
# ' addTiles() %>%
162
- # ' addEasyButtonBar(easyButtonList(
134
+ # ' addEasyButtonBar(
163
135
# ' easyButton(
164
136
# ' icon = htmltools::span(class='star','★'),
165
137
# ' onClick = JS("function(btn, map){ alert('Button 1');}")),
166
138
# ' easyButton(
167
139
# ' icon = htmltools::span(class='star','⌖'),
168
- # ' onClick = JS("function(btn, map){ alert('Button 2');}"))))
140
+ # ' onClick = JS("function(btn, map){ alert('Button 2');}")))
169
141
# '
170
142
# '
143
+ # ' @describeIn easyButton add an EasyButton to the map
171
144
# ' @export
172
145
addEasyButtonBar <- function (
173
146
map ,
174
- buttons ,
147
+ ... ,
175
148
position = ' topleft' ,
176
149
id = NULL
177
150
) {
178
- if (! inherits(buttons ,' leaflet_easybutton_list' )) {
179
- stop(' button should be created with easyButtonList()' )
151
+ buttons <- list (... )
152
+ if (! length(buttons ) > = 1 ||
153
+ ! all(sapply(buttons ,function (x ) inherits(x ,' leaflet_easybutton' )))) {
154
+ stop(' need buttons created with easyButton()' )
180
155
}
181
156
182
157
map $ dependencies <- c(map $ dependencies , leafletEasyButtonDependencies())
@@ -209,4 +184,3 @@ addEasyButtonBar <- function(
209
184
id
210
185
)
211
186
}
212
-
0 commit comments