Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Fix padding addition #973

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +12,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;


/**
* Created by nickitaliano on 9/5/17.
*/
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,13 +1115,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);
Expand All @@ -1140,10 +1140,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() {
Expand Down