[android] calculating camera's LatLng for bounds without map padding (#11410)
This commit is contained in:
@@ -1550,19 +1550,8 @@ public final class MapboxMap {
|
||||
* @return the camera position that fits the bounds and padding
|
||||
*/
|
||||
public CameraPosition getCameraForLatLngBounds(@Nullable LatLngBounds latLngBounds, int[] padding) {
|
||||
// calculate and set additional bounds padding
|
||||
int[] mapPadding = getPadding();
|
||||
for (int i = 0; i < padding.length; i++) {
|
||||
padding[i] = mapPadding[i] + padding[i];
|
||||
}
|
||||
projection.setContentPadding(padding);
|
||||
|
||||
// get padded camera position from LatLngBounds
|
||||
CameraPosition cameraPosition = nativeMapView.getCameraForLatLngBounds(latLngBounds);
|
||||
|
||||
// reset map padding
|
||||
setPadding(mapPadding);
|
||||
return cameraPosition;
|
||||
return nativeMapView.getCameraForLatLngBounds(latLngBounds, padding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1574,19 +1563,8 @@ public final class MapboxMap {
|
||||
* @return the camera position that fits the bounds and padding
|
||||
*/
|
||||
public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) {
|
||||
// calculate and set additional bounds padding
|
||||
int[] mapPadding = getPadding();
|
||||
for (int i = 0; i < padding.length; i++) {
|
||||
padding[i] = mapPadding[i] + padding[i];
|
||||
}
|
||||
projection.setContentPadding(padding);
|
||||
|
||||
// get padded camera position from LatLngBounds
|
||||
CameraPosition cameraPosition = nativeMapView.getCameraForGeometry(geometry, bearing);
|
||||
|
||||
// reset map padding
|
||||
setPadding(mapPadding);
|
||||
return cameraPosition;
|
||||
// get padded camera position from Geometry
|
||||
return nativeMapView.getCameraForGeometry(geometry, bearing, padding);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -229,18 +229,28 @@ final class NativeMapView {
|
||||
return nativeGetLatLng().wrap();
|
||||
}
|
||||
|
||||
public CameraPosition getCameraForLatLngBounds(LatLngBounds latLngBounds) {
|
||||
public CameraPosition getCameraForLatLngBounds(LatLngBounds latLngBounds, int[] padding) {
|
||||
if (isDestroyedOn("getCameraForLatLngBounds")) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetCameraForLatLngBounds(latLngBounds);
|
||||
return nativeGetCameraForLatLngBounds(
|
||||
latLngBounds,
|
||||
padding[1] / pixelRatio,
|
||||
padding[0] / pixelRatio,
|
||||
padding[3] / pixelRatio,
|
||||
padding[2] / pixelRatio);
|
||||
}
|
||||
|
||||
public CameraPosition getCameraForGeometry(Geometry geometry, double bearing) {
|
||||
public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) {
|
||||
if (isDestroyedOn("getCameraForGeometry")) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetCameraForGeometry(geometry, bearing);
|
||||
return nativeGetCameraForGeometry(
|
||||
geometry, bearing,
|
||||
padding[1] / pixelRatio,
|
||||
padding[0] / pixelRatio,
|
||||
padding[3] / pixelRatio,
|
||||
padding[2] / pixelRatio);
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
@@ -896,9 +906,11 @@ final class NativeMapView {
|
||||
|
||||
private native LatLng nativeGetLatLng();
|
||||
|
||||
private native CameraPosition nativeGetCameraForLatLngBounds(LatLngBounds latLngBounds);
|
||||
private native CameraPosition nativeGetCameraForLatLngBounds(
|
||||
LatLngBounds latLngBounds, double top, double left, double bottom, double right);
|
||||
|
||||
private native CameraPosition nativeGetCameraForGeometry(Geometry geometry, double bearing);
|
||||
private native CameraPosition nativeGetCameraForGeometry(
|
||||
Geometry geometry, double bearing, double top, double left, double bottom, double right);
|
||||
|
||||
private native void nativeResetPosition();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user