Skip to main content

<Camera />

Props

PropTypeDefaultRequiredDescription
centerCoordinateGeoJSON.PositionnonefalseThe location on which the map should center.
boundsCameraBoundsWithPaddingnonefalseThe corners of a box around which the map should bound. Contains padding props for backwards
compatibility; the root padding prop should be used instead.
headingnumbernonefalseThe heading (orientation) of the map.
pitchnumbernonefalseThe pitch of the map.
zoomLevelnumbernonefalseThe zoom level of the map.
paddingCameraPaddingnonefalseThe viewport padding in points.
animationDurationnumbernonefalseThe duration the map takes to animate to a new configuration.
animationMode"flyTo" | "easeTo" | "linearTo" | "moveTo"nonefalseThe easing or path the camera uses to animate to a new configuration.
defaultSettingsCameraStopnonefalseDefault view settings applied on camera
minZoomLevelnumbernonefalseMinimum zoom level of the map
maxZoomLevelnumbernonefalseMaximum zoom level of the map
maxBoundsCameraBoundsnonefalseRestrict map panning so that the center is within these bounds
followUserLocationbooleannonefalseShould the map orientation follow the user's.
followUserModeUserTrackingModenonefalseThe mode used to track the user location on the map. One of; "normal", "compass", "course". Each mode string is also available as a member on the UserTrackingMode object. Follow (normal), FollowWithHeading (compass), FollowWithCourse (course). NOTE: followUserLocation must be set to true for any of the modes to take effect.
followZoomLevelnumbernonefalseThe zoomLevel on map while followUserLocation is set to true
followPitchnumbernonefalseThe pitch on map while followUserLocation is set to true
followHeadingnumbernonefalseThe heading on map while followUserLocation is set to true
onUserTrackingModeChangefuncnonefalseTriggered when followUserLocation or followUserMode changes
signature:(event:MapLibreRNEvent) => void

Methods

fitBounds(ne, sw, [padding], [animationDuration])

Map camera transitions to fit provided bounds

Arguments

NameTypeRequiredDescription
neGeoJSON.PositionYesNorth east coordinate of bound
swGeoJSON.PositionYesSouth west coordinate of bound
paddingnumber | number[]NoPadding for the bounds
animationDurationnumberNoDuration of camera animation
cameraRef.current?.fitBounds([lng, lat], [lng, lat]);
cameraRef.current?.fitBounds([lng, lat], [lng, lat], 20, 1000); // padding for all sides
cameraRef.current?.fitBounds(
[lng, lat],
[lng, lat],
[verticalPadding, horizontalPadding],
1000,
);
cameraRef.current?.fitBounds(
[lng, lat],
[lng, lat],
[top, right, bottom, left],
1000,
);

flyTo(coordinates, [animationDuration])

Map camera will fly to new coordinate

Arguments

NameTypeRequiredDescription
coordinatesGeoJSON.PositionYesCoordinates that map camera will jump to
animationDurationnumberNoDuration of camera animation
cameraRef.current?.flyTo([lng, lat]);
cameraRef.current?.flyTo([lng, lat], 12000);

moveTo(coordinates, [animationDuration])

Map camera will move to new coordinate at the same zoom level

Arguments

NameTypeRequiredDescription
coordinatesGeoJSON.PositionYesCoordinates that map camera will move too
animationDurationnumberNoDuration of camera animation
cameraRef.current?.moveTo([lng, lat], 200); // eases camera to new location based on duration
cameraRef.current?.moveTo([lng, lat]); // snaps camera to new location without any easing

zoomTo(zoomLevel, [animationDuration])

Map camera will zoom to specified level

Arguments

NameTypeRequiredDescription
zoomLevelnumberYesZoom level that the map camera will animate too
animationDurationnumberNoDuration of camera animation
cameraRef.current?.zoomTo(16);
cameraRef.current?.zoomTo(16, 100);

setCamera([config])

Map camera will perform updates based on provided config. Advanced use only!

Arguments

NameTypeRequiredDescription
configObjectNoCamera configuration
cameraRef.current?.setCamera({
centerCoordinate: [lng, lat],
zoomLevel: 16,
animationDuration: 2000,
});

cameraRef.current?.setCamera({
stops: [
{ pitch: 45, animationDuration: 200 },
{ heading: 180, animationDuration: 300 },
],
});