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

Commit

Permalink
[android] #352 - initial implementation of the featureAt binding
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 26, 2016
1 parent 8f1a426 commit 636d16b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
Expand Down Expand Up @@ -62,6 +63,7 @@
import com.mapbox.mapboxsdk.MapboxAccountManager;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.Feature;
import com.mapbox.mapboxsdk.annotations.Shape;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
Expand Down Expand Up @@ -1353,6 +1355,14 @@ protected void onSizeChanged(int width, int height, int oldw, int oldh) {

return mNativeMapView.getScale();
}
List<Feature> getVisibleFeatures(PointF pointF, List<String> layerIds) {
if (mDestroyed) {
return new ArrayList<>();
}

return mNativeMapView.getVisibleFeatures(pointF.x, pointF.y, layerIds);
}


// This class handles TextureView callbacks
private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,11 @@ public void snapshot(@NonNull SnapshotReadyCallback callback) {
//

public List<Feature> getVisibleFeatures(PointF pointF) {
return new ArrayList<>();
return getVisibleFeatures(pointF, new ArrayList<String>());
}

public List<Feature> getVisibleFeatures(PointF pointF, List<String> layerIds) {
return mMapView.getVisibleFeatures(pointF, layerIds);
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Build;
import android.view.Surface;

import com.mapbox.mapboxsdk.annotations.Feature;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
Expand All @@ -17,6 +18,7 @@
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.offline.OfflineManager;

import java.util.ArrayList;
import java.util.List;

// Class that wraps the native methods for convenience
Expand Down Expand Up @@ -470,6 +472,11 @@ public double[] getCameraValues() {
return nativeGetCameraValues(mNativeMapViewPtr);
}

public List<Feature> getVisibleFeatures(float x, float y, List<String> layerIds) {
nativeGetVisibleFeatures(mNativeMapViewPtr, x, y, layerIds.toArray(new String[layerIds.size()]));
return new ArrayList<>();
}

//
// Callbacks
//
Expand Down Expand Up @@ -645,4 +652,6 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat
private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);

private native double[] nativeGetCameraValues(long mNativeMapViewPtr);

private native LatLng nativeGetVisibleFeatures(long mNativeMapViewPtr, float x, float y, String[] layerIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ProgressDialog;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;

if (actionBar != null) {
Expand All @@ -77,6 +78,14 @@ public void onMapReady(@NonNull MapboxMap mapboxMap) {
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(BulkMarkerActivity.this);
}

mMapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
PointF pointF = mapboxMap.getProjection().toScreenLocation(point);
mMapboxMap.getVisibleFeatures(pointF);
}
});
}
});

Expand Down
14 changes: 13 additions & 1 deletion platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,17 @@ void nativeRemoveCustomLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapView
nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id));
}

jni::jobject* nativeGetVisibleFeatures(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jfloat x, jfloat y, jobjectArray stringArray){
mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetVisibleFeatures");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
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()));
mbgl::LatLng latLng = nativeMapView->getMap().latLngForPixel(mbgl::ScreenCoordinate(x, y));
return &jni::NewObject(*env, *latLngClass, *latLngConstructorId, latLng.latitude, latLng.longitude);
}

// Offline calls begin

jlong createDefaultFileSource(JNIEnv *env, jni::jobject* obj, jni::jstring* cachePath_, jni::jstring* assetRoot_, jlong maximumCacheSize) {
Expand Down Expand Up @@ -1699,7 +1710,8 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
MAKE_NATIVE_METHOD(nativeFlyTo, "(JDDDJDD)V"),
MAKE_NATIVE_METHOD(nativeAddCustomLayer, "(JLcom/mapbox/mapboxsdk/layers/CustomLayer;Ljava/lang/String;)V"),
MAKE_NATIVE_METHOD(nativeRemoveCustomLayer, "(JLjava/lang/String;)V"),
MAKE_NATIVE_METHOD(nativeSetContentPadding, "(JDDDD)V")
MAKE_NATIVE_METHOD(nativeSetContentPadding, "(JDDDD)V"),
MAKE_NATIVE_METHOD(nativeGetVisibleFeatures,"(JFF[Ljava/lang/String;)Lcom/mapbox/mapboxsdk/geometry/LatLng;")
);

// Offline begin
Expand Down

0 comments on commit 636d16b

Please sign in to comment.