Display layer view state

View inJavaKotlin
View on GitHub
Sample viewer app

Determine if a layer is currently being viewed.

Image of display 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 in the map. For example, you could show a loading spinner next to its name when the view status is LOADING, grey out the name when NOTVISIBLE or OUTOF_SCALE, 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

Tap the Load layer button to create a new layer and add it to the map. As you pan and zoom around the map, note how the LayerViewStatus flags change; for example, OUT_OF_SCALE becomes true when the map is scaled outside of the layer's min and max scale range. Tap the Hide layer button to hide the layer and observe the view state change to NOT_VISIBLE.

If your device supports airplane mode, you can toggle this on and pan around the map to see layers display the WARNING status when they cannot online fetch data. Toggle airplane mode back off to see the warning disappear.

How it works

  1. Create an ArcGISMap with some operational layers.
  2. Set the map on a MapView.
  3. Listen to LayerViewStateChangedEvents from the map view.
  4. Get the current view status with event.getLayerViewStatus().

Relevant API

  • ArcGISMap
  • LayerViewStateChangedEvent
  • LayerViewStateChangedListener
  • 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 members of the LayerViewStatus enum:

  • ACTIVE: The layer in the view is active.
  • NOT_VISIBLE: The layer in the view is not visible.
  • OUT_OF_SCALE: The layer in the view is out of scale. A status of OUT_OF_SCALE 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 (eg. by requesting more features than the max feature count of a service) or a network request failure.


layer, load, map, status, view, visibility

Sample Code

/* Copyright 2016 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,
 * See the License for the specific language governing permissions and
 * limitations under the License.

package com.esri.arcgisruntime.sample.displaylayerviewstate;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.ArcGISRuntimeException;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.layers.FeatureLayer;
import com.esri.arcgisruntime.layers.Layer;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.BasemapStyle;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.LayerViewStatus;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

public class MainActivity extends AppCompatActivity {

  private FeatureLayer mFeatureLayer;
  private MapView mMapView;
  private Button loadButton;
  private View statesContainer;
  private Button hideButton;
  private TextView activeStateTextView;

  protected void onCreate(Bundle savedInstanceState) {

    // authentication with an API key or named user is required to access basemaps and other
    // location services

    // inflate MapView from layout
    mMapView = findViewById(R.id.mapView);
    // create a map with the BasemapType topographic
    final ArcGISMap mMap = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
    // add the map to the map view

    // zoom to custom ViewPoint
    mMapView.setViewpoint(new Viewpoint(new Point(-11000000, 4500000, SpatialReferences.getWebMercator()), 40000000));

    // Listen to changes in the status of the Layer
    mMapView.addLayerViewStateChangedListener(layerViewStateChangedEvent -> {
      // get the layer which changed it's state
      Layer layer = layerViewStateChangedEvent.getLayer();
      // we only want to check the view state of the image layer
      if (!layer.equals(mFeatureLayer)) {
      // get the View Status of the layer
      // View status will be either of ACTIVE, ERROR, LOADING, NOT_VISIBLE, OUT_OF_SCALE, WARNING
      EnumSet<LayerViewStatus> layerViewStatus = layerViewStateChangedEvent.getLayerViewStatus();
      // if there is an error or warning, display it in a toast
      ArcGISRuntimeException error = layerViewStateChangedEvent.getError();
      if (error != null) {
        Throwable cause = error.getCause();
        String message = cause != null ? cause.toString() : error.toString();
        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();

    loadButton = findViewById(R.id.loadButton);
    statesContainer = findViewById(R.id.statesContainer);
    hideButton = findViewById(R.id.hideButton);
    activeStateTextView = findViewById(R.id.activeStateTextView);

    loadButton.setOnClickListener(v -> {
      if (mFeatureLayer != null)
      // load a feature layer from a portal item
      PortalItem portalItem = new PortalItem(new Portal("https://runtime.maps.arcgis.com/"),

      mFeatureLayer = new FeatureLayer(portalItem, 0);
      // set the scales at which this layer can be viewed
      mFeatureLayer.setMaxScale(400_000_000.0 / 10);
      // add the layer on the map to load it
      // hide the button
      // show the view state UI and the hide layer button

    hideButton.setOnClickListener(v -> {
      if (mFeatureLayer == null)

      if (mFeatureLayer.isVisible()) {
      } else {

   * Formats and displays the layer view status flags in a textview.
   * @param layerViewStatus to display
  protected void displayViewStateText(EnumSet<LayerViewStatus> layerViewStatus) {
    // for each view state property that's active,
    // add it to a list and display the states as a comma-separated string
    List<String> stringList = new ArrayList<>();
    if (layerViewStatus.contains(LayerViewStatus.ACTIVE)) {
    if (layerViewStatus.contains(LayerViewStatus.ERROR)) {
    if (layerViewStatus.contains(LayerViewStatus.LOADING)) {
    if (layerViewStatus.contains(LayerViewStatus.NOT_VISIBLE)) {
    if (layerViewStatus.contains(LayerViewStatus.OUT_OF_SCALE)) {
    if (layerViewStatus.contains(LayerViewStatus.WARNING)) {
    // join the list of strings with a common and set to display in the text view
    activeStateTextView.setText(TextUtils.join(", ", stringList));

  protected void onPause() {

  protected void onResume() {

  protected void onDestroy() {