View on GitHub Sample viewer app

Update the orientation of a graphic using expressions based on its attributes.

Image of apply scene property expressions

Use case

Instead of reading the attribute and changing the rotation on the symbol for a single graphic (a manual CPU operation), you can bind the rotation to an expression that applies to the whole overlay (an automatic GPU operation). This usually results in a noticeable performance boost (smooth rotations).

How to use the sample

Adjust the heading and pitch sliders to rotate the cone.

How it works

  1. Create a new graphics overlay.
  2. Create a simple renderer and set its scene properties.
  3. Set the heading expression to [HEADING].
  4. Set the pitch expression to [PITCH].
  5. Apply the renderer to the graphics overlay.
  6. Create a graphic and add it to the overlay.
  7. To update the graphic’s rotation, update the HEADING or PITCH property in the graphic’s attributes.

Relevant API

  • Graphic.Attributes
  • GraphicsOverlay
  • SceneProperties
  • SceneProperties.headingExpression
  • SceneProperties.pitchExpression
  • SimpleRenderer
  • SimpleRenderer.SceneProperties

Tags

3D, expression, graphics, heading, pitch, rotation, scene, symbology

Sample Code

MainActivity.kt MainActivity.kt ApplyScenePropertyExpressionsViewModel.kt ApplyScenePropertyExpressionsScreen.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.applyscenepropertyexpressions
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.applyscenepropertyexpressions.screens.ApplyScenePropertyExpressionsScreen
import com.esri.arcgismaps.sample.sampleslib.BuildConfig
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 {
ApplyScenePropertyExpressionsApp()
}
}
}
@Composable
private fun ApplyScenePropertyExpressionsApp() {
Surface(color = MaterialTheme.colorScheme.background) {
ApplyScenePropertyExpressionsScreen(
sampleName = getString(R.string.apply_scene_property_expressions_app_name)
)
}
}
}