Skip to content

addOnMapClickListener callback is delayed by ~300 ms after tapping the map #4375

Description

@lts20050703

MapLibre Android Version

13.3.1

Android SDK Version

Android 17

Device

Google Pixel 7

What happened?

addOnMapClickListener callback is delayed by ~300 ms after tapping the map

Steps to reproduce

  1. https://maplibre.org/maplibre-native/android/examples/getting-started/ - Open Android Studio, New Project, Empty Views Activity, Next, Select "Kotlin" as the language, Select "Groovy DSL" as the build configuration language, Finish

  2. Gradle Scripts, build.gradle (Module :app)

// ...
dependencies {
  implementation 'org.maplibre.gl:android-sdk:0.13.0'
  // ...
}
  1. app, res, layout, activity_main.xml
...
<org.maplibre.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
...
  1. app, kotlin+java, com.example.myapplication, MainActivity.kt: Select All, Delete, Copy reproduction code, Paste
package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.SystemClock
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import org.maplibre.android.MapLibre
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapView

class MainActivity : AppCompatActivity() {

    private var downTime = 0L

    // Declare a variable for MapView
    private lateinit var mapView: MapView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Init MapLibre
        MapLibre.getInstance(this)

        // Init layout view
        val inflater = LayoutInflater.from(this)
        val rootView = inflater.inflate(R.layout.activity_main, null)
        setContentView(rootView)



        // Init the MapView
        mapView = rootView.findViewById(R.id.mapView)
        
        mapView.setOnTouchListener { _, event ->
            when (event.actionMasked) {
                MotionEvent.ACTION_DOWN -> {
                    downTime = SystemClock.elapsedRealtimeNanos()
                    Log.d("_PERF_", "ACTION_DOWN")
                }

                MotionEvent.ACTION_UP -> {
                    val elapsedMs =
                        (SystemClock.elapsedRealtimeNanos() - downTime) / 1_000_000.0
                    Log.d("_PERF_", "ACTION_UP after %.1f ms".format(elapsedMs))
                }
            }

            // Don't consume the event so MapLibre fire addOnMapClickListener
            false
        }
        
        mapView.getMapAsync { map ->
            map.setStyle("https://demotiles.maplibre.org/style.json")
            map.cameraPosition = CameraPosition.Builder().target(LatLng(0.0,0.0)).zoom(1.0).build()
            map.addOnMapClickListener {
                val elapsedMs = (SystemClock.elapsedRealtimeNanos() - downTime) / 1_000_000.0

                Log.d("_PERF_", "Map: Tap callback after %.1f ms".format(elapsedMs))

                true
            }
        }
    }

    override fun onStart() {
        super.onStart()
        mapView.onStart()
    }

    override fun onResume() {
        super.onResume()
        mapView.onResume()
    }

    override fun onPause() {
        super.onPause()
        mapView.onPause()
    }

    override fun onStop() {
        super.onStop()
        mapView.onStop()
    }

    override fun onLowMemory() {
        super.onLowMemory()
        mapView.onLowMemory()
    }

    override fun onDestroy() {
        super.onDestroy()
        mapView.onDestroy()
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        mapView.onSaveInstanceState(outState)
    }
}
  1. Run 'app'.
  2. Tap the map

Renderer

No response

Relevant log output

ACTION_DOWN
ACTION_UP after 7.0 ms
Map: Tap callback after 305.4 ms
ACTION_DOWN
ACTION_UP after 24.6 ms
Map: Tap callback after 303.0 ms

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions