Skip to content

Commit a565b08

Browse files
authored
leaflet htmlwidget sizing policy exposed (#548)
* first pass at expose sizingPolicy * document sizing policy * fix check issues * updated news
1 parent 6aa608f commit a565b08

File tree

5 files changed

+68
-9
lines changed

5 files changed

+68
-9
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export(leafletMap)
126126
export(leafletOptions)
127127
export(leafletOutput)
128128
export(leafletProxy)
129+
export(leafletSizingPolicy)
129130
export(makeAwesomeIcon)
130131
export(makeIcon)
131132
export(mapOptions)

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
leaflet 2.0.0.9000
22
--------------------------------------------------------------------------------
33

4+
FEATURES
5+
6+
* Exposed htmlwidgets sizingPolicy in leaflet() (#548)
7+
48
BUG FIXES
59

610
* Default marker icon locations will now use unpkg.com instead of the leaflet cdn when using https or file protocols. (#544)

R/leaflet.R

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
#' Leaflet sizing policy
2+
#'
3+
#' Sizing policy used withing leaflet htmlwidgets. All arguments are passed directly to \code{htmlwidgets::\link[htmlwidgets]{sizingPolicy}}
4+
#'
5+
#' @export
6+
#' @param defaultWidth defaults to \code{"100\%"} of the available width
7+
#' @param defaultHeight defaults to 400px tall
8+
#' @param padding defaults to 0px
9+
#' @param browser.fill defaults to \code{TRUE}
10+
#' @param ... all other arguments supplied to \code{htmlwidgets::\link[htmlwidgets]{sizingPolicy}}
11+
#' @return An \code{htmlwidgets::sizingPolicy} object
12+
leafletSizingPolicy <- function(
13+
defaultWidth = "100%",
14+
defaultHeight = 400,
15+
padding = 0,
16+
browser.fill = TRUE,
17+
...
18+
# not adding extra arguments as htmlwidgets::sizingPolicy can change their own args
19+
) {
20+
htmlwidgets::sizingPolicy(
21+
defaultWidth = defaultWidth,
22+
defaultHeight = defaultHeight,
23+
padding = padding,
24+
browser.fill = browser.fill,
25+
...
26+
)
27+
}
28+
29+
130
#' Create a Leaflet map widget
231
#'
332
#' This function creates a Leaflet map widget using \pkg{htmlwidgets}. The
@@ -23,13 +52,14 @@
2352
#' @param options the map options
2453
#' @param elementId Use an explicit element ID for the widget
2554
#' (rather than an automatically generated one).
55+
#' @param sizingPolicy htmlwidgets sizing policy object. Defaults to \code{\link{leafletSizingPolicy}()}
2656
#' @return A HTML widget object, on which we can add graphics layers using
2757
#' \code{\%>\%} (see examples).
2858
#' @example inst/examples/leaflet.R
2959
#' @export
3060
leaflet <- function(data = NULL, width = NULL, height = NULL,
3161
padding = 0, options = leafletOptions(),
32-
elementId = NULL) {
62+
elementId = NULL, sizingPolicy = leafletSizingPolicy(padding = padding)) {
3363

3464
# Validate the CRS if specified
3565
if (!is.null(options[["crs"]]) &&
@@ -44,12 +74,7 @@ leaflet <- function(data = NULL, width = NULL, height = NULL,
4474
leafletData = data
4575
),
4676
width = width, height = height,
47-
sizingPolicy = htmlwidgets::sizingPolicy(
48-
defaultWidth = "100%",
49-
defaultHeight = 400,
50-
padding = padding,
51-
browser.fill = TRUE
52-
),
77+
sizingPolicy = sizingPolicy,
5378
preRenderHook = function(widget) {
5479
if (!is.null(widget$jsHooks$render)) {
5580
widget$jsHooks$render <- lapply(widget$jsHooks$render, function(hook) {
@@ -119,7 +144,7 @@ mapOptions <- function(map, zoomToLimits = c("always", "first", "never")) {
119144
#' @param crs Coordinate Reference System to use. Don't change this if you're not sure what it means.
120145
#' @seealso \code{\link{leafletCRS}} for creating a custom CRS.
121146
#' @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.
122-
#' @param preferCanvas Whether leaflet.js Paths should be rendered on a Canvas renderer.
147+
#' @param preferCanvas Whether leaflet.js Paths should be rendered on a Canvas renderer.
123148
#' @param ... other options used for leaflet.js map creation.
124149
#' @describeIn leaflet Options for map creation
125150
#' @seealso See \url{http://leafletjs.com/reference-1.3.1.html#map-option} for details and more options.

man/leaflet.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/leafletSizingPolicy.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)