mapview (version 2.4.0)

addMapPane: Add additional panes to leaflet map to control layer order

Description

map panes can be created by supplying a name and a zIndex to control layer ordering. We recommend a 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 pane argument in 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 http://www.leafletjs.com/reference-1.3.0.html#map-pane for details.

Usage

addMapPane(map, name, zIndex)

Arguments

map

A leaflet or mapview object.

name

The name of the new pane (refer to this in leafletOptions.

zIndex

The zIndex of the pane. Panes with higher index are rendered above panes with lower indices.

Examples

Run this code
# NOT RUN {
library(leaflet)
library(mapview)

## points above polygons
leaflet() %>%
  addTiles() %>%
  addMapPane("polygons", zIndex = 410) %>%
  addMapPane("points", zIndex = 420) %>%
  addPolygons(data = franconia,
              group = "pol1",
              fillOpacity = 0.7,
              fillColor = "green",
              color = "black",
              options = leafletOptions(pane = "polygons")) %>%
  addPolygons(data = franconia,
              group = "pol2",
              color = "black",
              fillColor = "purple",
              fillOpacity = 0.7,
              options = leafletOptions(pane = "polygons")) %>%
  addCircleMarkers(data = breweries,
                   group = "pts",
                   color = "darkblue",
                   options = leafletOptions(pane = "points")) %>%
  addLayersControl(overlayGroups = c("pol1", "pol2", "pts"))


# }

Run the code above in your browser using DataLab