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

Commit 6f9b2d53 authored by Fynn Godau's avatar Fynn Godau
Browse files

Fix projection issues

* respect padding when calculating visible region
* in `CameraBoundsWithSizeUpdate`, do not redistribute existing padding
and do not modify map's padding
parent 4bdbc20f
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -29,14 +29,17 @@ 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)
        padding[0] += map.padding[0] + ((map.width - width) / 2).toInt()
        padding[1] += map.padding[1] + ((map.height - height) / 2).toInt()
        padding[2] += map.padding[2] + ((map.width - width) / 2).toInt()
        padding[3] += map.padding[3] + ((map.height - height) / 2).toInt()
        Log.d(TAG, "map ${map.width} ${map.height}, set $width $height -> ${Arrays.toString(padding)}")
        return map.getCameraForLatLngBounds(bounds, padding)?.let {
            CameraPosition.Builder(it).padding(
                map.padding[0].toDouble(), map.padding[1].toDouble(), map.padding[2].toDouble(), map.padding[3].toDouble()
            ).build()
        }

    }

    override fun equals(other: Any?): Boolean {
+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)