> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/android/maps/llms.txt)

# Map overlay

![Use Map Overlay.](https://docs.mapbox.com/android/assets/ideal-img/maps-examples-map-overlay.0fd21a9.480.png)

This example demonstrates using the [`MapOverlayPlugin`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps.plugin.overlay/-map-overlay-plugin/) to reframe dynamic map content within an overlay with the **Mapbox Maps SDK for Android**.

This example creates an overlay layer with text views in each of the 4 corners of the viewport and includes 3 markers loading onto the map. When clicking on the map, a new marker is added at every click location. When a user clicks the `FloatingActionButton` in `activity_map_overlay.xml` the map moves to reframe all markers within the selected overlay area.

> **Note: Android Examples App Available**
> 
> This example code is part of the **Maps SDK for Android Examples App**, a working Android project [available on GitHub](https://github.com/mapbox/mapbox-maps-android/tree/v11.35.0/). Android developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.
> 
> See our [Run the Maps SDK for Android Examples App](https://docs.mapbox.com/help/tutorials/maps-sdk-android-examples-app/) tutorial for step-by-step instructions.

**Kotlin**

Title: `MapOverlayActivity.kt`

[View on GitHub](https://github.com/mapbox/mapbox-maps-android/blob/v11.35.0/app/src/main/java/com/mapbox/maps/testapp/examples/MapOverlayActivity.kt)

```kt
package com.mapbox.maps.testapp.examples

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.mapbox.bindgen.Value
import com.mapbox.geojson.Feature
import com.mapbox.geojson.FeatureCollection
import com.mapbox.geojson.Point
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.extension.style.image.image
import com.mapbox.maps.extension.style.layers.generated.symbolLayer
import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.mapbox.maps.extension.style.sources.getSourceAs
import com.mapbox.maps.extension.style.style
import com.mapbox.maps.plugin.animation.MapAnimationOptions.Companion.mapAnimationOptions
import com.mapbox.maps.plugin.animation.camera
import com.mapbox.maps.plugin.gestures.OnMapClickListener
import com.mapbox.maps.plugin.gestures.addOnMapClickListener
import com.mapbox.maps.plugin.overlay.MapOverlayCoordinatesProvider
import com.mapbox.maps.plugin.overlay.MapOverlayPlugin
import com.mapbox.maps.plugin.overlay.mapboxOverlay
import com.mapbox.maps.testapp.R
import com.mapbox.maps.testapp.databinding.ActivityMapOverlayBinding

class MapOverlayActivity : AppCompatActivity(), OnMapClickListener {

  private val markerCoordinates = mutableListOf<Point>(
    Point.fromLngLat(-71.065634, 42.354950), // Boston Common Park
    Point.fromLngLat(-71.097293, 42.346645), // Fenway Park
    Point.fromLngLat(-71.053694, 42.363725) // The Paul Revere House
  )
  private lateinit var mapOverlayPlugin: MapOverlayPlugin
  private lateinit var mapboxMap: MapboxMap
  private val provider = MapOverlayCoordinatesProvider { markerCoordinates }
  private lateinit var binding: ActivityMapOverlayBinding

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMapOverlayBinding.inflate(layoutInflater)
    setContentView(binding.root)

    mapboxMap = binding.mapView.mapboxMap
    mapboxMap.loadStyle(
      styleExtension = style(Style.STANDARD) {
        +geoJsonSource(sourceId) {
          featureCollection(
            FeatureCollection.fromFeatures(
              markerCoordinates.map {
                Feature.fromGeometry(it)
              }
            )
          )
        }
        // Add the marker image to map
        +image(
          imageId,
          ContextCompat.getDrawable(
            this@MapOverlayActivity,
            R.drawable.ic_blue_marker
          )!!.toBitmap()
        )
        +symbolLayer(layerId, sourceId) {
          iconImage(imageId)
          iconAllowOverlap(true)
          iconOffset(listOf(0.0, -9.0))
        }
      }
    ) {
      mapboxMap.addOnMapClickListener(this@MapOverlayActivity)
      mapboxMap.setStyleImportConfigProperty("basemap", "theme", Value.valueOf("monochrome"))
    }
    mapOverlayPlugin = binding.mapView.mapboxOverlay
      .apply {
        registerMapOverlayCoordinatesProvider(provider)
        registerOverlay(binding.locationTopLeft)
        registerOverlay(binding.locationTopRight)
        registerOverlay(binding.locationBottomLeft)
        registerOverlay(binding.locationBottomRight)
        registerOverlay(binding.reframeButton)
        setDisplayingAreaMargins(100, 50, 50, 50)
      }

    val cameraAnimationsPlugin = binding.mapView.camera
    binding.reframeButton.setOnClickListener {
      mapOverlayPlugin.reframe { it?.let { cameraAnimationsPlugin.flyTo(it, mapAnimationOptions { duration(1000L) }) } }
    }
  }

  override fun onMapClick(point: Point): Boolean {
    markerCoordinates.add(point)
    mapboxMap.style?.getSourceAs<GeoJsonSource>(sourceId)!!.featureCollection(
      FeatureCollection.fromFeatures(
        markerCoordinates.map {
          Feature.fromGeometry(it)
        }
      )
    )
    return true
  }

  companion object {
    private const val sourceId = "marker-source"
    private const val imageId = "marker-image"
    private const val layerId = "marker-layer"
  }
}
```

Title: `activity_map_overlay.xml`

[View on GitHub](https://github.com/mapbox/mapbox-maps-android/blob/main/app/src/main/res/layout/activity_map_overlay.xml)

```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto">

    <com.mapbox.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="0dp"
        mapbox:mapbox_cameraTargetLat="42.353517"
        mapbox:mapbox_cameraTargetLng="-71.078625"
        mapbox:mapbox_cameraZoom="12"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/location_top_left"
        style="@style/MapOverlayStyle"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/location_top_right"
        style="@style/MapOverlayStyle"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/location_bottom_left"
        style="@style/MapOverlayStyle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

    <TextView
        android:id="@+id/location_bottom_right"
        style="@style/MapOverlayStyle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/reframe_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="116dp"
        android:src="@drawable/ic_baseline_refresh_24"
        app:backgroundTint="@color/primary" />

</androidx.constraintlayout.widget.ConstraintLayout>
```