summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukasz.paczos@mapbox.com>2018-07-17 13:05:38 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-07-17 13:19:09 +0200
commitc010ef56883f693e2a9e1f4b9bc591b6f854ff8d (patch)
treef51235f8bc1a241b06e408b6b4eb15db7943af8c
parent116770cb3f53f334f91c9dbd5bbb66b2c82d2508 (diff)
downloadqtlocation-mapboxgl-upstream/12379-visible-region-padding.tar.gz
[android] option to request the visible region restricted by the content paddingupstream/12379-visible-region-padding
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java37
1 files changed, 32 insertions, 5 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 d5166c17b0..5580dcf99e 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
@@ -87,15 +87,42 @@ public class Projection {
/**
* Gets a projection of the viewing frustum for converting between screen coordinates and
* geo-latitude/longitude coordinates.
+ * <p>
+ * This method ignores the content padding.
*
* @return The projection of the viewing frustum in its current state.
*/
@NonNull
public VisibleRegion getVisibleRegion() {
- float left = 0;
- float right = nativeMapView.getWidth();
- float top = 0;
- float bottom = nativeMapView.getHeight();
+ return getVisibleRegion(true);
+ }
+
+ /**
+ * Gets a projection of the viewing frustum for converting between screen coordinates and
+ * geo-latitude/longitude coordinates.
+ *
+ * @param ignorePadding True if the padding should be ignored,
+ * false if the returned region should be reduced by the padding.
+ * @return The projection of the viewing frustum in its current state.
+ */
+ @NonNull
+ public VisibleRegion getVisibleRegion(boolean ignorePadding) {
+ float left;
+ float right;
+ float top;
+ float bottom;
+
+ if (ignorePadding) {
+ left = 0;
+ right = nativeMapView.getWidth();
+ top = 0;
+ bottom = nativeMapView.getHeight();
+ } else {
+ left = contentPadding[0];
+ right = nativeMapView.getWidth() - contentPadding[2];
+ top = contentPadding[1];
+ bottom = nativeMapView.getHeight() - contentPadding[3];
+ }
LatLng topLeft = fromScreenLocation(new PointF(left, top));
LatLng topRight = fromScreenLocation(new PointF(right, top));
@@ -132,7 +159,7 @@ public class Projection {
double fourthLon = boundsPoints.get(3).getLongitude();
// if it does not go over the date line
- if (secondLon > fourthLon && firstLon < thridLon) {
+ if (secondLon > fourthLon && firstLon < thridLon) {
return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
LatLngBounds.from(north,
secondLon > thridLon ? secondLon : thridLon,