I'm curious about a potential functionality exactly like IMap.Layers, but instead of IMap, I want ICompositeLayer (or any reference to a group layer really).
I'm looking for the most elegant solution to getting a count of all IFeatureLayer layers, but only within a relatively complex group layer, not the entire map.
In my head, I would call ICompositeLayer.Layers(<insert IFeatureLayer UID here>, True), if it existed. But it doesn't, and I'm not sure if anything like it does.
Currently, the code I'm working with calls a function "GetNumLayers" which has a series of nested loops checking if a particular ILayer, is of type IFeatureLayer or not and adding +1 to the counter, and then returning the total. I'm convinced something faster exists as an alternative.
I think it would be a good learning experience, and to be honest, I'm really not worried about the time it takes, rather the "best" way to achieve this.
You can write a function that counts the feature layers in a given group layer by looping through the layers in that group layer. For each layer, check the type. If it's a feature layer, then add to the count. If it's a group layer then call the function recursively and add it's return value to the layer count. The function returns the count.
Unfortunately ICompositeLayer.Count would return a count similar to pMap.LayerCount wouldn't it?
The main group layer itself has multiple levels: sub-group layers and feature layers all kind of mixed in.
I'm looking for specifically: a count of feature layers (regardless of how deep they are). I don't want to include sub-group layers (that may contain feature layers), in that count. Only layers that are TypeOf IFeatureLayer.
Definitely an odd problem I'll admit that haha. Anyways, hopefully that clarifies things a little bit.
You can write a function that counts the feature layers in a given group layer by looping through the layers in that group layer. For each layer, check the type. If it's a feature layer, then add to the count. If it's a group layer then call the function recursively and add it's return value to the layer count. The function returns the count.
Hmmm, was hoping there would be a hidden property I wasn't aware of, oh well.
Currently, that's how the count is retrieved, though I didn't think about recursion, that's likely the faster method than a series of loops (also looks nicer).