diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2015-10-27 11:16:55 +0100 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2015-10-27 11:16:55 +0100 |
commit | f3ffb45cf6adbdca375217c645eb455ff47991ec (patch) | |
tree | ea4660dc6cd03ad4e8792d5d02bf8895f37438ee /platform | |
parent | fd33dfcd7321346631cd9237b5ae2993c29f9ca5 (diff) | |
download | qtlocation-mapboxgl-f3ffb45cf6adbdca375217c645eb455ff47991ec.tar.gz |
[android] #2809 - addPolylines and removeAnnotations in JNI, added feature activity + sanity test case
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/jni.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/platform/android/jni.cpp b/platform/android/jni.cpp index 5808dff9c8..3dca3c9b24 100644 --- a/platform/android/jni.cpp +++ b/platform/android/jni.cpp @@ -959,6 +959,83 @@ jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr return id; } +jlongArray JNICALL nativeAddPolylines(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject jlist) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolylines"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr); + + std::vector<mbgl::ShapeAnnotation> shapes; + + if (jlist == nullptr) { + if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) { + env->ExceptionDescribe(); + return nullptr; + } + return nullptr; + } + + jobjectArray jarray = + reinterpret_cast<jobjectArray>(env->CallObjectMethod(jlist, listToArrayId)); + if (env->ExceptionCheck() || (jarray == nullptr)) { + env->ExceptionDescribe(); + return nullptr; + } + + jsize len = env->GetArrayLength(jarray); + if (len < 0) { + env->ExceptionDescribe(); + return nullptr; + } + + shapes.reserve(len); + + for (jsize i = 0; i < len; i++) { + jobject polyline = reinterpret_cast<jobject>(env->GetObjectArrayElement(jarray, i)); + + jfloat alpha = env->GetFloatField(polyline, polylineAlphaId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return nullptr; + } + + jint color = env->GetIntField(polyline, polylineColorId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return nullptr; + } + + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = (color) & 0xFF; + int a = (color >> 24) & 0xFF; + + jfloat width = env->GetFloatField(polyline, polylineWidthId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return nullptr; + } + + mbgl::ShapeAnnotation::Properties shapeProperties; + mbgl::LinePaintProperties lineProperties; + lineProperties.opacity = alpha; + lineProperties.color = {{ static_cast<float>(r) / 255.0f, static_cast<float>(g) / 255.0f, static_cast<float>(b) / 255.0f, static_cast<float>(a) / 255.0f }}; + lineProperties.width = width; + shapeProperties.set<mbgl::LinePaintProperties>(lineProperties); + + jobject points = env->GetObjectField(polyline, polylinePointsId); + mbgl::AnnotationSegment segment = annotation_segment_from_latlng_jlist(env, points); + + shapes.emplace_back(mbgl::AnnotationSegments { segment }, shapeProperties); + + env->DeleteLocalRef(polyline); + } + + env->DeleteLocalRef(jarray); + + std::vector<uint32_t> shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); + return std_vector_uint_to_jobject(env, shapeAnnotationIDs); +} + jlong JNICALL nativeAddPolygon(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polygon) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygon"); assert(nativeMapViewPtr != 0); @@ -1852,6 +1929,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { reinterpret_cast<void *>(&nativeAddMarkers)}, {"nativeAddPolyline", "(JLcom/mapbox/mapboxsdk/annotations/Polyline;)J", reinterpret_cast<void *>(&nativeAddPolyline)}, + {"nativeAddPolylines", "(JLjava/util/List;)[J", + reinterpret_cast<void *>(&nativeAddPolylines)}, {"nativeAddPolygon", "(JLcom/mapbox/mapboxsdk/annotations/Polygon;)J", reinterpret_cast<void *>(&nativeAddPolygon)}, {"nativeAddPolygons", "(JLjava/util/List;)[J", |