diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2019-12-05 15:49:56 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2019-12-06 08:56:38 +0100 |
commit | 1ac3e9e9c2a8bfc731e3bba978a28562c3f083e5 (patch) | |
tree | 9cfffe2e803e4ee30818b9bd3feacc2326585f75 | |
parent | 9f3a384296f019b1b3719b39389ae5be995a4d37 (diff) | |
download | qtlocation-mapboxgl-1ac3e9e9c2a8bfc731e3bba978a28562c3f083e5.tar.gz |
[android] - add hooks for bulk conversion of geographic coordinates to screen coordinates
-rw-r--r-- | platform/android/src/native_map_view.cpp | 54 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.hpp | 4 |
2 files changed, 58 insertions, 0 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index d475d9b0d3..617f633699 100644 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -621,10 +621,62 @@ jni::Local<jni::Object<PointF>> NativeMapView::pixelForLatLng(JNIEnv& env, jdoub return PointF::New(env, static_cast<float>(pixel.x), static_cast<float>(pixel.y)); } +void NativeMapView::pixelsForLatLngs(JNIEnv& env, + const jni::Array<jdouble>& input, + jni::Array<jdouble>& output, + jfloat pixelRatio) { + jni::NullCheck(env, &input); + std::size_t len = input.Length(env); + + std::vector<mbgl::LatLng> latLngs; + latLngs.reserve(len); + + for (std::size_t i = 0; i < len; i += 2) { + auto latLng = mbgl::LatLng(input.Get(env, i), input.Get(env, i + 1)); + latLngs.push_back(latLng); + } + + std::vector<jdouble> buffer; + buffer.reserve(len); + std::vector<ScreenCoordinate> coordinates = map->pixelsForLatLngs(latLngs); + for (std::size_t i = 0; i < len / 2; i++) { + buffer.push_back(coordinates[i].x * pixelRatio); + buffer.push_back(coordinates[i].y * pixelRatio); + } + + output.SetRegion<std::vector<jdouble>>(env, 0, buffer); +} + jni::Local<jni::Object<LatLng>> NativeMapView::latLngForPixel(JNIEnv& env, jfloat x, jfloat y) { return LatLng::New(env, map->latLngForPixel(mbgl::ScreenCoordinate(x, y))); } +void NativeMapView::latLngsForPixels(JNIEnv& env, + const jni::Array<jdouble>& input, + jni::Array<jdouble>& output, + jfloat pixelRatio) { + jni::NullCheck(env, &input); + std::size_t len = input.Length(env); + + std::vector<mbgl::ScreenCoordinate> coordinates; + coordinates.reserve(len); + + for (std::size_t i = 0; i < len; i += 2) { + auto coordinate = mbgl::ScreenCoordinate(input.Get(env, i) / pixelRatio, input.Get(env, i + 1) / pixelRatio); + coordinates.push_back(coordinate); + } + + std::vector<jdouble> buffer; + buffer.reserve(len); + std::vector<mbgl::LatLng> latLngs = map->latLngsForPixels(coordinates); + for (std::size_t i = 0; i < len / 2; i++) { + buffer.push_back(latLngs[i].latitude()); + buffer.push_back(latLngs[i].longitude()); + } + + output.SetRegion<std::vector<jdouble>>(env, 0, buffer); +} + jni::Local<jni::Array<jlong>> NativeMapView::addPolylines(JNIEnv& env, const jni::Array<jni::Object<Polyline>>& polylines) { NullCheck(env, &polylines); std::size_t len = polylines.Length(env); @@ -1122,8 +1174,10 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::getMetersPerPixelAtLatitude, "nativeGetMetersPerPixelAtLatitude"), METHOD(&NativeMapView::projectedMetersForLatLng, "nativeProjectedMetersForLatLng"), METHOD(&NativeMapView::pixelForLatLng, "nativePixelForLatLng"), + METHOD(&NativeMapView::pixelsForLatLngs, "nativePixelsForLatLngs"), METHOD(&NativeMapView::latLngForProjectedMeters, "nativeLatLngForProjectedMeters"), METHOD(&NativeMapView::latLngForPixel, "nativeLatLngForPixel"), + METHOD(&NativeMapView::latLngsForPixels, "nativeLatLngsForPixels"), METHOD(&NativeMapView::addPolylines, "nativeAddPolylines"), METHOD(&NativeMapView::addPolygons, "nativeAddPolygons"), METHOD(&NativeMapView::updatePolyline, "nativeUpdatePolyline"), diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 11676981a2..622c454b7d 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -161,10 +161,14 @@ public: jni::Local<jni::Object<PointF>> pixelForLatLng(JNIEnv&, jdouble, jdouble); + void pixelsForLatLngs(JNIEnv&, const jni::Array<jdouble>&, jni::Array<jdouble>&, jfloat); + jni::Local<jni::Object<LatLng>> latLngForProjectedMeters(JNIEnv&, jdouble, jdouble); jni::Local<jni::Object<LatLng>> latLngForPixel(JNIEnv&, jfloat, jfloat); + void latLngsForPixels(JNIEnv&, const jni::Array<jdouble>&, jni::Array<jdouble>&, jfloat); + jni::Local<jni::Array<jlong>> addPolylines(JNIEnv&, const jni::Array<jni::Object<Polyline>>&); jni::Local<jni::Array<jlong>> addPolygons(JNIEnv&, const jni::Array<jni::Object<Polygon>>&); |