Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Map : private util::noncopyable {
void scaleBy(double scale, const std::optional<ScreenCoordinate>& anchor, const AnimationOptions& animation = {});
void pitchBy(double pitch, const AnimationOptions& animation = {});
void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
void rotateBy(double angleDegree, const AnimationOptions& = {});
CameraOptions cameraForLatLngBounds(const LatLngBounds&,
const EdgeInsets&,
const std::optional<double>& bearing = std::nullopt,
Expand Down
6 changes: 6 additions & 0 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ void Map::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second
impl->onUpdate();
}

void Map::rotateBy(double angleDegree, const AnimationOptions& animation) {
impl->cameraMutated = true;
impl->transform.rotateBy(angleDegree, animation);
impl->onUpdate();
}

CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds,
const EdgeInsets& padding,
const std::optional<double>& bearing,
Expand Down
10 changes: 10 additions & 0 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,16 @@ void Transform::rotateBy(const ScreenCoordinate& first,
easeTo(CameraOptions().withBearing(bearing), animation);
}

void Transform::rotateBy(double angleDegree, const AnimationOptions& animation) {
const double bearing = -util::rad2deg(state.getBearing()) - angleDegree;
easeTo(CameraOptions().withBearing(bearing), animation);
}

/*!
* \brief Transform::getBearing
* Bearing in radiant
* \return bearing in radians
*/
double Transform::getBearing() const {
return state.getBearing();
}
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/map/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Transform : private util::noncopyable {
// Bearing

void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {});
void rotateBy(double angleDegree, const AnimationOptions& = {});
double getBearing() const;

// Pitch
Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ class TransformState {

// map position
double x = 0, y = 0, z = 0;
/*!
* \brief bearing
* Bearing in radian
*/
double bearing = 0;
double scale = 1;
double fov = util::DEFAULT_FOV;
Expand Down
Loading