[android] - add LatLng for pixel conversion feature to MapSnapshotter
This commit is contained in:
@@ -42,6 +42,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.
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user