Skip to content

Commit 1bc41ee

Browse files
authored
Merge pull request #298 from bhaskarvk/feature/upgrade-leaflet-PR
2 new plugins Proj4Leaflet, EasyButton and Leaflet upgrade from 0.7.3 to 0.7.7
2 parents 4370ace + 999a003 commit 1bc41ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+20536
-430
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
node_modules
55
inst/htmlwidgets/sources
66
*.swp
7+
inst/examples/rsconnect
8+
inst/examples/*.html

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: leaflet
22
Type: Package
33
Title: Create Interactive Web Maps with the JavaScript 'Leaflet' Library
4-
Version: 1.0.2.9000
4+
Version: 1.0.2.9002
55
Date: 2016-09-17
66
Authors@R: c(
77
person("Joe", "Cheng", email = "[email protected]", role = c("aut", "cre")),

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export(addAwesomeMarkers)
1414
export(addCircleMarkers)
1515
export(addCircles)
1616
export(addControl)
17+
export(addEasyButton)
18+
export(addEasyButtonBar)
1719
export(addGeoJSON)
1820
export(addGraticule)
1921
export(addLabelOnlyMarkers)
@@ -53,7 +55,10 @@ export(colorNumeric)
5355
export(colorQuantile)
5456
export(createLeafletMap)
5557
export(dispatch)
58+
export(easyButton)
59+
export(easyButtonState)
5660
export(fitBounds)
61+
export(getMapData)
5762
export(hideGroup)
5863
export(iconList)
5964
export(icons)
@@ -62,7 +67,9 @@ export(labelFormat)
6267
export(labelOptions)
6368
export(layersControlOptions)
6469
export(leaflet)
70+
export(leafletCRS)
6571
export(leafletMap)
72+
export(leafletOptions)
6673
export(leafletOutput)
6774
export(leafletProxy)
6875
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: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ clearImages = function(map) {
242242
#' minZoom,maxZoom,maxNativeZoom,tileSize,subdomains,errorTileUrl,tms,continuousWorld,noWrap,zoomOffset,zoomReverse,zIndex,unloadInvisibleTiles,updateWhenIdle,detectRetina,reuseTiles
243243
#' the tile layer options; see
244244
#' \url{http://leafletjs.com/reference.html#tilelayer}
245+
#' @param ... extra options passed to underlying Javascript object constructor.
245246
#' @describeIn map-options Options for tile layers
246247
#' @export
247248
tileOptions = function(
@@ -261,8 +262,8 @@ tileOptions = function(
261262
unloadInvisibleTiles = NULL,
262263
updateWhenIdle = NULL,
263264
detectRetina = FALSE,
264-
reuseTiles = FALSE
265-
# bounds = TODO
265+
reuseTiles = FALSE,
266+
...
266267
) {
267268
list(
268269
minZoom = minZoom, maxZoom = maxZoom, maxNativeZoom = maxNativeZoom,
@@ -271,7 +272,8 @@ tileOptions = function(
271272
zoomOffset = zoomOffset, zoomReverse = zoomReverse, opacity = opacity,
272273
zIndex = zIndex, unloadInvisibleTiles = unloadInvisibleTiles,
273274
updateWhenIdle = updateWhenIdle, detectRetina = detectRetina,
274-
reuseTiles = reuseTiles
275+
reuseTiles = reuseTiles,
276+
...
275277
)
276278
}
277279

@@ -331,10 +333,9 @@ addWMSTiles = function(
331333
#' @param transparent if \code{TRUE}, the WMS service will return images with
332334
#' transparency
333335
#' @param version version of the WMS service to use
334-
#' @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}}
335338
#' to map CRS (don't change this if you're not sure what it means)
336-
#' @param ... other tile options for \code{WMSTileOptions()} (all arguments of
337-
#' \code{tileOptions()} can be used)
338339
#' @describeIn map-options Options for WMS tile layers
339340
#' @export
340341
WMSTileOptions = function(
@@ -398,12 +399,13 @@ popupOptions = function(
398399
# autoPanPadding = TODO,
399400
zoomAnimation = TRUE,
400401
closeOnClick = NULL,
401-
className = ""
402+
className = "",
403+
...
402404
) {
403405
list(
404406
maxWidth = maxWidth, minWidth = minWidth, maxHeight = maxHeight,
405407
autoPan = autoPan, keepInView = keepInView, closeButton = closeButton,
406-
zoomAnimation = zoomAnimation, closeOnClick = closeOnClick, className = className
408+
zoomAnimation = zoomAnimation, closeOnClick = closeOnClick, className = className, ...
407409
)
408410
}
409411

@@ -451,13 +453,14 @@ labelOptions = function(
451453
textsize = "10px",
452454
textOnly = FALSE,
453455
style = NULL,
454-
zoomAnimation = TRUE
456+
zoomAnimation = TRUE,
457+
...
455458
) {
456459
list(
457460
clickable = clickable, noHide = noHide, direction = direction,
458461
opacity = opacity, offset = offset,
459462
textsize = textsize, textOnly = textOnly, style = style,
460-
zoomAnimation = zoomAnimation, className = className
463+
zoomAnimation = zoomAnimation, className = className, ...
461464
)
462465
}
463466

@@ -731,12 +734,13 @@ markerOptions = function(
731734
zIndexOffset = 0,
732735
opacity = 1.0,
733736
riseOnHover = FALSE,
734-
riseOffset = 250
737+
riseOffset = 250,
738+
...
735739
) {
736740
list(
737741
clickable = clickable, draggable = draggable, keyboard = keyboard,
738742
title = title, alt = alt, zIndexOffset = zIndexOffset, opacity = opacity,
739-
riseOnHover = riseOnHover, riseOffset = riseOffset
743+
riseOnHover = riseOnHover, riseOffset = riseOffset, ...
740744
)
741745
}
742746

@@ -865,11 +869,12 @@ pathOptions = function(
865869
lineJoin = NULL,
866870
clickable = TRUE,
867871
pointerEvents = NULL,
868-
className = ""
872+
className = "",
873+
...
869874
) {
870875
list(
871876
lineCap = lineCap, lineJoin = lineJoin, clickable = clickable,
872-
pointerEvents = pointerEvents, className = className
877+
pointerEvents = pointerEvents, className = className, ...
873878
)
874879
}
875880

@@ -1094,9 +1099,10 @@ addLayersControl = function(map,
10941099
#' to have the layers control always appear in its expanded state.
10951100
#' @param autoZIndex if \code{TRUE}, the control will automatically maintain
10961101
#' the z-order of its various groups as overlays are switched on and off.
1102+
#' @param ... other options for \code{layersControlOptions()}
10971103
#' @export
1098-
layersControlOptions = function(collapsed = TRUE, autoZIndex = TRUE) {
1099-
list(collapsed = collapsed, autoZIndex = autoZIndex)
1104+
layersControlOptions = function(collapsed = TRUE, autoZIndex = TRUE, ...) {
1105+
list(collapsed = collapsed, autoZIndex = autoZIndex, ...)
11001106
}
11011107

11021108
#' @rdname addLayersControl

R/leaflet.R

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@
1919
#' @param width the width of the map
2020
#' @param height the height of the map
2121
#' @param padding the padding of the map
22+
#' @param options the map options
2223
#' @return A HTML widget object, on which we can add graphics layers using
2324
#' \code{\%>\%} (see examples).
2425
#' @example inst/examples/leaflet.R
2526
#' @export
26-
leaflet = function(data = NULL, width = NULL, height = NULL, padding = 0) {
27+
leaflet = function(data = NULL, width = NULL, height = NULL,
28+
padding = 0, options = leafletOptions()) {
29+
30+
# Validate the CRS if specified
31+
if(!is.null(options[['crs']]) &&
32+
!inherits(options[['crs']], 'leaflet_crs')) {
33+
stop("CRS in mapOptions should be a return value of leafletCRS() function")
34+
}
35+
2736
htmlwidgets::createWidget(
2837
'leaflet',
2938
structure(
30-
list(),
39+
list(options = options),
3140
leafletData = data
3241
),
3342
width = width, height = height,
@@ -36,10 +45,32 @@ leaflet = function(data = NULL, width = NULL, height = NULL, padding = 0) {
3645
defaultHeight = 400,
3746
padding = padding,
3847
browser.fill = TRUE
39-
)
48+
),
49+
preRenderHook = function(widget) {
50+
if (!is.null(widget$jsHooks$render)) {
51+
widget$jsHooks$render <- lapply(widget$jsHooks$render, function(hook) {
52+
if (is.list(hook)) {
53+
hook$code <- sprintf(hookWrapperTemplate, paste(hook$code, collapse = "\n"))
54+
} else if (is.character(hook)) {
55+
hook <- sprintf(hookWrapperTemplate, paste(hook, collapse = "\n"))
56+
} else {
57+
stop("Unknown hook class ", class(hook))
58+
}
59+
hook
60+
})
61+
}
62+
widget
63+
}
4064
)
4165
}
4266

67+
hookWrapperTemplate <- "function(el, x, data) {
68+
return (%s).call(this.getMap(), el, x, data);
69+
}"
70+
71+
#' returns the map's data
72+
#' @param map the map
73+
#' @export
4374
getMapData = function(map) {
4475
attr(map$x, "leafletData", exact = TRUE)
4576
}
@@ -70,3 +101,98 @@ mapOptions <- function(map, zoomToLimits = c("always", "first", "never")) {
70101

71102
map
72103
}
104+
105+
#' Options for Map creation
106+
#' @param minZoom Minimum zoom level of the map. Overrides any minZoom set on map layers.
107+
#' @param maxZoom Maximum zoom level of the map. This overrides any maxZoom set on map layers.
108+
#' @param crs Coordinate Reference System to use. Don't change this if you're not sure what it means.
109+
#' @seealso \code{\link{leafletCRS}} for creating a custom CRS.
110+
#' @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.
111+
#' @param ... other options.
112+
#' @describeIn leaflet Options for map creation
113+
#' @seealso \url{http://leafletjs.com/reference.html#map-options} for details.
114+
#' @export
115+
leafletOptions <- function(
116+
minZoom = NULL,
117+
maxZoom = NULL,
118+
crs = leafletCRS(),
119+
worldCopyJump = NULL,
120+
...) {
121+
filterNULL(
122+
list(
123+
minZoom = minZoom,
124+
maxZoom = maxZoom,
125+
crs = crs,
126+
worldCopyJump = worldCopyJump,
127+
...)
128+
)
129+
}
130+
131+
# CRS classes supported
132+
crsClasses <- list('L.CRS.EPSG3857', 'L.CRS.EPSG4326', 'L.CRS.EPSG3395',
133+
'L.CRS.Simple', 'L.Proj.CRS', 'L.Proj.CRS.TMS')
134+
135+
#' creates a custom CRS
136+
#' Refer to \url{https://kartena.github.io/Proj4Leaflet/api/} for details.
137+
#' @param crsClass One of L.CRS.EPSG3857, L.CRS.EPSG4326, L.CRS.EPSG3395,
138+
#' L.CRS.Simple, L.Proj.CRS, L.Proj.CRS.TMS
139+
#' @param code CRS identifier
140+
#' @param proj4def Proj4 string
141+
#' @param projectedBounds Only when crsClass = 'L.Proj.CRS.TMS'
142+
#' @param origin Origin in projected coordinates, if set overrides transformation option.
143+
#' @param transformation to use when transforming projected coordinates into pixel coordinates
144+
#' @param scales Scale factors (pixels per projection unit, for example pixels/meter)
145+
#' for zoom levels; specify either scales or resolutions, not both
146+
#' @param resolutions factors (projection units per pixel, for example meters/pixel)
147+
#' for zoom levels; specify either scales or resolutions, not both
148+
#' @param bounds Bounds of the CRS, in projected coordinates; if defined,
149+
#' Proj4Leaflet will use this in the getSize method, otherwise
150+
#' defaulting to Leaflet's default CRS size
151+
#' @param tileSize Tile size, in pixels, to use in this CRS (Default 256)
152+
#' Only needed when crsClass = 'L.Proj.CRS.TMS'
153+
#' @describeIn leaflet class to create a custom CRS
154+
#' @export
155+
leafletCRS <- function(
156+
crsClass = 'L.CRS.EPSG3857',
157+
code = NULL,
158+
proj4def = NULL,
159+
projectedBounds = NULL,
160+
origin = NULL,
161+
transformation = NULL,
162+
scales = NULL,
163+
resolutions = NULL,
164+
bounds = NULL,
165+
tileSize = NULL
166+
) {
167+
if(!crsClass %in% crsClasses) {
168+
stop(sprintf("crsClass argument must be one of %s",
169+
paste0(crsClasses, collapse = ', ')))
170+
171+
}
172+
if(crsClass %in% c('L.Proj.CRS', 'L.Proj.CRS.TMS') &&
173+
!is.null(scales) && !is.null(resolutions)) {
174+
stop(sprintf("Either input scales or resolutions"))
175+
}
176+
if(crsClass %in% c('L.Proj.CRS', 'L.Proj.CRS.TMS') &&
177+
is.null(scales) && is.null(resolutions)) {
178+
stop(sprintf("Input either scales or resolutions, not both"))
179+
}
180+
structure(
181+
list(
182+
crsClass = crsClass,
183+
code = code,
184+
proj4def = proj4def,
185+
projectedBounds = projectedBounds,
186+
options = filterNULL(list(
187+
origin = origin,
188+
transformation = transformation,
189+
scales = scales,
190+
resolutions = resolutions,
191+
bounds = bounds,
192+
tileSize = tileSize
193+
))
194+
),
195+
class = 'leaflet_crs'
196+
)
197+
}
198+

0 commit comments

Comments
 (0)