Add padding support to MapSnapshotter Android (#3882)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
@@ -25,7 +25,11 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
|
||||
const jni::Object<CameraPosition>& position,
|
||||
jni::jboolean _showLogo,
|
||||
jni::jboolean _showAttribution,
|
||||
const jni::String& _localIdeographFontFamily)
|
||||
const jni::String& _localIdeographFontFamily,
|
||||
jni::jfloat paddingLeft,
|
||||
jni::jfloat paddingTop,
|
||||
jni::jfloat paddingRight,
|
||||
jni::jfloat paddingBottom)
|
||||
: javaPeer(_env, _obj),
|
||||
pixelRatio(_pixelRatio) {
|
||||
// Get a reference to the JavaVM for callbacks
|
||||
@@ -57,6 +61,10 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
|
||||
}
|
||||
|
||||
if (region) {
|
||||
snapshotter->setPadding({static_cast<double>(paddingTop),
|
||||
static_cast<double>(paddingLeft),
|
||||
static_cast<double>(paddingBottom),
|
||||
static_cast<double>(paddingRight)});
|
||||
snapshotter->setRegion(LatLngBounds::getLatLngBounds(_env, region));
|
||||
}
|
||||
|
||||
@@ -138,6 +146,11 @@ void MapSnapshotter::setRegion(JNIEnv& env, const jni::Object<LatLngBounds>& reg
|
||||
snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region));
|
||||
}
|
||||
|
||||
void MapSnapshotter::setPadding(JNIEnv&, jni::jint left, jni::jint top, jni::jint right, jni::jint bottom) {
|
||||
snapshotter->setPadding(
|
||||
{static_cast<double>(top), static_cast<double>(left), static_cast<double>(bottom), static_cast<double>(right)});
|
||||
}
|
||||
|
||||
// Private methods //
|
||||
|
||||
void MapSnapshotter::activateFilesource(JNIEnv& env) {
|
||||
@@ -330,7 +343,11 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
|
||||
const jni::Object<CameraPosition>&,
|
||||
jni::jboolean,
|
||||
jni::jboolean,
|
||||
const jni::String&>,
|
||||
const jni::String&,
|
||||
jni::jfloat,
|
||||
jni::jfloat,
|
||||
jni::jfloat,
|
||||
jni::jfloat>,
|
||||
"nativeInitialize",
|
||||
"finalize",
|
||||
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),
|
||||
@@ -345,6 +362,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&MapSnapshotter::setSize, "setSize"),
|
||||
METHOD(&MapSnapshotter::setCameraPosition, "setCameraPosition"),
|
||||
METHOD(&MapSnapshotter::setRegion, "setRegion"),
|
||||
METHOD(&MapSnapshotter::setPadding, "setPadding"),
|
||||
METHOD(&MapSnapshotter::start, "nativeStart"),
|
||||
METHOD(&MapSnapshotter::cancel, "nativeCancel"));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,11 @@ public:
|
||||
const jni::Object<CameraPosition>& position,
|
||||
jni::jboolean showLogo,
|
||||
jni::jboolean _showAttribution,
|
||||
const jni::String& localIdeographFontFamily);
|
||||
const jni::String& localIdeographFontFamily,
|
||||
jni::jfloat paddingLeft,
|
||||
jni::jfloat paddingTop,
|
||||
jni::jfloat paddingRight,
|
||||
jni::jfloat paddingBottom);
|
||||
|
||||
virtual ~MapSnapshotter() override;
|
||||
|
||||
@@ -49,6 +53,8 @@ public:
|
||||
|
||||
void setRegion(JNIEnv&, const jni::Object<LatLngBounds>& region);
|
||||
|
||||
void setPadding(JNIEnv&, jni::jint left, jni::jint top, jni::jint right, jni::jint bottom);
|
||||
|
||||
void start(JNIEnv&);
|
||||
|
||||
void cancel(JNIEnv&);
|
||||
|
||||
@@ -126,6 +126,10 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
var region: LatLngBounds? = null
|
||||
private set
|
||||
|
||||
// only works when using region to specify the camera
|
||||
var regionPadding: IntArray = intArrayOf(0, 0, 0, 0)
|
||||
private set
|
||||
|
||||
/**
|
||||
* @return the camera position
|
||||
*/
|
||||
@@ -204,6 +208,16 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* @param padding of the padding of the region.
|
||||
* This is applied before the region, if region is null, it will not work
|
||||
* @return the mutated [Options]
|
||||
*/
|
||||
fun withPadding(left:Int, top:Int, right:Int, bottom:Int): Options {
|
||||
this.regionPadding = intArrayOf(left, top, right, bottom)
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pixelRatio the pixel ratio to use (default: 1)
|
||||
* @return the mutated [Options]
|
||||
@@ -349,7 +363,11 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
options.cameraPosition,
|
||||
options.showLogo,
|
||||
options.showAttribution,
|
||||
options.localIdeographFontFamily
|
||||
options.localIdeographFontFamily,
|
||||
options.regionPadding[0] / options.pixelRatio,
|
||||
options.regionPadding[1] / options.pixelRatio,
|
||||
options.regionPadding[2] / options.pixelRatio,
|
||||
options.regionPadding[3] / options.pixelRatio
|
||||
)
|
||||
}
|
||||
|
||||
@@ -394,6 +412,14 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
@Keep
|
||||
external fun setRegion(region: LatLngBounds?)
|
||||
|
||||
/**
|
||||
* Updates the snapshotter padding with a new [IntArray]
|
||||
*
|
||||
* @param left, top, right, bottom
|
||||
*/
|
||||
@Keep
|
||||
external fun setPadding(left:Int, top:Int, right:Int, bottom:Int)
|
||||
|
||||
/**
|
||||
* Updates the snapshotter with a new style url
|
||||
*
|
||||
@@ -746,7 +772,11 @@ open class MapSnapshotter(context: Context, options: Options) {
|
||||
position: CameraPosition?,
|
||||
showLogo: Boolean,
|
||||
showAttribution: Boolean,
|
||||
localIdeographFontFamily: String?
|
||||
localIdeographFontFamily: String?,
|
||||
paddingLeft: Float,
|
||||
paddingTop: Float,
|
||||
paddingRight: Float,
|
||||
paddingBottom: Float
|
||||
)
|
||||
|
||||
@Keep
|
||||
|
||||
Reference in New Issue
Block a user