Learn R Programming

mapboxapi (version 0.2)

addMapboxTiles: Use a Mapbox style in a Leaflet map

Description

Use a Mapbox style in a Leaflet map

Usage

addMapboxTiles(
  map,
  style_id,
  username,
  scaling_factor = c("1x", "0.5x", "2x"),
  access_token = NULL,
  layerId = NULL,
  group = NULL,
  options = leaflet::tileOptions(),
  data = leaflet::getMapData(map)
)

Arguments

map

A map widget object created by leaflet::leaflet()

style_id

The style ID of your Mapbox style

username

Your Mapbox username

scaling_factor

The scaling factor to use when rendering the tiles. A scaling factor of 1 (the default) returns 512px by 512px tiles. A factor of 0.5 returns 256x256 tiles, and a factor of 2 returns 1024x1024 tiles.

access_token

Your Mapbox access token; can be set with mb_access_token().

layerId

the layer ID

group

The name of the group the Mapbox tile layer should belong to (for use in Shiny and to modify layers control in a Leaflet workflow)

options

A list of extra options (optional)

data

The data object used to derive argument values; can be provided to the initial call to leaflet::leaflet()

Value

A pointer to the Mapbox Static Tiles API which will be translated appropriately by the leaflet R package.

Examples

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

leaflet() %>%
  addMapboxTiles(style_id = "light-v9",
                 username = "mapbox") %>%
  setView(lng = -74.0051,
          lat = 40.7251,
          zoom = 13)

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab