summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-05-01 15:15:30 +0200
committerTobrun <tobrun@mapbox.com>2018-05-02 12:23:37 +0200
commitfa700cc10864a6ec9df1f41062b210072f4926d4 (patch)
tree645d841115340b6e22626767fb1d138ce092df40
parentcf4b4e728c26e444514f6ba792c207692350eb57 (diff)
downloadqtlocation-mapboxgl-fa700cc10864a6ec9df1f41062b210072f4926d4.tar.gz
Revert "[android] - unwrap LatLngBounds for the shortest path when passing to core (#11759)"
This reverts commit eb39c80
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java45
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java13
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java22
3 files changed, 14 insertions, 66 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index eec0d566bb..05187cf333 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -28,7 +28,7 @@ public class LatLngBounds implements Parcelable {
/**
* Construct a new LatLngBounds based on its corners, given in NESW
* order.
- * <p>
+ *
* If eastern longitude is smaller than the western one, bounds will include antimeridian.
* For example, if the NE point is (10, -170) and the SW point is (-10, 170), then bounds will span over 20 degrees
* and cross the antimeridian.
@@ -46,11 +46,6 @@ public class LatLngBounds implements Parcelable {
this.longitudeWest = westLongitude;
}
- LatLngBounds(LatLngBounds latLngBounds) {
- this(latLngBounds.latitudeNorth, latLngBounds.longitudeEast,
- latLngBounds.latitudeSouth, latLngBounds.longitudeWest);
- }
-
/**
* Returns the world bounds.
*
@@ -80,6 +75,7 @@ public class LatLngBounds implements Parcelable {
if (longCenter >= GeometryConstants.MAX_LONGITUDE) {
longCenter = this.longitudeEast - halfSpan;
}
+ return new LatLng(latCenter, longCenter);
}
return new LatLng(latCenter, longCenter);
@@ -192,6 +188,7 @@ public class LatLngBounds implements Parcelable {
return GeometryConstants.LONGITUDE_SPAN - longSpan;
}
+
static double getLongitudeSpan(final double longEast, final double longWest) {
double longSpan = Math.abs(longEast - longWest);
if (longEast >= longWest) {
@@ -203,25 +200,6 @@ public class LatLngBounds implements Parcelable {
}
/**
- * If bounds cross the antimeridian, unwrap west longitude for the shortest path.
- *
- * @return unwrapped bounds
- */
- public LatLngBounds unwrapBounds() {
- double unwrapedLonWest = longitudeWest;
- if (longitudeEast < longitudeWest) {
- if (longitudeWest > 0 && longitudeEast < 0) {
- unwrapedLonWest -= GeometryConstants.LONGITUDE_SPAN;
- } else if (longitudeWest < 0 && longitudeEast > 0) {
- unwrapedLonWest += GeometryConstants.LONGITUDE_SPAN;
- }
- return unwrapped(latitudeNorth, longitudeEast, latitudeSouth, unwrapedLonWest);
- } else {
- return new LatLngBounds(this);
- }
- }
-
- /**
* Validate if LatLngBounds is empty, determined if absolute distance is
*
* @return boolean indicating if span is empty
@@ -301,11 +279,12 @@ public class LatLngBounds implements Parcelable {
/**
* Constructs a LatLngBounds from doubles representing a LatLng pair.
- * <p>
+ *
* This values of latNorth and latSouth should be in the range of [-90, 90],
* see {@link GeometryConstants#MIN_LATITUDE} and {@link GeometryConstants#MAX_LATITUDE},
* otherwise IllegalArgumentException will be thrown.
* latNorth should be greater or equal latSouth, otherwise IllegalArgumentException will be thrown.
+ *
* <p>
* This method doesn't recalculate most east or most west boundaries.
* Note that lonEast and lonWest will be wrapped to be in the range of [-180, 180],
@@ -339,20 +318,12 @@ public class LatLngBounds implements Parcelable {
throw new IllegalArgumentException("LatSouth cannot be less than latNorth");
}
- return wrapped(latNorth, lonEast, latSouth, lonWest);
- }
-
- static LatLngBounds wrapped(double latNorth, double lonEast, double latSouth, double lonWest) {
lonEast = LatLng.wrap(lonEast, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE);
lonWest = LatLng.wrap(lonWest, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE);
return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
}
- static LatLngBounds unwrapped(double latNorth, double lonEast, double latSouth, double lonWest) {
- return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
- }
-
private static double lat_(int z, int y) {
double n = Math.PI - 2.0 * Math.PI * y / Math.pow(2.0, z);
return Math.toDegrees(Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
@@ -364,14 +335,14 @@ public class LatLngBounds implements Parcelable {
/**
* Constructs a LatLngBounds from a Tile identifier.
- * <p>
+ *
* Returned bounds will have latitude in the range of Mercator projection.
+ * @see GeometryConstants#MIN_MERCATOR_LATITUDE
+ * @see GeometryConstants#MAX_MERCATOR_LATITUDE
*
* @param z Tile zoom level.
* @param x Tile X coordinate.
* @param y Tile Y coordinate.
- * @see GeometryConstants#MIN_MERCATOR_LATITUDE
- * @see GeometryConstants#MAX_MERCATOR_LATITUDE
*/
public static LatLngBounds from(int z, int x, int y) {
return new LatLngBounds(lat_(z, y), lon_(z, x + 1), lat_(z, y + 1), lon_(z, x));
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 745485e2d2..5e36dd0f78 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -1540,12 +1540,7 @@ public final class MapboxMap {
* @param latLngBounds the bounds to constrain the map with
*/
public void setLatLngBoundsForCameraTarget(@Nullable LatLngBounds latLngBounds) {
- if (latLngBounds == null) {
- nativeMapView.setLatLngBounds(latLngBounds);
- } else {
- //unwrapping the bounds to generate the right convex hull in core
- nativeMapView.setLatLngBounds(latLngBounds.unwrapBounds());
- }
+ nativeMapView.setLatLngBounds(latLngBounds);
}
/**
@@ -1555,9 +1550,9 @@ public final class MapboxMap {
* @param padding the padding to apply to the bounds
* @return the camera position that fits the bounds and padding
*/
- public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, int[] padding) {
- // get padded camera position from LatLngBounds, unwrapping the bounds to generate the right convex hull in core
- return nativeMapView.getCameraForLatLngBounds(latLngBounds.unwrapBounds(), padding);
+ public CameraPosition getCameraForLatLngBounds(@Nullable LatLngBounds latLngBounds, int[] padding) {
+ // get padded camera position from LatLngBounds
+ return nativeMapView.getCameraForLatLngBounds(latLngBounds, padding);
}
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
index c1e497af32..e072f07fb9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
@@ -524,6 +524,7 @@ public class LatLngBoundsTest {
LatLngBounds.from(0, Double.POSITIVE_INFINITY, -20, -20);
}
+
@Test
public void testConstructorChecksSouthLatitudeNaN() {
exception.expect(IllegalArgumentException.class);
@@ -542,7 +543,7 @@ public class LatLngBoundsTest {
public void testConstructorChecksSouthLatitudeGreaterThan90() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("latitude must be between -90 and 90");
- LatLngBounds.from(20, 20, 95, 0);
+ LatLngBounds.from(20, 20,95, 0);
}
@Test
@@ -565,23 +566,4 @@ public class LatLngBoundsTest {
exception.expectMessage("LatSouth cannot be less than latNorth");
LatLngBounds.from(0, 20, 20, 0);
}
-
- @Test
- public void testCopyConstructor() {
- LatLngBounds bounds = LatLngBounds.from(50, 10, -20, -30);
- LatLngBounds copyBounds = new LatLngBounds(bounds);
- assertEquals(bounds, copyBounds);
- }
-
- @Test
- public void testUnwrapBounds() {
- LatLngBounds bounds = LatLngBounds.from(16.5, -172.8, -35.127709, 172.6);
- LatLngBounds unwrappedBounds = bounds.unwrapBounds();
- assertEquals(bounds.getCenter().wrap(), unwrappedBounds.getCenter().wrap());
- assertEquals(bounds.getSpan(), unwrappedBounds.getSpan());
- assertTrue(unwrappedBounds.getLonEast() < 0 && unwrappedBounds.getLonWest() < 0);
-
- LatLngBounds bounds2 = LatLngBounds.from(16.5, -162.8, -35.127709, -177.4);
- assertEquals(bounds2, bounds2.unwrapBounds());
- }
}