ESRI.ArcGIS.Mobile
MapLayerCollection Class
Members  Example  See Also  Send Feedback
ESRI.ArcGIS.Mobile Namespace : MapLayerCollection Class

Represents a collection of MapLayers accessible from Map.

Object Model

Syntax

Visual Basic (Declaration) 
<DefaultMemberAttribute("Item")>
Public NotInheritable Class MapLayerCollection 
   Inherits Collection(Of MapLayer)
C# 
[DefaultMemberAttribute("Item")]
public sealed class MapLayerCollection : Collection<MapLayer> 

Example

Assuming you have a Map control called map1, and is using a valid MobileCache, the following example shows you how to get a MapLayer by index or layer name.
C#Copy Code
MapLayerCollection mlc = map1.MapLayers as MapLayerCollection; 
// Method 1: get a MapLayer by index 
MapLayer ml1 = mlc[0] as MapLayer; 
MessageBox.Show(ml1.Name); 
  
// Method 2: get a MapLayer by layer name 
MapLayer ml2 = mlc["EditTest"] as MapLayer; 
MessageBox.Show(ml2.Name);
Assuming you have a Map control called map1 that displays multiple layers, and a MobileService called myMobileService, the following example demonstrate how to change the location of the map layers in the collection.
C#Copy Code
MapLayerCollection mlc = map1.MapLayers as MapLayerCollection; 
// Switch the position of the first and second layer 
string info = "Layer Positions After Switch"; 
foreach (MapLayer ml_1 in mlc) 

info = info + "\n" + mlc.IndexOf(ml_1).ToString() + ": " + ml_1.Name; 

MessageBox.Show(info); 
  
// Remove a layer called "streams" from the collection 
MapLayer ml_streams = mlc["streams"] as MapLayer; 
mlc.Remove(ml_streams); 
  
MapLayer ml_2 = mlc[0] as MapLayer; 
mlc.Remove(ml_2); 
mlc.Insert(1, ml_2); 
  
info = "Layer Positions After Switch"; 
foreach (MapLayer ml_3 in mlc) 

info = info + "\n" + mlc.IndexOf(ml_3).ToString() + ": " + ml_3.Name; 

MessageBox.Show(info); 
  
// Remove two map layers by name, and insert them back at the very beginning of the map layer collection. 
mlc.Remove(mlc["Parcels"]); 
mlc.Remove(mlc["Zoning"]); 
Layer parcelsLayer = myMobileService.Layers["Parcels"] as Layer; 
Layer zoningLayer = myMobileService.Layers["Zoning"] as Layer; 
Layer[] layerCollection = {parcelsLayer, zoningLayer}; 
mlc.InsertRange(0, layerCollection);

Remarks

To add Layer/MapLayer to MapLayerCollection, use (Add, AddRange, Insert, or InsertRange. To remove Layer/MapLayer from MapLayerCollection, use Remove, RemoveRange.)

Use IndexOf to get the index for a specific MapLayer in the collection, or use Contains to check whether a specific MapLayer exists in a MapLayerCollection.

Inheritance Hierarchy

System.Object
   System.Collections.ObjectModel.Collection<MapLayer>
      ESRI.ArcGIS.Mobile.MapLayerCollection

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.