Skip to content

Commit

Permalink
MapController returns null if no intersection is found
Browse files Browse the repository at this point in the history
  • Loading branch information
matteblair committed Jul 12, 2016
1 parent 89a2991 commit a70362b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 6 additions & 4 deletions android/tangram/jni/jniExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ extern "C" {
return Tangram::getTilt();
}

JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeScreenPositionToLngLat(JNIEnv* jniEnv, jobject obj, jdoubleArray coordinates) {
JNIEXPORT jboolean JNICALL Java_com_mapzen_tangram_MapController_nativeScreenPositionToLngLat(JNIEnv* jniEnv, jobject obj, jdoubleArray coordinates) {
jdouble* arr = jniEnv->GetDoubleArrayElements(coordinates, NULL);
Tangram::screenPositionToLngLat(arr[0], arr[1], &arr[0], &arr[1]);
bool ret = Tangram::screenPositionToLngLat(arr[0], arr[1], &arr[0], &arr[1]);
jniEnv->ReleaseDoubleArrayElements(coordinates, arr, 0);
return ret;
}

JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeLngLatToScreenPosition(JNIEnv* jniEnv, jobject obj, jdoubleArray coordinates) {
JNIEXPORT jboolean JNICALL Java_com_mapzen_tangram_MapController_nativeLngLatToScreenPosition(JNIEnv* jniEnv, jobject obj, jdoubleArray coordinates) {
jdouble* arr = jniEnv->GetDoubleArrayElements(coordinates, NULL);
Tangram::lngLatToScreenPosition(arr[0], arr[1], &arr[0], &arr[1]);
bool ret = Tangram::lngLatToScreenPosition(arr[0], arr[1], &arr[0], &arr[1]);
jniEnv->ReleaseDoubleArrayElements(coordinates, arr, 0);
return ret;
}

JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeInit(JNIEnv* jniEnv, jobject obj, jobject tangramInstance, jobject assetManager, jstring stylePath) {
Expand Down
13 changes: 8 additions & 5 deletions android/tangram/src/com/mapzen/tangram/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,15 @@ public CameraType getCameraType() {
/**
* Find the geographic coordinates corresponding to the given position on screen
* @param screenPosition Position in pixels from the top-left corner of the map area
* @return LngLat corresponding to the given point
* @return LngLat corresponding to the given point, or null if the screen position
* does not intersect a geographic location.
*/
public LngLat screenPositionToLngLat(PointF screenPosition) {
double[] tmp = { screenPosition.x, screenPosition.y };
nativeScreenPositionToLngLat(tmp);
return new LngLat(tmp[0], tmp[1]);
if (nativeScreenPositionToLngLat(tmp)) {
return new LngLat(tmp[0], tmp[1]);
}
return null;
}

/**
Expand Down Expand Up @@ -681,8 +684,8 @@ public void useCachedGlState(boolean use) {
private synchronized native void nativeSetTilt(float radians);
private synchronized native void nativeSetTiltEased(float radians, float seconds, int ease);
private synchronized native float nativeGetTilt();
private synchronized native void nativeScreenPositionToLngLat(double[] coordinates);
private synchronized native void nativeLngLatToScreenPosition(double[] coordinates);
private synchronized native boolean nativeScreenPositionToLngLat(double[] coordinates);
private synchronized native boolean nativeLngLatToScreenPosition(double[] coordinates);
private synchronized native void nativeSetPixelScale(float scale);
private synchronized native void nativeSetCameraType(int type);
private synchronized native int nativeGetCameraType();
Expand Down

0 comments on commit a70362b

Please sign in to comment.