View on GitHub Sample viewer app

Create a feature collection layer from a portal item.

Image of add feature collection layer from portal item

Use case

Feature collection layers are often used to hold features with mixed geometry or unstructured data. You can display feature collections stored in a Portal, which are often used for showing content from a CSV or map notes.

How to use the sample

The feature collection is loaded from the Portal item when the sample starts.

How it works

  1. Create a Portal.
  2. Create the PortalItem, referring to the portal and an item ID.
  3. Verify that the item represents a feature collection.
  4. Create a FeatureCollection from the item.
  5. Create a FeatureCollectionLayer, referring to the feature collection.
  6. Add the feature collection layer to the map’s operationalLayers collection.

Relevant API

  • FeatureCollection
  • FeatureCollectionLayer
  • Portal
  • PortalItem

About the data

The sample uses a sample layer depicting World Cities Population Rank.

Tags

collection, feature collection, feature collection layer, id, item, map notes, portal

Sample Code

MainActivity.kt MainActivity.kt AddFeatureCollectionLayerFromPortalItemViewModel.kt AddFeatureCollectionLayerFromPortalItemScreen.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.addfeaturecollectionlayerfromportalitem
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.addfeaturecollectionlayerfromportalitem.screens.AddFeatureCollectionLayerFromPortalItemScreen
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 {
AddFeatureCollectionLayerFromPortalItemApp()
}
}
}
@Composable
private fun AddFeatureCollectionLayerFromPortalItemApp() {
Surface(color = MaterialTheme.colorScheme.background) {
AddFeatureCollectionLayerFromPortalItemScreen(
sampleName = getString(R.string.add_feature_collection_layer_from_portal_item_app_name)
)
}
}
}