attempting to put one annotation on the map - gets to the native call and then nothing happens

This commit is contained in:
Nicholas Hallahan
2015-06-20 16:21:41 -07:00
parent 1779dd870d
commit ef31fc5aed
6 changed files with 75 additions and 4 deletions

View File

@@ -419,6 +419,26 @@ void JNICALL nativeSetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, j
nativeMapView->getMap().setLatLng(mbgl::LatLng(latitude, longitude), std::chrono::milliseconds(duration));
}
void JNICALL nativeAddAnnotation(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject latLng) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddAnnotation");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
jdouble latitude = env->GetDoubleField(latLng, latLngLatitudeId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return;
}
jdouble longitude = env->GetDoubleField(latLng, latLngLongitudeId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
return;
}
nativeMapView->getMap().addPointAnnotation(mbgl::LatLng(latitude, longitude), std::string(""));
}
jobject JNICALL nativeGetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLatLng");
assert(nativeMapViewPtr != 0);
@@ -952,6 +972,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativeMoveBy", "(JDDJ)V", reinterpret_cast<void *>(&nativeMoveBy)},
{"nativeSetLatLng", "(JLcom/mapbox/mapboxgl/geometry/LatLng;J)V",
reinterpret_cast<void *>(&nativeSetLatLng)},
{"nativeAddAnnotation", "(JLcom/mapbox/mapboxgl/geometry/LatLng;)V",
reinterpret_cast<void *>(&nativeAddAnnotation)},
{"nativeGetLatLng", "(J)Lcom/mapbox/mapboxgl/geometry/LatLng;",
reinterpret_cast<void *>(&nativeGetLatLng)},
{"nativeResetPosition", "(J)V", reinterpret_cast<void *>(&nativeResetPosition)},

View File

@@ -204,6 +204,10 @@ public class MapView extends SurfaceView {
}
}
public void addAnnotation(LatLng marker) {
mNativeMapView.addAnnotation(marker);
}
//
// Property methods
//

View File

@@ -197,6 +197,10 @@ class NativeMapView {
nativeSetLatLng(mNativeMapViewPtr, latLng, duration);
}
public void addAnnotation(LatLng latLng) {
nativeAddAnnotation(mNativeMapViewPtr, latLng);
}
public LatLng getLatLng() {
return nativeGetLatLng(mNativeMapViewPtr);
}
@@ -422,6 +426,8 @@ class NativeMapView {
private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng,
long duration);
private native void nativeAddAnnotation(long nativeMapViewPtr, LatLng latLng);
private native LatLng nativeGetLatLng(long nativeMapViewPtr);
private native void nativeResetPosition(long nativeMapViewPtr);

View File

@@ -77,6 +77,9 @@ public class MainActivity extends ActionBarActivity {
private float mCompassBearing;
private boolean mCompassValid = false;
// Used for point annotations
private boolean mIsPointAnnotationsOn = false;
//
// Lifecycle events
//
@@ -210,6 +213,10 @@ public class MainActivity extends ActionBarActivity {
}
return true;
case R.id.action_point_annotations:
// Toggle point annotations
togglePointAnnotations(!mIsPointAnnotationsOn);
default:
return super.onOptionsItemSelected(item);
}
@@ -249,6 +256,32 @@ public class MainActivity extends ActionBarActivity {
}
}
/**
* Enable / Disable Point annotations.
*
* TODO: Implement updating the UI and removing point annotations from the map.
*
* @param enablePointAnnotations
*/
private void togglePointAnnotations(boolean enablePointAnnotations) {
if (enablePointAnnotations) {
if (!mIsPointAnnotationsOn) {
mIsPointAnnotationsOn = true;
addPointAnnotations();
}
} else {
if (mIsPointAnnotationsOn) {
mIsPointAnnotationsOn = false;
}
}
}
private void addPointAnnotations() {
LatLng backLot = new LatLng(38.649441, -121.369064);
mMapFragment.getMap().addAnnotation(backLot);
}
// This class forwards location updates to updateLocation()
private class GpsListener implements LocationListener {

View File

@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_gps"
android:icon="@drawable/ic_action_location_searching"
android:title="@string/action_gps"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_debug"
android:icon="@drawable/ic_action_about"
android:title="@string/action_debug"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_point_annotations"
android:icon="@android:drawable/ic_menu_myplaces"
android:title="@string/action_point_annotations"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_gps"
android:icon="@drawable/ic_action_location_searching"
android:title="@string/action_gps"
app:showAsAction="ifRoom" />
</menu>

View File

@@ -7,6 +7,8 @@
<string name="action_debug">Toggle debug mode</string>
<string name="action_point_annotations">Toggle point annotations</string>
<string name="label_fps">FPS:</string>
<string name="compass_desc">Map compass. Click to reset the map rotation to North.</string>