diff --git a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraStop.java b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraStop.java index cbc55b4a7..dd020cb26 100644 --- a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraStop.java +++ b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraStop.java @@ -16,6 +16,8 @@ import com.mapbox.rctmgl.components.camera.constants.CameraMode; import com.mapbox.rctmgl.utils.GeoJSONUtils; +import com.mapbox.rctmgl.components.mapview.RCTMGLMapView; + /** * Created by nickitaliano on 9/5/17. */ @@ -75,7 +77,8 @@ public void setMode(@CameraMode.Mode int mode) { mMode = mode; } - public CameraUpdateItem toCameraUpdate(MapboxMap map) { + public CameraUpdateItem toCameraUpdate(RCTMGLMapView mapView) { + MapboxMap map = mapView.getMapboxMap(); CameraPosition currentCamera = map.getCameraPosition(); CameraPosition.Builder builder = new CameraPosition.Builder(currentCamera); @@ -95,11 +98,12 @@ public CameraUpdateItem toCameraUpdate(MapboxMap map) { // Adding map padding to the camera padding which is the same behavior as // mapbox native does on iOS - int[] mapPadding = map.getPadding(); - int paddingLeft = mapPadding[0] + mBoundsPaddingLeft; - int paddingTop = mapPadding[1] + mBoundsPaddingTop; - int paddingRight = mapPadding[2] + mBoundsPaddingRight; - int paddingBottom = mapPadding[3] + mBoundsPaddingBottom; + double[] contentInset = mapView.getContentInset(); + + int paddingLeft = Double.valueOf(contentInset[0] + mBoundsPaddingLeft).intValue(); + int paddingTop = Double.valueOf(contentInset[1] + mBoundsPaddingTop).intValue(); + int paddingRight = Double.valueOf(contentInset[2] + mBoundsPaddingRight).intValue(); + int paddingBottom = Double.valueOf(contentInset[3] + mBoundsPaddingBottom).intValue(); int[] cameraPadding = {paddingLeft, paddingTop, paddingRight, paddingBottom}; CameraPosition boundsCamera = map.getCameraForLatLngBounds(mBounds, cameraPadding, bearing, tilt); diff --git a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraUpdateQueue.java b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraUpdateQueue.java index e9799ac16..5c2ca480d 100644 --- a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraUpdateQueue.java +++ b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/CameraUpdateQueue.java @@ -1,6 +1,7 @@ package com.mapbox.rctmgl.components.camera; import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.rctmgl.components.mapview.RCTMGLMapView; import java.util.ArrayList; import java.util.Iterator; @@ -11,6 +12,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; + /** * Created by nickitaliano on 9/5/17. */ @@ -51,7 +53,7 @@ public void setOnCompleteAllListener(OnCompleteAllListener listener) { mCompleteListener = listener; } - public void execute(MapboxMap map) { + public void execute(RCTMGLMapView map) { if (mQueue.isEmpty()) { if (mCompleteListener != null) { mCompleteListener.onCompleteAll(); diff --git a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/RCTMGLCamera.java b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/RCTMGLCamera.java index 4e1a64f08..daa51cb2e 100644 --- a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/RCTMGLCamera.java +++ b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/camera/RCTMGLCamera.java @@ -192,14 +192,14 @@ private void setInitialCamera() { if (mDefaultStop != null) { mDefaultStop.setDuration(0); mDefaultStop.setMode(com.mapbox.rctmgl.components.camera.constants.CameraMode.NONE); - CameraUpdateItem item = mDefaultStop.toCameraUpdate(mMapView.getMapboxMap()); + CameraUpdateItem item = mDefaultStop.toCameraUpdate(mMapView); item.run(); } } private void updateCamera() { mCameraUpdateQueue.offer(mCameraStop); - mCameraUpdateQueue.execute(mMapView.getMapboxMap()); + mCameraUpdateQueue.execute(mMapView); } private void updateUserTrackingMode(int userTrackingMode) { diff --git a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java index 7ea6f2b0b..9fdecea9c 100644 --- a/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java +++ b/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java @@ -1118,13 +1118,13 @@ private void updatePreferredFramesPerSecond() { setMaximumFps(mPreferredFramesPerSecond); } - private void updateInsets() { - if (mMap == null || mInsets == null) { - return; + public double[] getContentInset() { + if (mInsets == null) { + double[] result = {0,0,0,0}; + + return result; } - - final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); - int top = 0, right = 0, bottom = 0, left = 0; + double top = 0, right = 0, bottom = 0, left = 0; if (mInsets.size() == 4) { top = mInsets.getInt(0); @@ -1143,10 +1143,24 @@ private void updateInsets() { left = top; } - mMap.setPadding(Float.valueOf(left * metrics.scaledDensity).intValue(), - Float.valueOf(top * metrics.scaledDensity).intValue(), - Float.valueOf(right * metrics.scaledDensity).intValue(), - Float.valueOf(bottom * metrics.scaledDensity).intValue()); + final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); + + double[] result = {left * metrics.scaledDensity, top * metrics.scaledDensity, right * metrics.scaledDensity, bottom * metrics.scaledDensity}; + return result; + } + + private void updateInsets() { + if (mMap == null || mInsets == null) { + return; + } + + double padding[] = getContentInset(); + double top = padding[1], right = padding[2], bottom = padding[3], left = padding[0]; + + mMap.setPadding(Double.valueOf(left).intValue(), + Double.valueOf(top).intValue(), + Double.valueOf(right).intValue(), + Double.valueOf(bottom).intValue()); } private void setLifecycleListeners() {