mapbox / mapbox-gl-native-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
218 stars 114 forks source link

The animation of the location component has lags when the RenderMode.COMPASS and mapbox_elevation=0dp are set #736

Open Copatych opened 2 years ago

Copatych commented 2 years ago

Environment

Observed behavior and steps to reproduce

The animation of the location component has lags when the RenderMode.COMPASS and mapbox_elevation=0dp are set. Code to reproduce the bug

    private lateinit var mapView: MapView

    @SuppressLint("MissingPermission")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Mapbox.getInstance(this, getString(R.string.mapbox_access_token))
        setContentView(R.layout.activity_main)

        mapView = findViewById(R.id.mapView)
        mapView.onCreate(savedInstanceState)

        mapView.getMapAsync { mapboxMap ->
            mapboxMap.setStyle(Style.MAPBOX_STREETS) { style ->
                mapboxMap.locationComponent.apply {
                    val options = LocationComponentActivationOptions.builder(this@MainActivity, style)
                        .useDefaultLocationEngine(false)
                        .locationEngine(null)
                        .styleRes(R.style.MapView_LocationComponent)
                        .build()

                    activateLocationComponent(options)
                    isLocationComponentEnabled = true
                    renderMode = RenderMode.COMPASS
                }
            }

            mapboxMap.addOnMapClickListener { point ->
                val location = Location(LocationManager.GPS_PROVIDER).apply {
                    latitude = point.latitude
                    longitude = point.longitude
                    altitude = point.altitude
                    accuracy = 3f
                    bearing = Random.nextFloat() * 360
                    speed = Random.nextFloat() * 15
                    time = System.currentTimeMillis()
                }

                mapboxMap.locationComponent.forceLocationUpdate(LocationUpdate.Builder().location(location).build())

                true
            }
        }
    }
...
<style name="MapView.LocationComponent" parent="@style/mapbox_LocationComponent">
        <item name="mapbox_elevation">0dp</item>
    </style>

Video example of bug:

https://user-images.githubusercontent.com/57287061/180126647-3335745f-2892-451a-a3a3-43c33df2e934.mp4

Notes / preliminary analysis

When RenderMode.GPS or mapbox_elevation=1dp are used, the lags disappear, the animation becomes smooth, beautiful.