Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91132f66 authored by Fynn Godau's avatar Fynn Godau
Browse files

Merge branch '912-update-maplibre' into 'epic67-maps'

Bump MapLibre to 10.0.0

See merge request !61
parents f54d5cfb 811a7978
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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:9.6.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'
    }
+2 −2
Original line number Diff line number Diff line
@@ -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)
+14 −8
Original line number Diff line number Diff line
@@ -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<Point>()?.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())
+2 −2
Original line number Diff line number Diff line
@@ -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())