[android] #3758 - Projection / Visible Region implementation.

[android] #3758 - add VisibleRegion + unit tests, removed boundingbox, cleanup jni, cleanup test app, renamed CoordinateSpan to LatLng.
This commit is contained in:
Tobrun
2016-02-03 17:26:09 +01:00
parent bc1f4b1fc0
commit aa05cba0df
24 changed files with 460 additions and 686 deletions

View File

@@ -47,18 +47,12 @@ jmethodID latLngConstructorId = nullptr;
jfieldID latLngLatitudeId = nullptr;
jfieldID latLngLongitudeId = nullptr;
jclass latLngZoomClass = nullptr;
jmethodID latLngZoomConstructorId = nullptr;
jfieldID latLngZoomLatitudeId = nullptr;
jfieldID latLngZoomLongitudeId = nullptr;
jfieldID latLngZoomZoomId = nullptr;
jclass bboxClass = nullptr;
jmethodID bboxConstructorId = nullptr;
jfieldID bboxLatNorthId = nullptr;
jfieldID bboxLatSouthId = nullptr;
jfieldID bboxLonEastId = nullptr;
jfieldID bboxLonWestId = nullptr;
jclass latLngBoundsClass = nullptr;
jmethodID latLngBoundsConstructorId = nullptr;
jfieldID latLngBoundsLatNorthId = nullptr;
jfieldID latLngBoundsLatSouthId = nullptr;
jfieldID latLngBoundsLonEastId = nullptr;
jfieldID latLngBoundsLonWestId = nullptr;
jclass iconClass = nullptr;
jfieldID iconIdId = nullptr;
@@ -1148,35 +1142,35 @@ void JNICALL nativeRemoveAnnotations(JNIEnv *env, jobject obj, jlong nativeMapVi
nativeMapView->getMap().removeAnnotations(ids);
}
jlongArray JNICALL nativeGetAnnotationsInBounds(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject bbox) {
jlongArray JNICALL nativeGetAnnotationsInBounds(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject latLngBounds) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetAnnotationsInBounds");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
if (env->ExceptionCheck() || (bbox == nullptr)) {
if (env->ExceptionCheck() || (latLngBounds == nullptr)) {
env->ExceptionDescribe();
return nullptr;
}
jdouble swLat = env->GetDoubleField(bbox, bboxLatSouthId);
jdouble swLat = env->GetDoubleField(latLngBounds, latLngBoundsLatSouthId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble swLon = env->GetDoubleField(bbox, bboxLonWestId);
jdouble swLon = env->GetDoubleField(latLngBounds, latLngBoundsLonWestId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble neLat = env->GetDoubleField(bbox, bboxLatNorthId);
jdouble neLat = env->GetDoubleField(latLngBounds, latLngBoundsLatNorthId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
}
jdouble neLon = env->GetDoubleField(bbox, bboxLonEastId);
jdouble neLon = env->GetDoubleField(latLngBounds, latLngBoundsLonEastId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return nullptr;
@@ -1625,38 +1619,38 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
bboxClass = env->FindClass("com/mapbox/mapboxsdk/geometry/BoundingBox");
if (bboxClass == nullptr) {
latLngBoundsClass = env->FindClass("com/mapbox/mapboxsdk/geometry/LatLngBounds");
if (latLngBoundsClass == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxConstructorId = env->GetMethodID(bboxClass, "<init>", "(DDDD)V");
if (bboxConstructorId == nullptr) {
latLngBoundsConstructorId = env->GetMethodID(latLngBoundsClass, "<init>", "(DDDD)V");
if (latLngBoundsConstructorId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLatNorthId = env->GetFieldID(bboxClass, "mLatNorth", "D");
if (bboxLatNorthId == nullptr) {
latLngBoundsLatNorthId = env->GetFieldID(latLngBoundsClass, "mLatNorth", "D");
if (latLngBoundsLatNorthId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLatSouthId = env->GetFieldID(bboxClass, "mLatSouth", "D");
if (bboxLatSouthId == nullptr) {
latLngBoundsLatSouthId = env->GetFieldID(latLngBoundsClass, "mLatSouth", "D");
if (latLngBoundsLatSouthId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLonEastId = env->GetFieldID(bboxClass, "mLonEast", "D");
if (bboxLonEastId == nullptr) {
latLngBoundsLonEastId = env->GetFieldID(latLngBoundsClass, "mLonEast", "D");
if (latLngBoundsLonEastId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
bboxLonWestId = env->GetFieldID(bboxClass, "mLonWest", "D");
if (bboxLonWestId == nullptr) {
latLngBoundsLonWestId = env->GetFieldID(latLngBoundsClass, "mLonWest", "D");
if (latLngBoundsLonWestId == nullptr) {
env->ExceptionDescribe();
return JNI_ERR;
}
@@ -2052,7 +2046,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
reinterpret_cast<void *>(&nativeAddPolygons)},
{"nativeRemoveAnnotation", "(JJ)V", reinterpret_cast<void *>(&nativeRemoveAnnotation)},
{"nativeRemoveAnnotations", "(J[J)V", reinterpret_cast<void *>(&nativeRemoveAnnotations)},
{"nativeGetAnnotationsInBounds", "(JLcom/mapbox/mapboxsdk/geometry/BoundingBox;)[J",
{"nativeGetAnnotationsInBounds", "(JLcom/mapbox/mapboxsdk/geometry/LatLngBounds;)[J",
reinterpret_cast<void *>(&nativeGetAnnotationsInBounds)},
{"nativeAddAnnotationIcon", "(JLjava/lang/String;IIF[B)V", reinterpret_cast<void *>(&nativeAddAnnotationIcon)},
{"nativeSetVisibleCoordinateBounds", "(J[Lcom/mapbox/mapboxsdk/geometry/LatLng;Landroid/graphics/RectF;DJ)V",
@@ -2101,12 +2095,11 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_ERR;
}
bboxClass = reinterpret_cast<jclass>(env->NewGlobalRef(bboxClass));
if (bboxClass == nullptr) {
latLngBoundsClass = reinterpret_cast<jclass>(env->NewGlobalRef(latLngBoundsClass));
if (latLngBoundsClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
return JNI_ERR;
}
@@ -2114,8 +2107,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (iconClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
return JNI_ERR;
}
@@ -2123,8 +2115,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (markerClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
return JNI_ERR;
}
@@ -2133,8 +2124,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (polylineClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
return JNI_ERR;
@@ -2144,8 +2134,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (polygonClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2156,8 +2145,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (runtimeExceptionClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2170,8 +2158,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (nullPointerExceptionClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2184,8 +2171,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (arrayListClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2199,8 +2185,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (projectedMetersClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2215,8 +2200,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (pointFClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(polylineClass);
@@ -2233,8 +2217,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(polylineClass);
env->DeleteGlobalRef(polygonClass);
env->DeleteGlobalRef(runtimeExceptionClass);
@@ -2249,8 +2232,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (httpContextClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2267,8 +2249,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
if (httpRequestClass == nullptr) {
env->ExceptionDescribe();
env->DeleteGlobalRef(latLngClass);
env->DeleteGlobalRef(latLngZoomClass);
env->DeleteGlobalRef(bboxClass);
env->DeleteGlobalRef(latLngBoundsClass);
env->DeleteGlobalRef(iconClass);
env->DeleteGlobalRef(markerClass);
env->DeleteGlobalRef(polylineClass);
@@ -2307,20 +2288,13 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
latLngLongitudeId = nullptr;
latLngLatitudeId = nullptr;
env->DeleteGlobalRef(latLngZoomClass);
latLngZoomClass = nullptr;
latLngZoomConstructorId = nullptr;
latLngZoomLongitudeId = nullptr;
latLngZoomLatitudeId = nullptr;
latLngZoomZoomId = nullptr;
env->DeleteGlobalRef(bboxClass);
bboxClass = nullptr;
bboxConstructorId = nullptr;
bboxLatNorthId = nullptr;
bboxLatSouthId = nullptr;
bboxLonEastId = nullptr;
bboxLonWestId = nullptr;
env->DeleteGlobalRef(latLngBoundsClass);
latLngBoundsClass = nullptr;
latLngBoundsConstructorId = nullptr;
latLngBoundsLatNorthId = nullptr;
latLngBoundsLatSouthId = nullptr;
latLngBoundsLonEastId = nullptr;
latLngBoundsLonWestId = nullptr;
env->DeleteGlobalRef(iconClass);
iconClass = nullptr;