-
Notifications
You must be signed in to change notification settings - Fork 507
/
Copy pathaddMapPane.Rd
80 lines (73 loc) · 2.95 KB
/
addMapPane.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mapPane.R
\name{addMapPane}
\alias{addMapPane}
\title{Add additional panes to leaflet map to control layer order}
\usage{
addMapPane(map, name, zIndex)
}
\arguments{
\item{map}{A \code{leaflet} or \code{mapview} object.}
\item{name}{The name of the new pane (refer to this in \code{leafletOptions()}.}
\item{zIndex}{The zIndex of the pane. Panes with higher index are rendered
above panes with lower indices.}
}
\description{
map panes can be created by supplying a name and a zIndex to control layer
ordering. We recommend a \code{zIndex} value between 400 (the default
overlay pane) and 500 (the default shadow pane). You can then use this pane
to render overlays (points, lines, polygons) by setting the \code{pane}
argument in \code{\link[=leafletOptions]{leafletOptions()}}. This will give you control
over the order of the layers, e.g., points always on top of polygons.
If two layers are provided to the same pane, overlay will be determined by
order of adding. See examples below.
See \url{https://web.archive.org/web/20220702182250/https://leafletjs.com/reference-1.3.4.html#map-pane} for details.
If the error "Cannot read property 'appendChild' of undefined" occurs, make
sure the pane being used for used for display has already been added to the map.
}
\examples{
\donttest{rand_lng <- function(n = 10) rnorm(n, -93.65, .01)
rand_lat <- function(n = 10) rnorm(n, 42.0285, .01)
random_data <- data.frame(
lng = rand_lng(50),
lat = rand_lat(50),
radius = runif(50, 50, 150),
circleId = paste0("circle #", 1:50),
lineId = paste0("circle #", 1:50)
)
# display circles (zIndex: 420) above the lines (zIndex: 410), even when added first
leaflet() \%>\%
addTiles() \%>\%
# move the center to Snedecor Hall
setView(-93.65, 42.0285, zoom = 14) \%>\%
addMapPane("ames_lines", zIndex = 410) \%>\% # shown below ames_circles
addMapPane("ames_circles", zIndex = 420) \%>\% # shown above ames_lines
# points above polygons
addCircles(
data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,
options = pathOptions(pane = "ames_circles")
) \%>\%
# lines in 'ames_lines' pane
addPolylines(
data = random_data, ~lng, ~lat, color = "#F00", weight = 20,
options = pathOptions(pane = "ames_lines")
)
# same example but circles (zIndex: 420) are below the lines (zIndex: 430)
leaflet() \%>\%
addTiles() \%>\%
# move the center to Snedecor Hall
setView(-93.65, 42.0285, zoom = 14) \%>\%
addMapPane("ames_lines", zIndex = 430) \%>\% # shown below ames_circles
addMapPane("ames_circles", zIndex = 420) \%>\% # shown above ames_lines
# points above polygons
addCircles(
data = random_data, ~lng, ~lat, radius = ~radius, popup = ~circleId,
options = pathOptions(pane = "ames_circles")
) \%>\%
# lines in 'ames_lines' pane
addPolylines(
data = random_data, ~lng, ~lat, color = "#F00", weight = 20,
options = pathOptions(pane = "ames_lines")
)
}
}