Closed mfazekas closed 2 weeks ago
Cannot hide compass with mapView.compass.updateSettings { enabled = false }
mapView.compass.updateSettings { enabled = false }
In the repo change SimpleMapActivity.kt to this
SimpleMapActivity.kt
package com.mapbox.maps.testapp.examples import android.os.Bundle import android.os.Handler import android.os.Looper import android.util.Log import android.view.Gravity import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import com.mapbox.geojson.Point import com.mapbox.maps.CameraOptions import com.mapbox.maps.MapView import com.mapbox.maps.plugin.attribution.attribution import com.mapbox.maps.plugin.compass.compass import com.mapbox.maps.plugin.logo.logo import com.mapbox.maps.plugin.scalebar.scalebar import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import java.util.* import kotlin.concurrent.schedule fun GlobalScope.runDelayedUITask(delay: Long, task: () -> Unit) { launch(Dispatchers.IO) { delay(delay) launch(Dispatchers.Main) { task() } } } /** * Example of displaying a map. */ class SimpleMapActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val mapView = MapView(this) setContentView(mapView) mapView.getMapboxMap() .apply { setCamera( CameraOptions.Builder() .center(Point.fromLngLat(LONGITUDE, LATITUDE)) .zoom(9.0) .build() ) } mapView.compass.updateSettings { enabled = true fadeWhenFacingNorth = false position = Gravity.BOTTOM or Gravity.RIGHT } GlobalScope.launch(Dispatchers.IO) { delay(2000) launch(Dispatchers.Main) { Log.e("SimpleMapActivity", "hide compass") mapView.compass.updateSettings { enabled = false } } } } companion object { private const val LATITUDE = 40.0 private const val LONGITUDE = -74.5 } }
Run the example app and select Display map view compass appears but after 2 seconds or so, console log appears hide compass but the compass will be still visible
Display map view
hide compass
Compass hides
@mfazekas I checked this issue with latest code (v11.8.0-rc.1) and it is fixed now.
Environment
Observed behavior and steps to reproduce
Cannot hide compass with
mapView.compass.updateSettings { enabled = false }
In the repo change
SimpleMapActivity.kt
to thisRun the example app and select
Display map view
compass appears but after 2 seconds or so, console log appearshide compass
but the compass will be still visibleExpected behavior
Compass hides
Notes / preliminary analysis
Additional links and references