diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-10-09 11:50:48 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-10-09 13:58:11 -0700 |
commit | 24bd336b88b4f2dae25277efeeb36a96061139a3 (patch) | |
tree | c1b3a95eb86753be703a33532e00aa682c5a100b /platform/android | |
parent | df20b0cbecb25b8bc6812c4a558fc0f0e6cfb7ed (diff) | |
download | qtlocation-mapboxgl-24bd336b88b4f2dae25277efeeb36a96061139a3.tar.gz |
[android][ios][macOS] Implement bindings for `Map::cameraForGeometry`. On macOS, also added -[MGLMapView setCamera: withDuration: animationTimingFunction: edgePadding: completionHandler:] for parity with iOS
Diffstat (limited to 'platform/android')
5 files changed, 45 insertions, 0 deletions
diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 56a33f7e6b..520a678b73 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -59,6 +59,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to - build release package once during ci build [#9351](https://github.com/mapbox/mapbox-gl-native/pull/9351) * Add support for ImageSource [#9110](https://github.com/mapbox/mapbox-gl-native/pull/9110) * Increased the default maximum zoom level from 20 to 22. [#9835](https://github.com/mapbox/mapbox-gl-native/pull/9835) +* Added `MapboxMap.getCameraForGeometry()` to get a camera with zoom level and center coordinate computed to fit a shape. ([#10107](https://github.com/mapbox/mapbox-gl-native/pull/10107)) ### 5.1.4 - September 25, 2017 diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index a5c49dae7c..6a88470ee7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -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 // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 3ce6aab581..bd8a54783e 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -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(); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index a9ed6d5ead..24a35a7068 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -291,6 +291,11 @@ jni::Object<CameraPosition> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& return CameraPosition::New(env, map->cameraForLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds), insets)); } +jni::Object<CameraPosition> NativeMapView::getCameraForGeometry(jni::JNIEnv& env, jni::Object<geojson::Geometry> jGeometry, double bearing) { + auto geometry = geojson::Geometry::convert(env, jGeometry); + return CameraPosition::New(env, map->cameraForGeometry(geometry, insets, bearing)); +} + void NativeMapView::setReachability(jni::JNIEnv&, jni::jboolean reachable) { if (reachable) { mbgl::NetworkStatus::Reachable(); @@ -949,6 +954,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::getLatLng, "nativeGetLatLng"), METHOD(&NativeMapView::setLatLng, "nativeSetLatLng"), METHOD(&NativeMapView::getCameraForLatLngBounds, "nativeGetCameraForLatLngBounds"), + METHOD(&NativeMapView::getCameraForGeometry, "nativeGetCameraForGeometry"), METHOD(&NativeMapView::setReachability, "nativeSetReachability"), METHOD(&NativeMapView::resetPosition, "nativeResetPosition"), METHOD(&NativeMapView::getPitch, "nativeGetPitch"), diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 72c7b1a9eb..4d226d0fa9 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -15,6 +15,7 @@ #include "graphics/pointf.hpp" #include "graphics/rectf.hpp" #include "geojson/feature.hpp" +#include "geojson/geometry.hpp" #include "geometry/lat_lng.hpp" #include "geometry/projected_meters.hpp" #include "style/layers/layers.hpp" @@ -104,6 +105,8 @@ public: jni::Object<CameraPosition> getCameraForLatLngBounds(jni::JNIEnv&, jni::Object<mbgl::android::LatLngBounds>); + jni::Object<CameraPosition> getCameraForGeometry(jni::JNIEnv&, jni::Object<geojson::Geometry>, double bearing); + void setReachability(jni::JNIEnv&, jni::jboolean); void resetPosition(jni::JNIEnv&); |