summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java45
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java33
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java77
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_marker.xml14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml1
-rw-r--r--platform/android/config.cmake10
-rwxr-xr-xplatform/android/src/jni.cpp2
-rw-r--r--platform/android/src/snapshotter/map_snapshot.cpp57
-rw-r--r--platform/android/src/snapshotter/map_snapshot.hpp41
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp12
14 files changed, 293 insertions, 28 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
new file mode 100644
index 0000000000..2d1412aeda
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
@@ -0,0 +1,45 @@
+package com.mapbox.mapboxsdk.snapshotter;
+
+import android.graphics.Bitmap;
+import android.graphics.PointF;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
+
+/**
+ * A completed snapshot.
+ *
+ * @see MapSnapshotter
+ */
+public class MapSnapshot {
+
+ private long nativePtr = 0;
+ private Bitmap bitmap;
+
+ /**
+ * Created from native side
+ */
+ private MapSnapshot(long nativePtr, Bitmap bitmap) {
+ this.nativePtr = nativePtr;
+ this.bitmap = bitmap;
+ }
+
+ /**
+ * @return the bitmap
+ */
+ public Bitmap getBitmap() {
+ return bitmap;
+ }
+
+ /**
+ * Calculate the point in pixels on the Image from geographical coordinates.
+ *
+ * @param latLng the geographical coordinates
+ * @return the point on the image
+ */
+ public native PointF pixelForLatLng(LatLng latLng);
+
+ // Unused, needed for peer binding
+ private native void initialize();
+
+ protected native void finalize();
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 8118f9ad92..37d05fc328 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -12,7 +12,6 @@ import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.storage.FileSource;
/**
@@ -24,10 +23,26 @@ import com.mapbox.mapboxsdk.storage.FileSource;
public class MapSnapshotter {
/**
+ * Get notified on snapshot completion.
+ *
+ * @see MapSnapshotter#start(SnapshotReadyCallback, ErrorHandler)
+ */
+ public interface SnapshotReadyCallback {
+
+ /**
+ * Called when the snapshot is complete.
+ *
+ * @param snapshot the snapshot
+ */
+ void onSnapshotReady(MapSnapshot snapshot);
+
+ }
+
+ /**
* Can be used to get notified of errors
* in snapshot generation
*
- * @see MapSnapshotter#start(MapboxMap.SnapshotReadyCallback, ErrorHandler)
+ * @see MapSnapshotter#start(SnapshotReadyCallback, ErrorHandler)
*/
public interface ErrorHandler {
@@ -46,7 +61,7 @@ public class MapSnapshotter {
private long nativePtr = 0;
private final Context context;
- private MapboxMap.SnapshotReadyCallback callback;
+ private SnapshotReadyCallback callback;
private ErrorHandler errorHandler;
/**
@@ -176,7 +191,7 @@ public class MapSnapshotter {
*
* @param callback the callback to use when the snapshot is ready
*/
- public void start(@NonNull MapboxMap.SnapshotReadyCallback callback) {
+ public void start(@NonNull SnapshotReadyCallback callback) {
this.start(callback, null);
}
@@ -187,7 +202,7 @@ public class MapSnapshotter {
* @param callback the callback to use when the snapshot is ready
* @param errorHandler the error handler to use on snapshot errors
*/
- public void start(@NonNull MapboxMap.SnapshotReadyCallback callback, ErrorHandler errorHandler) {
+ public void start(@NonNull SnapshotReadyCallback callback, ErrorHandler errorHandler) {
if (this.callback != null) {
throw new IllegalStateException("Snapshotter was already started");
}
@@ -247,12 +262,12 @@ public class MapSnapshotter {
* Called by JNI peer when snapshot is ready.
* Always called on the origin (main) thread.
*
- * @param bitmap the generated snapshot
+ * @param snapshot the generated snapshot
*/
- protected void onSnapshotReady(Bitmap bitmap) {
+ protected void onSnapshotReady(MapSnapshot snapshot) {
if (callback != null) {
- addOverlay(bitmap);
- callback.onSnapshotReady(bitmap);
+ addOverlay(snapshot.getBitmap());
+ callback.onSnapshotReady(snapshot);
reset();
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index d6237bc161..7f955cb45c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -387,6 +387,16 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
+ <activity android:name=".activity.snapshot.MapSnapshotterMarkerActivity"
+ android:description="@string/description_map_snapshotter_marker"
+ android:label="@string/activity_map_snapshotter_marker">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_imagegenerator"/>
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity"/>
+ </activity>
<activity
android:name=".activity.maplayout.DoubleMapActivity"
android:description="@string/description_doublemap"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java
index 6b1cb920fc..245786e1d0 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java
@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
-import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewTreeObserver;
@@ -11,7 +10,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
import com.mapbox.mapboxsdk.testapp.R;
@@ -96,12 +95,12 @@ public class MapSnapshotterActivity extends AppCompatActivity {
MapSnapshotter snapshotter = new MapSnapshotter(MapSnapshotterActivity.this, options);
- snapshotter.start(new MapboxMap.SnapshotReadyCallback() {
+ snapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
@Override
- public void onSnapshotReady(Bitmap snapshot) {
+ public void onSnapshotReady(MapSnapshot snapshot) {
Timber.i("Got the snapshot");
ImageView imageView = new ImageView(MapSnapshotterActivity.this);
- imageView.setImageBitmap(snapshot);
+ imageView.setImageBitmap(snapshot.getBitmap());
grid.addView(
imageView,
new GridLayout.LayoutParams(GridLayout.spec(row), GridLayout.spec(column))
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
new file mode 100644
index 0000000000..582d4a29c5
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterMarkerActivity.java
@@ -0,0 +1,77 @@
+package com.mapbox.mapboxsdk.testapp.activity.snapshot;
+
+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.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;
+
+/**
+ * Test activity showing how to use a the {@link MapSnapshotter} and overlay
+ * {@link android.graphics.Bitmap}s on top.
+ */
+public class MapSnapshotterMarkerActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_map_snapshotter_marker);
+
+ final View container = findViewById(R.id.container);
+ container.getViewTreeObserver()
+ .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ //noinspection deprecation
+ container.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+
+ Timber.i("Starting snapshot");
+
+ MapSnapshotter mapSnapshotter = new MapSnapshotter(
+ getApplicationContext(),
+ new MapSnapshotter
+ .Options(Math.min(container.getMeasuredWidth(), 1024), Math.min(container.getMeasuredHeight(), 1024))
+ .withStyle(Style.TRAFFIC_DAY)
+ .withCameraPosition(new CameraPosition.Builder().target(new LatLng(52.090737, 5.121420)).zoom(15).build())
+ );
+ mapSnapshotter.start(MapSnapshotterMarkerActivity.this);
+ }
+ });
+ }
+
+ @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);
+ }
+
+ private Bitmap addMarker(MapSnapshot snapshot) {
+ Canvas canvas = new Canvas(snapshot.getBitmap());
+ Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default, null);
+ // Dom toren
+ PointF markerLocation = snapshot.pixelForLatLng(new LatLng(52.090649433011315, 5.121310651302338));
+ canvas.drawBitmap(marker,
+ markerLocation.x,
+ /* Subtract height (in dp) so the bottom of the marker aligns correctly */
+ markerLocation.y - (marker.getHeight() / getResources().getDisplayMetrics().density),
+ null
+ );
+ return snapshot.getBitmap();
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
index ac51bd9d5f..50f9be77fa 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
-import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
@@ -10,7 +9,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
import com.mapbox.mapboxsdk.testapp.R;
@@ -19,7 +18,7 @@ import java.util.Random;
/**
* Test activity showing how to use a the {@link MapSnapshotter}
*/
-public class MapSnapshotterReuseActivity extends AppCompatActivity implements MapboxMap.SnapshotReadyCallback {
+public class MapSnapshotterReuseActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback {
private MapSnapshotter mapSnapshotter;
private View fab;
@@ -61,10 +60,10 @@ public class MapSnapshotterReuseActivity extends AppCompatActivity implements Ma
}
@Override
- public void onSnapshotReady(Bitmap snapshot) {
+ public void onSnapshotReady(MapSnapshot snapshot) {
fab.setVisibility(View.VISIBLE);
ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
- imageView.setImageBitmap(snapshot);
+ imageView.setImageBitmap(snapshot.getBitmap());
}
private LatLngBounds getRandomBounds() {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_marker.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_marker.xml
new file mode 100644
index 0000000000..a10fb904db
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_marker.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ImageView
+ android:id="@+id/snapshot_image"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:contentDescription=""/>
+
+</RelativeLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 94dc669781..a2bf1d8596 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -61,6 +61,7 @@
<string name="description_bottom_sheet">Show 2 MapView on screen with a bottom sheet</string>
<string name="description_map_snapshotter">Show a static bitmap taken with the MapSnapshotter</string>
<string name="description_map_snapshotter_reuse">Show how to reuse a MapSnapshotter instance</string>
+ <string name="description_map_snapshotter_marker">Show how to add a marker to a Snapshot</string>
<string name="description_camera_animator">Use Android SDK Animators to animate camera position changes</string>
<string name="description_symbol_generator">Use Android SDK Views as symbols</string>
</resources> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index 4942bcab36..1fb2f6ba7f 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -61,6 +61,7 @@
<string name="activity_bottom_sheet">Bottom sheet</string>
<string name="activity_map_snapshotter">Map Snapshotter</string>
<string name="activity_map_snapshotter_reuse">Map Snapshotter Reuse</string>
+ <string name="activity_map_snapshotter_marker">Map Snapshot with marker</string>
<string name="activity_camera_animator">Animator animation</string>
<string name="activity_symbol_generator">SymbolGenerator</string>
</resources> \ No newline at end of file
diff --git a/platform/android/config.cmake b/platform/android/config.cmake
index e6813d5a22..47f894f7b9 100644
--- a/platform/android/config.cmake
+++ b/platform/android/config.cmake
@@ -59,7 +59,7 @@ macro(mbgl_platform_core)
PRIVATE platform/android/src/android_renderer_frontend.cpp
PRIVATE platform/android/src/android_renderer_frontend.hpp
- # Snapshots
+ # Snapshots (core)
PRIVATE platform/default/mbgl/gl/headless_backend.cpp
PRIVATE platform/default/mbgl/gl/headless_backend.hpp
PRIVATE platform/default/mbgl/gl/headless_frontend.cpp
@@ -68,8 +68,6 @@ macro(mbgl_platform_core)
PRIVATE platform/default/mbgl/map/map_snapshotter.hpp
PRIVATE platform/linux/src/headless_backend_egl.cpp
PRIVATE platform/linux/src/headless_display_egl.cpp
- PRIVATE platform/android/src/snapshotter/map_snapshotter.cpp
- PRIVATE platform/android/src/snapshotter/map_snapshotter.hpp
)
target_include_directories(mbgl-core
@@ -295,6 +293,12 @@ add_library(mbgl-android STATIC
platform/android/src/offline/offline_region_status.cpp
platform/android/src/offline/offline_region_status.hpp
+ # Snapshots (SDK)
+ platform/android/src/snapshotter/map_snapshotter.cpp
+ platform/android/src/snapshotter/map_snapshotter.hpp
+ platform/android/src/snapshotter/map_snapshot.cpp
+ platform/android/src/snapshotter/map_snapshot.hpp
+
# Main jni bindings
platform/android/src/attach_env.cpp
platform/android/src/attach_env.hpp
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index f6ddb8b6ee..f4e5734861 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -50,6 +50,7 @@
#include "style/sources/sources.hpp"
#include "style/light.hpp"
#include "snapshotter/map_snapshotter.hpp"
+#include "snapshotter/map_snapshot.hpp"
namespace mbgl {
namespace android {
@@ -186,6 +187,7 @@ void registerNatives(JavaVM *vm) {
// Snapshotter
MapSnapshotter::registerNative(env);
+ MapSnapshot::registerNative(env);
}
} // namespace android
diff --git a/platform/android/src/snapshotter/map_snapshot.cpp b/platform/android/src/snapshotter/map_snapshot.cpp
new file mode 100644
index 0000000000..09e83bbb8a
--- /dev/null
+++ b/platform/android/src/snapshotter/map_snapshot.cpp
@@ -0,0 +1,57 @@
+#include "map_snapshot.hpp"
+
+#include "../bitmap.hpp"
+
+#include <memory>
+
+namespace mbgl {
+namespace android {
+
+MapSnapshot::MapSnapshot(float pixelRatio_, MapSnapshot::PointForFn pointForFn_)
+ : pixelRatio(pixelRatio_)
+ , pointForFn(std::move(pointForFn_)) {
+}
+
+MapSnapshot::~MapSnapshot() = default;
+
+jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<LatLng> jLatLng) {
+ ScreenCoordinate point = pointForFn(LatLng::getLatLng(env, jLatLng));
+ return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio);
+}
+
+
+// Static methods //
+
+jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
+ PremultipliedImage&& image,
+ float pixelRatio,
+ mbgl::MapSnapshotter::PointForFn pointForFn) {
+ // Create the bitmap
+ auto bitmap = Bitmap::CreateBitmap(env, std::move(image));
+
+ // Create the Mapsnapshot peers
+ static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>>(env);
+ auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn);
+ return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap);
+}
+
+jni::Class<MapSnapshot> MapSnapshot::javaClass;
+
+void MapSnapshot::registerNative(jni::JNIEnv& env) {
+ // Lookup the class
+ MapSnapshot::javaClass = *jni::Class<MapSnapshot>::Find(env).NewGlobalRef(env).release();
+
+#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
+
+ // Register the peer
+ jni::RegisterNativePeer<MapSnapshot>(env, MapSnapshot::javaClass,
+ "nativePtr",
+ std::make_unique<MapSnapshot, JNIEnv&>,
+ "initialize",
+ "finalize",
+ METHOD(&MapSnapshot::pixelForLatLng, "pixelForLatLng")
+ );
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/snapshotter/map_snapshot.hpp b/platform/android/src/snapshotter/map_snapshot.hpp
new file mode 100644
index 0000000000..6d60d49728
--- /dev/null
+++ b/platform/android/src/snapshotter/map_snapshot.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <mbgl/map/map_snapshotter.hpp>
+
+#include <jni/jni.hpp>
+
+#include "../geometry/lat_lng.hpp"
+#include "../graphics/pointf.hpp"
+
+namespace mbgl {
+namespace android {
+
+class MapSnapshot {
+public:
+
+ using PointForFn = mbgl::MapSnapshotter::PointForFn;
+
+ static constexpr auto Name() { return "com/mapbox/mapboxsdk/snapshotter/MapSnapshot"; };
+
+ static void registerNative(jni::JNIEnv&);
+
+ static jni::Object<MapSnapshot> New(JNIEnv& env,
+ PremultipliedImage&& image,
+ float pixelRatio,
+ PointForFn pointForFn);
+
+ MapSnapshot(jni::JNIEnv&) {};
+ MapSnapshot(float pixelRatio, PointForFn);
+ ~MapSnapshot();
+
+ jni::Object<PointF> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>);
+
+private:
+ static jni::Class<MapSnapshot> javaClass;
+
+ float pixelRatio;
+ mbgl::MapSnapshotter::PointForFn pointForFn;
+};
+
+} // namespace android
+} // namespace mbgl \ No newline at end of file
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index 74e43c70a1..a13e91ccd3 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -8,7 +8,7 @@
#include <mbgl/actor/scheduler.hpp>
#include "../attach_env.hpp"
-#include "../bitmap.hpp"
+#include "map_snapshot.hpp"
namespace mbgl {
namespace android {
@@ -58,7 +58,7 @@ MapSnapshotter::~MapSnapshotter() = default;
void MapSnapshotter::start(JNIEnv&) {
MBGL_VERIFY_THREAD(tid);
- snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>(*Scheduler::GetCurrent(), [this](std::exception_ptr err, PremultipliedImage image) {
+ snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>(*Scheduler::GetCurrent(), [this](std::exception_ptr err, PremultipliedImage image, mbgl::MapSnapshotter::PointForFn pointForFn) {
MBGL_VERIFY_THREAD(tid);
android::UniqueEnv _env = android::AttachEnv();
@@ -67,12 +67,12 @@ void MapSnapshotter::start(JNIEnv&) {
static auto onSnapshotFailed = javaClass.GetMethod<void (jni::String)>(*_env, "onSnapshotFailed");
javaPeer->Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
} else {
- // Create the bitmap
- auto bitmap = Bitmap::CreateBitmap(*_env, std::move(image));
+ // Create the wrapper
+ auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, pointForFn);
// invoke callback
- static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<Bitmap>)>(*_env, "onSnapshotReady");
- javaPeer->Call(*_env, onSnapshotReady, bitmap);
+ static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
+ javaPeer->Call(*_env, onSnapshotReady, mapSnapshot);
}
});