View on GitHub Sample viewer app

Display a message when a graphic on the map is tapped.

Image of identify graphics

Use case

A user may wish to select a graphic on a map to view relevant information about it.

How to use the sample

Tap on a graphic to identify it. You will see an alert message displayed.

How it works

  1. Create a GraphicsOverlay and add it to the MapView.
  2. Build a Graphic from a Polygon and a SimpleFillSymbol and add it to the graphics overlay.
  3. Listen for MapView.onSingleTapConfirmed to obtain the ScreenCoordinate where the user tapped.
  4. Identify the graphic on the map view using MapViewProxy.identify function while providing the graphicsOverlay, screenCoordinate, tolerance, maximumResults.

Relevant API

  • Graphic
  • GraphicsOverlay
  • IdentifyGraphicsOverlayResult
  • MapView
  • MapViewProxy

Tags

graphics, identify

Sample Code

MainActivity.kt MainActivity.kt IdentifyGraphicsViewModel.kt IdentifyGraphicsScreen.kt
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.identifygraphics
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.identifygraphics.screens.IdentifyGraphicsScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
setContent {
SampleAppTheme {
IdentifyGraphicsApp()
}
}
}
@Composable
private fun IdentifyGraphicsApp() {
Surface(color = MaterialTheme.colorScheme.background) {
IdentifyGraphicsScreen(
sampleName = getString(R.string.identify_graphics_app_name)
)
}
}
}