Select to view content in your preferred language

Set SelectedLayer other than by Index or ID?

2798
2
07-29-2013 09:39 AM
SteveClark
New Contributor III
MapApplication.Current.SelectedLayer = MapApplication.Current.Map.Layers[] has the ability to select by ID (which can change if layer is re-added) or by Index (which the order can change as well). How could set the SelectedLayer by URL or by something that is unique and constant?
0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: PietaS175

Something like this:

string layerName = "My layer name";
if (MapApplication.Current != null && MapApplication.Current.Map != null && MapApplication.Current.Map.Layers != null)
{
     LayerCollection layers = MapApplication.Current.Map.Layers;
     while (layers.Any(l => MapApplication.GetLayerName(l) == layerName))
     {
           Do what you want here ....................
     }
}
0 Kudos
SteveClark
New Contributor III
Thank you, I will give that a try.
0 Kudos