Learn how to apply renderers A renderer is a collection of rules and symbols used to display the data in a layer. Learn more and label definitions to a feature layer A feature layer (client-side) is a data layer that can access and display features from a feature service that has the same type of geometry and attribute fields. Learn more based on attribute values.

style a feature layer

Applications can display feature layer data with different styles to enhance the visualization. The type of Renderer you choose depends on your application. A SimpleRenderer applies the same symbol to all features, a UniqueValueRenderer applies a different symbol to each unique attribute value, and a ClassBreaksRenderer applies a symbol to a range of numeric values. Renderers are responsible for accessing the data and applying the appropriate symbol to each feature when the layer draws. You can also use a LabelDefinition to show attribute information for features. Visit the Styles and data visualization documentation to learn more about styling layers.

You can also author, style and save web maps, web scenes, and layers as portal items and then add them to the map in your application. Visit the following tutorials to learn more about adding portal items.

In this tutorial, you will apply different renderers A renderer is a collection of rules and symbols used to display the data in a layer. Learn more to enhance the visualization of three feature layers with data for the Santa Monica Mountains: Trailheads with a single symbol, Trails based on elevation change and bike use, and Parks and Open Spaces based on the type of park.

Prerequisites

Before starting this tutorial, you need the following:

  1. An ArcGIS Location Platform or ArcGIS Online account.

  2. A development and deployment environment that meets the system requirements.

  3. An IDE for Android development in Kotlin.

Develop or download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

Open an Android Studio project

  1. Open the project you created by completing the Display a map tutorial.

  2. Continue with the following instructions to apply renderers and label definitions to a feature layer based on attribute values.

  3. Modify the old project for use in this new tutorial.

Add import statements

In the Android view, open app > kotlin+java > com.example.app > MainScreen.kt. Replace the import statements with the imports needed for this tutorial.

MainScreen.kt
@file:OptIn(ExperimentalMaterial3Api::class)
package com.example.app.screens
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.arcgismaps.Color
import com.arcgismaps.data.ServiceFeatureTable
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.Viewpoint
import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
import com.arcgismaps.mapping.labeling.LabelDefinition
import com.arcgismaps.mapping.layers.FeatureLayer
import com.arcgismaps.mapping.symbology.ClassBreak
import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
import com.arcgismaps.mapping.symbology.FontStyle
import com.arcgismaps.mapping.symbology.FontWeight
import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
import com.arcgismaps.mapping.symbology.SimpleFillSymbol
import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
import com.arcgismaps.mapping.symbology.SimpleLineSymbol
import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
import com.arcgismaps.mapping.symbology.SimpleRenderer
import com.arcgismaps.mapping.symbology.TextSymbol
import com.arcgismaps.mapping.symbology.UniqueValue
import com.arcgismaps.mapping.symbology.UniqueValueRenderer
import com.arcgismaps.toolkit.geoviewcompose.MapView
import com.example.app.R

Create a function to add a feature layer

You can add a feature layer A feature layer (client-side) is a data layer that can access and display features from a feature service that has the same type of geometry and attribute fields. Learn more from a feature service A feature service is a data service that provides access to spatial and non-spatial data in feature layers, feature layer views, and tables. Learn more hosted in ArcGIS ArcGIS is the brand name for all of the desktop, server, and developer products and technologies offered by Esri. Learn more . Each feature layer contains features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more with a single geometry A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more type ( point A point is a type of geometry containing a single set of x,y coordinates and a spatial reference. Learn more , line A polyline is a type of geometry containing ordered point coordinates and a spatial reference. Learn more , or polygon A polygon is a type of geometry containing an array of rings and a spatial reference. Each ring contains an array of point coordinates, where the first and last point are the same. Learn more ), and a set of attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more . Once added to the map, feature layers can be symbolized, styled, and labeled in a variety of ways.

Define variables that store feature service URLs used by the app’s layers, and then create a helper function to add a layer to the map’s list of operational layers An operational layer is a layer used by a map or a scene to visualize geographic data. Operational layers are displayed on top of a basemap layer. Learn more . You will use this code throughout the tutorial as you add and symbolize various layers.

  1. In createMap() add four read-only String variables: three for accessing feature layers, and a fourth for accessing a static image for use in a picture marker symbol. You will use these resources in future steps.

    MainScreen.kt
    53 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    }
    }
    7 collapsed lines
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
  2. In the apply block for ArcGISMap, insert code that adds FeatureLayers to the map’s operationalLayers. For now, the listOf() function has no parameters. In this tutorial, you will be adding each new feature layer to the list of parameters.

    MainScreen.kt
    53 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    )
    )
    }
    }
    7 collapsed lines
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
  3. Add a top-level helper function named createFeatureLayer() that takes a feature service URI as an argument and returns a FeatureLayer created from the URI.

    MainScreen.kt
    82 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }

Add a layer with a unique value renderer

Create a method to apply a different symbol for each type of park area to the Parks and Open Spaces feature layer.

  1. Add a top-level function named createOpenSpaceLayer().

    MainScreen.kt
    89 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
  2. In createMap(), add the Parks and Open Space feature layer to the map’s operational layers by calling createOpenSpaceLayer().

    MainScreen.kt
    53 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    )
    )
    }
    }
    67 collapsed lines
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
  3. Click Run > Run > app to run the app.

When the app opens, Parks and Open Spaces feature layer is added to the map. The map displays the different types of parks and open spaces with four unique symbols.

Add a layer with a class breaks renderer

Create a method to apply a different symbol for each of the five ranges of elevation gain to the Trails feature layer.

  1. Add a top-level function named createTrailsLayer().

    MainScreen.kt
    151 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
  2. Update createMap() to call the new createTrailsLayer() function.

    MainScreen.kt
    53 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    )
    )
    }
    }
    133 collapsed lines
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
  3. Click Run > Run > app to run the app.

When the app opens, the Trails feature layer is added to the map. The map displays trails with different symbols depending on trail elevation.

Add layers with definition expressions

You can use a definition expression to define a subset of features to display. Features that do not meet the expression criteria are not displayed by the layer. In the following steps, you will create two methods that use a definition expression to apply a symbol to a subset of features in the Trails feature layer.

  1. Add a top-level function named createBikeOnlyTrailsLayer() that uses a definitionExpression to filter for trails that permit bikes.

    MainScreen.kt
    219 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
    fun createBikeOnlyTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create blue dot style simple line symbol to represent the bike trails
    val bikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(0, 0, 255), 2.0f)
    // Create a simple renderer for the feature layer
    val bikeTrailRenderer = SimpleRenderer(bikeTrailSymbol)
    // Create a bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = bikeTrailRenderer
    // Write a definition expression to filter for trails that permit the use of bikes
    definitionExpression = "USE_BIKE = 'Yes'"
    }
    return featureLayer
    }
  2. Add another top-level function named createNoBikeTrailsLayer() with a definition expression to filter for trails that don’t allow bikes.

    MainScreen.kt
    236 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
    fun createBikeOnlyTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create blue dot style simple line symbol to represent the bike trails
    val bikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(0, 0, 255), 2.0f)
    // Create a simple renderer for the feature layer
    val bikeTrailRenderer = SimpleRenderer(bikeTrailSymbol)
    // Create a bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = bikeTrailRenderer
    // Write a definition expression to filter for trails that permit the use of bikes
    definitionExpression = "USE_BIKE = 'Yes'"
    }
    return featureLayer
    }
    fun createNoBikeTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create a yellow dot style simple line symbol to represent no bike trails
    val noBikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(255, 255, 0), 2.0f)
    // Create a simple renderer for the feature layer
    val noBikeTrailRenderer = SimpleRenderer(noBikeTrailSymbol)
    // Create a no-bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = noBikeTrailRenderer
    // Write a definition expression to filter for trails that don't permit the use of bikes
    definitionExpression = "USE_BIKE = 'No'"
    }
    return featureLayer
    }
  3. Update createMap() to call the new createBikeOnlyTrailsLayer() and createNoBikeTrailsLayer() functions.

    MainScreen.kt
    53 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    createBikeOnlyTrailsLayer(trails),
    createNoBikeTrailsLayer(trails),
    )
    )
    }
    }
    167 collapsed lines
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
    fun createBikeOnlyTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create blue dot style simple line symbol to represent the bike trails
    val bikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(0, 0, 255), 2.0f)
    // Create a simple renderer for the feature layer
    val bikeTrailRenderer = SimpleRenderer(bikeTrailSymbol)
    // Create a bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = bikeTrailRenderer
    // Write a definition expression to filter for trails that permit the use of bikes
    definitionExpression = "USE_BIKE = 'Yes'"
    }
    return featureLayer
    }
    fun createNoBikeTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create a yellow dot style simple line symbol to represent no bike trails
    val noBikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(255, 255, 0), 2.0f)
    // Create a simple renderer for the feature layer
    val noBikeTrailRenderer = SimpleRenderer(noBikeTrailSymbol)
    // Create a no-bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = noBikeTrailRenderer
    // Write a definition expression to filter for trails that don't permit the use of bikes
    definitionExpression = "USE_BIKE = 'No'"
    }
    return featureLayer
    }
  4. Click Run > Run > app to run the app.

When the app opens, two Trails feature layers are added to the map. One shows where bikes are permitted and the other where they are prohibited.

Symbolize a layer with a picture symbol and label features with an attribute

Create a method to style trailheads with hiker images and labels for the Trailheads feature layer.

  1. Add a top-level function named createTrailheadsLayer().

    Use a PictureMarkerSymbol to draw a trailhead hiker image. Use the LabelDefinition to label each trailhead by its name.

    MainScreen.kt
    257 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    createBikeOnlyTrailsLayer(trails),
    createNoBikeTrailsLayer(trails),
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
    fun createBikeOnlyTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create blue dot style simple line symbol to represent the bike trails
    val bikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(0, 0, 255), 2.0f)
    // Create a simple renderer for the feature layer
    val bikeTrailRenderer = SimpleRenderer(bikeTrailSymbol)
    // Create a bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = bikeTrailRenderer
    // Write a definition expression to filter for trails that permit the use of bikes
    definitionExpression = "USE_BIKE = 'Yes'"
    }
    return featureLayer
    }
    fun createNoBikeTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create a yellow dot style simple line symbol to represent no bike trails
    val noBikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(255, 255, 0), 2.0f)
    // Create a simple renderer for the feature layer
    val noBikeTrailRenderer = SimpleRenderer(noBikeTrailSymbol)
    // Create a no-bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = noBikeTrailRenderer
    // Write a definition expression to filter for trails that don't permit the use of bikes
    definitionExpression = "USE_BIKE = 'No'"
    }
    return featureLayer
    }
    fun createTrailheadsLayer(featureServiceUri: String, trailheadImage: String): FeatureLayer {
    // Create a new picture marker symbol that uses the trailhead image
    val pictureMarkerSymbol = PictureMarkerSymbol(trailheadImage).apply {
    height = 18.0f
    width = 18.0f
    }
    // Create a new simple renderer based on the picture marker symbol
    val simpleRenderer = SimpleRenderer(pictureMarkerSymbol)
    // Create the label definition
    val trailHeadsDefinition = makeLabelDefinition(labelAttribute = "TRL_NAME")
    // Create a trail heads feature layer
    val featureLayer: FeatureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = simpleRenderer
    // Set labeling on the layer to be enabled
    labelsEnabled = true
    // Add the label definition to the layer's label definition collection
    labelDefinitions.add(trailHeadsDefinition)
    }
    return featureLayer
    }
  2. Create a top-level function named makeLabelDefinition() that defines a label definition based on the passed in feature layer attribute. This helper function will also define the label placement and text symbol.

    MainScreen.kt
    281 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    createBikeOnlyTrailsLayer(trails),
    createNoBikeTrailsLayer(trails),
    )
    )
    }
    }
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
    fun createBikeOnlyTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create blue dot style simple line symbol to represent the bike trails
    val bikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(0, 0, 255), 2.0f)
    // Create a simple renderer for the feature layer
    val bikeTrailRenderer = SimpleRenderer(bikeTrailSymbol)
    // Create a bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = bikeTrailRenderer
    // Write a definition expression to filter for trails that permit the use of bikes
    definitionExpression = "USE_BIKE = 'Yes'"
    }
    return featureLayer
    }
    fun createNoBikeTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create a yellow dot style simple line symbol to represent no bike trails
    val noBikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(255, 255, 0), 2.0f)
    // Create a simple renderer for the feature layer
    val noBikeTrailRenderer = SimpleRenderer(noBikeTrailSymbol)
    // Create a no-bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = noBikeTrailRenderer
    // Write a definition expression to filter for trails that don't permit the use of bikes
    definitionExpression = "USE_BIKE = 'No'"
    }
    return featureLayer
    }
    fun createTrailheadsLayer(featureServiceUri: String, trailheadImage: String): FeatureLayer {
    // Create a new picture marker symbol that uses the trailhead image
    val pictureMarkerSymbol = PictureMarkerSymbol(trailheadImage).apply {
    height = 18.0f
    width = 18.0f
    }
    // Create a new simple renderer based on the picture marker symbol
    val simpleRenderer = SimpleRenderer(pictureMarkerSymbol)
    // Create the label definition
    val trailHeadsDefinition = makeLabelDefinition(labelAttribute = "TRL_NAME")
    // Create a trail heads feature layer
    val featureLayer: FeatureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = simpleRenderer
    // Set labeling on the layer to be enabled
    labelsEnabled = true
    // Add the label definition to the layer's label definition collection
    labelDefinitions.add(trailHeadsDefinition)
    }
    return featureLayer
    }
    fun makeLabelDefinition(labelAttribute: String): LabelDefinition {
    // Create a text symbol for the label definition
    val labelTextSymbol = TextSymbol().apply {
    color = Color.white
    size = 12.0f
    haloColor = Color.red
    haloWidth = 1.0f
    fontFamily = "Arial"
    fontStyle = FontStyle.Italic
    fontWeight = FontWeight.Normal
    }
    // Create an Arcade label expression based on the field name
    val labelExpression = ArcadeLabelExpression("\$feature.$labelAttribute")
    // Create and return the label definition
    return LabelDefinition(labelExpression, labelTextSymbol)
    }
  3. Update createMap() to call the new createTrailheadsLayer() function.

    MainScreen.kt
    53 collapsed lines
    @file:OptIn(ExperimentalMaterial3Api::class)
    package com.example.app.screens
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.ExperimentalMaterial3Api
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.material3.TopAppBar
    import androidx.compose.runtime.Composable
    import androidx.compose.runtime.remember
    import androidx.compose.ui.Modifier
    import androidx.compose.ui.res.stringResource
    import com.arcgismaps.Color
    import com.arcgismaps.data.ServiceFeatureTable
    import com.arcgismaps.mapping.ArcGISMap
    import com.arcgismaps.mapping.BasemapStyle
    import com.arcgismaps.mapping.Viewpoint
    import com.arcgismaps.mapping.labeling.ArcadeLabelExpression
    import com.arcgismaps.mapping.labeling.LabelDefinition
    import com.arcgismaps.mapping.layers.FeatureLayer
    import com.arcgismaps.mapping.symbology.ClassBreak
    import com.arcgismaps.mapping.symbology.ClassBreaksRenderer
    import com.arcgismaps.mapping.symbology.FontStyle
    import com.arcgismaps.mapping.symbology.FontWeight
    import com.arcgismaps.mapping.symbology.PictureMarkerSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbol
    import com.arcgismaps.mapping.symbology.SimpleFillSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleLineSymbol
    import com.arcgismaps.mapping.symbology.SimpleLineSymbolStyle
    import com.arcgismaps.mapping.symbology.SimpleRenderer
    import com.arcgismaps.mapping.symbology.TextSymbol
    import com.arcgismaps.mapping.symbology.UniqueValue
    import com.arcgismaps.mapping.symbology.UniqueValueRenderer
    import com.arcgismaps.toolkit.geoviewcompose.MapView
    import com.example.app.R
    @Composable
    fun MainScreen() {
    val map = remember {
    createMap()
    }
    Scaffold(
    topBar = { TopAppBar(title = { Text(text = stringResource(id = R.string.app_name)) }) }
    ) {
    MapView(
    modifier = Modifier.fillMaxSize().padding(it),
    arcGISMap = map
    )
    }
    }
    fun createMap(): ArcGISMap {
    val parksAndOpenSpaces =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer/0"
    val trails =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer/0"
    val trailheads =
    "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
    val trailheadImage =
    "https://static.arcgis.com/images/Symbols/NPS/npsPictograph_0231b.png"
    return ArcGISMap(BasemapStyle.ArcGISTopographic).apply {
    initialViewpoint = Viewpoint(
    latitude = 34.0270,
    longitude = -118.8050,
    scale = 72000.0
    )
    operationalLayers.addAll(
    listOf(
    createOpenSpaceLayer(parksAndOpenSpaces),
    createTrailsLayer(trails),
    createBikeOnlyTrailsLayer(trails),
    createNoBikeTrailsLayer(trails),
    createTrailheadsLayer(trailheads, trailheadImage)
    )
    )
    }
    }
    210 collapsed lines
    fun createFeatureLayer(featureServiceUri: String): FeatureLayer {
    // Create a service feature table from a Uri
    val serviceFeatureTable = ServiceFeatureTable(featureServiceUri)
    // Return a feature layer created from the service feature table
    return FeatureLayer.createWithFeatureTable(serviceFeatureTable)
    }
    fun createOpenSpaceLayer(featureServiceUri: String): FeatureLayer {
    // Create fill symbol objects to represent the parks and open spaces layer
    val magentaFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(255, 0, 255), null)
    val greenFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.green, null)
    val blueFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.fromRgba(0, 0, 255), null)
    val redFillSymbol = SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.red, null)
    // Create a unique value for natural areas, regional open spaces, local parks, and regional recreation parks
    val naturalAreas = UniqueValue(
    description = "Natural Areas",
    label = "Natural Areas",
    symbol = magentaFillSymbol,
    values = listOf("Natural Areas")
    )
    val regionalOpenSpace = UniqueValue(
    description = "Regional Open Space",
    label = "Regional Open Space",
    symbol = greenFillSymbol,
    values = listOf("Regional Open Space")
    )
    val localPark = UniqueValue(
    description = "Local Park",
    label = "Local Park",
    symbol = blueFillSymbol,
    values = listOf("Local Park")
    )
    val regionalRecreationPark = UniqueValue(
    description = "Regional Recreation Park",
    label = "Regional Recreation Park",
    symbol = redFillSymbol,
    values = listOf("Regional Recreation Park")
    )
    // Create a unique value list with the fill symbols
    val uniqueValuesList = listOf(
    naturalAreas,
    regionalOpenSpace,
    localPark,
    regionalRecreationPark
    )
    // Create and assign a unique value renderer to the feature layer
    val openSpacesUniqueValueRenderer =
    UniqueValueRenderer(
    fieldNames = listOf("TYPE"),
    uniqueValues = uniqueValuesList,
    defaultLabel = "Open Spaces",
    defaultSymbol = null
    )
    // Create a parks and open spaces feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the unique value renderer
    renderer = openSpacesUniqueValueRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.2f
    }
    return featureLayer
    }
    fun createTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create simple symbol objects to represent the trails layer
    val firstClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 3.0f)
    val secondClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 4.0f)
    val thirdClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 5.0f)
    val fourthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 6.0f)
    val fifthClassSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.fromRgba(255, 0, 255), 7.0f)
    // Create 5 class breaks
    val firstClassBreak = ClassBreak(
    description = "Under 500",
    label = "0 - 500",
    minValue = 0.0,
    maxValue = 500.0,
    symbol = firstClassSymbol
    )
    val secondClassBreak = ClassBreak(
    description = "501 to 1000",
    label = "501 - 1000",
    minValue = 501.0,
    maxValue = 1000.0,
    symbol = secondClassSymbol
    )
    val thirdClassBreak = ClassBreak(
    description = "1001 to 1500",
    label = "1001 - 1500",
    minValue = 1001.0,
    maxValue = 1500.0,
    symbol = thirdClassSymbol
    )
    val fourthClassBreak = ClassBreak(
    description = "1501 to 2000",
    label = "1501 - 2000",
    minValue = 1501.0,
    maxValue = 2000.0,
    symbol = fourthClassSymbol
    )
    val fifthClassBreak = ClassBreak(
    description = "2001 to 2300",
    label = "2001 - 2300",
    minValue = 2001.0,
    maxValue = 2300.0,
    symbol = fifthClassSymbol
    )
    val elevationBreaks = listOf(
    firstClassBreak,
    secondClassBreak,
    thirdClassBreak,
    fourthClassBreak,
    fifthClassBreak
    )
    // Create and assign a class breaks renderer to the feature layer
    val elevationClassBreaksRenderer = ClassBreaksRenderer("ELEV_GAIN", elevationBreaks)
    // Create a trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the class breaks renderer
    renderer = elevationClassBreaksRenderer
    // Set the layer opacity to semi-transparent
    opacity = 0.75f
    }
    return featureLayer
    }
    fun createBikeOnlyTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create blue dot style simple line symbol to represent the bike trails
    val bikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(0, 0, 255), 2.0f)
    // Create a simple renderer for the feature layer
    val bikeTrailRenderer = SimpleRenderer(bikeTrailSymbol)
    // Create a bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = bikeTrailRenderer
    // Write a definition expression to filter for trails that permit the use of bikes
    definitionExpression = "USE_BIKE = 'Yes'"
    }
    return featureLayer
    }
    fun createNoBikeTrailsLayer(featureServiceUri: String): FeatureLayer {
    // Create a yellow dot style simple line symbol to represent no bike trails
    val noBikeTrailSymbol = SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.fromRgba(255, 255, 0), 2.0f)
    // Create a simple renderer for the feature layer
    val noBikeTrailRenderer = SimpleRenderer(noBikeTrailSymbol)
    // Create a no-bike trails feature layer
    val featureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = noBikeTrailRenderer
    // Write a definition expression to filter for trails that don't permit the use of bikes
    definitionExpression = "USE_BIKE = 'No'"
    }
    return featureLayer
    }
    fun createTrailheadsLayer(featureServiceUri: String, trailheadImage: String): FeatureLayer {
    // Create a new picture marker symbol that uses the trailhead image
    val pictureMarkerSymbol = PictureMarkerSymbol(trailheadImage).apply {
    height = 18.0f
    width = 18.0f
    }
    // Create a new simple renderer based on the picture marker symbol
    val simpleRenderer = SimpleRenderer(pictureMarkerSymbol)
    // Create the label definition
    val trailHeadsDefinition = makeLabelDefinition(labelAttribute = "TRL_NAME")
    // Create a trail heads feature layer
    val featureLayer: FeatureLayer = createFeatureLayer(featureServiceUri).apply {
    // Style the feature layer using the simple renderer
    renderer = simpleRenderer
    // Set labeling on the layer to be enabled
    labelsEnabled = true
    // Add the label definition to the layer's label definition collection
    labelDefinitions.add(trailHeadsDefinition)
    }
    return featureLayer
    }
    fun makeLabelDefinition(labelAttribute: String): LabelDefinition {
    // Create a text symbol for the label definition
    val labelTextSymbol = TextSymbol().apply {
    color = Color.white
    size = 12.0f
    haloColor = Color.red
    haloWidth = 1.0f
    fontFamily = "Arial"
    fontStyle = FontStyle.Italic
    fontWeight = FontWeight.Normal
    }
    // Create an Arcade label expression based on the field name
    val labelExpression = ArcadeLabelExpression("\$feature.$labelAttribute")
    // Create and return the label definition
    return LabelDefinition(labelExpression, labelTextSymbol)
    }
  4. Click Run > Run > app to run the app.

When the app opens, all the layers you’ve created and symbolized are displayed on the map.

  • Parks and open spaces are displayed with four unique symbols
  • Trails use different symbols (line widths) depending on trail elevation
  • Trails are blue where bikes are permitted and red where they are prohibited
  • Trailheads are displayed with a hiker icon and labels display each trail’s name

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link in the right-hand side of this page.

  2. Unzip the file to a location on your machine.

  3. Run Android Studio.

  4. Go to File > Open…. Navigate to the solution folder and click Open.

    On Windows: If you are in the Welcome to Android Studio dialog, click Open and navigate to the solution folder. Then click Open.

Since the downloaded solution does not contain authentication credentials, you must first set up authentication to create credentials, and then add the developer credentials to the solution.

Set up authentication

To access the secure ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more used in this tutorial, you must implement API key authentication API key authentication is a type of authentication that uses an API key to authenticate requests to ArcGIS services and secure portal items. Learn more or user authentication User authentication is a type of authentication that allows users with an ArcGIS account to sign into an application and allow it to access ArcGIS content, services, and resources on their behalf. The typical authorization protocol used is OAuth2.0. Learn more using an ArcGIS Location Platform An ArcGIS Location Platform account, formerly known as an ArcGIS Developer account, is an identity associated with an ArcGIS Location Platform subscription. Learn more or an ArcGIS Online An ArcGIS Online account, also known as an ArcGIS Organization account, is an identity associated with an ArcGIS Online subscription. It can be used to access ArcGIS tools and develop applications with ArcGIS location services for an organization. Learn more account.

To complete this tutorial, click on the tab in the switcher below for your authentication type of choice, either API key authentication or User authentication.

Create a new API key access token An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. Learn more with privileges Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s) Privileges are a set of permissions assigned to ArcGIS accounts, developer credentials, and applications that grant access to secure resources and functionality in ArcGIS. Learn more :

    • Privileges
      • Location services > Basemaps
  2. Copy and paste the API key access token into a safe location. It will be used in a later step.

Set developer credentials in the solution

To allow your app users to access ArcGIS location services ArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. Learn more , use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.

  1. In the Android view of Android Studio, open app > kotlin+java > com.example.app > MainActivity. Set the AuthenticationMode to .API_KEY.

    MainActivity.kt
    14 collapsed lines
    package com.example.app
    import android.os.Bundle
    import androidx.activity.ComponentActivity
    import androidx.activity.compose.setContent
    import androidx.activity.enableEdgeToEdge
    import com.arcgismaps.ApiKey
    import com.arcgismaps.ArcGISEnvironment
    import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
    import com.arcgismaps.toolkit.authentication.AuthenticatorState
    import com.arcgismaps.toolkit.authentication.DialogAuthenticator
    import com.example.app.screens.MainScreen
    import com.example.app.ui.theme.TutorialTheme
    class MainActivity : ComponentActivity() {
    private enum class AuthenticationMode { API_KEY, USER_AUTH }
    private val authenticationMode = AuthenticationMode.API_KEY
    42 collapsed lines
    private val authenticatorState = AuthenticatorState()
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    when (authenticationMode) {
    AuthenticationMode.API_KEY -> {
    ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
    }
    AuthenticationMode.USER_AUTH -> {
    authenticatorState.oAuthUserConfigurations = listOf(
    OAuthUserConfiguration(
    portalUrl = "https://www.arcgis.com",
    clientId = "YOUR_CLIENT_ID",
    redirectUrl = "YOUR_REDIRECT_URL"
    )
    )
    }
    }
    enableEdgeToEdge()
    setContent {
    TutorialTheme {
    MainScreen()
    if (authenticationMode == AuthenticationMode.USER_AUTH) {
    DialogAuthenticator(authenticatorState)
    }
    }
    }
    }
    }
  2. Set the apiKey property with your API key access token.

    MainActivity.kt
    22 collapsed lines
    package com.example.app
    import android.os.Bundle
    import androidx.activity.ComponentActivity
    import androidx.activity.compose.setContent
    import androidx.activity.enableEdgeToEdge
    import com.arcgismaps.ApiKey
    import com.arcgismaps.ArcGISEnvironment
    import com.arcgismaps.httpcore.authentication.OAuthUserConfiguration
    import com.arcgismaps.toolkit.authentication.AuthenticatorState
    import com.arcgismaps.toolkit.authentication.DialogAuthenticator
    import com.example.app.screens.MainScreen
    import com.example.app.ui.theme.TutorialTheme
    class MainActivity : ComponentActivity() {
    private enum class AuthenticationMode { API_KEY, USER_AUTH }
    private val authenticationMode = AuthenticationMode.API_KEY
    private val authenticatorState = AuthenticatorState()
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    when (authenticationMode) {
    AuthenticationMode.API_KEY -> {
    ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
    }
    30 collapsed lines
    AuthenticationMode.USER_AUTH -> {
    authenticatorState.oAuthUserConfigurations = listOf(
    OAuthUserConfiguration(
    portalUrl = "https://www.arcgis.com",
    clientId = "YOUR_CLIENT_ID",
    redirectUrl = "YOUR_REDIRECT_URL"
    )
    )
    }
    }
    enableEdgeToEdge()
    setContent {
    TutorialTheme {
    MainScreen()
    if (authenticationMode == AuthenticationMode.USER_AUTH) {
    DialogAuthenticator(authenticatorState)
    }
    }
    }
    }
    }

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.

Run the app

Click Run > Run > app to run the app.

When the app opens, all the layers you’ve created and symbolized are displayed on the map.

  • Parks and open spaces are displayed with four unique symbols
  • Trails use different symbols (line widths) depending on trail elevation
  • Trails are blue where bikes are permitted and red where they are prohibited
  • Trailheads are displayed with a hiker icon and labels display each trail’s name

What’s next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: