summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-06-26 16:21:16 +0200
committerTobrun <tobrun@mapbox.com>2018-07-05 18:50:21 +0200
commit473dd9b23f3bbd933a3af52d896803659f80acfb (patch)
tree81cdec5e135e36ac67fa3e2890ba0002ec6b3d89 /platform/android
parentd4ca3014eb92ca4d7154e57539100413b32b397f (diff)
downloadqtlocation-mapboxgl-473dd9b23f3bbd933a3af52d896803659f80acfb.tar.gz
[android] - add LatLng for pixel conversion feature to MapSnapshotter
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java8
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java14
-rw-r--r--platform/android/src/snapshotter/map_snapshot.cpp4
-rw-r--r--platform/android/src/snapshotter/map_snapshot.hpp1
4 files changed, 25 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
index 38c1491461..0dbf977e4e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
@@ -43,6 +43,14 @@ public class MapSnapshot {
public native PointF pixelForLatLng(LatLng latLng);
/**
+ * Calculate geographical coordinates from a point in pixels on the Image
+ *
+ * @param pointF the point in pixels
+ * @return the geographical coordinates
+ */
+ public native LatLng latLngForPixel(PointF pointF);
+
+ /**
* @return The attributions for the sources of this snapshot.
*/
protected String[] getAttributions() {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java
index 11d1df008a..3af343e946 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java
@@ -1,22 +1,22 @@
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
+import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
-
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
import com.mapbox.mapboxsdk.testapp.R;
-
import timber.log.Timber;
/**
@@ -26,6 +26,7 @@ import timber.log.Timber;
public class MapSnapshotterMarkerActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback {
private MapSnapshotter mapSnapshotter;
+ private MapSnapshot mapSnapshot;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -60,12 +61,21 @@ public class MapSnapshotterMarkerActivity extends AppCompatActivity implements M
mapSnapshotter.cancel();
}
+ @SuppressLint("ClickableViewAccessibility")
@Override
public void onSnapshotReady(MapSnapshot snapshot) {
Timber.i("Snapshot ready");
ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
Bitmap image = addMarker(snapshot);
imageView.setImageBitmap(image);
+ imageView.setOnTouchListener((v, event) -> {
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ LatLng latLng = snapshot.latLngForPixel(new PointF(event.getX(), event.getY()));
+ Timber.e("Clicked LatLng is %s", latLng);
+ return true;
+ }
+ return false;
+ });
}
private Bitmap addMarker(MapSnapshot snapshot) {
diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp
index f5092b3c56..bbbf7cc207 100644
--- a/platform/android/src/snapshotter/map_snapshot.cpp
+++ b/platform/android/src/snapshotter/map_snapshot.cpp
@@ -20,6 +20,9 @@ jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<La
return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio);
}
+jni::Object<LatLng> MapSnapshot::latLngForPixel(jni::JNIEnv& env, jni::Object<PointF>) {
+ return LatLng::New(env, {0, 0});
+}
// Static methods //
@@ -52,6 +55,7 @@ void MapSnapshot::registerNative(jni::JNIEnv& env) {
std::make_unique<MapSnapshot, JNIEnv&>,
"initialize",
"finalize",
+ METHOD(&MapSnapshot::latLngForPixel, "latLngForPixel"),
METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng")
);
}
diff --git a/platform/android/src/snapshotter/map_snapshot.hpp b/platform/android/src/snapshotter/map_snapshot.hpp
index 4673dcd16e..48dd1b6049 100644
--- a/platform/android/src/snapshotter/map_snapshot.hpp
+++ b/platform/android/src/snapshotter/map_snapshot.hpp
@@ -34,6 +34,7 @@ public:
~MapSnapshot();
jni::Object<PointF> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>);
+ jni::Object<LatLng> latLngForPixel(jni::JNIEnv&, jni::Object<PointF>);
private:
static jni::Class<MapSnapshot> javaClass;