From 6d24ef9a03c2f441a7055d12612d36c589919d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Tue, 17 Jul 2018 13:05:38 +0200 Subject: [android] option to request the visible region restricted by the content padding --- .../java/com/mapbox/mapboxsdk/maps/Projection.java | 37 +++++++++++++++++++--- 1 file 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. + *

+ * 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, -- cgit v1.2.1