-
Notifications
You must be signed in to change notification settings - Fork 1.3k
addMarkers in JNI #2428
Comments
Jake Wharton gave a nice presentation about eliminating code overhead in Android applications. He has some nice pointers that will improve scalability. |
@tobrun Big improvment will be to use arrays/lists to pass markers to JNI in bulk rather than having to loop in Java. |
@ljbade Also while compiling I'm getting:
jni.cpp:jlongArray JNICALL nativeAddMarkers(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject jlist) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarkers");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
std::vector<mbgl::PointAnnotation> markers;
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;
}
markers.reserve(len);
for (jsize i = 0; i < len; i++) {
/* Could you validate that this loop is correct? */
jobject marker = reinterpret_cast<jobject>(env->GetObjectArrayElement(jarray, i));
jobject position = env->GetObjectField(marker, markerPositionId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jstring jsprite = reinterpret_cast<jstring>(env->GetObjectField(marker, markerSpriteId));
std::string sprite = std_string_from_jstring(env, jsprite);
jdouble latitude = env->GetDoubleField(position, latLngLatitudeId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble longitude = env->GetDoubleField(position, latLngLongitudeId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
markers.emplace_back(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), sprite));
/* Do I need to delete other LocalRefs? */
env->DeleteLocalRef(marker);
}
env->DeleteLocalRef(jarray);
std::vector<uint32_t> pointAnnotationIDs = nativeMapView->getMap().addPointAnnotations(markers);
return std_vector_uint_to_jobject(env, pointAnnotationIDs);
}
NativeMapView public long[] addMarkers(List<Marker> markers) {
return nativeAddMarkers(mNativeMapViewPtr, markers);
} private native long[] nativeAddMarkers(long nativeMapViewPtr, List<Marker> markers); |
@tobrun That error is because you need to add an entry to https://github.com/mapbox/mapbox-gl-native/blob/master/android/cpp/jni.cpp#L1614 Loop looks good. You should be fine with the local refs. JNI automatically releases any local references on return from the C++ function (that is why you see |
Z-index, great circles, and even circle primitives are non-essential right now. Let's step back and consider more carefully what we focus on in Android — full parity with the raster SDK isn't necessarily the goal. /cc @bleege |
@incanus Thanks for the direction. That said Z-Index I believe is coming from the Google Maps API for Annotations. |
Refs #991 |
Ah... thanks for clarifying @incanus. 👍 |
@tobrun Can we close this now PR landed? |
[android] mapbox#2428 add markers jni
Add markers to JNI
Original post:
List missing features:
- add Z index- #1726- #1882The text was updated successfully, but these errors were encountered: