Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #352 - added PolylineFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 26, 2016
1 parent 3c8a77e commit f2f836c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> attributes;

public PolylineFeature() {
}

@Override
public long getFeatureId() {
return featureId;
}

@Override
public Map<String, Object> getAttributes() {
return attributes;
}

@Override
public Object getAttribute(String key) {
return attributes.get(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ public double[] getCameraValues() {
}

public List<Feature> getVisibleFeatures(float x, float y, List<String> 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<>();
}

Expand Down
10 changes: 9 additions & 1 deletion platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1101,7 +1104,7 @@ jni::jobject* nativeGetVisibleFeatures(JNIEnv *env, jni::jobject* obj, jlong na
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::optional<std::vector<std::string>> optionalLayerIDs;
x std::vector<mbgl::Feature> features = nativeMapView->getMap().queryRenderedFeatures(mbgl::ScreenCoordinate(x, y), optionalLayerIDs);
std::vector<mbgl::Feature> 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
Expand All @@ -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<void>(*env, joutput, *featureWrapperAddId,&jni::NewObject(*env, *polylineFeatureClass, *polylineFeatureConstructorId));
}else if(featureType==mbgl::FeatureType::Polygon) {
jni::CallMethod<void>(*env, joutput, *featureWrapperAddId,&jni::NewObject(*env, *polygonFeatureClass, *polygonFeatureConstructorId));
mbgl::Log::Debug(mbgl::Event::JNI, "It's a polygon");
Expand Down Expand Up @@ -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, "<init>", "()V");

polylineFeatureClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/PolylineFeature");
polylineFeatureClass = jni::NewGlobalRef(env, polylineFeatureClass).release();
polylineFeatureConstructorId = &jni::GetMethodID(env, *polylineFeatureClass, "<init>", "()V");

featureWrapperClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/annotations/FeatureWrapper");
featureWrapperClass = jni::NewGlobalRef(env, featureWrapperClass).release();
featureWrapperConstructorId = &jni::GetMethodID(env, *featureWrapperClass, "<init>", "()V");;
Expand Down

0 comments on commit f2f836c

Please sign in to comment.