Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Display layer view state

This code sample is available for these platforms:
View Sample on GitHub

View the status of the layers on the map.


How to use the sample

Pan and zoom on the map to view changes in status.

How it works

  1. The layer view state is obtained from the enum value of LayerViewStatus.
  2. Listen for the LayerViewStateChanged event.

Relevant API

  • Map
  • MapView


MapViews, layer, status, view state

Sample Code

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
      <RowDefinition Height="*" />
      <RowDefinition Height="150" />
    <esriUI:MapView x:Name="MyMapView" Grid.Row="0"/>
    <ListView x:Name="layerStatusListView" Grid.Row="1">
          <TextCell Text="{Binding Message}"/>
// 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:
// 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.

using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.DisplayLayerViewState
        "Display layer view state",
        "This sample demonstrates how to get view status for layers in a map.",
    public partial class DisplayLayerViewState : ContentPage
        // Reference to list of view status for each layer
        private List<LayerStatusModel> _layerStatusModels = new List<LayerStatusModel>();

        public DisplayLayerViewState()

            // Create the UI, setup the control references and execute initialization 

        private void Initialize()
            // Create new Map
            Map myMap = new Map();

            // Create the uri for the tiled layer
            Uri tiledLayerUri = new Uri(

            // Create a tiled layer using url
            ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tiledLayerUri)
                Name = "Tiled Layer"

            // Add the tiled layer to map

            // Create the uri for the ArcGISMapImage layer
            Uri imageLayerUri = new Uri(

            // Create ArcGISMapImage layer using a url
            ArcGISMapImageLayer imageLayer = new ArcGISMapImageLayer(imageLayerUri)
                Name = "Image Layer",

                // Set the visible scale range for the image layer
                MinScale = 40000000,
                MaxScale = 2000000

            // Add the image layer to map

            // Create Uri for feature layer
            Uri featureLayerUri = new Uri(

            // Create a feature layer using url
            FeatureLayer myFeatureLayer = new FeatureLayer(featureLayerUri)
                Name = "Feature Layer"

            // Add the feature layer to map

            // Create a mappoint the map should zoom to
            MapPoint mapPoint = new MapPoint(-11000000, 4500000, SpatialReferences.WebMercator);

            // Set the initial viewpoint for map
            myMap.InitialViewpoint = new Viewpoint(mapPoint, 50000000);

            // Initialize the model list with unknown status for each layer
            foreach (Layer layer in myMap.OperationalLayers)
                _layerStatusModels.Add(new LayerStatusModel(layer.Name, "Unknown"));

            // Set models list as a itemssource
            layerStatusListView.ItemsSource = _layerStatusModels;

            // Event for layer view state changed
            MyMapView.LayerViewStateChanged += OnLayerViewStateChanged;

            // Provide used Map to the MapView
            MyMapView.Map = myMap;

        private void OnLayerViewStateChanged(object sender, LayerViewStateChangedEventArgs e)
            // State changed event is sent by a layer. In the list, find the layer which sends this event. 
            // If it exists then update the status
            LayerStatusModel model = _layerStatusModels.FirstOrDefault(l => l.LayerName == e.Layer.Name);
            if (model != null)
                model.LayerViewStatus = e.LayerViewState.Status.ToString();

        /// <summary>
        /// This is a custom class that holds information for layer name and status
        /// </summary>
        public class LayerStatusModel : INotifyPropertyChanged
            private string layerViewStatus;

            public string LayerName { get; private set; }

            public string LayerViewStatus
                get { return layerViewStatus; }
                set { layerViewStatus = value; NotifyPropertyChanged(); NotifyPropertyChanged("Message"); }

            public string Message {  get { return LayerName + " - " + LayerViewStatus; } }

            public LayerStatusModel(string layerName, string layerStatus)
                LayerName = layerName;
                LayerViewStatus = layerStatus;

            public event PropertyChangedEventHandler PropertyChanged;

            private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));