Skip to content

Commit f0c2f9a

Browse files
committed
All Changes as per comments in rstudio/leaflet/#294 & rstudio/leaflet/#295
1 parent 5c1cc0b commit f0c2f9a

23 files changed

+1845
-339
lines changed

NAMESPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ export(colorQuantile)
5656
export(createLeafletMap)
5757
export(dispatch)
5858
export(easyButton)
59-
export(easyButtonList)
6059
export(easyButtonState)
61-
export(easyButtonStateList)
6260
export(fitBounds)
6361
export(hideGroup)
6462
export(iconList)
@@ -70,6 +68,7 @@ export(layersControlOptions)
7068
export(leaflet)
7169
export(leafletCRS)
7270
export(leafletMap)
71+
export(leafletOptions)
7372
export(leafletOutput)
7473
export(leafletProxy)
7574
export(makeAwesomeIcon)

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
leaflet 1.1
22
--------------------------------------------------------------------------------
33

4+
* Added 2 new plugins Proj4Leaflet (PR #294) and EasyButton (PR #295).
5+
46
* Upgraded existing plugins to their respective latest versions and added missing/new functionality from those plugins. (PR #293)
57

68
* Added Graticule plugin (PR #293)

R/layers.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ addWMSTiles = function(
333333
#' @param transparent if \code{TRUE}, the WMS service will return images with
334334
#' transparency
335335
#' @param version version of the WMS service to use
336-
#' @param crs Coordinate Reference System to use for the WMS requests, defaults
336+
#' @param crs Coordinate Reference System to use for the WMS requests, defaults.
337+
#' @seealso \code{\link{leafletCRS}}
337338
#' to map CRS (don't change this if you're not sure what it means)
338339
#' @describeIn map-options Options for WMS tile layers
339340
#' @export

R/leaflet.R

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#' @example inst/examples/leaflet.R
2626
#' @export
2727
leaflet = function(data = NULL, width = NULL, height = NULL,
28-
padding = 0, options = list()) {
28+
padding = 0, options = leafletOptions()) {
2929

3030
# Validate the CRS if specified
3131
if(!is.null(options[['crs']]) &&
@@ -99,9 +99,35 @@ mapOptions <- function(map, zoomToLimits = c("always", "first", "never")) {
9999
map
100100
}
101101

102+
#' Options for Map creation
103+
#' @param minZoom Minimum zoom level of the map. Overrides any minZoom set on map layers.
104+
#' @param maxZoom Maximum zoom level of the map. This overrides any maxZoom set on map layers.
105+
#' @param crs Coordinate Reference System to use. Don't change this if you're not sure what it means.
106+
#' @seealso \code{\link{leafletCRS}} for creating a custom CRS.
107+
#' @param worldCopyJump With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.
108+
#' @param ... other options.
109+
#' @describeIn leaflet Options for map creation
110+
#' @seealso \url{http://leafletjs.com/reference.html#map-options} for details.
111+
#' @export
112+
leafletOptions <- function(
113+
minZoom = NULL,
114+
maxZoom = NULL,
115+
crs = leafletCRS(),
116+
worldCopyJump = NULL,
117+
...) {
118+
filterNULL(
119+
list(
120+
minZoom = minZoom,
121+
maxZoom = maxZoom,
122+
crs = crs,
123+
worldCopyJump = worldCopyJump,
124+
...)
125+
)
126+
}
127+
102128
# CRS classes supported
103-
crsClasses <- list( 'L.CRS.EPSG3857', 'L.CRS.EPSG4326', 'L.CRS.EPSG3395',
104-
'L.CRS.Simple', 'L.Proj.CRS', 'L.Proj.CRS.TMS' )
129+
crsClasses <- list('L.CRS.EPSG3857', 'L.CRS.EPSG4326', 'L.CRS.EPSG3395',
130+
'L.CRS.Simple', 'L.Proj.CRS', 'L.Proj.CRS.TMS')
105131

106132
#' creates a custom CRS
107133
#' Refer to \url{https://kartena.github.io/Proj4Leaflet/api/} for details.
@@ -121,6 +147,7 @@ crsClasses <- list( 'L.CRS.EPSG3857', 'L.CRS.EPSG4326', 'L.CRS.EPSG3395',
121147
#' defaulting to Leaflet's default CRS size
122148
#' @param tileSize Tile size, in pixels, to use in this CRS (Default 256)
123149
#' Only needed when crsClass = 'L.Proj.CRS.TMS'
150+
#' @describeIn leaflet class to create a custom CRS
124151
#' @export
125152
leafletCRS <- function(
126153
crsClass = 'L.CRS.EPSG3857',

R/plugin-easybutton.R

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ leafletEasyButtonDependencies <- function() {
1111
}
1212

1313
#' 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.
1817
#' @export
1918
easyButtonState <- function(
2019
stateName,
@@ -34,22 +33,8 @@ easyButtonState <- function(
3433
class='leaflet_easybutton_state')
3534
}
3635

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-
5136
#' Creates an easy button.
52-
#' see \url{https://github.com/CliffCloud/Leaflet.EasyButton}
37+
#' @seealso \url{https://github.com/CliffCloud/Leaflet.EasyButton}
5338
#' @param icon the button icon
5439
#' @param title text to show on hover
5540
#' @param onClick the action to take
@@ -68,8 +53,10 @@ easyButton <- function(
6853
if(!inherits(onClick,'JS_EVAL')) {
6954
stop("onClick needs to be a returned value from a JS() call")
7055
}
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")
7360
}
7461
structure(list(
7562
icon = as.character(icon),
@@ -82,20 +69,6 @@ easyButton <- function(
8269
class='leaflet_easybutton')
8370
}
8471

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-
9972
#' Add a EasyButton on the map
10073
#' see \url{https://github.com/CliffCloud/Leaflet.EasyButton}
10174
#'
@@ -110,6 +83,7 @@ easyButtonList = function(...) {
11083
#' icon = htmltools::span(class='star','&starf;'),
11184
#' onClick = JS("function(btn, map){ map.setZoom(1);}")))
11285
#'
86+
#' @describeIn easyButton add an EasyButton to the map
11387
#' @export
11488
addEasyButton <- function(
11589
map,
@@ -150,33 +124,34 @@ addEasyButton <- function(
150124
#' Add a easyButton bar on the map
151125
#' see \url{https://github.com/CliffCloud/Leaflet.EasyButton}
152126
#'
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}}
157129
#' @examples
158130
#' library(leaflet)
159131
#'
160132
#' leaf <- leaflet() %>%
161133
#' addTiles() %>%
162-
#' addEasyButtonBar(easyButtonList(
134+
#' addEasyButtonBar(
163135
#' easyButton(
164136
#' icon = htmltools::span(class='star','&starf;'),
165137
#' onClick = JS("function(btn, map){ alert('Button 1');}")),
166138
#' easyButton(
167139
#' icon = htmltools::span(class='star','&target;'),
168-
#' onClick = JS("function(btn, map){ alert('Button 2');}"))))
140+
#' onClick = JS("function(btn, map){ alert('Button 2');}")))
169141
#'
170142
#'
143+
#' @describeIn easyButton add an EasyButton to the map
171144
#' @export
172145
addEasyButtonBar <- function(
173146
map,
174-
buttons,
147+
...,
175148
position = 'topleft',
176149
id = NULL
177150
) {
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()')
180155
}
181156

182157
map$dependencies <- c(map$dependencies, leafletEasyButtonDependencies())
@@ -209,4 +184,3 @@ addEasyButtonBar <- function(
209184
id
210185
)
211186
}
212-

0 commit comments

Comments
 (0)