summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2017-08-10 15:07:48 +0200
committerTobrun <tobrun@mapbox.com>2017-08-17 16:48:18 +0200
commit830bf151be41609526a662c08bfdf04d358defbf (patch)
treea97f3b5d3381ca8dc7ae2bdc5a614c86453d017c
parentfb05d2e16a403077597ceeba6548b4246c8b1c8c (diff)
downloadqtlocation-mapboxgl-830bf151be41609526a662c08bfdf04d358defbf.tar.gz
[android] - create smallest possible LatLngBounds when visible region crosses the dateline
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java10
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java20
3 files changed, 37 insertions, 8 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 505b2db192..8b2ccffef1 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
@@ -222,6 +222,16 @@ public class LatLngBounds implements Parcelable {
}
/**
+ * Constructs a LatLngBounds from doubles representing a LatLng pair.
+ * <p>
+ * This method doesn't recalculate most east or most west boundaries.
+ * </p>
+ */
+ public static LatLngBounds from(double latNorth, double lonEast, double latSouth, double lonWest) {
+ return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
+ }
+
+ /**
* Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair.
*
* @param latLng the latitude lognitude pair to include in the bounds.
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 a2d759d006..16c73b1ca5 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
@@ -93,8 +93,6 @@ public class Projection {
* @return The projection of the viewing frustum in its current state.
*/
public VisibleRegion getVisibleRegion() {
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
-
float left = 0;
float right = nativeMapView.getWidth();
float top = 0;
@@ -105,12 +103,13 @@ public class Projection {
LatLng bottomRight = fromScreenLocation(new PointF(right, bottom));
LatLng bottomLeft = fromScreenLocation(new PointF(left, bottom));
- builder.include(topLeft)
- .include(topRight)
- .include(bottomRight)
- .include(bottomLeft);
-
- return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight, builder.build());
+ return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
+ LatLngBounds.from(
+ topRight.getLatitude(),
+ topRight.getLongitude(),
+ bottomLeft.getLatitude(),
+ bottomLeft.getLongitude())
+ );
}
/**
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java
index 8f8a5af3cc..badb6718cf 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.java
@@ -1,11 +1,18 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
+import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
+import com.mapbox.mapboxsdk.maps.Projection;
import com.mapbox.mapboxsdk.testapp.R;
+import timber.log.Timber;
+
/**
* Test activity showcasing a simple MapView without any MapboxMap interaction.
*/
@@ -20,6 +27,19 @@ public class SimpleMapActivity extends AppCompatActivity {
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(new OnMapReadyCallback() {
+ @Override
+ public void onMapReady(MapboxMap mapboxMap) {
+ final Projection projection = mapboxMap.getProjection();
+
+ mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
+ @Override
+ public void onMapClick(@NonNull LatLng point) {
+ Timber.e(projection.getVisibleRegion().toString());
+ }
+ });
+ }
+ });
}
@Override