Click or drag to resize
LayerCollection Class
A collection of Map Layers.
Inheritance Hierarchy
SystemObject
  System.Collections.ObjectModelCollectionLayer
    System.Collections.ObjectModelObservableCollectionLayer
      Esri.ArcGISRuntime.LayersLayerCollection

Namespace: Esri.ArcGISRuntime.Layers
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 10.2.7.0 (10.2.7.1234)
Syntax
public class LayerCollection : ObservableCollection<Layer>

The LayerCollection type exposes the following members.

Constructors
  NameDescription
Public methodLayerCollection
Initializes a new instance of the LayerCollection class
Top
Methods
  NameDescription
Public methodAdd (Inherited from CollectionLayer.)
Protected methodBlockReentrancy
Disallows reentrant attempts to change this collection.
(Inherited from ObservableCollectionLayer.)
Protected methodCheckReentrancy
Checks for reentrant attempts to change this collection.
(Inherited from ObservableCollectionLayer.)
Public methodClear (Inherited from CollectionLayer.)
Protected methodClearItems
Clears the items.
(Overrides ObservableCollectionTClearItems.)
Public methodContains (Inherited from CollectionLayer.)
Public methodContainsLayer
Public methodCopyTo (Inherited from CollectionLayer.)
Public methodEnumerateAllLayers
Iterates all layers in the collection, including GroupLayer and children of GroupLayer, recursively.
Public methodEnumerateLeaves
Iterates all layers in the collection, skipping through GroupLayer and returning its children instead
Public methodStatic memberEnumerateLeaves(IEnumerableLayer)
Iterates all layers in the collection, skipping through GroupLayer and returning its children instead
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator (Inherited from CollectionLayer.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf (Inherited from CollectionLayer.)
Public methodInsert (Inherited from CollectionLayer.)
Protected methodInsertItem
Inserts the layer.
(Overrides ObservableCollectionTInsertItem(Int32, T).)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMove
Moves the item at the specified index to a new location in the collection.
(Inherited from ObservableCollectionLayer.)
Protected methodMoveItem
Moves the item at the specified index to a new location in the collection.
(Inherited from ObservableCollectionLayer.)
Protected methodOnCollectionChanged
Raises the [E:CollectionChanged] event.
(Overrides ObservableCollectionTOnCollectionChanged(NotifyCollectionChangedEventArgs).)
Protected methodOnPropertyChanged
Raises the PropertyChanged event with the provided arguments.
(Inherited from ObservableCollectionLayer.)
Public methodRemove(String)
Removes the Layer with the specified ID, recursively searching contained GroupLayers if necessary.
Public methodRemove(T) (Inherited from CollectionLayer.)
Public methodRemoveAt (Inherited from CollectionLayer.)
Protected methodRemoveItem
Removes the item at the specified index of the collection.
(Inherited from ObservableCollectionLayer.)
Public methodRemoveRecursive
Removes the specified Layer, recursively searching contained GroupLayers if necessary.
Protected methodSetItem
Sets the layer into the collection.
(Overrides ObservableCollectionTSetItem(Int32, T).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyCount (Inherited from CollectionLayer.)
Public propertyItemInt32
Gets or sets the element at the specified index.
(Inherited from CollectionLayer.)
Public propertyItemString
Gets the Layer with the specified ID.
Protected propertyItems (Inherited from CollectionLayer.)
Top
Events
  NameDescription
Public eventCollectionChanged
Occurs when an item is added, removed, changed, moved, or the entire list is refreshed.
(Inherited from ObservableCollectionLayer.)
Protected eventPropertyChanged
Occurs when a property value changes.
(Inherited from ObservableCollectionLayer.)
Top
Examples

Demonstrates the work-flow of creating a layer dynamically via code-behind. The process of a layer: (1) initializing, (2) determining when initialization is complete, and (3) error trapping for bad initialization is described in detail.

Workflow of creating a layer in code-behind and adding it to the Map.LayerColletion.

XAML
<Window x:Class="LayerCollection.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="800"
        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>

        <StackPanel>

            <!-- ListBox to hold the ServiceUri strings that the user can choose. -->
            <ListBox x:Name="ListBox1" Height="75"/>

            <!-- Button to create an ArcGISDynaicMapServiceLayer at runtime based upon the ServiceUri chosen. -->
            <Button x:Name="Button1" Content="Add the Layer to the Map" Click="Button1_Click" />

            <!-- MapView with empty Map. -->
            <esri:MapView x:Name="MapView1" Height="500">
                <esri:Map x:Name="Map1">
                </esri:Map>
            </esri:MapView>

        </StackPanel>

    </Grid>
</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "LayerCollection.MainWindow" to be just "MainWindow".

// This application shows a simplified work flow of creating a layer dynamically. MessageBox'es display:
// (1) the progress of the layer is initializing
// (2) when the layer has completely initialized
// (3) if there was a problem initializing displaying an error message

namespace LayerCollection
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Add various ServiceUri strings into the ListBox. Some are good and others do not exist.
            ListBox1.Items.Add("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"); // This is a good web service
            ListBox1.Items.Add("http://sampleserver1.arcgisonline.com/arcgis/rest/services/Specialty/BOGUS_SERVICE/MapServer"); // This web service does not exist
        }

        private async void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // Create a variable to hold the name of the ServiceUri string.
            string theArcGISDynamicMapServiceLayerName = null;

            try
            {
                // Set the ServiceUri string to the user selected ListBox item.
                theArcGISDynamicMapServiceLayerName = ListBox1.SelectedItem.ToString();
            }
            catch (System.Exception)
            {
                // Notify the user that they must select a ListBox item.
                System.Windows.MessageBox.Show("You must select a ServiceUri string in the listbox before clicking the button.");
                return;
            }

            // Create a new ArcGISDynamicMapServiceLayer.
            Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = new Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer();

            // Set the ServiceUri property.
            myArcGISDynamicMapServiceLayer.ServiceUri = theArcGISDynamicMapServiceLayerName;

            // Call the InitializeAsync method which will load the metadata for the layer. 
            System.Threading.Tasks.Task myTask = myArcGISDynamicMapServiceLayer.InitializeAsync();

            if (!myTask.IsCompleted)
            {
                // The Task (i.e. the layer loading) has not completed yet, let the user know that.
                System.Windows.MessageBox.Show("Initializing");

                try
                {
                    // Now wait for the Task to complete. This will lock the GUI until the Task completes. Notify the user of the result.  
                    await myTask;
                    System.Windows.MessageBox.Show("Initialized Successfully");

                    // Now add the ArcGISDynamicMapServiceLayer to the Map's LayerCollection
                    Esri.ArcGISRuntime.Layers.LayerCollection theLayerCollection = MapView1.Map.Layers;
                    theLayerCollection.Add(myArcGISDynamicMapServiceLayer);
                }
                catch (System.Exception ex)
                {
                    // The Task has completed but we have an error. Display to the user that there is something wrong with the layer.
                    Esri.ArcGISRuntime.Http.ArcGISWebException myArcGISWebException = (Esri.ArcGISRuntime.Http.ArcGISWebException)ex;
                    System.Windows.MessageBox.Show(ex.ToString(), "Initialized Failed");
                }
            }
        }

    }
}
See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store
Additional Examples
Hyperlink to ExampleDescription
AllLayersServiceInfo_FeatureServiceLayerInfoDemonstrates getting detailed ArcGIS Server MapServer metadata for various ArcGISDynamicMapServiceLayer and ArcGISTiledMapServiceLayer web services.
ArcGISDynamicMapServiceLayer_GetDetailsShows adding an ArcGISDynamicMapServiceLayer with a LayerDefinition applied (discovered by the ArcGISDynamicMapServiceLayer.GetDetailsAsync Method) and then modifying the LayerDefinition to change the features returned.
ArcGISDynamicMapServiceLayer_VisibleLayersShows obtaining which sub-layers are visible using the ArcGISDynamicMapServiceLayer.GetAllDetailsAsync Method. Then the user can interact with application and change the VisibleLayers of the ArcGISDynamicMapServiceLayer.
ArcGISDynamicMapServiceLayerImageFormatShows changing the return ImageFormat for ArcGISDynamicMapServiceLayer and how that appears visually in the Map.
ArcGISDynamicMapServiceLayerXamlAndCodeBehindShows creating an ArcGISDynamicMapServiceLayer in XAML and via code-behind. The ArcGISDynamicMapServiceLayer.InitializeAsync Method is used to obtain metadata about the layer (i.e. ID and Copyright) using the Async/Task framework.
ArcGISImageServiceLayerWindowShows creating an ArcGIS Image Service Layer and applying rendering rules.
ArcGISImageServiceLayerXamlAndCodeBehindShows adding an ArcGISImageServiceLayer via XAML and code-behind. The ArcGISImageServiceLayer.InitializeAsync Method is used to obtain metadata about the layer (i.e. ID and Description) using the Async/Task framework.
BaseMapsDemonstrates switching out various BaseMap (via ArcGISTiledMapServiceLayer) layers served up by ArcGIS Online.
BingLayer_AdvancedTeaches one method (advanced) for using the Microsoft WebClient and a DataContract to poll a Microsoft Bing development server to determine if a Bing Key is correct and then loading multiple BingLayer's into the Map and allowing the user to switch between various BingLayer.MapStyles.
Camera_PropertiesShows adjusting the Camera Properties of a SceneView to view different perspectives of data on the Earth.
Camera_SetMethodsDemonstrates navigating/animating between MapPoint Graphics with a Camera. Simultaneous changes of X, Y, Z, Pitch, and Heading during the animation is shown.
CreateDynamicLayerInfosFromLayerInfosDemonstrates applying a custom rendering via XAML using the Dynamic Layer option of an ArcGISDynamicMapServiceLayer. Also, shows how to use the ArcGISDynamicMapServiceLayer.CreateDynamicLayerInfosFromLayerInfos Method to obtain the original rendering of the layer that was defined in the map service. The CreateDynamicLayerInfosFromLayerInfos is then used to reset the layer back to orignal rendering.
DynamicLayerInfoCollectionDemonstrates using various Renderers on a Dynamic Layer when the 'WorkspaceID' and 'DataSourceName' are known using a TableDataSource.
DynamicLayerInfosDemonstrates using various Renderers on a Dynamic Layer (via XAML and code-behind) when the 'WorkspaceID' and 'DataSourceName' are known using a TableDataSource.
Editor_SketchingDemonstrates sketching various geometric shapes on the map via the Editor.RequestShapeAsync method. The sketches are then added as Graphics in a GraphicsLayer and drawn on the map.
EditorConfigurationDemonstrates sketching Polyline shapes on the map via the Editor.RequestShapeAsync method. The sketches are then added as Graphics in a GraphicsLayer and drawn on the map. Multiple versions of customizing the symbology of the Editor are shown.
EqualGeometriesDemonstrates the differences in comparing a few polygon geometries to via the Geometry.IsEqual and GeometryEngine.Equals Methods.
FeatureLayer_IdentifyDemonstrates performing and Identify on a FeatureLayer. The FeatureLayer.HitTestAsync method is used to select (and highlight) the feature a user clicks/taps on as well as display specific attributes for that feature.
FeatureLayer_LabelingDemonstrates labeling highway names in a FeatureLayer.
FeatureLayer_SelectFeaturesByRectangleDemonstrates selecting features in a FeatureLayer by dragging a rectangle across the map. Features are then highlighted in the FeatureLayer and their selected ID values are displayed in a Listbox.
FeatureLayer_SetFeatureVisibleDemonstrates being able to turn off the visibility of a feature in a FeatureLayer by tapping on it.
FeatureLayerViaGeodatabaseDemonstrates creating a FeatureLayer from a GeodatabaseFeatureTable in an ArcGIS Runtime provisioned Geodatabase that is stored locally on disk.
FeatureLayerViaGeodatabaseWebDownloadDemonstrates downloading a Geodatabase on ArcGIS Server to the local disk and then creating a FeatureLayer from a GeodatabaseFeatureTable in the downloaded Geodatabase.
FeatureLayerViaShapefileDemonstrates creating a FeatureLayer from a ShapefileTable that is stored locally on disk.
FeatureLayerXamlAndCodeBehindShows creating a FeatureLayer in XAML and via code-behind. The FeatureLayer.InitializeAsync Method is used to obtain metadata about the layer (i.e. ID and Copyright) using the Async/Task framework.
FeatureServiceLayerInfo_CopyrightTextDemonstrates using the GetDetailsAsync Method to obtain the FeatureServiceLayerInfo.CopyrightText on an ArcGISDynamicMapServiceLayer.
FindTaskDemonstrates using the Query.FindTask operation to search for text in attribute fields of an ArcGIS Server map service and display the features found as graphics in a GraphicsLayer.
GeocodeFullAddressInputDemonstrates performing a geocode by submitting values for multiple address fields.
GeocodeSingleLineInputPerforms a single line geocode using either an online ArcGIS Locator service or a local Locator.
GeoRSSLayerWindowCreates a GeoRssLayer based on the United States Geological Survey earthquake feed and assigned a SimpleRenderer.
GetAreaAllows the user to draw a polygon on the map and calculate the area via several methods.
GraphicsLayer_LabelingDemonstrates labeling city names where two AttributeLabelClass'es are used (one for smaller cities and one for larger ones).
GraphicsLayer_RenderingModeDemonstrates setting the various GraphicsLayer.RenderingMode options and their effect on TextSymbols when the MapView is rotated.
GraphicsLayerWindowDemonstrates various Graphics and GraphicsLayer related actions.
IdentifyParameter_DynamicLayerInfosDemonstrates performing an Identify on a Dynamic Layer using the ESRI.ArcGISRuntime.Tasks.Query.IdentifyParameter.DynamicLayerInfos Property.
IdentifyTaskDemonstrates using the Query.IdentifyTask operation find a feature based upon it's geographic position in an ArcGIS Server map service and display it as a graphic in a GraphicsLayer.
LayerCollectionDemonstrates the work-flow of creating a layer dynamically via code-behind. The process of a layer: (1) initializing, (2) determining when initialization is complete, and (3) error trapping for bad initialization is described in detail.
LayerDefinitionsDemonstrates setting numerous LayerDefinitions values on an ArcGISDynamicMapServiceLayer and visualizing the impact of the features being returned in the Map.
LayerDefinitionsSimpleDemonstrates setting the LayerDefinitions Property of an ArcGISDynamicMapServiceLayer where two sub-layers are present. One sub-layer has the LayerDefinition set in XAML and the other sub-layer has it's LayerDefinition set via code-behind.
LayerDrawingOptionCollectionDemonstrates using the existing rendering of a Dynamic Layer sub-layer of an ArcGISDynamicMapServiceLayer and switching to a custom rendering defined in code-behind for the Dynamic Layer.
LayerDrawingOptionsDemonstrates changing the rendering of the first sub-layer of an ArcGISDynamicMapServiceLayer using the Dynamic Layer capabilities of ArcGIS Server 10.1 and higher.
LayersInitializedDemonstrates implementing logic which is dependent on the layer collection being initialized.
MapServiceInfo_DocumentInfo_LayerServiceInfoDemonstrates getting detailed ArcGIS Server MapServer metadata to obtain MapServiceInfo data for various ArcGISDynamicMapServiceLayer and ArcGISTiledMapServiceLayer web services.
MapView_DragDropEventsDemonstrates creating a CsvLayer by performing a Drag-and-Drop from a file on the local disk in File Explorer to the MapView.
MapView_OverlaysDemonstrates displaying a UIElement on top of the MapView using the MapView.Overlays Property. This is useful for performing MapTip functionality.
MapView_SpatialReferenceDemonstrates reseting the MapView.SpatialReference by setting it to a new Map.
MultipleMapsInMapViewDemonstrates switching out different Map objects (with different layers) for the MapView.Map Property.
PictureFillSymbolDemonstrates the using a SimpleRenderer with options for PictureFillSymbol.
PictureMarkerSymbolDemonstrates the using a SimpleRenderer with options for SimpleMarkerSymbol, PictureMarkerSymbol, and TextMarkerSymbol.
PolygonBuilder_MakeIslandsShows how to use the PolygonBuilder to turn multiple independent Polygons into a single Polygon (use case: grouping island Polygons together into one record).
QueryTableDataSourceDemonstrates adding a Dynamic Layer via code-behind using a QueryTableDataSource.
RoutingPointToPointDemonstrates simple point to point routing between two input locations.
RoutingWithBarriersShows routing and re-routing around user defined point, polyline, and polygon barriers.
RoutingWithDirectionsInteraction logic for RoutingWithDirections.xaml
SmoothGraphicAnimationAnimates a graphic smoothly between two user defined locations by calling the MapPoint.MoveTo method at regular intervals as defined by a DispatcherTimer. The distance the point is moved each time is calculated by a quintic easing function.