diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/FeatureWrapper.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/FeatureWrapper.java index 63afa5602c4..24b8242213a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/FeatureWrapper.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/FeatureWrapper.java @@ -11,8 +11,16 @@ public FeatureWrapper() { features = new ArrayList<>(); } - public void add(Feature feature){ + public void add(Feature feature) { features.add(feature); } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + for (Feature f : features) { + builder.append("\n").append(f.getClass().getSimpleName()); + } + return builder.toString(); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java index aceff82156f..3d79b8457f1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java @@ -5,7 +5,7 @@ /** * Polyline is a geometry feature with an unclosed list of coordinates drawn as a line */ -public final class Polyline extends PointCollectionShape { +public class Polyline extends PointCollectionShape { private int color = Color.BLACK; // default color is black private float width = 10; // As specified by Google API Docs (in pixels) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineFeature.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineFeature.java new file mode 100644 index 00000000000..f255667f42d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineFeature.java @@ -0,0 +1,27 @@ +package com.mapbox.mapboxsdk.annotations; + +import java.util.Map; + +public class PolylineFeature extends Polyline implements Feature{ + + private long featureId; + private Map attributes; + + public PolylineFeature() { + } + + @Override + public long getFeatureId() { + return featureId; + } + + @Override + public Map getAttributes() { + return attributes; + } + + @Override + public Object getAttribute(String key) { + return attributes.get(key); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 84ea93a535e..e0be047974f 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -477,8 +477,8 @@ public double[] getCameraValues() { } public List getVisibleFeatures(float x, float y, List layerIds) { - PolygonFeature polygonFeature = nativeGetVisibleFeatures(mNativeMapViewPtr, x, y, layerIds.toArray(new String[layerIds.size()])); - Log.v(MapboxConstants.TAG,polygonFeature.toString()); + FeatureWrapper wrapper = nativeGetVisibleFeatures(mNativeMapViewPtr, x, y, layerIds.toArray(new String[layerIds.size()])); + Log.v(MapboxConstants.TAG,wrapper.toString()); return new ArrayList<>(); } diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index a5b186d532c..af5301175d2 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -163,6 +163,9 @@ jni::jmethodID* offlineRegionDeleteOnErrorId = nullptr; jni::jclass* polygonFeatureClass = nullptr; jni::jmethodID* polygonFeatureConstructorId = nullptr; +jni::jclass* polylineFeatureClass = nullptr; +jni::jmethodID* polylineFeatureConstructorId = nullptr; + jni::jclass* featureWrapperClass = nullptr; jni::jmethodID* featureWrapperConstructorId = nullptr; jni::jmethodID* featureWrapperAddId = nullptr; @@ -1101,7 +1104,7 @@ jni::jobject* nativeGetVisibleFeatures(JNIEnv *env, jni::jobject* obj, jlong na assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); mbgl::optional> optionalLayerIDs; - x std::vector features = nativeMapView->getMap().queryRenderedFeatures(mbgl::ScreenCoordinate(x, y), optionalLayerIDs); + std::vector features = nativeMapView->getMap().queryRenderedFeatures(mbgl::ScreenCoordinate(x, y), optionalLayerIDs); mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetVisibleFeatures 2: "+std::to_string(features.size())); // create FeatureWrapper return type @@ -1115,6 +1118,7 @@ jni::jobject* nativeGetVisibleFeatures(JNIEnv *env, jni::jobject* obj, jlong na mbgl::Log::Debug(mbgl::Event::JNI, "It's a point"); }else if(featureType==mbgl::FeatureType::LineString) { mbgl::Log::Debug(mbgl::Event::JNI, "It's a polyline"); + jni::CallMethod(*env, joutput, *featureWrapperAddId,&jni::NewObject(*env, *polylineFeatureClass, *polylineFeatureConstructorId)); }else if(featureType==mbgl::FeatureType::Polygon) { jni::CallMethod(*env, joutput, *featureWrapperAddId,&jni::NewObject(*env, *polygonFeatureClass, *polygonFeatureConstructorId)); mbgl::Log::Debug(mbgl::Event::JNI, "It's a polygon"); @@ -1668,6 +1672,10 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { polygonFeatureClass = jni::NewGlobalRef(env, polygonFeatureClass).release(); polygonFeatureConstructorId = &jni::GetMethodID(env, *polygonFeatureClass, "", "()V"); + polylineFeatureClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/PolylineFeature"); + polylineFeatureClass = jni::NewGlobalRef(env, polylineFeatureClass).release(); + polylineFeatureConstructorId = &jni::GetMethodID(env, *polylineFeatureClass, "", "()V"); + featureWrapperClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/FeatureWrapper"); featureWrapperClass = jni::NewGlobalRef(env, featureWrapperClass).release(); featureWrapperConstructorId = &jni::GetMethodID(env, *featureWrapperClass, "", "()V");;