private static IEnumerable<int> InternalGenerateVisibilityIDs(KmlLayer layer)
{
// For NetworkLinks (i.e. _isRoot), don't go through the hierarchy and return an empty enumeration (Network links visibility is not managed by arcgis.com)
if (layer._isRoot)
return Enumerable.Empty<int>();
// Create an enumeration either empty (if the layer is not visible) or containing the current ID (if the layer is visible)
IEnumerable<int> ownIDs = layer.Visible ? new[] { layer._folderId } : Enumerable.Empty<int>();
// Go recursively through the sublayers and concat with the visible IDs of the sublayers
return ownIDs.Concat(layer.ChildLayers.OfType<KmlLayer>().SelectMany(InternalGenerateVisibilityIDs));
}