I have ArcMap with tons of layers. Some of these layers may contain another layers with data (aka Composite layers) or they don't. The depth of composite layers in unknown. I need to query all layer names and put it to comboBox (done). Next step is finding selected in comboBox layer (by name? by index?) and get all its fields to another comboBox.
My problem is I can't get access to layer by name or index because they may be represented as composite layers and my method for finding layers by name or index will not work. How should I get direct access to layer or maybe create custom array with indexes and names?
Here is my code:
private List GetAllLayers(IMap mp, ICompositeLayer cl)
{
listIndexesAndNames.Add(new comboBoxLayerListItemsClass(){ItemName = "", ItemIndex = 0} );
if (mp == null && cl == null)
{
return null;
}
//ILayer l;
List listOfLayers = new List();
if (mp != null && cl == null)
{
for (int i = 0; i < mp.LayerCount; i++)
{
if (mp.Layer[i] is ICompositeLayer)
{
cl = mp.Layer[i] as ICompositeLayer;
GetAllLayers(null, cl);
++index;
listIndexesAndNames.Add(new comboBoxLayerListItemsClass() { ItemName = mp.Layer[i].Name, ItemIndex = index });
}
else
{
listOfLayers.Add(mp.Layer[i]);
comboBoxLayerList_Houses.Items.Add(new comboBoxLayerListItemsClass() { ItemName = mp.Layer[i].Name});
}
}
}
else if (mp == null && cl != null)
{
for (int i = 0; i < cl.Count; i++)
{
if (cl.Layer[i] is ICompositeLayer)
{
ICompositeLayer cl2 = (ICompositeLayer)cl.Layer[i];
GetAllLayers(null, cl2);
}
else
{
listOfLayers.Add(cl.Layer[i]);
comboBoxLayerList_Houses.Items.Add(new comboBoxLayerListItemsClass() { ItemName = cl.Layer[i].Name });
}
}
}
return listOfLayers;
}
No comments:
Post a Comment