Skip to content
View on GitHubSample viewer app

Changes the appearance of the atmosphere in a scene.

Image of Set atmosphere effect in scene sample

Use case

Atmospheric effect can be used to make the scene view look more realistic.

How to use the sample

Select one of the three available atmosphere effects. The sky will change to display the selected atmosphere effect.

How it works

  1. Create an ArcGISScene and add it to a SceneView composable.
  2. Expose the selected AtmosphereEffect from a ViewModel and observe it in the Compose screen using collectAsStateWithLifecycle.
  3. Pass the AtmosphereEffect value into the SceneView composable, so changing the selected value updates the composable SceneView.

Relevant API

  • ArcGISScene
  • ArcGISTiledElevationSource
  • AtmosphereEffect
  • SceneView
  • Viewpoint

Additional information

There are three atmosphere effect options:

  • Realistic - A realistic atmosphere effect is applied over the entire surface.
  • HorizonOnly - Atmosphere effect applied to the sky (horizon) only.
  • None - No atmosphere effect. The sky is rendered black with a starfield consisting of randomly placed white dots.

Tags

atmosphere, horizon, scene, sky

Sample Code

SetAtmosphereEffectInSceneViewModel.ktSetAtmosphereEffectInSceneViewModel.ktMainActivity.ktSetAtmosphereEffectInSceneScreen.kt
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* 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.setatmosphereeffectinscene.components

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.arcgismaps.mapping.ArcGISScene
import com.arcgismaps.mapping.ArcGISTiledElevationSource
import com.arcgismaps.mapping.BasemapStyle
import com.arcgismaps.mapping.Viewpoint
import com.arcgismaps.mapping.view.AtmosphereEffect
import com.arcgismaps.mapping.view.Camera
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

/**
 * ViewModel for the sample demonstrating setting the atmosphere effect on a Scene.
 */
class SetAtmosphereEffectInSceneViewModel(app: Application) : AndroidViewModel(app) {

    // Create a scene with an imagery basemap & set an initial viewpoint.
    var arcGISScene = ArcGISScene(BasemapStyle.ArcGISImagery).apply {
        val camera = Camera(
            latitude = 64.416919,
            longitude = -14.483728,
            altitude = 0.0,
            heading = 318.0,
            pitch = 105.0,
            roll = 0.0
        )
        // Add an initial viewpoint using a camera.
        initialViewpoint = Viewpoint(
            boundingGeometry = camera.location,
            camera = camera
        )
        // Creates an elevation source and set it on the scene's base surface.
        baseSurface.elevationSources.add(
            ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")
        )
    }

    // Keep track of the SceneView's atmosphere effect state.
    private val _atmosphereEffect = MutableStateFlow<AtmosphereEffect>(AtmosphereEffect.HorizonOnly)
    val atmosphereEffect = _atmosphereEffect.asStateFlow()

    // Message dialog view model for error handling.
    val messageDialogVM = MessageDialogViewModel()

    init {
        // Load the scene and report load failures if they occur.
        viewModelScope.launch {
            arcGISScene.load().onFailure { messageDialogVM.showMessageDialog(it) }
        }
    }

    /**
     * Update the [AtmosphereEffect] applied to the SceneView.
     */
    fun updateAtmosphereEffect(newEffect: AtmosphereEffect) {
        _atmosphereEffect.value = newEffect
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.