Make Android snapshotter supports hiding the attribution (#3878)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -31,6 +31,7 @@ jni::Local<jni::Object<MapSnapshot>> MapSnapshot::New(JNIEnv& env,
|
||||
float pixelRatio,
|
||||
std::vector<std::string> attributions,
|
||||
bool showLogo,
|
||||
bool showAttribution,
|
||||
mbgl::MapSnapshotter::PointForFn pointForFn,
|
||||
mbgl::MapSnapshotter::LatLngForFn latLngForFn) {
|
||||
// Create the bitmap
|
||||
@@ -39,14 +40,17 @@ jni::Local<jni::Object<MapSnapshot>> MapSnapshot::New(JNIEnv& env,
|
||||
// Create the Mapsnapshot peers
|
||||
static auto& javaClass = jni::Class<MapSnapshot>::Singleton(env);
|
||||
static auto constructor =
|
||||
javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>, jni::jboolean>(env);
|
||||
javaClass
|
||||
.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>, jni::jboolean, jni::jboolean>(
|
||||
env);
|
||||
auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn, latLngForFn);
|
||||
return javaClass.New(env,
|
||||
constructor,
|
||||
reinterpret_cast<jlong>(nativePeer.release()),
|
||||
bitmap,
|
||||
conversion::toArray(env, attributions),
|
||||
(jni::jboolean)showLogo);
|
||||
(jni::jboolean)showLogo,
|
||||
(jni::jboolean)showAttribution);
|
||||
}
|
||||
|
||||
void MapSnapshot::registerNative(jni::JNIEnv& env) {
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
float pixelRatio,
|
||||
std::vector<std::string> attributions,
|
||||
bool showLogo,
|
||||
bool showAttribution,
|
||||
PointForFn pointForFn,
|
||||
LatLngForFn latLngForFn);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
|
||||
const jni::Object<LatLngBounds>& region,
|
||||
const jni::Object<CameraPosition>& position,
|
||||
jni::jboolean _showLogo,
|
||||
jni::jboolean _showAttribution,
|
||||
const jni::String& _localIdeographFontFamily)
|
||||
: javaPeer(_env, _obj),
|
||||
pixelRatio(_pixelRatio) {
|
||||
@@ -39,6 +40,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
|
||||
auto size = mbgl::Size{static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||
|
||||
showLogo = _showLogo;
|
||||
showAttribution = _showAttribution;
|
||||
|
||||
// Create the core snapshotter
|
||||
snapshotter = std::make_unique<mbgl::MapSnapshotter>(
|
||||
@@ -94,7 +96,7 @@ void MapSnapshotter::start(JNIEnv& env) {
|
||||
} else {
|
||||
// Create the wrapper
|
||||
auto mapSnapshot = android::MapSnapshot::New(
|
||||
*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn, latLngForFn);
|
||||
*_env, std::move(image), pixelRatio, attributions, showLogo, showAttribution, pointForFn, latLngForFn);
|
||||
|
||||
// invoke callback
|
||||
static auto onSnapshotReady = javaClass.GetMethod<void(jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
|
||||
@@ -327,6 +329,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
|
||||
const jni::Object<LatLngBounds>&,
|
||||
const jni::Object<CameraPosition>&,
|
||||
jni::jboolean,
|
||||
jni::jboolean,
|
||||
const jni::String&>,
|
||||
"nativeInitialize",
|
||||
"finalize",
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
const jni::Object<LatLngBounds>& region,
|
||||
const jni::Object<CameraPosition>& position,
|
||||
jni::jboolean showLogo,
|
||||
jni::jboolean _showAttribution,
|
||||
const jni::String& localIdeographFontFamily);
|
||||
|
||||
virtual ~MapSnapshotter() override;
|
||||
@@ -73,6 +74,7 @@ private:
|
||||
|
||||
float pixelRatio;
|
||||
bool showLogo;
|
||||
bool showAttribution;
|
||||
|
||||
FileSource* jFileSource;
|
||||
void activateFilesource(JNIEnv&);
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.maplibre.android.geometry.LatLng
|
||||
* @see MapSnapshotter
|
||||
*/
|
||||
@Keep
|
||||
class MapSnapshot private constructor(val nativePtr: Long, bitmap: Bitmap, attributions: Array<String>, showLogo: Boolean) {
|
||||
class MapSnapshot private constructor(val nativePtr: Long, bitmap: Bitmap, attributions: Array<String>, showLogo: Boolean, showAttribution: Boolean) {
|
||||
|
||||
/**
|
||||
* @return the large
|
||||
@@ -28,6 +28,11 @@ class MapSnapshot private constructor(val nativePtr: Long, bitmap: Bitmap, attri
|
||||
*/
|
||||
val isShowLogo: Boolean
|
||||
|
||||
/**
|
||||
* @return Flag indicating to show the attribution.
|
||||
*/
|
||||
val isShowAttribution: Boolean
|
||||
|
||||
/**
|
||||
* Created from native side
|
||||
*/
|
||||
@@ -35,6 +40,7 @@ class MapSnapshot private constructor(val nativePtr: Long, bitmap: Bitmap, attri
|
||||
this.bitmap = bitmap
|
||||
this.attributions = attributions
|
||||
isShowLogo = showLogo
|
||||
isShowAttribution = showAttribution
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -134,6 +134,8 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
|
||||
var showLogo = true
|
||||
|
||||
var showAttribution = true
|
||||
|
||||
/**
|
||||
* @return the font family used for locally generating ideographs,
|
||||
* Default font for local ideograph font family is [MapLibreConstants.DEFAULT_FONT].
|
||||
@@ -231,6 +233,15 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* @param showAttribution The flag indicating to show the attribution.
|
||||
* @return the mutated [Options]
|
||||
*/
|
||||
fun withAttribution(showAttribution: Boolean): Options {
|
||||
this.showAttribution = showAttribution
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font family for generating glyphs locally for ideographs in the 'CJK Unified Ideographs'
|
||||
* and 'Hangul Syllables' ranges.
|
||||
@@ -337,6 +348,7 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
options.region,
|
||||
options.cameraPosition,
|
||||
options.showLogo,
|
||||
options.showAttribution,
|
||||
options.localIdeographFontFamily
|
||||
)
|
||||
}
|
||||
@@ -476,7 +488,7 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
*/
|
||||
protected open fun addOverlay(mapSnapshot: MapSnapshot) {
|
||||
val snapshot = mapSnapshot.bitmap
|
||||
val canvas = Canvas(snapshot!!)
|
||||
val canvas = Canvas(snapshot)
|
||||
val margin = context.resources.displayMetrics.density.toInt() * LOGO_MARGIN_DP
|
||||
drawOverlay(mapSnapshot, snapshot, canvas, margin)
|
||||
}
|
||||
@@ -511,6 +523,7 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
|
||||
private fun drawAttribution(mapSnapshot: MapSnapshot, canvas: Canvas, measure: AttributionMeasure, layout: AttributionLayout?) {
|
||||
// draw attribution
|
||||
if (!mapSnapshot.isShowAttribution) return
|
||||
val anchorPoint = layout!!.anchorPoint
|
||||
if (anchorPoint != null) {
|
||||
drawAttribution(canvas, measure, anchorPoint)
|
||||
@@ -732,6 +745,7 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
region: LatLngBounds?,
|
||||
position: CameraPosition?,
|
||||
showLogo: Boolean,
|
||||
showAttribution: Boolean,
|
||||
localIdeographFontFamily: String?
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user