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

Commit 3a38d22b authored by Fynn Godau's avatar Fynn Godau
Browse files

Merge branch '909-projection-padding' into 'epic67-maps'

Fix projection issues

See merge request !54
parents 34743e0c 90c175cc
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -29,14 +29,31 @@ internal class CameraBoundsWithSizeUpdate(val bounds: LatLngBounds, val width: I

    override fun getCameraPosition(map: MapboxMap): CameraPosition? {
        val padding = this.padding.clone()
        val widthPad = ((map.width + map.padding[0] + map.padding[2] - width) / 2).toInt()
        val heightPad = ((map.height + map.padding[1] + map.padding[3] - height) / 2).toInt()
        padding[0] += widthPad
        padding[1] += heightPad
        padding[2] += widthPad
        padding[3] += heightPad
        Log.d(TAG, "map ${map.width} ${map.height}, set $width $height -> ${padding.map { it.toString() }.reduce { a, b -> "$a,$b"}}")
        return map.getCameraForLatLngBounds(bounds, padding)

        val mapPadding = map.cameraPosition.padding
        mapPadding?.let {
            for (i in 0..3) {
                padding[i] += it[i].toInt()
            }
        }

        val widthPadding = ((map.width - width) / 2).toInt()
        val heightPadding = ((map.height - height) / 2).toInt()
        padding[0] += widthPadding
        padding[1] += heightPadding
        padding[2] += widthPadding
        padding[3] += heightPadding

        Log.d(TAG, "map ${map.width} ${map.height}, set $width $height -> ${Arrays.toString(padding)}")
        return map.getCameraForLatLngBounds(bounds, padding)?.let {
            CameraPosition.Builder(it)
                .apply {
                    mapPadding?.let {
                        padding(it)
                    }
                }.build()
        }

    }

    override fun equals(other: Any?): Boolean {
+4 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.mapbox.mapboxsdk.plugins.annotation.Annotation
import com.mapbox.mapboxsdk.style.layers.Property.LINE_CAP_ROUND
import com.google.android.gms.dynamic.unwrap
import com.mapbox.mapboxsdk.WellKnownTileServer
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import org.microg.gms.maps.MapsConstants.*
import org.microg.gms.maps.mapbox.model.*
import org.microg.gms.maps.mapbox.utils.MapContext
@@ -488,7 +489,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
    override fun setPadding(left: Int, top: Int, right: Int, bottom: Int) {
        Log.d(TAG, "setPadding: $left $top $right $bottom")
        map?.let { map ->
            map.setPadding(left, top, right, bottom)
            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()
                    ?: 0
            val ninetyTwoDp = mapView?.context?.resources?.getDimension(R.dimen.mapbox_ninety_two_dp)?.toInt()
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import kotlin.math.roundToInt

// 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.visibleRegion
    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)