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:
liyanjin
2025-10-14 21:32:27 +08:00
committed by GitHub
parent 6a6634370f
commit 5f808e0308
6 changed files with 35 additions and 5 deletions

View File

@@ -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
}
/**

View File

@@ -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 &#x27;CJK Unified Ideographs&#x27;
* and &#x27;Hangul Syllables&#x27; 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?
)