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

Commit c61ccb3

Browse files
committed
[android] - make snapshot logo optional
1 parent a42455c commit c61ccb3

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ public class MapSnapshot {
1515
private long nativePtr = 0;
1616
private Bitmap bitmap;
1717
private String[] attributions;
18+
private boolean showLogo;
1819

1920
/**
2021
* Created from native side
2122
*/
22-
private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions) {
23+
private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions, boolean showLogo) {
2324
this.nativePtr = nativePtr;
2425
this.bitmap = bitmap;
2526
this.attributions = attributions;
27+
this.showLogo = showLogo;
2628
}
2729

2830
/**
@@ -47,6 +49,13 @@ protected String[] getAttributions() {
4749
return attributions;
4850
}
4951

52+
/**
53+
* @return Flag indicating to show the Mapbox logo.
54+
*/
55+
boolean isShowLogo() {
56+
return showLogo;
57+
}
58+
5059
// Unused, needed for peer binding
5160
private native void initialize();
5261

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static class Options {
7474
private String styleUrl = Style.MAPBOX_STREETS;
7575
private LatLngBounds region;
7676
private CameraPosition cameraPosition;
77+
private boolean showLogo = true;
7778

7879
/**
7980
* @param width the width of the image
@@ -123,6 +124,15 @@ public Options withCameraPosition(CameraPosition cameraPosition) {
123124
return this;
124125
}
125126

127+
/**
128+
* @param showLogo The flag indicating to show the Mapbox logo.
129+
* @return the mutated {@link Options}
130+
*/
131+
public Options withLogo(boolean showLogo) {
132+
this.showLogo = showLogo;
133+
return this;
134+
}
135+
126136
/**
127137
* @return the width of the image
128138
*/
@@ -182,7 +192,7 @@ public MapSnapshotter(@NonNull Context context, @NonNull Options options) {
182192

183193
nativeInitialize(this, fileSource, options.pixelRatio, options.width,
184194
options.height, options.styleUrl, options.region, options.cameraPosition,
185-
programCacheDir);
195+
options.showLogo, programCacheDir);
186196
}
187197

188198
/**
@@ -266,7 +276,9 @@ protected void addOverlay(Bitmap original) {
266276
*/
267277
protected void onSnapshotReady(MapSnapshot snapshot) {
268278
if (callback != null) {
269-
addOverlay(snapshot.getBitmap());
279+
if (snapshot.isShowLogo()) {
280+
addOverlay(snapshot.getBitmap());
281+
}
270282
callback.onSnapshotReady(snapshot);
271283
reset();
272284
}
@@ -294,7 +306,7 @@ protected native void nativeInitialize(MapSnapshotter mapSnapshotter,
294306
FileSource fileSource, float pixelRatio,
295307
int width, int height, String styleUrl,
296308
LatLngBounds region, CameraPosition position,
297-
String programCacheDir);
309+
boolean showLogo, String programCacheDir);
298310

299311
protected native void nativeStart();
300312

platform/android/src/snapshotter/map_snapshot.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
2727
PremultipliedImage&& image,
2828
float pixelRatio,
2929
std::vector<std::string> attributions,
30+
bool showLogo,
3031
mbgl::MapSnapshotter::PointForFn pointForFn) {
3132
// Create the bitmap
3233
auto bitmap = Bitmap::CreateBitmap(env, std::move(image));
3334

3435
// Create the Mapsnapshot peers
35-
static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>>(env);
36+
static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>, jni::jboolean>(env);
3637
auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn);
37-
return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, jni::Make<jni::Array<jni::String>>(env, attributions));
38+
return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, jni::Make<jni::Array<jni::String>>(env, attributions), (jni::jboolean) showLogo);
3839
}
3940

4041
jni::Class<MapSnapshot> MapSnapshot::javaClass;

platform/android/src/snapshotter/map_snapshot.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MapSnapshot {
2626
PremultipliedImage&& image,
2727
float pixelRatio,
2828
std::vector<std::string> attributions,
29+
bool showLogo,
2930
PointForFn pointForFn);
3031

3132
MapSnapshot(jni::JNIEnv&) {};

platform/android/src/snapshotter/map_snapshotter.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
2222
jni::String styleURL,
2323
jni::Object<LatLngBounds> region,
2424
jni::Object<CameraPosition> position,
25+
jni::jboolean _showLogo,
2526
jni::String _programCacheDir)
2627
: javaPeer(SeizeGenericWeakRef(_env, jni::Object<MapSnapshotter>(jni::NewWeakGlobalRef(_env, _obj.Get()).release())))
2728
, pixelRatio(_pixelRatio)
@@ -41,6 +42,8 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
4142
bounds = LatLngBounds::getLatLngBounds(_env, region);
4243
}
4344

45+
showLogo = _showLogo;
46+
4447
// Create the core snapshotter
4548
snapshotter = std::make_unique<mbgl::MapSnapshotter>(fileSource,
4649
*threadPool,
@@ -70,7 +73,7 @@ void MapSnapshotter::start(JNIEnv&) {
7073
javaPeer->Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
7174
} else {
7275
// Create the wrapper
73-
auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, pointForFn);
76+
auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn);
7477

7578
// invoke callback
7679
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
@@ -117,7 +120,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
117120

118121
// Register the peer
119122
jni::RegisterNativePeer<MapSnapshotter>(env, MapSnapshotter::javaClass, "nativePtr",
120-
std::make_unique<MapSnapshotter, JNIEnv&, jni::Object<MapSnapshotter>, jni::Object<FileSource>, jni::jfloat, jni::jint, jni::jint, jni::String, jni::Object<LatLngBounds>, jni::Object<CameraPosition>, jni::String>,
123+
std::make_unique<MapSnapshotter, JNIEnv&, jni::Object<MapSnapshotter>, jni::Object<FileSource>, jni::jfloat, jni::jint, jni::jint, jni::String, jni::Object<LatLngBounds>, jni::Object<CameraPosition>, jni::jboolean, jni::String>,
121124
"nativeInitialize",
122125
"finalize",
123126
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),

platform/android/src/snapshotter/map_snapshotter.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MapSnapshotter {
3636
jni::String styleURL,
3737
jni::Object<LatLngBounds> region,
3838
jni::Object<CameraPosition> position,
39+
jni::jboolean showLogo,
3940
jni::String programCacheDir);
4041

4142
~MapSnapshotter();
@@ -59,6 +60,7 @@ class MapSnapshotter {
5960
GenericUniqueWeakObject<MapSnapshotter> javaPeer;
6061

6162
float pixelRatio;
63+
bool showLogo;
6264

6365
std::shared_ptr<mbgl::ThreadPool> threadPool;
6466
std::unique_ptr<Actor<mbgl::MapSnapshotter::Callback>> snapshotCallback;

0 commit comments

Comments
 (0)