Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53d0fa3

Browse files
committed
Merge branch 'master' into flyTo
* master: addMapPane to add extra panes within leaflet (rstudio#549)
2 parents c0daa02 + 0eddf7e commit 53d0fa3

File tree

6 files changed

+169
-1
lines changed

6 files changed

+169
-1
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export(addGraticule)
6464
export(addLabelOnlyMarkers)
6565
export(addLayersControl)
6666
export(addLegend)
67+
export(addMapPane)
6768
export(addMarkers)
6869
export(addMeasure)
6970
export(addMiniMap)

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ leaflet 2.0.0.9000
33

44
FEATURES
55

6+
* Added method `addMapPane` to add custom pane layers to have fine tune control over layer ordering. New feature from within leaflet.js v1.x. (#549)
67
* Exposed htmlwidgets sizingPolicy in leaflet() (#548)
78

89
BUG FIXES
910

1011
* Default marker icon locations will now use unpkg.com instead of the leaflet cdn when using https or file protocols. (#544)
1112
* `.leaflet-map-pane` `z-index` switched to 'auto'. Allows for map panes to appear above the map if they appear later in the dom. (#537)
12-
* Use correct Leaflet.js scale control remove method (#547)
13+
* Use correct Leaflet.js scale control remove method. (#547)
1314

1415

1516
leaflet 2.0.0

R/mapPane.R

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#' Add additional panes to leaflet map to control layer order
2+
#'
3+
#' @description
4+
#' map panes can be created by supplying a name and a zIndex to control layer
5+
#' ordering. We recommend a \code{zIndex} value between 400 (the default
6+
#' overlay pane) and 500 (the default shadow pane). You can then use this pane
7+
#' to render overlays (points, lines, polygons) by setting the \code{pane}
8+
#' argument in \code{leafletOptions}. This will give you control
9+
#' over the order of the layers, e.g. points always on top of polygons.
10+
#' If two layers are provided to the same pane, overlay will be determined by
11+
#' order of adding. See examples below.
12+
#' See \url{http://www.leafletjs.com/reference-1.3.0.html#map-pane} for details.
13+
#'
14+
#' If the error "Cannot read property 'appendChild' of undefined" occurs, make
15+
#' sure the pane being used for used for display has already been added to the map.
16+
#'
17+
#' @param map A \code{leaflet} or \code{mapview} object.
18+
#' @param name The name of the new pane (refer to this in \code{leafletOptions}.
19+
#' @param zIndex The zIndex of the pane. Panes with higher index are rendered
20+
#' above panes with lower indices.
21+
#'
22+
#' @export
23+
#' @examples
24+
#' \donttest{rand_lng <- function(n = 10) rnorm(n, -93.65, .01)
25+
#' rand_lat <- function(n = 10) rnorm(n, 42.0285, .01)
26+
#'
27+
#' random_data <- data.frame(
28+
#' lng = rand_lng(50),
29+
#' lat = rand_lat(50),
30+
#' radius = runif(50, 50, 150),
31+
#' circleId = paste0("circle #", 1:50),
32+
#' lineId = paste0("circle #", 1:50)
33+
#' )
34+
#'
35+
#' # display circles (zIndex: 420) above the lines (zIndex: 410), even when added first
36+
#' leaflet() %>%
37+
#' addTiles() %>%
38+
#' # move the center to Snedecor Hall
39+
#' setView(-93.65, 42.0285, zoom = 14) %>%
40+
#' addMapPane("ames_lines", zIndex = 410) %>% # shown below ames_circles
41+
#' addMapPane("ames_circles", zIndex = 420) %>% # shown above ames_lines
42+
#' # points above polygons
43+
#' addCircles(
44+
#' data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,
45+
#' options = pathOptions(pane = "ames_circles")
46+
#' ) %>%
47+
#' # lines in 'ames_lines' pane
48+
#' addPolylines(
49+
#' data = random_data, ~lng, ~lat, color = "#F00", weight = 20,
50+
#' options = pathOptions(pane = "ames_lines")
51+
#' )
52+
#'
53+
#'
54+
#' # same example but circles (zIndex: 420) are below the lines (zIndex: 430)
55+
#' leaflet() %>%
56+
#' addTiles() %>%
57+
#' # move the center to Snedecor Hall
58+
#' setView(-93.65, 42.0285, zoom = 14) %>%
59+
#' addMapPane("ames_lines", zIndex = 430) %>% # shown below ames_circles
60+
#' addMapPane("ames_circles", zIndex = 420) %>% # shown above ames_lines
61+
#' # points above polygons
62+
#' addCircles(
63+
#' data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,
64+
#' options = pathOptions(pane = "ames_circles")
65+
#' ) %>%
66+
#' # lines in 'ames_lines' pane
67+
#' addPolylines(
68+
#' data = random_data, ~lng, ~lat, color = "#F00", weight = 20,
69+
#' options = pathOptions(pane = "ames_lines")
70+
#' )
71+
#'}
72+
addMapPane = function(map, name, zIndex) {
73+
invokeMethod(map, getMapData(map), 'createMapPane', name, zIndex)
74+
}

inst/htmlwidgets/leaflet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,11 @@ methods.removeSelect = function () {
25152515
}
25162516
};
25172517

2518+
methods.createMapPane = function (name, zIndex) {
2519+
this.createPane(name);
2520+
this.getPane(name).style.zIndex = zIndex;
2521+
};
2522+
25182523

25192524
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
25202525
},{"./cluster-layer-store":1,"./crs_utils":3,"./dataframe":4,"./global/htmlwidgets":8,"./global/jquery":9,"./global/leaflet":10,"./global/shiny":12,"./mipmapper":16,"./util":17}],16:[function(require,module,exports){

javascript/src/methods.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,3 +1339,10 @@ methods.removeSelect = function() {
13391339
this._selectButton = null;
13401340
}
13411341
};
1342+
1343+
1344+
1345+
methods.createMapPane = function (name, zIndex) {
1346+
this.createPane(name);
1347+
this.getPane(name).style.zIndex = zIndex;
1348+
};

man/addMapPane.Rd

Lines changed: 80 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)