From 97c143a3388647e74a9f74a4994ab9d6aafe26a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 18 Dec 2015 22:02:50 -0800 Subject: [PATCH] [core] Fly across the meridian or antemeridian, whichever is shorter ref mapbox/mapbox-gl-js#1853 --- src/mbgl/map/transform.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 759e6b4e0f8..badd5d89a3a 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -344,6 +344,16 @@ void Transform::flyTo(const CameraOptions &options) { return; } + // If a path crossing the antemeridian would be shorter, extend the final + // coordinate so that interpolating between the two endpoints will cross it. + if (std::abs(startLatLng.longitude) + std::abs(latLng.longitude) > 180) { + if (startLatLng.longitude > 0 && latLng.longitude < 0) { + latLng.longitude += 360; + } else if (startLatLng.longitude < 0 && latLng.longitude > 0) { + latLng.longitude -= 360; + } + } + const PrecisionPoint startPoint = { state.lngX(startLatLng.longitude), state.latY(startLatLng.latitude),