From b3641c4b7ab3afc30624c934d046a10e0ae9c383 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Mon, 13 Feb 2023 12:21:09 +0100 Subject: [PATCH 1/2] Bump MapLibre to 10.0.0-pre.0 --- play-services-maps-core-mapbox/build.gradle | 2 +- .../org/microg/gms/maps/mapbox/GoogleMap.kt | 4 ++-- .../org/microg/gms/maps/mapbox/Projection.kt | 22 ++++++++++++------- .../gms/maps/mapbox/utils/typeConverter.kt | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/play-services-maps-core-mapbox/build.gradle b/play-services-maps-core-mapbox/build.gradle index e0fcff51b..b4a2779f4 100644 --- a/play-services-maps-core-mapbox/build.gradle +++ b/play-services-maps-core-mapbox/build.gradle @@ -20,7 +20,7 @@ apply plugin: 'kotlin-android' dependencies { implementation project(':play-services-api') implementation project(':play-services-base-core') - implementation("org.maplibre.gl:android-sdk:9.6.0") { + implementation("org.maplibre.gl:android-sdk:10.0.0-pre.0") { exclude group: 'com.google.android.gms' } implementation("org.maplibre.gl:android-plugin-annotation-v9:1.0.0") { diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt index 297dc873a..30450843b 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt @@ -547,9 +547,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) CameraUpdateFactory.paddingTo(left.toDouble(), top.toDouble(), right.toDouble(), bottom.toDouble()) .let { map.moveCamera(it) } - val fourDp = mapView?.context?.resources?.getDimension(R.dimen.mapbox_four_dp)?.toInt() + val fourDp = mapView?.context?.resources?.getDimension(R.dimen.maplibre_four_dp)?.toInt() ?: 0 - val ninetyTwoDp = mapView?.context?.resources?.getDimension(R.dimen.mapbox_ninety_two_dp)?.toInt() + val ninetyTwoDp = mapView?.context?.resources?.getDimension(R.dimen.maplibre_ninety_two_dp)?.toInt() ?: 0 map.uiSettings.setLogoMargins(left + fourDp, top + fourDp, right + fourDp, bottom + fourDp) map.uiSettings.setCompassMargins(left + fourDp, top + fourDp, right + fourDp, bottom + fourDp) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Projection.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Projection.kt index d4ed42f91..a8c0e4a86 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Projection.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Projection.kt @@ -30,21 +30,25 @@ import org.microg.gms.maps.mapbox.utils.toGms import org.microg.gms.maps.mapbox.utils.toMapbox import kotlin.math.roundToInt +val ZERO_LAT_LNG = com.mapbox.mapboxsdk.geometry.LatLng(0.0, 0.0) + // TODO: Do calculations using backed up locations instead of live (which requires UI thread) class ProjectionImpl(private val projection: Projection, private val withoutTiltOrBearing: Boolean) : IProjectionDelegate.Stub() { private val visibleRegion = projection.getVisibleRegion(false) - private val farLeft = projection.toScreenLocation(visibleRegion.farLeft) - private val farRight = projection.toScreenLocation(visibleRegion.farRight) - private val nearLeft = projection.toScreenLocation(visibleRegion.nearLeft) - private val nearRight = projection.toScreenLocation(visibleRegion.nearRight) + private val farLeft = projection.toScreenLocation(visibleRegion.farLeft?: ZERO_LAT_LNG) + private val farRight = projection.toScreenLocation(visibleRegion.farRight?: ZERO_LAT_LNG) + private val nearLeft = projection.toScreenLocation(visibleRegion.nearLeft?: ZERO_LAT_LNG) + private val nearRight = projection.toScreenLocation(visibleRegion.nearRight?: ZERO_LAT_LNG) override fun fromScreenLocation(obj: IObjectWrapper?): LatLng? = try { obj.unwrap()?.let { if (withoutTiltOrBearing) { val xPercent = (it.x.toFloat() - farLeft.x) / (farRight.x - farLeft.x) val yPercent = (it.y.toFloat() - farLeft.y) / (nearLeft.y - farLeft.y) - val lon = visibleRegion.farLeft.longitude + xPercent * (visibleRegion.farRight.longitude - visibleRegion.farLeft.longitude) - val lat = visibleRegion.farLeft.latitude + yPercent * (visibleRegion.nearLeft.latitude - visibleRegion.farLeft.latitude) + val lon = (visibleRegion.farLeft?.longitude ?: 0.0) + xPercent * + ((visibleRegion.farRight?.longitude ?: 0.0) - (visibleRegion.farLeft?.longitude ?: 0.0)) + val lat = (visibleRegion.farLeft?.latitude?: 0.0) + yPercent * + ((visibleRegion.nearLeft?.latitude?: 0.0) - (visibleRegion.farLeft?.latitude?: 0.0)) LatLng(lat, lon) } else { projection.fromScreenLocation(PointF(it)).toGms() @@ -58,8 +62,10 @@ class ProjectionImpl(private val projection: Projection, private val withoutTilt override fun toScreenLocation(latLng: LatLng?): IObjectWrapper = try { ObjectWrapper.wrap(latLng?.toMapbox()?.let { if (withoutTiltOrBearing) { - val xPercent = (it.longitude - visibleRegion.farLeft.longitude) / (visibleRegion.farRight.longitude - visibleRegion.farLeft.longitude) - val yPercent = (it.latitude - visibleRegion.farLeft.latitude) / (visibleRegion.nearLeft.latitude - visibleRegion.farLeft.latitude) + val xPercent = (it.longitude - (visibleRegion.farLeft?.longitude ?: 0.0)) / + ((visibleRegion.farRight?.longitude ?: 0.0) - (visibleRegion.farLeft?.longitude ?: 0.0)) + val yPercent = (it.latitude - (visibleRegion.farLeft?.longitude ?: 0.0)) / + ((visibleRegion.nearLeft?.longitude ?: 0.0) - (visibleRegion.farLeft?.longitude ?: 0.0)) val x = farLeft.x + xPercent * (farRight.x - farLeft.x) val y = farLeft.y + yPercent * (nearLeft.y - farLeft.y) Point(x.roundToInt(), y.roundToInt()) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/typeConverter.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/typeConverter.kt index 9664aea6f..1a27c3a07 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/typeConverter.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/utils/typeConverter.kt @@ -71,7 +71,7 @@ fun LatLng.toGms(): GmsLatLng = GmsLatLng(latitude, longitude) fun LatLngBounds.toGms(): GmsLatLngBounds = GmsLatLngBounds(southWest.toGms(), northEast.toGms()) fun CameraPosition.toGms(): GmsCameraPosition = - GmsCameraPosition(target.toGms(), zoom.toFloat() + 1.0f, tilt.toFloat(), bearing.toFloat()) + GmsCameraPosition(target?.toGms(), zoom.toFloat() + 1.0f, tilt.toFloat(), bearing.toFloat()) fun Bundle.toGms(): Bundle { val newBundle = Bundle(this) @@ -91,4 +91,4 @@ fun Bundle.toGms(): Bundle { } fun VisibleRegion.toGms(): GmsVisibleRegion = - GmsVisibleRegion(nearLeft.toGms(), nearRight.toGms(), farLeft.toGms(), farRight.toGms(), latLngBounds.toGms()) + GmsVisibleRegion(nearLeft?.toGms(), nearRight?.toGms(), farLeft?.toGms(), farRight?.toGms(), latLngBounds.toGms()) -- GitLab From 811a797816577e120e1c2adfa8fef2b4ff5450bb Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Thu, 16 Feb 2023 21:24:30 +0100 Subject: [PATCH 2/2] MapLibre version 10.0.0 --- play-services-maps-core-mapbox/build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/play-services-maps-core-mapbox/build.gradle b/play-services-maps-core-mapbox/build.gradle index b4a2779f4..535ac97cd 100644 --- a/play-services-maps-core-mapbox/build.gradle +++ b/play-services-maps-core-mapbox/build.gradle @@ -20,9 +20,7 @@ apply plugin: 'kotlin-android' dependencies { implementation project(':play-services-api') implementation project(':play-services-base-core') - implementation("org.maplibre.gl:android-sdk:10.0.0-pre.0") { - exclude group: 'com.google.android.gms' - } + implementation("org.maplibre.gl:android-sdk:10.0.0") implementation("org.maplibre.gl:android-plugin-annotation-v9:1.0.0") { exclude group: 'com.google.android.gms' } -- GitLab