Skip to content

Disable Map Gestures

This tutorial shows how to selectively enable or disable map interaction gestures on your MapMetrics Android map — useful for embedded maps, kiosk displays, or guided experiences.

Prerequisites

Disable All Gestures

Create a static, non-interactive map:

kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.MapMetricsMap
import org.maplibre.android.maps.Style

class StaticMapActivity : AppCompatActivity() {

    private lateinit var mapView: MapView
    private lateinit var map: MapMetricsMap

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_map)

        mapView = findViewById(R.id.mapView)
        mapView.onCreate(savedInstanceState)
        mapView.getMapAsync { mapMetricsMap ->
            map = mapMetricsMap

            // Disable all gestures at once
            map.uiSettings.setAllGesturesEnabled(false)

            map.setStyle(
                Style.Builder().fromUri(
                    "https://gateway.mapmetrics.org/styles/YOUR_STYLE_ID?token=YOUR_API_KEY"
                )
            )

            map.cameraPosition = CameraPosition.Builder()
                .target(LatLng(48.8566, 2.3522))
                .zoom(14.0)
                .build()
        }
    }

    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 onDestroy() { super.onDestroy(); mapView.onDestroy() }
    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        mapView.onSaveInstanceState(outState)
    }
}

Disable via XML Attributes

Configure gestures directly in the layout:

xml
<org.maplibre.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:maplibre_uiScrollGestures="false"
    app:maplibre_uiZoomGestures="false"
    app:maplibre_uiRotateGestures="false"
    app:maplibre_uiTiltGestures="false"
    app:maplibre_uiDoubleTapGestures="false"
    app:maplibre_cameraTargetLat="48.8566"
    app:maplibre_cameraTargetLng="2.3522"
    app:maplibre_cameraZoom="14" />

Selective Gesture Control

Disable specific gestures while keeping others:

kotlin
map.getMapAsync { mapMetricsMap ->
    map = mapMetricsMap

    val ui = map.uiSettings

    // Allow pan and zoom, but disable rotation and tilt
    ui.isScrollGesturesEnabled = true     // Panning
    ui.isZoomGesturesEnabled = true       // Pinch zoom
    ui.isDoubleTapGesturesEnabled = true  // Double-tap zoom
    ui.isRotateGesturesEnabled = false    // Two-finger rotate
    ui.isTiltGesturesEnabled = false      // Two-finger tilt
}

Interactive Toggle Panel

Let users control each gesture with switches:

kotlin
import android.widget.Switch

private fun setupGestureToggles() {
    val ui = map.uiSettings

    findViewById<Switch>(R.id.switchScroll).apply {
        isChecked = ui.isScrollGesturesEnabled
        setOnCheckedChangeListener { _, checked ->
            ui.isScrollGesturesEnabled = checked
        }
    }

    findViewById<Switch>(R.id.switchZoom).apply {
        isChecked = ui.isZoomGesturesEnabled
        setOnCheckedChangeListener { _, checked ->
            ui.isZoomGesturesEnabled = checked
            ui.isDoubleTapGesturesEnabled = checked
        }
    }

    findViewById<Switch>(R.id.switchRotate).apply {
        isChecked = ui.isRotateGesturesEnabled
        setOnCheckedChangeListener { _, checked ->
            ui.isRotateGesturesEnabled = checked
        }
    }

    findViewById<Switch>(R.id.switchTilt).apply {
        isChecked = ui.isTiltGesturesEnabled
        setOnCheckedChangeListener { _, checked ->
            ui.isTiltGesturesEnabled = checked
        }
    }
}

Disable Velocity Animations

Stop inertia/fling after pan, zoom, or rotate:

kotlin
val ui = map.uiSettings
ui.isFlingVelocityAnimationEnabled = false     // No fling after pan
ui.isScaleVelocityAnimationEnabled = false     // No momentum after zoom
ui.isRotateVelocityAnimationEnabled = false    // No momentum after rotate

Available Gesture Settings

SettingXML AttributeDefaultDescription
isScrollGesturesEnabledmaplibre_uiScrollGesturestruePan/drag
isZoomGesturesEnabledmaplibre_uiZoomGesturestruePinch zoom
isDoubleTapGesturesEnabledmaplibre_uiDoubleTapGesturestrueDouble-tap zoom
isRotateGesturesEnabledmaplibre_uiRotateGesturestrueTwo-finger rotate
isTiltGesturesEnabledmaplibre_uiTiltGesturestrueTwo-finger tilt
isHorizontalScrollGesturesEnabledmaplibre_uiHorizontalScrollGesturestrueHorizontal scroll
isQuickZoomGesturesEnabledtrueDouble-tap-drag zoom
isFlingVelocityAnimationEnabledtruePan momentum
isScaleVelocityAnimationEnabledtrueZoom momentum
isRotateVelocityAnimationEnabledtrueRotation momentum

Next Steps


Tip: For embedded maps inside a ScrollView or RecyclerView, disable scroll gestures so the map doesn't capture vertical scroll events — users can still tap markers and the map stays interactive for other gestures.