public IEnumerable<int> GenerateVisibilityIDs()
{
// First create an enumeration for the current layer
IList<int> ownIDs = new List<int>();
if (Visible)
{
if (_isRoot)
{
ownIDs.Add(0); // ID for the root layer itself
if (_hasRootContainer)
ownIDs.Add(1); // for root container which is not shown in SL
}
else
ownIDs.Add(_folderId); // ID of the layer
}
// Then go recursively through the sublayers and concat with the visible IDs of the sublayers (but don't go through the hierarchy for networklinks (i.e. _isRoot))
return ownIDs.Concat(ChildLayers.OfType<KmlLayer>().SelectMany(InternalGenerateVisibilityIDs)).ToArray(); // ToArray freezes the result
}