summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorosana <osana.babayan@mapbox.com>2018-02-26 02:25:34 +0100
committer“osana” <osana.babayan@mapbox.com>2018-02-28 18:43:56 -0500
commit6f2886789194f2e19f12bbb9f02a8ae243f0f90a (patch)
treed8d2bf3b7e103041a502512dfbba296ea0c2b9a4
parent848d7dff4e682c3d2485366f95649a5de4b1bd75 (diff)
downloadqtlocation-mapboxgl-upstream/osana-visibleregion-rotatied-11137-dateline.tar.gz
[android] rotated map returns incorrect bounds when going over date lineupstream/osana-visibleregion-rotatied-11137-dateline
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java54
1 files changed, 46 insertions, 8 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index ae559189ad..4709ebd060 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -9,6 +9,9 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* A projection is used to translate between on screen location and geographic coordinates on
* the surface of the Earth. Screen location is in screen pixels (not display pixels)
@@ -103,14 +106,49 @@ public class Projection {
LatLng bottomRight = fromScreenLocation(new PointF(right, bottom));
LatLng bottomLeft = fromScreenLocation(new PointF(left, bottom));
- return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
- new LatLngBounds.Builder()
- .include(topRight)
- .include(bottomLeft)
- .include(bottomRight)
- .include(topLeft)
- .build()
- );
+ // Map can be rotated, find correct LatLngBounds that encompasses the visible region (that might be rotated)
+ List<LatLng> boundsPoints = new ArrayList<>();
+ boundsPoints.add(topLeft);
+ boundsPoints.add(topRight);
+ boundsPoints.add(bottomRight);
+ boundsPoints.add(bottomLeft);
+
+ // order so that two most northern point are put first
+ while ((boundsPoints.get(0).getLatitude() < boundsPoints.get(3).getLatitude())
+ || (boundsPoints.get(1).getLatitude() < boundsPoints.get(2).getLatitude())) {
+ LatLng first = boundsPoints.remove(0);
+ boundsPoints.add(first);
+ }
+
+ double north = boundsPoints.get(0).getLatitude();
+ if (north < boundsPoints.get(1).getLatitude()) {
+ north = boundsPoints.get(1).getLatitude();
+ }
+
+ double south = boundsPoints.get(2).getLatitude();
+ if (south > boundsPoints.get(3).getLatitude()) {
+ south = boundsPoints.get(3).getLatitude();
+ }
+
+ double firstLon = boundsPoints.get(0).getLongitude();
+ double secondLon = boundsPoints.get(1).getLongitude();
+ double thridLon = boundsPoints.get(2).getLongitude();
+ double fourthLon = boundsPoints.get(3).getLongitude();
+
+ // if it does not go over the date line
+ if (secondLon > fourthLon && firstLon < thridLon) {
+ return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
+ LatLngBounds.from(north,
+ secondLon > thridLon ? secondLon : thridLon,
+ south,
+ firstLon < fourthLon ? firstLon : fourthLon));
+ } else {
+ return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
+ LatLngBounds.from(north,
+ secondLon < thridLon ? secondLon : thridLon,
+ south,
+ firstLon > fourthLon ? firstLon : fourthLon));
+ }
}
/**