Click or drag to resize

LayerViewStateChangedEventArgs Class

Event arguments for the GeoView.LayerViewStateChanged event
Inheritance Hierarchy
SystemObject
  SystemEventArgs
    Esri.ArcGISRuntime.MappingLayerViewStateChangedEventArgs

Namespace:  Esri.ArcGISRuntime.Mapping
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public sealed class LayerViewStateChangedEventArgs : EventArgs

The LayerViewStateChangedEventArgs type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleLayer
Gets the layer for which the view state has changed
Public propertyCode exampleLayerViewState
Gets the updated view state
Top
Examples

Android

Example Name: DisplayLayerViewState

View the status of the layers on the map.

Code example screen shot.

C#
// 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, 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 Esri.ArcGISRuntime.UI.Controls;
using System;
using Android.App;
using Android.OS;
using Android.Widget;

namespace ArcGISRuntime.Samples.DisplayLayerViewState
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Display layer view state",
        "MapView",
        "This sample demonstrates how to get view status for layers in a map.",
        "")]
    public class DisplayLayerViewState : Activity
    {
        // Hold a reference to the map view
        private MapView _myMapView;

        // Controls to show status of each layers' loading
        private TextView _TextViewTiledLayer;
        private TextView _TextViewImageLayer;
        private TextView _TextViewFeatureLayer;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Display Layer View State";

            // Create the UI, setup the control references and execute initialization 
            CreateLayout();
            Initialize();
        }

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

            // Create the uri for the tiled layer
            Uri tiledLayerUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer");

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

            // Add the tiled layer to map
            myMap.OperationalLayers.Add(tiledLayer);

            // Create the uri for the ArcGISMapImage layer
            Uri imageLayerUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer");

            // 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
            myMap.OperationalLayers.Add(imageLayer);

            // Create Uri for feature layer
            Uri featureLayerUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Recreation/FeatureServer/0");

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

            // Add the feature layer to map
            myMap.OperationalLayers.Add(myFeatureLayer);

            // Create a map point 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);

            // 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)
        {
            // For each execution of the MapView.LayerViewStateChanged Event, get the name of
            // the layer and its LayerViewState.Status
            string lName = e.Layer.Name;
            string lViewStatus = e.LayerViewState.Status.ToString();

            // Display the layer name and view status in the appropriate TextView control
            switch (lName)
            {
                case "Tiled Layer":
                    _TextViewTiledLayer.Text = lName + " - " + lViewStatus;
                    break;
                case "Image Layer":
                    _TextViewImageLayer.Text = lName + " - " + lViewStatus;
                    break;
                case "Feature Layer":
                    _TextViewFeatureLayer.Text = lName + " - " + lViewStatus;
                    break;
                default:
                    break;
            }
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app
            LinearLayout layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            // Create the controls to show the various layers' loading status
            _TextViewTiledLayer = new TextView(this);
            layout.AddView(_TextViewTiledLayer);
            _TextViewImageLayer = new TextView(this);
            layout.AddView(_TextViewImageLayer);
            _TextViewFeatureLayer = new TextView(this);
            layout.AddView(_TextViewFeatureLayer);

            // Add the map view to the layout
            _myMapView = new MapView(this);
            layout.AddView(_myMapView);

            // Show the layout in the app
            SetContentView(layout);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: DisplayLayerViewState

View the status of the layers on the map.

Code example screen shot.

C#
// 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, 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
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Display layer view state",
        "MapView",
        "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()
        {
            InitializeComponent();

            // Create the UI, setup the control references and execute initialization 
            Initialize();
        }

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

            // Create the uri for the tiled layer
            Uri tiledLayerUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer");

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

            // Add the tiled layer to map
            myMap.OperationalLayers.Add(tiledLayer);

            // Create the uri for the ArcGISMapImage layer
            Uri imageLayerUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer");

            // 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
            myMap.OperationalLayers.Add(imageLayer);

            // Create Uri for feature layer
            Uri featureLayerUri = new Uri(
                "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Recreation/FeatureServer/0");

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

            // Add the feature layer to map
            myMap.OperationalLayers.Add(myFeatureLayer);

            // 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));
                }
            }
        }
    }
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime" 
             x:Class="ArcGISRuntime.Samples.DisplayLayerViewState.DisplayLayerViewState">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="150" />
    </Grid.RowDefinitions>
    <esriUI:MapView x:Name="MyMapView" Grid.Row="0"/>
    <ListView x:Name="layerStatusListView" Grid.Row="1">
      <ListView.ItemTemplate>
        <DataTemplate>
          <TextCell Text="{Binding Message}"/>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
DisplayLayerViewStateView the status of the layers on the map.