mapboxgl: Initialize a Mapbox GL Map

View source: R/mapboxgl.R

mapboxglR Documentation

Initialize a Mapbox GL Map

Description

Initialize a Mapbox GL Map

Usage

mapboxgl(
  style = NULL,
  center = c(0, 0),
  zoom = 0,
  bearing = 0,
  pitch = 0,
  projection = "globe",
  parallels = NULL,
  access_token = NULL,
  bounds = NULL,
  width = "100%",
  height = NULL,
  ...
)

Arguments

style

The Mapbox style to use.

center

A numeric vector of length 2 specifying the initial center of the map.

zoom

The initial zoom level of the map.

bearing

The initial bearing (rotation) of the map, in degrees.

pitch

The initial pitch (tilt) of the map, in degrees.

projection

The map projection to use (e.g., "mercator", "globe").

parallels

A vector of two numbers representing the standard parallels of the projection. Only available when the projection is "albers" or "lambertConformalConic".

access_token

Your Mapbox access token.

bounds

The bounding box to fit the map to. Accepts one of the following:

  • sf object;

  • output of st_bbox();

  • unnamed numeric vector of the form c(xmin, ymin, xmax, ymax).

width

The width of the output htmlwidget.

height

The height of the output htmlwidget.

...

Additional named parameters to be passed to the Mapbox GL JS Map. See the Mapbox GL JS documentation for a full list of options: https://docs.mapbox.com/mapbox-gl-js/api/map/#map-parameters. Common options include:

  • minZoom / maxZoom: Minimum and maximum zoom levels (0-24).

  • maxBounds: Restrict panning to a bounding box, specified as list(c(sw_lng, sw_lat), c(ne_lng, ne_lat)).

  • dragRotate: If FALSE, disables rotation via mouse drag (default TRUE).

  • touchZoomRotate: If FALSE, disables pinch-to-rotate on touch (default TRUE).

  • scrollZoom: If FALSE, disables scroll wheel zoom (default TRUE).

Value

An HTML widget for a Mapbox GL map.

Examples

## Not run: 
# Basic map
mapboxgl(projection = "globe")

# Constrained map with zoom limits and disabled rotation
mapboxgl(
  bounds = my_sf_object,
  minZoom = 5,
  maxZoom = 12,
  dragRotate = FALSE,
  touchZoomRotate = FALSE
)

## End(Not run)

mapgl documentation built on Jan. 12, 2026, 5:06 p.m.