View on GitHub Sample viewer app

Determine whether a layer is currently visible.

Image of Monitor changes to layer view state

Use case

The view status includes information on the loading state of layers and whether layers are visible at a given scale. You might change how a layer is displayed in a layer list to communicate whether it is being viewed on the map. For example, you could show a loading spinner next to its name when the view status is Loading, gray out the name when notVisible or OutOfScale, show the name normally when Active, or with a warning or error icon when the status is Warning or Error.

How to use the sample

When the feature layer is loaded, pan and zoom around the map. Note how the LayerViewState flags change. For example, the layer status OutOfScale is retrieved when the map is scaled outside the layer’s min and max scale range. Tap the toggle to hide the layer and observe the view state change to NotVisible. Disconnect from the network and pan around the map to see the Warning status when the layer cannot fetch online data. Reconnect to the network to see the warning disappear.

How it works

  1. Create a ArcGISMap with an operational layer.
  2. Use the onLayerViewStateChanged() callback on the map view to get updates to the layers’ view states.
  3. Get the Layer and the current view status of the LayerViewState defining the new state.

Relevant API

  • GeoViewLayerViewStateChanged
  • Layer
  • LayerViewState
  • Map
  • MapView

About the data

The Satellite (MODIS) Thermal Hotspots and Fire Activity layer presents detectable thermal activity from MODIS satellites for the last 48 hours. MODIS Global Fires is a product of NASA’s Earth Observing System Data and Information System (EOSDIS), part of NASA’s Earth Science Data. EOSDIS integrates remote sensing and GIS technologies to deliver global MODIS hotspot/fire locations to natural resource managers and other stakeholders around the World.

Additional information

The following are the LayerViewState.status options:

  • Active: The layer in the view is active.
  • NotVisible: The layer in the view is not visible.
  • OutOfScale: The layer in the view is out of scale. A status of OutOfScale indicates that the view is zoomed outside of the scale range of the layer. If the view is zoomed too far in (e.g., to a street level), it is beyond the max scale defined for the layer. If the view has zoomed too far out (e.g., to global scale), it is beyond the min scale defined for the layer.
  • Loading: The layer in the view is loading. Once loading has completed, the layer will be available for display in the view. If there was a problem loading the layer, the status will be set to Error.
  • Error: The layer in the view has an unrecoverable error. When the status is Error, the layer cannot be rendered in the view. For example, it may have failed to load, be an unsupported layer type, or contain invalid data.
  • Warning: The layer in the view has a non-breaking problem with its display, such as incomplete information (e.g., by requesting more features than the max feature count of a service) or a network request failure.

Tags

layer, load, map, status, view, visibility

Sample Code

MainActivity.kt MainActivity.kt MonitorChangesToLayerViewStateViewModel.kt MonitorChangesToLayerViewStateScreen.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.monitorchangestolayerviewstate
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
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.monitorchangestolayerviewstate.screens.MonitorChangesToLayerViewStateScreen
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 {
MonitorChangesToLayerViewStateApp()
}
}
}
@Composable
private fun MonitorChangesToLayerViewStateApp() {
Surface(color = MaterialTheme.colorScheme.background) {
MonitorChangesToLayerViewStateScreen(
sampleName = getString(R.string.monitor_changes_to_layer_view_state_app_name)
)
}
}
}