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

# Draw a polygon

![Draw a vector polygon on a map.](https://docs.mapbox.com/android/assets/ideal-img/maps-examples-draw-a-polygon.3aad023.480.png)

This example demonstrates how to draw a vector polygon on a map using the Mapbox Android SDK.

The code below grabs data from a GeoJSON data source adds the information to a [`LineLayer`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps.extension.style.layers.generated/-line-layer/-line-layer.html?query=fun%20LineLayer(layerId:%20String,%20sourceId:%20String)) to display the polygon outline and a [`FillLayer`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps.extension.compose.style.layers.generated/-fill-layer.html) to color in the shape.

The example also includes functionality to add a pattern fill to the polygon by setting a custom image as the fill pattern. This is achieved by loading the image from resources, adding it to the style, and updating the `FillLayer` with the new fill pattern.

> **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.2/). 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: `DrawPolygonActivity.kt`

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

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

import android.graphics.Color
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.Point
import com.mapbox.maps.Style
import com.mapbox.maps.dsl.cameraOptions
import com.mapbox.maps.extension.style.layers.generated.FillLayer
import com.mapbox.maps.extension.style.layers.generated.fillLayer
import com.mapbox.maps.extension.style.layers.generated.lineLayer
import com.mapbox.maps.extension.style.layers.getLayer
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.mapbox.maps.extension.style.style
import com.mapbox.maps.testapp.R
import com.mapbox.maps.testapp.databinding.ActivityDdsDrawPolygonBinding

/**
 * Draw a vector polygon on a map with the Mapbox Android SDK.
 */
class DrawPolygonActivity : AppCompatActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val binding = ActivityDdsDrawPolygonBinding.inflate(layoutInflater)
    setContentView(binding.root)
    binding.mapView.mapboxMap.setCamera(
      START_CAMERA_POSITION
    )
    binding.mapView.mapboxMap.loadStyle(
      style(style = Style.STANDARD) {
        +geoJsonSource(SOURCE_ID) {
          data(SOURCE_URL)
        }
        +fillLayer(LAYER_ID, SOURCE_ID) {
          fillColor(Color.parseColor("#0080ff")).fillOpacity(0.5)
          slot("middle")
        }
        +lineLayer(
          TOP_LAYER_ID, SOURCE_ID
        ) {
          lineColor(ContextCompat.getColor(this@DrawPolygonActivity, R.color.black))
          lineWidth(3.0)
        }
      }
    ) {
      binding.mapView.mapboxMap.setStyleImportConfigProperty("basemap", "theme", Value.valueOf("monochrome"))
    }
    binding.patternFab.setOnClickListener {
      binding.mapView.mapboxMap.getStyle { style ->
        val bitmap = ContextCompat.getDrawable(this@DrawPolygonActivity, R.drawable.pattern)
          ?.toBitmap(128, 128)!!
        style.addImage(IMAGE_ID, bitmap)
        val layer = style.getLayer(LAYER_ID) as FillLayer
        layer.fillPattern(IMAGE_ID)
        layer.fillOpacity(0.7)
      }
    }
  }

  companion object {
    private const val IMAGE_ID = "stripe-pattern"
    private const val LAYER_ID = "layer-id"
    private const val SOURCE_ID = "source-id"
    private const val TOP_LAYER_ID = "line-layer"
    private const val SETTLEMENT_LABEL = "settlement-major-label"
    private const val SOURCE_URL = "asset://maine_polygon.geojson"
    private val START_CAMERA_POSITION = cameraOptions {
      center(
        Point.fromLngLat(-68.137343, 45.137451)
      )
      zoom(5.0)
      bearing(0.0)
      pitch(0.0)
    }
  }
}
```