gi-nx / CameraOptions
ts
type CameraOptions = {
around?: LngLatLike;
bearing?: number;
center?: LngLatLike;
maxZoom?: number;
minZoom?: number;
padding?: number | PaddingOptions;
pitch?: number;
retainPadding?: boolean;
zoom?: number;
};Options common to Map#jumpTo, Map#easeTo, and Map#flyTo, controlling the desired location, zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current camera value for that property will remain unchanged.
Example
ts
// set the map's initial perspective with CameraOptions
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-73.5804, 45.53483],
pitch: 60,
bearing: -60,
zoom: 10
});See
- Example: Set pitch and bearing
- Example: Jump to a series of locations
- Example: Fly to a location
- Example: Display buildings in 3D
Properties
| Property | Type | Description |
|---|---|---|
around? | LngLatLike | The location serving as the origin for a change in zoom, pitch and/or bearing. This location will remain at the same screen position following the transform. This is useful for drawing attention to a location that is not in the screen center. center is ignored if around is included. |
bearing? | number | The desired bearing in degrees. The bearing is the compass direction that is "up". For example, bearing: 90 orients the map so that east is up. |
center? | LngLatLike | The location to place at the screen center. |
maxZoom? | number | - |
minZoom? | number | - |
padding? | number | PaddingOptions | Dimensions in pixels applied on each side of the viewport for shifting the vanishing point. Note that when padding is used with jumpTo, easeTo, and flyTo, it also sets the global map padding as a side effect, affecting all subsequent camera movements until the padding is reset. To avoid this, add the retainPadding: false option. |
pitch? | number | The desired pitch in degrees. The pitch is the angle towards the horizon measured in degrees with a range between 0 and 85 degrees. For example, pitch: 0 provides the appearance of looking straight down at the map, while pitch: 60 tilts the user's perspective towards the horizon. Increasing the pitch value is often used to display 3D objects. |
retainPadding? | boolean | If false, the value provided with the padding option will not be retained as the global map padding. When set to true the current camera transform will be modified by the function being called with this option. This is true by default. |
zoom? | number | The desired zoom level. |