[core] Camera center and anchor points are mutually exclusive

This commit is contained in:
Bruno de Oliveira Abinader
2018-11-23 22:47:40 +02:00
parent 82be3104cd
commit 52cce7925d
3 changed files with 20 additions and 2 deletions

View File

@@ -10,7 +10,10 @@
namespace mbgl {
/** Various options for describing the viewpoint of a map. All fields are
optional. */
optional.
Anchor and center points are mutually exclusive, with preference for the
center point when both are set.
*/
struct CameraOptions {
/** Coordinate at the center of the map. */
optional<LatLng> center;

View File

@@ -561,7 +561,9 @@ void Transform::startTransition(const CameraOptions& camera,
observer.onCameraWillChange(isAnimated ? MapObserver::CameraChangeMode::Animated : MapObserver::CameraChangeMode::Immediate);
// Associate the anchor, if given, with a coordinate.
optional<ScreenCoordinate> anchor = camera.anchor;
// Anchor and center points are mutually exclusive, with preference for the
// center point when both are set.
optional<ScreenCoordinate> anchor = camera.center ? nullopt : camera.anchor;
LatLng anchorLatLng;
if (anchor) {
anchor->y = state.size.height - anchor->y;

View File

@@ -476,6 +476,19 @@ TEST(Transform, Camera) {
transform.updateTransitions(transform.getTransitionStart() + Milliseconds(750));
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_FALSE(transform.inTransition());
// Anchor and center points are mutually exclusive.
CameraOptions camera;
camera.center = LatLng { 0, 0 };
camera.anchor = ScreenCoordinate { 0, 0 }; // top-left
camera.zoom = transform.getState().getMaxZoom();
transform.easeTo(camera, AnimationOptions(Seconds(1)));
transform.updateTransitions(transform.getTransitionStart() + Milliseconds(250));
transform.updateTransitions(transform.getTransitionStart() + Milliseconds(500));
transform.updateTransitions(transform.getTransitionStart() + Milliseconds(750));
transform.updateTransitions(transform.getTransitionStart() + transform.getTransitionDuration());
ASSERT_DOUBLE_EQ(transform.getLatLng().latitude(), 0);
ASSERT_DOUBLE_EQ(transform.getLatLng().longitude(), 0);
}
TEST(Transform, DefaultTransform) {