From aebd4196ac345a1eb49f0c9e2f8ec2215cad4ad7 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Thu, 16 Jul 2015 10:08:02 -0700 Subject: [PATCH] attempting to make ShapeAnnotation with segment and properties #1716 --- android/cpp/jni.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 9049c8566..fcf53ad0c 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -466,7 +467,7 @@ jlong JNICALL nativeAddMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polyline) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolyline"); assert(nativeMapViewPtr != 0); - // NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); // ***** Java fields ***** // // float alpha; @@ -480,7 +481,6 @@ jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr env->ExceptionDescribe(); return -1; } - ++alpha; jboolean visible = env->GetBooleanField(polyline, polylineVisibleId); if (env->ExceptionCheck()) { @@ -502,6 +502,14 @@ jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr return -1; } + mbgl::StyleProperties shapeProperties; + mbgl::LineProperties lineProperties; + lineProperties.opacity = alpha; + lineProperties.color = {{ 0.3, 0.7, 0.1, 1 }};; + lineProperties.width = width; + shapeProperties.set(lineProperties); + + jobject points = env->GetObjectField(polyline, polylinePointsId); if (points == nullptr) { if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) { @@ -524,6 +532,9 @@ jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr return -1; } + mbgl::AnnotationSegment segment; + segment.reserve(len); + for (jsize i = 0; i < len; i++) { jobject latLng = reinterpret_cast(env->GetObjectArrayElement(array, i)); if (latLng == nullptr) { @@ -536,16 +547,19 @@ jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr env->ExceptionDescribe(); return -1; } - latitude++; + jdouble longitude = env->GetDoubleField(latLng, latLngLongitudeId); if (env->ExceptionCheck()) { env->ExceptionDescribe(); return -1; } - longitude++; + + segment.push_back(mbgl::LatLng(latitude, longitude)); } - return (jlong)width; + + + return (jlong) nativeMapView->getMap().addShapeAnnotation(mbgl::ShapeAnnotation(segment, shapeProperties)); } void JNICALL nativeRemoveAnnotation(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlong annotationId) {