basic single marker point annotation

Merge branch 'android-annotations-poc' into android-annotations
This commit is contained in:
Nicholas Hallahan
2015-07-13 16:32:16 -07:00
6 changed files with 76 additions and 4 deletions

View File

@@ -16,6 +16,7 @@
#include <mbgl/android/jni.hpp>
#include <mbgl/android/native_map_view.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/platform/event.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/storage/network_status.hpp>
@@ -433,6 +434,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::PointAnnotation(mbgl::LatLng(latitude, longitude), std::string("default_marker")));
}
jobject JNICALL nativeGetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLatLng");
assert(nativeMapViewPtr != 0);
@@ -976,6 +997,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

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

View File

@@ -214,6 +214,10 @@ class NativeMapView {
nativeSetLatLng(mNativeMapViewPtr, latLng, duration);
}
public void addAnnotation(LatLng latLng) {
nativeAddAnnotation(mNativeMapViewPtr, latLng);
}
public LatLng getLatLng() {
return nativeGetLatLng(mNativeMapViewPtr);
}
@@ -446,6 +450,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>