Use float suppliers to dynamically update numeric inputs to a map algebra expression and automatically refresh analysis results as input values change.

Use case
Many spatial analysis workflows rely on numeric parameters that control how data is filtered, classified, or evaluated. As users adjust these parameters, analysis results often need to be updated repeatedly to explore different scenarios. Float suppliers allow numeric inputs to be changed dynamically, enabling map algebra expressions to refresh automatically without rebuilding the analysis each time a value changes.
How to use the sample
When the sample opens, the map shows the result of a slope analysis which displays slopes between 0 to 10 degrees. This range shows gentle hills and flatter areas such as roads and man-made structures in dark purple. Open the Settings pane and drag the range slider handles to adjust the minimum and maximum slope values between 0 and 85 degrees (the maximum slope value of the data). The analysis updates automatically to show only slopes within the selected range. An indicator in the settings pane shows when the analysis is updating. The slope results are drawn on top of an elevation field which is rendered with a surface color ramp to provide context for the data. Green areas represent lower lying terrain, and brown to white reflects higher elevations.
How it works
- Create a
ContinuousFieldfrom an elevation raster file usingContinuousField.createFromFiles. - Create a
ContinuousFieldFunctionfrom the continuous field usingContinuousFieldSupplier. - Derive a
slopefunction from the continuous field function. - Create two
FloatSupplierinstances and set theirvalueproperties to the initial minimum and maximum slope values. - Create a
BooleanFieldFunctionbased on the minimum and maximum slope suppliers. Use the map algebra functionsisGreaterThanOrEqualToandisLessThanOrEqualTowith theFloatSupplierinstances as inputs, and combine them using the infix functionand. - Apply the boolean selection to the slope function using
maskto retain only slopes within the selected range. - Create a
FieldAnalysisfor the masked slope function using theFieldAnalysisconstructor that takes aContinuousFieldFunctionand aStretchRenderer. - Add the field analysis to an
AnalysisOverlayand add the overlay to the map view. - Update the float suppliers’
valueproperties to update the analysis result dynamically.
Relevant API
- AnalysisOverlay
- BooleanFieldFunction
- ColorRamp
- ContinuousField
- ContinuousFieldFunction
- ContinuousFieldSupplier
- FieldAnalysis
- FloatSupplier
- StretchRenderer
Offline data
The sample uses a 1m resolution digital terrain elevation raster of the area over Méribel, in the French Alps. It is downloaded from ArcGIS Online automatically. The spatial reference of the data is UTM32N.
Tags
elevation, map algebra, raster, slope, spatial analysis, terrain
Sample code
/* Copyright 2026 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.controlmapalgebrainputswithfloatsuppliers.components
import android.app.Applicationimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.setValueimport androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.viewModelScopeimport com.arcgismaps.analysis.ContinuousFieldimport com.arcgismaps.analysis.ContinuousFieldSupplierimport com.arcgismaps.analysis.FloatSupplierimport com.arcgismaps.analysis.interactive.Analysisimport com.arcgismaps.analysis.interactive.FieldAnalysisimport com.arcgismaps.geometry.SpatialReferenceimport com.arcgismaps.mapping.ArcGISMapimport com.arcgismaps.mapping.symbology.raster.ColorRampimport com.arcgismaps.mapping.symbology.raster.MinMaxStretchParametersimport com.arcgismaps.mapping.symbology.raster.PresetColorRampTypeimport com.arcgismaps.mapping.symbology.raster.StretchRendererimport com.arcgismaps.mapping.view.AnalysisOverlayimport com.arcgismaps.mapping.view.AnalysisViewStatusimport com.arcgismaps.mapping.view.GeoViewimport com.arcgismaps.toolkit.geoviewcompose.MapViewProxyimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.Rimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.components.FloatSuppliersUiState.Companion.initialFloatSuppliersUiStateimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModelimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.flow.updateimport kotlinx.coroutines.launchimport java.io.File
const val MAXIMUM_SLOPE_DEGREES = 85.0
class ControlMapAlgebraInputsWithFloatSuppliersViewModel(app: Application) : AndroidViewModel(app) { // Create a state flow to hold the UI state for the supporting pane controls private val _floatSuppliersUiState = MutableStateFlow(initialFloatSuppliersUiState)
// Expose the state flow as read-only for the UI val uiState = _floatSuppliersUiState.asStateFlow()
// Create the spatial reference for the map and the elevation file (UTM zone 32N). val spatialReference = SpatialReference(wkid = 32632)
// Create a MapViewProxy, used to set viewpoint val mapViewProxy = MapViewProxy()
// Initialize and keep track of the ArcGISMap & the analysis overlay it uses val arcGISMap by mutableStateOf(ArcGISMap(spatialReference)) var analysisOverlay by mutableStateOf(AnalysisOverlay())
// Indicates when the ProgressIndicator should be displayed var displayProgressIndicator by mutableStateOf(false) private set
// Collection of Analysis instances currently updating, ProgressIndicator displayed when non-empty val updatingAnalyses = mutableSetOf<Analysis>()
// Create a message dialog view model for handling error messages val messageDialogVM = MessageDialogViewModel()
// Location of file containing elevation data private val provisionPath: String by lazy { app.getExternalFilesDir(null)?.path + File.separator + app.getString( R.string.control_map_algebra_inputs_with_float_suppliers_app_name ) + File.separator } private val filePath = provisionPath + "Meribel_32N.tif"
// Create slope range suppliers, initialized with values of 0 to 10 degrees; this will highlight // gentle hills and flatter areas such as roads and man-made structures private val minimumSlopeFloatSupplier = FloatSupplier(initialFloatSuppliersUiState.minimumSlope) private val maximumSlopeFloatSupplier = FloatSupplier(initialFloatSuppliersUiState.maximumSlope)
// Stretch renderer for visualizing the slope, using a fixed degree scale as the selected slope // range changes private val slopeRenderer = StretchRenderer( parameters = MinMaxStretchParameters( minValues = listOf(0.0), maxValues = listOf(MAXIMUM_SLOPE_DEGREES) ), gammas = listOf(1.0), estimateStatistics = false, colorRamp = ColorRamp.create( type = PresetColorRampType.Viridis, size = 256 ) )
// Stretch renderer for visualizing the elevation private val elevationRenderer = StretchRenderer( parameters = MinMaxStretchParameters( minValues = listOf(1199.0), maxValues = listOf(2740.0) ), gammas = listOf(1.0), estimateStatistics = false, colorRamp = ColorRamp.create( type = PresetColorRampType.Surface, size = 256 ) )
init { viewModelScope.launch { // // Load the map and handle any errors by showing a message dialog arcGISMap.load().onFailure { messageDialogVM.showMessageDialog(it) }.onSuccess { // Create a ContinuousField from a raster file containing elevation data ContinuousField.createFromFiles( filePaths = listOf(filePath), band = 0, spatialReference = spatialReference ).onFailure { messageDialogVM.showMessageDialog(it) }.onSuccess { continuousField -> // Create the elevation function from the continuous field val elevationFunction = ContinuousFieldSupplier(continuousField)
// Create the slope function from the elevation function val slopeFunction = elevationFunction.slope()
// Create a boolean field function based on the minimum and maximum slope suppliers val slopeSelection = slopeFunction.isGreaterThanOrEqualTo(minimumSlopeFloatSupplier) and slopeFunction.isLessThanOrEqualTo(maximumSlopeFloatSupplier)
// Mask the slope function with the selected slope range to create a continuous // field function val maskedSlope = slopeFunction.mask(slopeSelection)
// Set the initial viewpoint of the map to the center of the continuous field's // extent mapViewProxy.setViewpointCenter( center = continuousField.extent.center, scale = 10000.0 )
// Create the elevation field analysis using the elevation function. // Note: This acts as a basemap for the slope analysis in this sample. val elevationFieldAnalysis = FieldAnalysis(elevationFunction, elevationRenderer) elevationFieldAnalysis.opacity = 0.6f
// Add the elevation field analysis to the analysis overlay analysisOverlay.analyses.add(elevationFieldAnalysis)
// Create the slope field analysis using the masked slope field function val slopeFieldAnalysis = FieldAnalysis(maskedSlope, slopeRenderer)
// Add the slope field analysis to the analysis overlay analysisOverlay.analyses.add(slopeFieldAnalysis) } } } }
/** * An AnalysisViewStatus listener that displays the progress indicator when the status of any * analysis is Updating and hides it when no analysis is Updating. Also displays details of any * error that occurs when an analysis is displayed. */ fun analysisViewStatusListener(event: GeoView.GeoViewAnalysisViewStatusChanged) { when (event.analysisViewStatus) { is AnalysisViewStatus.Error -> { messageDialogVM.showMessageDialog( throwable = (event.analysisViewStatus as AnalysisViewStatus.Error).details ) updatingAnalyses.remove(event.analysis) } AnalysisViewStatus.UpToDate -> { updatingAnalyses.remove(event.analysis) } AnalysisViewStatus.Updating -> { updatingAnalyses.add(event.analysis) } } displayProgressIndicator = updatingAnalyses.isNotEmpty() }
/** * Updates the minimum slope and maximum slope values. */ fun onMinMaxSlopeChange(minimumSlope: Float, maximumSlope: Float) { _floatSuppliersUiState.update { it.copy(minimumSlope = minimumSlope, maximumSlope = maximumSlope) } minimumSlopeFloatSupplier.value = minimumSlope maximumSlopeFloatSupplier.value = maximumSlope }}
data class FloatSuppliersUiState( val minimumSlope: Float, val maximumSlope: Float) { companion object { // Initial parameters to drive the UI on launch val initialFloatSuppliersUiState = FloatSuppliersUiState( minimumSlope = 0.0f, maximumSlope = 10.0f ) }}/* Copyright 2026 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.controlmapalgebrainputswithfloatsuppliers
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.activity.enableEdgeToEdgeimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.screens.ControlMapAlgebraInputsWithFloatSuppliersScreenimport com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { SampleAppTheme { Surface(color = MaterialTheme.colorScheme.background) { ControlMapAlgebraInputsWithFloatSuppliersScreen() } } } }}/* Copyright 2026 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.controlmapalgebrainputswithfloatsuppliers.screens
import androidx.compose.animation.animateContentSizeimport androidx.compose.foundation.layout.BoxScopeimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.Scaffoldimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifierimport androidx.compose.ui.res.stringResourceimport androidx.lifecycle.compose.collectAsStateWithLifecycleimport androidx.lifecycle.viewmodel.compose.viewModelimport com.arcgismaps.toolkit.geoviewcompose.MapViewimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.Rimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.components.ControlMapAlgebraInputsWithFloatSuppliersViewModelimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.components.FloatSuppliersUiStateimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogimport com.esri.arcgismaps.sample.sampleslib.components.SampleDeviceLightDarkPreviewimport com.esri.arcgismaps.sample.sampleslib.components.SamplePreviewSurfaceimport com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBarimport com.esri.arcgismaps.sample.sampleslib.components.adaptive.AdaptiveThreePaneimport com.esri.arcgismaps.sample.sampleslib.components.adaptive.ThreePaneConfig
/** * Main composable screen for the sample. * It owns the ViewModel and hoists UI state for the scaffold and the MapView. */@Composablefun ControlMapAlgebraInputsWithFloatSuppliersScreen( viewModel: ControlMapAlgebraInputsWithFloatSuppliersViewModel = viewModel()) { val uiState = viewModel.uiState.collectAsStateWithLifecycle().value
MainScreenScaffold( uiState = uiState, displayProgressIndicator = viewModel.displayProgressIndicator, onMinMaxSlopeChange = viewModel::onMinMaxSlopeChange, mainPaneContent = { MapView( modifier = Modifier .fillMaxSize() .animateContentSize(), arcGISMap = viewModel.arcGISMap, mapViewProxy = viewModel.mapViewProxy, analysisOverlays = listOf(viewModel.analysisOverlay), onAnalysisViewStatusChanged = viewModel::analysisViewStatusListener ) } )
viewModel.messageDialogVM.apply { if (dialogStatus) { MessageDialog( title = messageTitle, description = messageDescription, onDismissRequest = ::dismissDialog ) } }}
@Composableprivate fun MainScreenScaffold( uiState: FloatSuppliersUiState, displayProgressIndicator: Boolean, onMinMaxSlopeChange: (Float, Float) -> Unit = { _, _ ->}, mainPaneContent: @Composable BoxScope.() -> Unit) { Scaffold( topBar = { SampleTopAppBar(title = stringResource(R.string.control_map_algebra_inputs_with_float_suppliers_app_name)) }, content = { paddingValues -> AdaptiveThreePane( modifier = Modifier .fillMaxSize() .padding(paddingValues), supportingPaneTitle = "Settings", config = ThreePaneConfig(compactSupportingPaneHeightRatio = 0.3f), mainPane = { _, _ -> mainPaneContent() }, supportingPane = { _, _ -> ControlMapAlgebraInputsWithFloatSuppliersSupportingPane( uiState = uiState, displayProgressIndicator = displayProgressIndicator, onMinMaxSlopeChange = onMinMaxSlopeChange ) } ) } )}
@SampleDeviceLightDarkPreview@Composablefun MainScreenPreview() { SamplePreviewSurface { MainScreenScaffold( uiState = FloatSuppliersUiState.initialFloatSuppliersUiState, displayProgressIndicator = true, mainPaneContent = {} ) }}/* Copyright 2026 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.controlmapalgebrainputswithfloatsuppliers.screens
import androidx.compose.foundation.backgroundimport androidx.compose.foundation.borderimport androidx.compose.foundation.interaction.MutableInteractionSourceimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.sizeimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.material3.CircularProgressIndicatorimport androidx.compose.material3.ExperimentalMaterial3Apiimport androidx.compose.material3.RangeSliderimport androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.runtime.rememberimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.graphics.Brushimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.lerpimport androidx.compose.ui.platform.LocalLayoutDirectionimport androidx.compose.ui.unit.LayoutDirectionimport androidx.compose.ui.unit.dpimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.components.FloatSuppliersUiStateimport com.esri.arcgismaps.sample.controlmapalgebrainputswithfloatsuppliers.components.MAXIMUM_SLOPE_DEGREES
// Lists of colors used to approximate the color gradient of the Viridis color schemeprivate val viridis = listOf( Color(0xFF440154), Color(0xFF3B528B), Color(0xFF21918C), Color(0xFF5EC962), Color(0xFFFDE725))private val viridisReversed = viridis.reversed()
/** * Supporting pane content for the sample. */@Composableinternal fun ControlMapAlgebraInputsWithFloatSuppliersSupportingPane( uiState: FloatSuppliersUiState, displayProgressIndicator: Boolean, onMinMaxSlopeChange: (Float, Float) -> Unit) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center ) { val message = when (displayProgressIndicator) { false -> "Analysis up to date" true -> "Analysis updating..." } Text(text = message) if (displayProgressIndicator) { CircularProgressIndicator(modifier = Modifier.size(20.dp)) } } Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center ) { Text(text = "Slope range: ${uiState.minimumSlope.toInt()} to ${uiState.maximumSlope.toInt()} degrees") } SlopeRangeSlider(uiState, onMinMaxSlopeChange)}
/** * A range slider for selecting the minimum and maximum slope values. Uses a customized color * scheme. */@OptIn(ExperimentalMaterial3Api::class)@Composableprivate fun SlopeRangeSlider( uiState: FloatSuppliersUiState, onMinMaxSlopeChange: (Float, Float) -> Unit) { // Order of colors used for the slider's track needs to match the horizontal layout direction val trackColors = if (LocalLayoutDirection.current == LayoutDirection.Rtl) { viridisReversed } else { viridis }
val startInteractionSource = remember { MutableInteractionSource() } val endInteractionSource = remember { MutableInteractionSource() } val maxSlope = MAXIMUM_SLOPE_DEGREES.toFloat()
RangeSlider( value = uiState.minimumSlope..uiState.maximumSlope, modifier = Modifier.fillMaxWidth(), onValueChange = { newRange -> if (newRange.start < newRange.endInclusive) { onMinMaxSlopeChange(newRange.start, newRange.endInclusive) } }, valueRange = 0.0f..maxSlope, startInteractionSource = startInteractionSource, endInteractionSource = endInteractionSource, startThumb = { // Make the start thumb the same color as the point on the track where it is placed Box( Modifier .size(20.dp) .background( color = colorAtFraction( colors = viridis, fraction = uiState.minimumSlope / maxSlope ), shape = CircleShape ) .border(width = 1.dp, color = Color.Black, shape = CircleShape) ) }, endThumb = { // Make the end thumb the same color as the point on the track where it is placed Box( Modifier .size(20.dp) .background( color = colorAtFraction( colors = viridis, fraction = uiState.maximumSlope / maxSlope ), shape = CircleShape ) .border(width = 1.dp, color = Color.Black, shape = CircleShape) ) }, track = { // The track of the slider, using a horizontal gradient that matches the color ramp used // when the slope data is rendered Box( Modifier .fillMaxWidth() .height(8.dp) .clip(CircleShape) .background(Brush.horizontalGradient(trackColors)) ) } )}
/** * Returns a Color that is a linear interpolation between the given list of [colors], based on the * given [fraction]. */private fun colorAtFraction(colors: List<Color>, fraction: Float): Color { val position = fraction.coerceIn(0f, 1f) * (colors.size - 1) val index = position.toInt().coerceAtMost(colors.lastIndex - 1) val t = position - index
val start = colors[index] val stop = colors[index + 1] return lerp(start, stop, fraction = t)}