View on GitHub Sample viewer app

Display a web map from an ArcGIS Online portal item.

Screenshot of display map from portal item

Use case

Display web maps stored on ArcGIS Online by referencing their portal item IDs.

How to use the sample

Select a map from the dropdown menu to display it in the map view. The map will update to show the selected web map.

How it works

  1. Create a Portal instance for ArcGIS Online.
  2. Create a PortalItem using the portal and the web map’s item ID.
  3. Create an ArcGISMap from the PortalItem.
  4. Set the map to the MapView.

Relevant API

  • ArcGISMap
  • MapView
  • Portal
  • PortalItem

About the data

The web maps accessed by this sample show:

Tags

portal item, web map

Sample Code

MainActivity.kt MainActivity.kt DisplayMapFromPortalItemScreen.kt DisplayMapFromPortalItemViewModel.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.displaymapfromportalitem
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
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.displaymapfromportalitem.screens.DisplayMapFromPortalItemScreen
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)
enableEdgeToEdge()
setContent {
SampleAppTheme {
DisplayMapFromPortalItemApp()
}
}
}
@Composable
private fun DisplayMapFromPortalItemApp() {
Surface(color = MaterialTheme.colorScheme.background) {
DisplayMapFromPortalItemScreen(
sampleName = getString(R.string.display_map_from_portal_item_app_name)
)
}
}
}