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 point features, try determining type of geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 26, 2016
1 parent 636d16b commit b5aa1a6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mapbox.mapboxsdk.annotations;

import java.util.Map;

public class PointFeature extends Marker implements Feature {

private long featureId;
private Map<String, Object>attributes;

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

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

@Override
public Object getAttribute(String key) {
return attributes.get(key);
}
}
36 changes: 36 additions & 0 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ jni::jfieldID* customLayerInitializeFunctionId = nullptr;
jni::jfieldID* customLayerRenderFunctionId = nullptr;
jni::jfieldID* customLayerDeinitializeFunctionId = nullptr;

//jni::jclass* mapClass = nullptr;
//jni::jmethodID* mapConstructorId = nullptr;
//jni::jmethodID* putFunctionId = nullptr;

// Offline declarations start

jni::jfieldID* offlineManagerClassPtrId = nullptr;
Expand Down Expand Up @@ -1092,6 +1096,33 @@ jni::jobject* nativeGetVisibleFeatures(JNIEnv *env, jni::jobject* obj, jlong na
mbgl::optional<std::vector<std::string>> 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()));

//jni::jobject* jhashmap = &jni::NewObject(*env, *mapClass, *mapConstructorId);

for (const auto &feature : features) {
//for (auto &pair : feature.properties) {
// auto &value = pair.second;
// PropertyValueEvaluator evaluator;
// jni::CallMethod<void>(*env, hashMap, *put, std_string_to_jstring(env2, pair.first.c_str(),mbgl::Value::visit(value, evaluator)));
//}
if(typeid(feature.geometry)==typeid(mbgl::Point<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a point");
}else if(typeid(feature.geometry)==typeid(mbgl::LineString<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a line");
}else if(typeid(feature.geometry)==typeid(mbgl::Polygon<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a polygon");
}else if(typeid(feature.geometry)==typeid(mbgl::MultiPoint<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a multipoint");
}else if(typeid(feature.geometry)==typeid(mbgl::MultiLineString<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a multilinestring");
}else if(typeid(feature.geometry)==typeid(mbgl::MultiPolygon<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a mulitpolygon");
}else if(typeid(feature.geometry)==typeid(mapbox::geometry::geometry_collection<double>)) {
mbgl::Log::Debug(mbgl::Event::JNI, "It's a geometrycollecition");
}else{
mbgl::Log::Debug(mbgl::Event::JNI, "It's a something else");
}
}
mbgl::LatLng latLng = nativeMapView->getMap().latLngForPixel(mbgl::ScreenCoordinate(x, y));
return &jni::NewObject(*env, *latLngClass, *latLngConstructorId, latLng.latitude, latLng.longitude);
}
Expand Down Expand Up @@ -1630,6 +1661,11 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
customLayerRenderFunctionId = &jni::GetFieldID(env, *customLayerClass, "mRenderFunction", "J");
customLayerDeinitializeFunctionId = &jni::GetFieldID(env, *customLayerClass, "mDeinitializeFunction", "J");

//mapClass = &jni::FindClass(env, "com/mapbox/mapboxsdk/layers/CustomLayer");
//mapClass = jni::NewGlobalRef(env, mapClass).release();
//mapConstructorId = &jni::GetMethodID(env, *mapClass, "<init>", "()V");
//putFunctionId = &jni::GetMethodID(env, *mapClass, "put","(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");

jni::jclass& nativeMapViewClass = jni::FindClass(env, "com/mapbox/mapboxsdk/maps/NativeMapView");

onInvalidateId = &jni::GetMethodID(env, nativeMapViewClass, "onInvalidate", "()V");
Expand Down

0 comments on commit b5aa1a6

Please sign in to comment.