diff options
author | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-07-17 13:05:38 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-07-18 15:03:31 +0200 |
commit | 6d24ef9a03c2f441a7055d12612d36c589919d5e (patch) | |
tree | e5400c6a37ef52ea6734d5f853cbb19bec01f099 | |
parent | 782c58be0008c12881efcdfb6d81db0deda2e702 (diff) | |
download | qtlocation-mapboxgl-6d24ef9a03c2f441a7055d12612d36c589919d5e.tar.gz |
[android] option to request the visible region restricted by the content padding
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java | 37 |
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, |