View on GitHub Sample viewer app

Apply a renderer to a sublayer.

Image of Apply class breaks renderer to sublayer sample

Use case

A layer showing animal populations contains sublayers for different species. A renderer could be applied which gives each sublayer a different color, so that populations of each species can be compared visually.

How to use the sample

Wait for the map image layer to load. Tap the ‘Change sublayer renderer’ button to apply a unique value renderer to see different population ranges in the counties sub-layer data.

How it works

  1. Create an ArcGISMapImageLayer from a URL.
  2. After it is done loading, get its map image sublayers.
  3. Get the MapImageSublayer.
  4. Create a ClassBreaksRenderer with a collection of ClassBreaks for different population ranges.
  5. Set class breaks renderer as the renderer of the sublayer.

Relevant API

  • ArcGISMapImageLayer
  • ArcGISMapImageSublayer
  • ClassBreak
  • ClassBreaksRenderer

About the data

This application displays census data from an ArcGIS Server map service. It contains various population statistics, including total population for each county in 2007.

Additional information

The service hosting the layer must support dynamic layers to be able to change the rendering of sublayers.

Tags

class breaks, dynamic layer, dynamic rendering, renderer, sublayer, symbology, visualization

Sample Code

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