diff options
author | Peng Liu <peng.liu@mapbox.com> | 2020-01-09 15:53:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-09 15:53:23 +0200 |
commit | 236afc03958cc729b3b8121a1c5a72660f0e9fa2 (patch) | |
tree | ad7da4d786c7ef7ce0ee14ecacd303e5a3eb34f2 /platform | |
parent | d3a5ed968cc5288c171404d5c3f8d16a552ff28a (diff) | |
download | qtlocation-mapboxgl-236afc03958cc729b3b8121a1c5a72660f0e9fa2.tar.gz |
[android][core] Add `Map::latLngBoundsForCameraUnwrapped` and jni binding for `getVisibleCoordinateBounds`. (#16069)
* [android] Add getVisibleCoordinateBounds method.
* Fix Map::latLngBoundsForCamera, add Android binding for getVisibleRegionBounds.
* Add unit tests for CameraToLatLngBoundsWithRotation and CameraToLatLngBoundsCrossDateLine.
* Move API breaking changes to a new method name latLngBoundsForCameraUnwrapped.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/src/native_map_view.cpp | 21 | ||||
-rw-r--r--[-rwxr-xr-x] | platform/android/src/native_map_view.hpp | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 554a59de76..d7351c7677 100644 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -529,6 +529,26 @@ void NativeMapView::setVisibleCoordinateBounds(JNIEnv& env, const jni::Array<jni map->easeTo(cameraOptions, animationOptions); } +void NativeMapView::getVisibleCoordinateBounds(JNIEnv& env, jni::Array<jdouble>& output) { + auto latlngBounds = map->latLngBoundsForCameraUnwrapped(map->getCameraOptions(mbgl::nullopt)); + + double latNorth = latlngBounds.north(); + double lonEast = latlngBounds.east(); + double latSouth = latlngBounds.south(); + double lonWest = latlngBounds.west(); + + std::vector<jdouble> buffer; + buffer.reserve(4); + + // Order of the LatLngBounds: double latNorth, double lonEast, double latSouth, double lonWest + buffer.push_back(latNorth); + buffer.push_back(lonEast); + buffer.push_back(latSouth); + buffer.push_back(lonWest); + + output.SetRegion<std::vector<jdouble>>(env, 0, buffer); +} + void NativeMapView::scheduleSnapshot(jni::JNIEnv&) { mapRenderer.requestSnapshot([&](PremultipliedImage image) { auto _env = android::AttachEnv(); @@ -1172,6 +1192,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::projectedMetersForLatLng, "nativeProjectedMetersForLatLng"), METHOD(&NativeMapView::pixelForLatLng, "nativePixelForLatLng"), METHOD(&NativeMapView::pixelsForLatLngs, "nativePixelsForLatLngs"), + METHOD(&NativeMapView::getVisibleCoordinateBounds, "nativeGetVisibleCoordinateBounds"), METHOD(&NativeMapView::latLngForProjectedMeters, "nativeLatLngForProjectedMeters"), METHOD(&NativeMapView::latLngForPixel, "nativeLatLngForPixel"), METHOD(&NativeMapView::latLngsForPixels, "nativeLatLngsForPixels"), diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 622c454b7d..ab93fab81f 100755..100644 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -139,6 +139,8 @@ public: void setVisibleCoordinateBounds(JNIEnv&, const jni::Array<jni::Object<LatLng>>&, const jni::Object<RectF>&, jni::jdouble, jni::jlong); + void getVisibleCoordinateBounds(JNIEnv& env, jni::Array<jdouble>& output); + void scheduleSnapshot(jni::JNIEnv&); jni::Local<jni::Object<CameraPosition>> getCameraPosition(jni::JNIEnv&); |