addMapboxGL: Adds a Mapbox GL layer to a Leaflet map

Description Usage Arguments Examples

Description

Uses the Mapbox GL Leaflet plugin to add a Mapbox GL layer to a Leaflet map.

Usage

1
2
3
4
5
mapboxOptions(accessToken = NULL, ...)

addMapboxGL(map, style = "mapbox://styles/mapbox/streets-v9",
  accessToken = getOption("mapbox.accessToken"), layerId = NULL,
  group = NULL, setView = TRUE, options = mapboxOptions())

Arguments

accessToken

A Mapbox access token, or NA to explicitly pass no token. You can also set a token globally by calling options(mapbox.accessToken = "...").

...

Other options to pass to Mapbox GL JS.

map

The Leaflet R object (see leaflet::leaflet()).

style

Tile vector URL; can begin with http://, https://, or mapbox://.

layerId

A layer ID; see docs.

group

The name of the group the newly created layer should belong to (for leaflet::clearGroup() and leaflet::addLayersControl() purposes). (Warning: Due to the way Leaflet and Mapbox GL JS integrate, showing/hiding a GL layer may give unexpected results.)

setView

If TRUE (the default), drive the map to the center/zoom specified in the style (if any). Note that this will override any leaflet::setView() or leaflet::fitBounds() calls that occur between the addMapboxGL call and when the style finishes loading; use setView=FALSE in those cases.

options

A list of Map options. See the Mapbox GL JS documentation for more details. Not all options may work in the context of Leaflet.

Examples

1
2
3
4
5
6
7
8
# Before running, set your Mapbox access token using:
# `options(mapbox.accessToken = "...")`

library(leaflet)

leaflet(quakes) %>%
  addMapboxGL(style = "mapbox://styles/mapbox/streets-v9") %>%
  addCircleMarkers(weight = 1, fillOpacity = 0, radius = 3)

rstudio/leaflet.mapboxgl documentation built on May 6, 2019, 8:30 p.m.