[android] #5034 - LatLngBounds Camera update not taking map padding in account

[android] #5034 - padding not being included in getVisibleBounds
This commit is contained in:
Tobrun
2016-05-17 09:54:04 +02:00
committed by Tobrun Van Nuland
parent 102e62ae55
commit 034246e00a
4 changed files with 23 additions and 7 deletions

View File

@@ -226,7 +226,14 @@ public final class CameraUpdateFactory {
// Get required objects
Projection projection = mapboxMap.getProjection();
UiSettings uiSettings = mapboxMap.getUiSettings();
RectF padding = getPadding();
// calculate correct padding
int[] mapPadding = mapboxMap.getPadding();
RectF latLngPadding = getPadding();
RectF padding = new RectF(latLngPadding.left + mapPadding[0],
latLngPadding.top + mapPadding[1],
latLngPadding.right + mapPadding[2],
latLngPadding.bottom + mapPadding[3]);
// Calculate the bounds of the possibly rotated shape with respect to the viewport
PointF nePixel = new PointF(-Float.MAX_VALUE, -Float.MAX_VALUE);
@@ -244,7 +251,6 @@ public final class CameraUpdateFactory {
float width = nePixel.x - swPixel.x;
float height = nePixel.y - swPixel.y;
double zoom = 0;
float minScale = 1;
// Calculate the zoom level

View File

@@ -672,6 +672,14 @@ public class MapView extends FrameLayout {
return mContentPaddingBottom;
}
int getContentWidth(){
return getWidth() - mContentPaddingLeft - mContentPaddingRight;
}
int getContentHeight(){
return getHeight() - mContentPaddingBottom - mContentPaddingTop;
}
//
// Zoom
//

View File

@@ -57,8 +57,8 @@ public class Projection {
public VisibleRegion getVisibleRegion() {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
int viewportWidth = mMapView.getWidth();
int viewportHeight = mMapView.getHeight();
int viewportWidth = mMapView.getContentWidth();
int viewportHeight = mMapView.getContentHeight();
LatLng topLeft = fromScreenLocation(new PointF(0, 0));
LatLng topRight = fromScreenLocation(new PointF(viewportWidth, 0));

View File

@@ -68,10 +68,12 @@ public class LatLngBoundsActivity extends AppCompatActivity {
.include(LOS_ANGELES)
.build();
// And padding
int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
// Add map padding
int mapPadding = (int) getResources().getDimension(R.dimen.fab_margin);
mapboxMap.setPadding(mapPadding, mapPadding, mapPadding, mapPadding);
// Move camera to the bounds with padding
// Move camera to the bounds with added padding
int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
// Call mapboxMap.getProjection().getVisibleRegion().latLngBounds to retrieve the bounds