Optimized RemoveAnnotations to a single call
This commit is contained in:
@@ -746,6 +746,36 @@ void JNICALL nativeRemoveAnnotation(JNIEnv *env, jobject obj, jlong nativeMapVie
|
||||
nativeMapView->getMap().removeAnnotation((uint32_t)annotationId);
|
||||
}
|
||||
|
||||
void JNICALL nativeRemoveAnnotations(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlongArray array) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotations");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
|
||||
|
||||
std::vector<uint32_t> ids;
|
||||
|
||||
if (env->ExceptionCheck() || (array == nullptr)) {
|
||||
env->ExceptionDescribe();
|
||||
return;
|
||||
}
|
||||
|
||||
jsize len = env->GetArrayLength(array);
|
||||
if (len < 0) {
|
||||
env->ExceptionDescribe();
|
||||
return;
|
||||
}
|
||||
|
||||
ids.reserve(len);
|
||||
jlong* jids = env->GetLongArrayElements(array, nullptr);
|
||||
|
||||
for (jsize i = 0; i < len; i++) {
|
||||
if(jids[i] == -1L)
|
||||
continue;
|
||||
ids.push_back((uint32_t) jids[i]);
|
||||
}
|
||||
|
||||
nativeMapView->getMap().removeAnnotations(ids);
|
||||
}
|
||||
|
||||
jobject JNICALL nativeGetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLatLng");
|
||||
assert(nativeMapViewPtr != 0);
|
||||
@@ -1418,6 +1448,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
{"nativeAddPolygons", "(JLjava/util/List;)[J",
|
||||
reinterpret_cast<void *>(&nativeAddPolygons)},
|
||||
{"nativeRemoveAnnotation", "(JJ)V", reinterpret_cast<void *>(&nativeRemoveAnnotation)},
|
||||
{"nativeRemoveAnnotations", "(J[J)V", reinterpret_cast<void *>(&nativeRemoveAnnotations)},
|
||||
{"nativeGetLatLng", "(J)Lcom/mapbox/mapboxgl/geometry/LatLng;",
|
||||
reinterpret_cast<void *>(&nativeGetLatLng)},
|
||||
{"nativeResetPosition", "(J)V", reinterpret_cast<void *>(&nativeResetPosition)},
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class Annotation {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,17 +49,6 @@ public class Marker extends Annotation {
|
||||
return anchorV;
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: Google Maps Android API uses String for IDs.
|
||||
*
|
||||
* Internal C++ id is stored as unsigned int.
|
||||
*
|
||||
* @return the annotation id
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -270,9 +270,16 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
public void removeAnnotations() {
|
||||
for (Annotation annotation : annotations) {
|
||||
annotation.remove();
|
||||
long[] ids = new long[annotations.size()];
|
||||
for(int i=0; i<annotations.size(); i++) {
|
||||
Long id = annotations.get(i).getId();
|
||||
if(id == null) {
|
||||
ids[i] = -1;
|
||||
} else {
|
||||
ids[i] = id;
|
||||
}
|
||||
}
|
||||
mNativeMapView.removeAnnotations(ids);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -239,6 +239,10 @@ class NativeMapView {
|
||||
nativeRemoveAnnotation(mNativeMapViewPtr, id);
|
||||
}
|
||||
|
||||
public void removeAnnotations(long[] ids) {
|
||||
nativeRemoveAnnotations(mNativeMapViewPtr, ids);
|
||||
}
|
||||
|
||||
public LatLng getLatLng() {
|
||||
return nativeGetLatLng(mNativeMapViewPtr);
|
||||
}
|
||||
@@ -481,6 +485,8 @@ class NativeMapView {
|
||||
|
||||
private native void nativeRemoveAnnotation(long nativeMapViewPtr, long id);
|
||||
|
||||
private native void nativeRemoveAnnotations(long nativeMapViewPtr, long[] id);
|
||||
|
||||
private native LatLng nativeGetLatLng(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeResetPosition(long nativeMapViewPtr);
|
||||
|
||||
Reference in New Issue
Block a user