Apply a unique value with alternate symbols at different scales.

Use case
When a layer is symbolized with unique value symbology, you can specify the visible scale range for each unique value. This is an effective strategy to limit the amount of detailed data at smaller scales without having to make multiple versions of the layer, each with a unique definition query.
Once scale ranges are applied to unique values, you can further refine the appearance of features within those scale ranges by establishing alternate symbols to different parts of the symbol class scale range.
How to use the sample
Zoom in and out of the map to see alternate symbols at each scale. The symbology changes according to the following scale ranges: 0-5,000, 5,000-10,000, 10,000-20,000. To go back to the initial viewpoint, tap “Reset Viewpoint”.
How it works
- Create a
FeatureLayerusing the service URL and add it to the map’s list of operational layers. - Create two alternate symbols (a blue square and a yellow diamond) to be used as alternate symbols. To create an alternate symbol:
- Create a symbol using
SimpleMarkerSymbol. - Convert the simple marker symbol to an
MultilayerSymbolusingSimpleMarkerSymbol.toMultilayerSymbol(). - Set the multilayer symbol’s
referencePropertiesto the valid scale ranges with the blue square and yellow diamond.
- Create a symbol using
- Create a third multilayer symbol to be used to create a
UniqueValueclass. - Create a unique value using the red triangle from step 3 and the list of alternate symbols from step 2.
- Create a
UniqueValueRendererand add the unique value from step 4 to it. - Create a purple diamond simple marker and convert it to a multilayer symbol to be used as the default symbol.
- Set the unique value renderer’s
defaultSymbolproperty to the purple diamond from step 6. - Set the unique value renderer’s
fieldNamesproperty to “req_type”. - Apply this unique value renderer to the renderer on feature layer.
Relevant API
- MultilayerSymbol
- SimpleMarkerSymbol
- SymbolReferenceProperties
- UniqueValue
- UniqueValueRenderer
About the data
The San Francisco 311 incidents layer in this sample displays point features related to crime incidents such as graffiti and tree damage that have been reported by city residents.
Tags
alternate symbols, multilayer symbol, scale based rendering, simple marker symbol, symbol reference properties, symbology, unique value, unique value renderer
Sample Code
/* Copyright 2025 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.displayalternatesymbolsatdifferentscales
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport androidx.compose.runtime.Composableimport com.arcgismaps.ApiKeyimport com.arcgismaps.ArcGISEnvironmentimport com.esri.arcgismaps.sample.sampleslib.theme.SampleAppThemeimport com.esri.arcgismaps.sample.displayalternatesymbolsatdifferentscales.screens.DisplayAlternateSymbolsAtDifferentScalesScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // authentication with an API key or named user is // required to access basemaps and other location services ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
setContent { SampleAppTheme { DisplayAlternateSymbolsAtDifferentScalesApp() } } }
@Composable private fun DisplayAlternateSymbolsAtDifferentScalesApp() { Surface(color = MaterialTheme.colorScheme.background) { DisplayAlternateSymbolsAtDifferentScalesScreen( sampleName = getString(R.string.display_alternate_symbols_at_different_scales_app_name) ) } }}/* Copyright 2025 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.displayalternatesymbolsatdifferentscales.components
import android.app.Applicationimport androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.viewModelScopeimport com.arcgismaps.Colorimport com.arcgismaps.data.ServiceFeatureTableimport com.arcgismaps.geometry.Pointimport com.arcgismaps.mapping.ArcGISMapimport com.arcgismaps.mapping.BasemapStyleimport com.arcgismaps.mapping.Viewpointimport com.arcgismaps.mapping.layers.FeatureLayerimport com.arcgismaps.mapping.symbology.SimpleMarkerSymbolimport com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyleimport com.arcgismaps.mapping.symbology.SymbolReferencePropertiesimport com.arcgismaps.mapping.symbology.UniqueValueimport com.arcgismaps.mapping.symbology.UniqueValueRendererimport com.arcgismaps.toolkit.geoviewcompose.MapViewProxyimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModelimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.launch
/** * ViewModel for the sample demonstrating alternate symbols at different scales. */class DisplayAlternateSymbolsAtDifferentScalesViewModel(app: Application) : AndroidViewModel(app) {
// Feature layer created from the service, using URL for the SF311 incidents feature layer private val featureLayer = FeatureLayer.createWithFeatureTable( featureTable = ServiceFeatureTable( uri = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/0" ) )
// Map initialized to the a viewpoint and feature layer. val arcGISMap: ArcGISMap = ArcGISMap(BasemapStyle.ArcGISTopographic).apply { val center = Point( x = -13631200.0, y = 4546830.0, spatialReference = com.arcgismaps.geometry.SpatialReference.webMercator() ) initialViewpoint = Viewpoint(center = center, scale = 7500.0) // Add the incidents feature layer operationalLayers += featureLayer }
// MapViewProxy to perform viewpoint changes val mapViewProxy = MapViewProxy()
// Expose the current MapView scale private val _currentScale = MutableStateFlow(arcGISMap.initialViewpoint?.targetScale) val currentScale = _currentScale.asStateFlow()
// Message dialog helper for errors val messageDialogVM = MessageDialogViewModel()
init { viewModelScope.launch { // Load the map with the feature layer arcGISMap.load().onFailure { return@launch messageDialogVM.showMessageDialog(it) } // Configure the unique value renderer configureUniqueValueRenderer() } }
/** * Build the multilayer symbols with reference scale ranges and apply a [UniqueValueRenderer] * to the feature layer. Alternate symbols are assigned to scale ranges. */ private fun configureUniqueValueRenderer() { // Red triangle used for the base symbol (0 - 5,000) val redTriangle = SimpleMarkerSymbol( style = SimpleMarkerSymbolStyle.Triangle, color = Color.red, size = 30f ).toMultilayerSymbol().apply { referenceProperties = SymbolReferenceProperties( minScale = 5_000.0, maxScale = 0.0 ) }
// Blue square alternate symbol (5,000 - 10,000) val blueSquare = SimpleMarkerSymbol( style = SimpleMarkerSymbolStyle.Square, color = Color.blue, size = 30f ).toMultilayerSymbol().apply { referenceProperties = SymbolReferenceProperties( minScale = 10_000.0, maxScale = 5_000.0 ) }
// Yellow diamond alternate symbol (10,000 - 20,000) val yellowDiamond = SimpleMarkerSymbol( style = SimpleMarkerSymbolStyle.Diamond, color = Color.yellow, size = 30f ).toMultilayerSymbol().apply { referenceProperties = SymbolReferenceProperties( minScale = 20_000.0, maxScale = 10_000.0 ) }
// Unique value using the red triangle and the alternate symbols val uniqueValue = UniqueValue( description = "unique values based on request type", label = "unique value", symbol = redTriangle, values = listOf("Damaged Property"), alternateSymbols = listOf(blueSquare, yellowDiamond) )
// Default purple diamond for other values val purpleDiamond = SimpleMarkerSymbol( style = SimpleMarkerSymbolStyle.Diamond, color = Color.fromRgba(r = 128, g = 0, b = 128), size = 15f ).toMultilayerSymbol()
val uniqueValueRenderer = UniqueValueRenderer( fieldNames = listOf("req_type"), uniqueValues = listOf(uniqueValue), defaultSymbol = purpleDiamond )
// Set the renderer to symbolize geo-elements with a distinct symbol. featureLayer.renderer = uniqueValueRenderer }
/** * Called from the MapView composable when the viewpoint changes. */ fun updateScale(newScale: Double?) { _currentScale.value = newScale }
/** * Reset the viewpoint to the map's initial viewpoint using MapViewProxy. */ fun resetViewpoint() { val initialViewpoint = arcGISMap.initialViewpoint ?: return viewModelScope.launch { mapViewProxy.setViewpointAnimated(initialViewpoint) } }}/* Copyright 2025 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */
package com.esri.arcgismaps.sample.displayalternatesymbolsatdifferentscales.screens
import androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.OutlinedButtonimport androidx.compose.material3.Scaffoldimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.unit.dpimport androidx.lifecycle.compose.collectAsStateWithLifecycleimport androidx.lifecycle.viewmodel.compose.viewModelimport com.arcgismaps.mapping.Viewpointimport com.arcgismaps.toolkit.geoviewcompose.MapViewimport com.esri.arcgismaps.sample.displayalternatesymbolsatdifferentscales.components.DisplayAlternateSymbolsAtDifferentScalesViewModelimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogimport com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
/** * Main screen layout for the sample. */@Composablefun DisplayAlternateSymbolsAtDifferentScalesScreen(sampleName: String) { val mapViewModel: DisplayAlternateSymbolsAtDifferentScalesViewModel = viewModel()
// Collect the current scale val currentScale by mapViewModel.currentScale.collectAsStateWithLifecycle()
Scaffold(topBar = { SampleTopAppBar(title = sampleName) }) { padding -> Column( modifier = Modifier .fillMaxSize() .padding(padding) ) { MapView( modifier = Modifier .fillMaxWidth() .weight(1f), arcGISMap = mapViewModel.arcGISMap, mapViewProxy = mapViewModel.mapViewProxy, onViewpointChangedForCenterAndScale = { newViewpoint: Viewpoint? -> // Update only the scale in the view model when viewpoint changes mapViewModel.updateScale(newViewpoint?.targetScale) } )
// Controls displayed below the MapView RendererControls( scale = currentScale, onReset = mapViewModel::resetViewpoint ) }
// Show message dialogs for errors mapViewModel.messageDialogVM.apply { if (dialogStatus) { MessageDialog( title = messageTitle, description = messageDescription, onDismissRequest = ::dismissDialog ) } } }}
@Composableprivate fun RendererControls(scale: Double?, onReset: () -> Unit) { Column( modifier = Modifier .fillMaxWidth() .padding(12.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp) ) { // Display the current scale; format if available val scaleText = scale?.let { String.format(null, "Scale: 1:%,d", it.toInt()) } ?: "Scale: N/A"
Text(text = scaleText, style = MaterialTheme.typography.titleMedium) // Reset viewpoint button OutlinedButton(onClick = onReset) { Text(text = "Reset Viewpoint") } }}