[android][ios][macOS] Implement bindings for Map::cameraForGeometry. On macOS, also added -[MGLMapView setCamera: withDuration: animationTimingFunction: edgePadding: completionHandler:] for parity with iOS
This commit is contained in:
@@ -44,6 +44,7 @@ import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.services.commons.geojson.Feature;
|
||||
import com.mapbox.services.commons.geojson.Geometry;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.List;
|
||||
@@ -1666,6 +1667,30 @@ public final class MapboxMap {
|
||||
return cameraPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided shape with a given bearing and padding.
|
||||
*
|
||||
* @param geometry the geometry to constrain the map with
|
||||
* @param bearing the bearing at which to compute the geometry's bounds
|
||||
* @param padding the padding to apply to the bounds
|
||||
* @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, myLocationViewSettings.getPadding());
|
||||
|
||||
// get padded camera position from LatLngBounds
|
||||
CameraPosition cameraPosition = nativeMapView.getCameraForGeometry(geometry, bearing);
|
||||
|
||||
// reset map padding
|
||||
setPadding(mapPadding);
|
||||
return cameraPosition;
|
||||
}
|
||||
|
||||
//
|
||||
// Padding
|
||||
//
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.mapboxsdk.utils.BitmapUtils;
|
||||
import com.mapbox.services.commons.geojson.Feature;
|
||||
import com.mapbox.services.commons.geojson.Geometry;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -232,6 +233,13 @@ final class NativeMapView {
|
||||
return nativeGetCameraForLatLngBounds(latLngBounds);
|
||||
}
|
||||
|
||||
public CameraPosition getCameraForGeometry(Geometry geometry, double bearing) {
|
||||
if (isDestroyedOn("getCameraForGeometry")) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetCameraForGeometry(geometry, bearing);
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
if (isDestroyedOn("resetPosition")) {
|
||||
return;
|
||||
@@ -873,6 +881,8 @@ final class NativeMapView {
|
||||
|
||||
private native CameraPosition nativeGetCameraForLatLngBounds(LatLngBounds latLngBounds);
|
||||
|
||||
private native CameraPosition nativeGetCameraForGeometry(Geometry geometry, double bearing);
|
||||
|
||||
private native void nativeResetPosition();
|
||||
|
||||
private native double nativeGetPitch();
|
||||
|
||||
Reference in New Issue
Block a user