mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
476 stars 133 forks source link

Can't hide compass #1856

Closed mfazekas closed 2 weeks ago

mfazekas commented 1 year ago

Environment

Observed behavior and steps to reproduce

Cannot hide compass with mapView.compass.updateSettings { enabled = false }

In the repo change SimpleMapActivity.kt to this

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

image

Expected behavior

Compass hides

Notes / preliminary analysis

Additional links and references

kiryldz commented 2 weeks ago

@mfazekas I checked this issue with latest code (v11.8.0-rc.1) and it is fixed now.